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.723 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, posX) -- local btn_showtip = self._main_view._view:GetChild("btn_showtip") local lst_card = self._view:GetChild("lst_card") lst_card:SetVirtual() local num = #cards if num > 0 then if num == lst_card.numItems then lst_card:RefreshVirtualList() else lst_card.numItems = num end else SetObjEnabled(self._view, false) end end function M:GetPrefix() return get_majiang_prefix(DataManager.CurrenRoom.game_id) end return M