diff --git a/lua/app/common/module_manager.lua b/lua/app/common/module_manager.lua index 638f3341..438cd95e 100644 --- a/lua/app/common/module_manager.lua +++ b/lua/app/common/module_manager.lua @@ -11,6 +11,7 @@ local MODULE_PATHS = { ToastManager = "app/ui/common/toast", TaskManager = "app/module/task/task_manager", BattleManager = "app/module/battle/battle_manager", + FormationManager = "app/module/formation/formation_manager", } -- 这里的key对应func_open里的id diff --git a/lua/app/module/formation/formation_manager.lua b/lua/app/module/formation/formation_manager.lua new file mode 100644 index 00000000..8905c2c2 --- /dev/null +++ b/lua/app/module/formation/formation_manager.lua @@ -0,0 +1,20 @@ +local FormationManager = class("FormationManager", BaseModule) + +function FormationManager:upHeroToStageFormation(heroId, matchType) + local formation = DataManager.FormationData:getStageFormation() + if formation[matchType] == heroId then + return + end + local args = { + formationType = GConst.BattleConst.BATTLE_TYPE.STAGE, + matchType = matchType, + heroId = heroId + } + ServerDataManager:dataOperate(GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION, args, function(msgData) + if msgData.status == 0 then + DataManager.FormationData:upHeroToFormation(GConst.BattleConst.BATTLE_TYPE.STAGE, matchType, heroId) + end + end) +end + +return FormationManager \ No newline at end of file diff --git a/lua/app/module/formation/formation_manager.lua.meta b/lua/app/module/formation/formation_manager.lua.meta new file mode 100644 index 00000000..c06cd8fa --- /dev/null +++ b/lua/app/module/formation/formation_manager.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: a5234cdd00d84e543a3afe369d8a4c4d +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/server/data/server_formation_data.lua b/lua/app/server/data/server_formation_data.lua index 581a845a..57460544 100644 --- a/lua/app/server/data/server_formation_data.lua +++ b/lua/app/server/data/server_formation_data.lua @@ -8,4 +8,22 @@ function ServerFormationData:init(data) end end +function ServerFormationData:getFormation(formationType) + local formation = self.data.formations[formationType] + if formation == nil then + formation = {} + self.data.formations[formationType] = formation + end + return formation +end + +function ServerFormationData:upHeroToFormation(formationType, matchType, heroId) + local formation = self:getFormation(formationType) + if formation[matchType] == heroId then + return false + end + formation[matchType] = heroId + return true +end + return ServerFormationData \ No newline at end of file diff --git a/lua/app/server/manager.meta b/lua/app/server/manager.meta new file mode 100644 index 00000000..014a827a --- /dev/null +++ b/lua/app/server/manager.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 09d17db485e3192459d5fcd0a0cefb49 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/lua/app/server/manager/server_formation_manager.lua b/lua/app/server/manager/server_formation_manager.lua new file mode 100644 index 00000000..e22d8082 --- /dev/null +++ b/lua/app/server/manager/server_formation_manager.lua @@ -0,0 +1,27 @@ +local ServerFormationManager = {} + +function ServerFormationManager:updateFormation(params, callback) + local result = { + status = 1 + } + if params == nil then + if callback then + callback(result) + end + return + end + local formationType = params.formationType + local matchType = tostring(params.matchType) + local heroId = params.heroId + if formationType and matchType and heroId then + local ServerGameData = require "app/server/server_game_data" + if ServerGameData.FormationData:upHeroToFormation(formationType, matchType, heroId) then + result.status = 0 + end + end + if callback then + callback(result) + end +end + +return ServerFormationManager \ No newline at end of file diff --git a/lua/app/server/manager/server_formation_manager.lua.meta b/lua/app/server/manager/server_formation_manager.lua.meta new file mode 100644 index 00000000..54f093a9 --- /dev/null +++ b/lua/app/server/manager/server_formation_manager.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 3f6f74ff6268bec4593ef0e060480d93 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/server/server_data_const.lua b/lua/app/server/server_data_const.lua index 408973a3..f34bd71e 100644 --- a/lua/app/server/server_data_const.lua +++ b/lua/app/server/server_data_const.lua @@ -8,6 +8,7 @@ ServerDataConst.REWARD_TYPE = { ServerDataConst.DATA_OP_BEHAVIOR = { SYNC_DATA = "SYNC_DATA", CROSS_DAY = "CROSS_DAY", + UPDATE_FORMATION = "UPDATE_FORMATION" } return ServerDataConst \ No newline at end of file diff --git a/lua/app/server/server_data_manager.lua b/lua/app/server/server_data_manager.lua index c0494d6c..41f3be21 100644 --- a/lua/app/server/server_data_manager.lua +++ b/lua/app/server/server_data_manager.lua @@ -3,6 +3,7 @@ local ServerGameData = require "app/server/server_game_data" local ServerDataManager = {} function ServerDataManager:init() + self.ServerFormationManager = require("app/server/manager/server_formation_manager") end function ServerDataManager:saveData() @@ -40,7 +41,7 @@ function ServerDataManager:dataOperate(behavior, params, callback) end end) -- TODO临时处理 - LocalData:save() + ServerGameData:saveData() else Logger.logError("Undefined data operation function, please check :%s", behavior) end @@ -57,6 +58,7 @@ end ServerDataManager.OP_FUNC = { [GConst.ServerDataConst.DATA_OP_BEHAVIOR.SYNC_DATA] = function (...) ServerDataManager:onSyncData(...) end, + [GConst.ServerDataConst.DATA_OP_BEHAVIOR.UPDATE_FORMATION] = function (...) ServerDataManager.ServerFormationManager:updateFormation(...) end, } return ServerDataManager \ No newline at end of file diff --git a/lua/app/server/server_game_data.lua b/lua/app/server/server_game_data.lua index f9b00021..28ed8337 100644 --- a/lua/app/server/server_game_data.lua +++ b/lua/app/server/server_game_data.lua @@ -70,9 +70,8 @@ function ServerGameData:initData() end end end - self:saveData() self:setNotNewPlayer() - LocalData:save() + self:saveData() else for k, v in pairs(self.dataMap) do v:init(v:loadLocalData()) @@ -100,6 +99,7 @@ function ServerGameData:saveData() for k, v in pairs(self.dataMap) do v:saveLocalData() end + LocalData:save() end -- 根据配置表添加奖励 diff --git a/lua/app/ui/common/cell/hero_cell.lua b/lua/app/ui/common/cell/hero_cell.lua index a4e88655..9c0f8922 100644 --- a/lua/app/ui/common/cell/hero_cell.lua +++ b/lua/app/ui/common/cell/hero_cell.lua @@ -7,6 +7,11 @@ function HeroCell:init() self.check = uiMap["hero_cell.hero_bg.mask"] self.matchImg = uiMap["hero_cell.hero_bg.match_img"] self.isGray = false + self.baseObject:addClickListener(function() + if self.clickCallback then + self.clickCallback() + end + end) end function HeroCell:refresh(heroEntity, isGray) @@ -20,6 +25,7 @@ function HeroCell:refreshWithCfgId(id, isGray) end function HeroCell:_refresh(heroInfo, isGray) + self.clickCallback = nil if isGray then self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HERO_FRAME_GRAY_QLT[heroInfo.qlt]) else @@ -31,6 +37,14 @@ function HeroCell:_refresh(heroInfo, isGray) self:setGray(isGray) end +function HeroCell:showCheck(visible) + self.check:setVisible(visible) +end + +function HeroCell:addClickListener(callback) + self.clickCallback = callback +end + function HeroCell:setVisible(visible) self.baseObject:setVisible(visible) end diff --git a/lua/app/ui/hero/cell/hero_list_cell.lua b/lua/app/ui/hero/cell/hero_list_cell.lua index 2dbfa24c..41bff86a 100644 --- a/lua/app/ui/hero/cell/hero_list_cell.lua +++ b/lua/app/ui/hero/cell/hero_list_cell.lua @@ -17,7 +17,7 @@ function HeroListCell:init() self.titleTx = self.uiMap["hero_list_cell.title.title_desc"] end -function HeroListCell:refresh(index, heroList, allHeroCount, activeCount) +function HeroListCell:refresh(index, heroList, stageFormation, allHeroCount, activeCount) if activeCount > 0 and index == 1 then self.title:setVisible(true) self.titleTx:setText("临时文本:已解锁") @@ -38,7 +38,14 @@ function HeroListCell:refresh(index, heroList, allHeroCount, activeCount) for i = 1, 4 do if heroIndex <= activeCount then self.heroCells[i]:setVisible(true) - self.heroCells[i]:refresh(DataManager.HeroData:getHeroById(heroList[heroIndex]), false) + local heroId = heroList[heroIndex] + local heroEntity = DataManager.HeroData:getHeroById(heroId) + local matchType = heroEntity:getMatchType() + self.heroCells[i]:refresh(heroEntity, false) + self.heroCells[i]:showCheck(stageFormation[matchType] == heroId) + self.heroCells[i]:addClickListener(function() + ModuleManager.FormationManager:upHeroToStageFormation(heroId, matchType) + end) elseif heroIndex <= allHeroCount then if heroStartIndex <= activeCount then self.heroCells[i]:setVisible(false) diff --git a/lua/app/ui/hero/hero_comp.lua b/lua/app/ui/hero/hero_comp.lua index 66813423..3ba9ba61 100644 --- a/lua/app/ui/hero/hero_comp.lua +++ b/lua/app/ui/hero/hero_comp.lua @@ -9,7 +9,7 @@ function HeroComp:init() return HERO_LIST_CELL end) self.scrollRect:addRefreshCallback(function(index, cell) - cell:refresh(index, self.heroList, self.allHeroCount, self.activeCount) + cell:refresh(index, self.heroList, self.stageFormation, self.allHeroCount, self.activeCount) end) self.heroList = {} local heroCfg = ConfigManager:getConfig("hero") @@ -19,9 +19,15 @@ function HeroComp:init() end function HeroComp:refresh() + self.stageFormation = DataManager.FormationData:getStageFormation() + self:refreshStageFormation() self:refreshScrollRect() end +function HeroComp:refreshStageFormation() + +end + function HeroComp:refreshScrollRect() self:sortHeroList() self.allHeroCount = #self.heroList diff --git a/lua/app/ui/main_city/main_city_ui.lua b/lua/app/ui/main_city/main_city_ui.lua index 6feccebc..cd865e97 100644 --- a/lua/app/ui/main_city/main_city_ui.lua +++ b/lua/app/ui/main_city/main_city_ui.lua @@ -119,13 +119,17 @@ function MainCityUI:_bind() self.subComps[self.selectedIndex]:refreshChapter() end end) - self:bind(DataManager.PlayerData, "dirty", function(binder, value) self:refreshRoleInfo() end, true) self:bind(DataManager.PlayerData, "lvUpDirty", function(binder, value) self:checkMainPop() end) + self:bind(DataManager.FormationData, "dirty", function(binder, value) + if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.HERO then + self.subComps[self.selectedIndex]:refresh() + end + end) -- self:bind(DataManager.BagData.ItemData, "dirty", function(binder, value) -- UIManager:refreshCurrencyBarTxt() diff --git a/lua/app/userdata/formation/formation_data.lua b/lua/app/userdata/formation/formation_data.lua index b150ab6a..25a92700 100644 --- a/lua/app/userdata/formation/formation_data.lua +++ b/lua/app/userdata/formation/formation_data.lua @@ -1,7 +1,17 @@ local FormationData = class("FormationData", BaseData) function FormationData:init(data) - self.formations = data and data.formations or {} + self.data.dirty = false + self.formations = {} + if data and data.formations then + for formationType, formation in pairs(data.formations) do + local clientFormation = {} + self.formations[formationType] = clientFormation + for matchTypeStr, heroId in pairs(formation) do + clientFormation[tonumber(matchTypeStr)] = heroId + end + end + end end function FormationData:getStageFormation() @@ -17,4 +27,17 @@ function FormationData:getFormation(formationType) return formation end +function FormationData:upHeroToFormation(formationType, matchType, heroId) + local formation = self:getFormation(formationType) + if formation[matchType] == heroId then + return + end + formation[matchType] = heroId + self:setDirty() +end + +function FormationData:setDirty() + self.data.dirty = not self.data.dirty +end + return FormationData \ No newline at end of file