local ShopComp = class("ShopComp", LuaComponent) local TOP_HEIGHT = 136 local BOTTOM_HEIGHT = 218 local PAGE_DISCOUNT = 1 local PAGE_MAIN = 2 local PAGE_MAIN_BOX_SELL_CELL = "app/ui/shop/cell/box_sell_cell" local PAGE_MAIN_HOT_SELL_CELL = "app/ui/shop/cell/hot_sell_cell" local PAGE_MAIN_GEM_SELL_CELL = "app/ui/shop/cell/gem_sell_cell" local PAGE_MAIN_GOLD_SELL_CELL = "app/ui/shop/cell/gold_sell_cell" function ShopComp:init() self.uiMap = self.baseObject:genAllChildren() self:initMainPage() self:initDiscountPage() self.page = PAGE_MAIN end function ShopComp:initMainPage() self.mainNode = self.uiMap["shop_comp.main"] local scrollrect = self.uiMap["shop_comp.scrollrect"] local height = self.baseObject:getTransform().rect.height height = height - TOP_HEIGHT - BOTTOM_HEIGHT local safeHeight = SafeAreaManager:getNotchScreenHeight() height = height - safeHeight scrollrect:setSizeDeltaY(height) self.mainScrollContent = self.uiMap["shop_comp.main.scrollrect.viewport.content"] self.boxSellCell = self.uiMap["shop_comp.main.scrollrect.viewport.content.box_sell_cell"]:addLuaComponent(PAGE_MAIN_BOX_SELL_CELL) self.hotSellCell = self.uiMap["shop_comp.main.scrollrect.viewport.content.hot_sell_cell"]:addLuaComponent(PAGE_MAIN_HOT_SELL_CELL) self.gemSellCell = self.uiMap["shop_comp.main.scrollrect.viewport.content.gem_sell_cell"]:addLuaComponent(PAGE_MAIN_GEM_SELL_CELL) self.goldSellCell = self.uiMap["shop_comp.main.scrollrect.viewport.content.gold_sell_cell"]:addLuaComponent(PAGE_MAIN_GOLD_SELL_CELL) end function ShopComp:initDiscountPage() self.discountNode = self.uiMap["shop_comp.discount"] end function ShopComp:updateMainList() end function ShopComp:refresh() if self.page == PAGE_DISCOUNT then self.mainNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) self.discountNode:setAnchoredPositionX(0) self:refreshDiscountPage() else self.mainNode:setAnchoredPositionX(0) self.discountNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) self:refreshMainPage() end end function ShopComp:refreshDiscountPage() end function ShopComp:refreshMainPage() local y = 0 local cellHeight = 0 -- 宝箱 if self.boxSellCell:getIsOpen() then self.boxSellCell:setVisible(true) self.boxSellCell:refresh() self.boxSellCell:getBaseObject():setAnchoredPositionY(0) cellHeight = self.boxSellCell:getCellHeight() y = y + cellHeight else self.boxSellCell:setVisible(false) end -- 每日特惠 if self.hotSellCell:getIsOpen() then self.hotSellCell:setVisible(true) self.hotSellCell:refresh() self.hotSellCell:getBaseObject():setAnchoredPositionY(-y) cellHeight = self.hotSellCell:getCellHeight() y = y + cellHeight else self.hotSellCell:setVisible(false) end -- 钻石 if self.gemSellCell:getIsOpen() then self.gemSellCell:setVisible(true) self.gemSellCell:refresh() self.gemSellCell:getBaseObject():setAnchoredPositionY(-y) cellHeight = self.gemSellCell:getCellHeight() y = y + cellHeight else self.gemSellCell:setVisible(false) end -- 金币 if self.goldSellCell:getIsOpen() then self.goldSellCell:setVisible(true) self.goldSellCell:refresh() self.goldSellCell:getBaseObject():setAnchoredPositionY(-y) cellHeight = self.goldSellCell:getCellHeight() y = y + cellHeight else self.goldSellCell:setVisible(false) end self.mainScrollContent:setSizeDeltaY(y) end return ShopComp