local HuTipView = { _view_start_pos = nil, _touch_start_pos = nil, } local M = HuTipView function M.new(main_view) local self = {} self.class = "HuTipView" setmetatable(self, { __index = HuTipView }) self._main_view = main_view self:init() return self end local function SetObjEnabled(obj, enabled) obj.visible = enabled obj.touchable = false end function M:OnTouchBegin(context) self._view_start_pos = Vector2(self._view.x, self._view.y) self._touch_start_pos = self._main_view._view:GlobalToLocal(Vector2(context.inputEvent.x, context.inputEvent.y)) end function M:OnTouchMove(context) local xy = self._main_view._view:GlobalToLocal(Vector2.New(context.inputEvent.x, context.inputEvent.y)) local dist = Vector2(xy.x - self._touch_start_pos.x, xy.y - self._touch_start_pos.y) local posx = self._view_start_pos.x + dist.x local posy = self._view_start_pos.y + dist.y local max_x = self._main_view._view.width - self._view.width local max_y = self._main_view._view.height - self._view.height self._view.x = posx < 0 and 0 or posx > max_x and max_x or posx self._view.y = posy < 0 and 0 or posy > max_y and max_y or posy end function M:init() self._view = UIPackage.CreateObjectFromURL("ui://Main_Majiang/Hu_tip") self._main_view._view:AddChild(self._view) -- 初始位置 self._view:Center() self._view.y = GRoot.inst.height * 0.8085 SetObjEnabled(self._view, false) -- self._view.onTouchBegin:Add(handler(self, self.OnTouchBegin)) -- self._view.onTouchMove:Add(handler(self, self.OnTouchMove)) end -- function M:FillData(cards) -- local lst_card = self._view:GetChild("lst_card") -- lst_card:RemoveChildrenToPool() -- local num = #cards -- if num > 0 then -- if num > 3 and num <= 28 then -- self._view.width = 191 + ((num > 7 and 7 or num) - 3) * 38 -- self._view.height = 69 + (math.ceil(num / 7) - 1) * 56 -- else -- self._view.width = 191 -- self._view.height = 69 -- end -- for i = 1, num do -- local item = lst_card:AddItemFromPool() -- item:GetChild("icon").icon = "ui://Main_Majiang/b202_" .. cards[i] -- end -- SetObjEnabled(self._view, true) -- else -- SetObjEnabled(self._view, false) -- end -- end function M:FillData(cards, have_bg) -- local btn_showtip = self._main_view._view:GetChild("btn_showtip") local lst_card = self._view:GetChild("lst_card") lst_card:RemoveChildrenToPool() local num = #cards if num > 0 then for i = 1, num do local item = lst_card:AddItemFromPool() item.icon = "ui://Main_Majiang/b202_" .. cards[i] item.text = string.format("剩%d张", self._main_view.cardMap[cards[i]] or 0) end lst_card:ResizeToFit(num) SetObjEnabled(self._view, true) else SetObjEnabled(self._view, false) end if have_bg then self._view_bg = UIPackage.CreateObjectFromURL("ui://Main_Majiang/btn_bg") self._main_view._view:AddChild(self._view_bg) self._view_bg:GetChild('n3').color = Color(1, 1, 1, 0) -- self._view_bg:Center() self._view_bg.width = GRoot.inst.width self._view_bg.height = GRoot.inst.height self._view_bg.onClick:Set(function() self._view_bg:RemoveFromParent() self._view_bg:Dispose() SetObjEnabled(self._view, false) end) end end function M:GetPrefix() return get_majiang_prefix(DataManager.CurrenRoom.game_id) end return M