GoodsUseToolTips = GoodsUseToolTips or BaseClass(BaseView) function GoodsUseToolTips:__init() self.base_file = "common" self.layout_file = "GoodsUseToolTips" self.layer_name = "Top" -- self.use_local_view = true self.use_background = true self.is_set_zdepth = true self.click_bg_toClose = true self.pos_x = 0 self.pos_y = 0 self.model = GoodsModel:getInstance() self.curr_height = 0 self.load_callback = function () self:LoadSuccess() self:InitData() end self.open_callback = function () self:SetData() end self.close_callback = function () end self.destroy_callback = function () end end function GoodsUseToolTips:LoadSuccess() self.bg = self:GetChild("layout/bg") self.layout = self:GetChild("layout") self.icon_img = self:GetChild("layout/icon_con/img"):GetComponent("Image") self.icon = self:GetChild("layout/icon_con"):GetComponent("Image") self.name_text = self:GetChild("layout/nameText"):GetComponent("Text") self.use_text = self:GetChild("layout/useText"):GetComponent("Text") self.content_text = self:GetChild("layout/contentText") self.getway = self:GetChild("layout/getway") self.getway_text = self:GetChild("layout/getway/getwayText"):GetComponent("Text") self.close_btn = self:GetChild("layout/close_btn").gameObject self:InitEvent() end function GoodsUseToolTips:InitEvent() function OnClickEvent(target) if target == self.close_btn then self:Close() end end AddClickEvent(self.close_btn,OnClickEvent) end -- goods_id:物品id、max_times:最大使用数、attr:属性加成表 use_times:物品当前使用次数 function GoodsUseToolTips:Open(goods_id,max_times,attr,use_times,x,y,module_id, combat) self.goods_id = goods_id self.max_times = max_times self.attr = attr self.use_times = use_times self.pos_x = x self.pos_y = y self.module_id = module_id self.combat = combat self.cfg = ConfigItemMgr.Instance:GetGoodItem(self.goods_id) BaseView.Open(self) end function GoodsUseToolTips:InitData() --在load完设置位置就不会出现闪屏的现象了 if not self.is_loaded then return end if self.pos_x and self.pos_y then local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y) if x+400 > ScreenWidth then x = ScreenWidth-400-20 elseif x<20 then x = 20 end if y < 20 then y = 20 elseif y+self.bg.sizeDelta.y > ScreenHeight then y = ScreenHeight-self.bg.sizeDelta.y -20 end self.layout.anchoredPosition = Vector3(x + 10,y +self.bg.sizeDelta.y,0) end end function GoodsUseToolTips:SetData() if self.cfg == nil then return end local id = self.goods_id local max_times = self.max_times local attr_list = self.attr if type(self.attr) ~= "table" then attr_list = ErlangParser:GetInstance():Parse(self.attr) end if self.cfg.color then lua_resM:setImageSprite(self, self.icon, "common_asset", "tyui_pz_"..self.cfg.color) end lua_resM:setOutsideImageSprite(self,self.icon_img,GameResPath.GetGoodsIcon(id)) self.name_text.text = ""..self.cfg.goods_name.."" self.use_text.text = "当前使用: "..self.use_times.."/"..max_times.."个" self.curr_height = 161 self.content_text.localPosition = co.TableXYZ(43,-self.curr_height,0) local str = "" if #attr_list >0 then local attr_name = "" local attr_value = "" for i = 1,#attr_list do local attr_id = attr_list[i].attr_id or tonumber(attr_list[i][1]) local attr_num = attr_list[i].attr_num or tonumber(attr_list[i][2]) attr_name = WordManager:GetProperties(attr_id,self.module_id) attr_value = WordManager:GetPropertyValue(attr_id,attr_num) --str = str .. WordManager:GetProperties(tonumber(attr_list[i][1])).."+"..attr_list[i][2].."\n" str = str .. attr_name.." + "..attr_value.."\n" end end if self.combat then str = str.."战力 + "..self.combat.."\n" end local good_type = WordManager:GetGoodsTypeStr(self.cfg.type, self.cfg.subtype) self.content_text:GetComponent("Text").text = "使用后"..good_type.."属性变化:\n"..""..str.."" self.curr_height = self.curr_height + self.content_text:GetComponent("Text").preferredHeight + 10 self.getway.localPosition = co.TableXYZ(18,-self.curr_height,0) self.getway_text.text = ""..Trim(self.cfg.getway).."" self.bg.sizeDelta = Vector2(394,self.curr_height + 80) -- local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y) -- self.layout.anchoredPosition = Vector3(x + 10,y +self.bg.sizeDelta.y,0) end