local ShopComp = class("ShopComp", LuaComponent) local TOP_HEIGHT = 136 local BOTTOM_HEIGHT = 218 local TITLE_HEIGHT = 54 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" local PAGE_DISCOUNT_CHAPTER_SELL_CELL = "app/ui/shop/cell/chapter_sell_cell" -- 章节 local PAGE_DISCOUNT_BEGINNER_SELL_CELL = "app/ui/shop/cell/beginner_sell_cell" -- 新手 local PAGE_DISCOUNT_LEVEL_SELL_CELL = "app/ui/shop/cell/level_sell_cell" -- 助力 local PAGE_DISCOUNT_GROW_SELL_CELL = "app/ui/shop/cell/grow_sell_cell" -- 成长 local PAGE_DISCOUNT_COIN_SELL_CELL = "app/ui/shop/cell/coin_sell_cell" -- 金币 function ShopComp:init() self.uiMap = self.baseObject:genAllChildren() self.page = PAGE_MAIN -- 默认展示主要商品 self:initTitlePage() self:initMainPage() self:initDiscountPage() self:switchPage(self.page) end function ShopComp:initTitlePage() self.subTitleText1 = self.uiMap["shop_comp.title_node.btn_cell_1.text"] self.subTitleSelectText1 = self.uiMap["shop_comp.title_node.btn_cell_1.select_text"] self.subTitleIcon1 = self.uiMap["shop_comp.title_node.btn_cell_1.icon"] self.subTitleBtn1 = self.uiMap["shop_comp.title_node.btn_cell_1"] self.subTitleText2 = self.uiMap["shop_comp.title_node.btn_cell_2.text"] self.subTitleSelectText2 = self.uiMap["shop_comp.title_node.btn_cell_2.select_text"] self.subTitleIcon2 = self.uiMap["shop_comp.title_node.btn_cell_2.icon"] self.subTitleBtn2 = self.uiMap["shop_comp.title_node.btn_cell_2"] self.subTitleText1:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_16)) -- 特惠商品 self.subTitleSelectText1:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_16)) -- 特惠商品 self.subTitleText2:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_17)) -- 主要商品 self.subTitleSelectText2:setText(I18N:getGlobalText(I18N.GlobalConst.SHOP_DESC_17)) -- 主要商品 self.subTitleBtn1:addClickListener(function() self:switchPage(PAGE_DISCOUNT) end) self.subTitleBtn2:addClickListener(function() self:switchPage(PAGE_MAIN) end) self:refreshTitle() end function ShopComp:refreshTitle() if self.page == PAGE_DISCOUNT then self.subTitleText1:setAnchoredPositionY(GConst.NOT_VISIBLE_POS) self.subTitleSelectText1:setAnchoredPositionY(0) self.subTitleIcon1:setAnchoredPositionY(0) self.subTitleText2:setAnchoredPositionY(0) self.subTitleSelectText2:setAnchoredPositionY(GConst.NOT_VISIBLE_POS) self.subTitleIcon2:setAnchoredPositionY(GConst.NOT_VISIBLE_POS) else self.subTitleText1:setAnchoredPositionY(0) self.subTitleSelectText1:setAnchoredPositionY(GConst.NOT_VISIBLE_POS) self.subTitleIcon1:setAnchoredPositionY(GConst.NOT_VISIBLE_POS) self.subTitleText2:setAnchoredPositionY(GConst.NOT_VISIBLE_POS) self.subTitleSelectText2:setAnchoredPositionY(0) self.subTitleIcon2:setAnchoredPositionY(0) end end function ShopComp:switchPage(page) if self.page ~= page then self.page = page self:refresh() end end function ShopComp:initMainPage() self.mainNode = self.uiMap["shop_comp.main"] local scrollrect = self.uiMap["shop_comp.main.scrollrect"] local height = self.baseObject:getTransform().rect.height height = height - TITLE_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"] local scrollrect = self.uiMap["shop_comp.discount.scrollrect"] local height = self.baseObject:getTransform().rect.height height = height - TITLE_HEIGHT - TOP_HEIGHT - BOTTOM_HEIGHT local safeHeight = SafeAreaManager:getNotchScreenHeight() height = height - safeHeight scrollrect:setSizeDeltaY(height) self.discountContent = self.uiMap["shop_comp.discount.scrollrect.viewport.content"] self.chapterSellCell = self.uiMap["shop_comp.discount.scrollrect.viewport.content.chapter_sell_cell"]:addLuaComponent(PAGE_DISCOUNT_CHAPTER_SELL_CELL) self.beginnerSellCell = self.uiMap["shop_comp.discount.scrollrect.viewport.content.beginner_sell_cell"]:addLuaComponent(PAGE_DISCOUNT_BEGINNER_SELL_CELL) self.levelSellCell = self.uiMap["shop_comp.discount.scrollrect.viewport.content.level_sell_cell"]:addLuaComponent(PAGE_DISCOUNT_LEVEL_SELL_CELL) self.growSellCell = self.uiMap["shop_comp.discount.scrollrect.viewport.content.grow_sell_cell"]:addLuaComponent(PAGE_DISCOUNT_GROW_SELL_CELL) self.coinSellCell = self.uiMap["shop_comp.discount.scrollrect.viewport.content.coin_sell_cell"]:addLuaComponent(PAGE_DISCOUNT_COIN_SELL_CELL) end function ShopComp:refresh() if self.page == PAGE_DISCOUNT then self.mainNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) self.discountNode:setAnchoredPositionX(0) else self.mainNode:setAnchoredPositionX(0) self.discountNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) end self:refreshTitle() self:refreshDiscountPage() self:refreshMainPage() -- 如果已经跨天了 需要重新请求每日礼包数据 if DataManager.ShopData:getMallDailyDirty() then DataManager.ShopData:markMallDailyDirty(false) ModuleManager.ShopManager:mallDailyGiftOverDay() end self:refreshTime() end function ShopComp:refreshTime() if self.hotSellCell and self.hotSellCell:getIsOpen() then self.hotSellCell:refreshTime() end if self.coinSellCell and self.coinSellCell:getIsOpen() then self.coinSellCell:refreshTime() end if self.growSellCell and self.growSellCell:getIsOpen() then self.growSellCell:refreshTime() end end function ShopComp:refreshDiscountPage() local y = 0 local cellHeight = 0 -- 章节 if self.chapterSellCell:getIsOpen() then self.chapterSellCell:setVisible(true) self.chapterSellCell:refresh() self.chapterSellCell:getBaseObject():setAnchoredPositionY(0) cellHeight = self.chapterSellCell:getCellHeight() y = y + cellHeight else self.chapterSellCell:setVisible(false) end -- 新手 if self.beginnerSellCell:getIsOpen() then self.beginnerSellCell:setVisible(true) self.beginnerSellCell:refresh() self.beginnerSellCell:getBaseObject():setAnchoredPositionY(-y) cellHeight = self.beginnerSellCell:getCellHeight() y = y + cellHeight else self.beginnerSellCell:setVisible(false) end -- 助力 if self.levelSellCell:getIsOpen() then self.levelSellCell:setVisible(true) self.levelSellCell:refresh() self.levelSellCell:getBaseObject():setAnchoredPositionY(-y) cellHeight = self.levelSellCell:getCellHeight() y = y + cellHeight else self.levelSellCell:setVisible(false) end -- 成长 if self.growSellCell:getIsOpen() then self.growSellCell:setVisible(true) self.growSellCell:refresh() self.growSellCell:getBaseObject():setAnchoredPositionY(-y) cellHeight = self.growSellCell:getCellHeight() y = y + cellHeight else self.growSellCell:setVisible(false) end -- 金币 if self.coinSellCell:getIsOpen() then self.coinSellCell:setVisible(true) self.coinSellCell:refresh() self.coinSellCell:getBaseObject():setAnchoredPositionY(-y) cellHeight = self.coinSellCell:getCellHeight() y = y + cellHeight else self.coinSellCell:setVisible(false) end self.discountContent:setSizeDeltaY(y) 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