From cbec901af5c6819d7e2801c014d1e227a0c5f58a Mon Sep 17 00:00:00 2001 From: Fang Date: Mon, 19 Jun 2023 14:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E5=A4=B4=E5=83=8F=E6=8A=BD?= =?UTF-8?q?=E8=B1=A1=E6=88=90=E7=8B=AC=E7=AB=8Bcell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/global/global_const.lua | 1 + lua/app/ui/common/cell/player_head_cell.lua | 36 +++++++++++++++++++ .../ui/common/cell/player_head_cell.lua.meta | 10 ++++++ lua/app/ui/main_city/main_city_ui.lua | 22 ++---------- 4 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 lua/app/ui/common/cell/player_head_cell.lua create mode 100644 lua/app/ui/common/cell/player_head_cell.lua.meta diff --git a/lua/app/global/global_const.lua b/lua/app/global/global_const.lua index 05f2e453..c788d397 100644 --- a/lua/app/global/global_const.lua +++ b/lua/app/global/global_const.lua @@ -171,6 +171,7 @@ GConst.TYPEOF_LUA_CLASS = { -- cell ITEM_CELL = "app/ui/common/cell/item_cell", HERO_CELL = "app/ui/common/cell/hero_cell", + PLAYER_HEAD_CELL = "app/ui/common/cell/player_head_cell", REWARD_CELL = "app/ui/common/cell/reward_cell", LARGE_HERO_CELL = "app/ui/common/cell/large_hero_cell", POP_HERO_CELL = "app/ui/shop/cell/pop_hero_cell", diff --git a/lua/app/ui/common/cell/player_head_cell.lua b/lua/app/ui/common/cell/player_head_cell.lua new file mode 100644 index 00000000..48122fa5 --- /dev/null +++ b/lua/app/ui/common/cell/player_head_cell.lua @@ -0,0 +1,36 @@ +local PlayerHeadCell = class("PlayerHeadCell", BaseCell) + +function PlayerHeadCell:init() + local uiMap = self.baseObject:genAllChildren() + + self.imgFrame = uiMap["player_head_cell.img_frame"] + self.imgAvatar = uiMap["player_head_cell.img_avatar"] +end + +function PlayerHeadCell:refresh() + -- 头像 + local avatarName = DataManager.PlayerData:getAvatarIconId(DataManager.PlayerData:getUsingAvatarId()) + if avatarName then + self.imgAvatar:setSprite(GConst.ATLAS_PATH.ICON_HERO, avatarName, function() + self.imgAvatar:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize() + end) + end + + -- 头像框 + local frameName = DataManager.PlayerData:getFrameIconId(DataManager.PlayerData:getUsingFrameId()) + if frameName then + self.imgFrame:setSprite(GConst.ATLAS_PATH.ICON_AVATAR, frameName, function() + self.imgFrame:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize() + end) + end + + -- 红点 + if DataManager.PlayerData:hasNewAvatar() or DataManager.PlayerData:hasNewFrame() then + self.baseObject:addRedPoint(50, 50, 0.7) + else + self.baseObject:removeRedPoint() + end +end + + +return PlayerHeadCell \ No newline at end of file diff --git a/lua/app/ui/common/cell/player_head_cell.lua.meta b/lua/app/ui/common/cell/player_head_cell.lua.meta new file mode 100644 index 00000000..dd3a69ee --- /dev/null +++ b/lua/app/ui/common/cell/player_head_cell.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 48bedef5797f1be4b91882994a4ff540 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/ui/main_city/main_city_ui.lua b/lua/app/ui/main_city/main_city_ui.lua index 88e2277c..7ce3ec31 100644 --- a/lua/app/ui/main_city/main_city_ui.lua +++ b/lua/app/ui/main_city/main_city_ui.lua @@ -596,36 +596,18 @@ function MainCityUI:initPlayerInfo() self.playerSlider = self.uiMap["main_ui.player_node.info.slider.img_prog"] self.playerLvTx = self.uiMap["main_ui.player_node.info.slider.tx_lv"] self.playerNameTx = self.uiMap["main_ui.player_node.info.tx_name"] - self.playerAvatarImg = self.uiMap["main_ui.player_node.avatar.img_avatar"] - self.playerFrameImg = self.uiMap["main_ui.player_node.avatar.img_frame"] - self.playerAvatar = self.uiMap["main_ui.player_node.avatar"] + self.headCell = CellManager:addCellComp(self.uiMap["main_ui.player_node.player_head_cell"], GConst.TYPEOF_LUA_CLASS.PLAYER_HEAD_CELL) self.uiMap["main_ui.player_node"]:addClickListener(function () UIManager:showUI("app/ui/player_info/player_info_ui") end) end function MainCityUI:refreshPlayerInfo() + self.headCell:refresh() local lv = DataManager.PlayerData:getLv() self.playerLvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, lv)) self.playerSlider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = DataManager.PlayerData:getExpPercent() self.playerNameTx:setText(DataManager.PlayerData:getNickname()) - local avatarName = DataManager.PlayerData:getAvatarIconId(DataManager.PlayerData:getUsingAvatarId()) - if avatarName then - self.playerAvatarImg:setSprite(GConst.ATLAS_PATH.ICON_HERO, avatarName, function() - self.playerAvatarImg:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize() - end) - end - local frameName = DataManager.PlayerData:getFrameIconId(DataManager.PlayerData:getUsingFrameId()) - if frameName then - self.playerFrameImg:setSprite(GConst.ATLAS_PATH.ICON_AVATAR, frameName, function() - self.playerFrameImg:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize() - end) - end - if DataManager.PlayerData:hasNewAvatar() or DataManager.PlayerData:hasNewFrame() then - self.playerAvatar:addRedPoint(50, 50, 0.7) - else - self.playerAvatar:removeRedPoint() - end end function MainCityUI:initTopNode()