From 9a0ebd13181222f77e4ff4499490856a2a52ccf7 Mon Sep 17 00:00:00 2001 From: chenxi Date: Fri, 21 Apr 2023 16:27:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=80=E8=83=BD=E6=8A=96=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/component/battle_unit_comp.lua | 7 +++ .../battle/controller/battle_controller.lua | 4 ++ lua/app/ui/battle/battle_ui.lua | 58 +++++++++++++++++-- .../battle/skill/battle_skill_entity.lua | 8 +++ 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 810ecec7..07fbc5f6 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -1001,6 +1001,13 @@ function BattleUnitComp:onSkillTakeEffect(skill) end if succ and skill:getIsNormalType() then -- 普攻攻击成功的话 self:checkPassiveEvent(PASSIVE_EVENT.USE_NORMAL_SKILL, target) + local shakeType = skill:getShakeType() + if shakeType then + local shakeTime = skill:getShakeTime() or 0 + if shakeTime > 0 then + self.battleController:shakeScreen(shakeType, shakeTime/TIME_FACTOR) + end + end end end diff --git a/lua/app/module/battle/controller/battle_controller.lua b/lua/app/module/battle/controller/battle_controller.lua index ad302024..900f0291 100644 --- a/lua/app/module/battle/controller/battle_controller.lua +++ b/lua/app/module/battle/controller/battle_controller.lua @@ -1655,6 +1655,10 @@ function BattleController:getFxNode() return self.battleUI:getFxNode() end +function BattleController:shakeScreen(shakeType, duration) + self.battleUI:shakeScreen(shakeType, duration) +end + local function _addCurRoundAttr(self, instruction, callback) if instruction.effectList then local defComp = self:getOtherSideMainUnit(BattleConst.SIDE_ATK) diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index c1210059..3b9f5b42 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -10,6 +10,7 @@ local BOARD_POS_UP = BF.Vector2(0, 47) local BOARD_POS_DOWN = BF.Vector2(0, -740) local BG_PATH = "assets/arts/textures/background/battle/%s.png" local CacheVector2 = CS.UnityEngine.Vector2(0, 0) +local CacheVector3 = CS.UnityEngine.Vector3(0, 0, 0) function BattleUI:getPrefabPath() return "assets/prefabs/ui/battle/battle_ui.prefab" @@ -31,11 +32,12 @@ function BattleUI:_display() self.gridNode = uiMap["battle_ui.bg_2.board_node.grid_node"] self.boardNode = uiMap["battle_ui.bg_2.board_node"] self.boardMask2D = self.gridNode:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_RECT_MASK_2D) - self.boardMask = uiMap["battle_ui.bg_2.board_mask"] + self.boardMask = uiMap["battle_ui.bg_2.board_node.grid_node.board_mask"] self.boardMask:setVisible(false) self.boardCacheNode = uiMap["battle_ui.bg_2.board_cache_node"] self.boardCacheNode:setVisible(false) self.boardCacheBox = uiMap["battle_ui.bg_2.board_cache_node.skill_box"] + self.battleRoot = uiMap["battle_ui.battle_root"] self:initBg() self:initSkill() self:initBuff() @@ -48,7 +50,7 @@ end function BattleUI:_addListeners() local uiMap = self.root:genAllChildren() - uiMap["battle_ui.close_btn"]:addClickListener(function() + uiMap["battle_ui.top_node.close_btn"]:addClickListener(function() ModuleManager.BattleManager:showPauseUI() end) end @@ -60,7 +62,7 @@ function BattleUI:_bind() end function BattleUI:initBg() - self.bg = self.uiMap["battle_ui.bg"] + self.bg = self.uiMap["battle_ui.battle_root.bg"] self.bg:setLocalScale(0, 0, 0) local width = self.bg:fastGetSizeDelta() self.bg:setAnchoredPositionX(width/4) @@ -325,7 +327,7 @@ function BattleUI:getBattleBuffTipsObj(index) end function BattleUI:initBattlefield() - self.battleNode = self.uiMap["battle_ui.battle_node"] + self.battleNode = self.uiMap["battle_ui.battle_root.battle_node"] end function BattleUI:getBattleNode() @@ -333,7 +335,7 @@ function BattleUI:getBattleNode() end function BattleUI:initNumberNode() - self.battleNumberNode = self.uiMap["battle_ui.battle_number_node"] + self.battleNumberNode = self.uiMap["battle_ui.battle_root.battle_number_node"] self.battleNumber = self.uiMap["battle_ui.cache_node.battle_number"] self.battleNumberRed = self.uiMap["battle_ui.cache_node.battle_number_red"] self.battleNumberGreen = self.uiMap["battle_ui.cache_node.battle_number_green"] @@ -361,7 +363,7 @@ function BattleUI:getBattleNumberYellow() end function BattleUI:initFxNode() - self.fxNode = self.uiMap["battle_ui.batttle_fx_node"] + self.fxNode = self.uiMap["battle_ui.battle_root.batttle_fx_node"] end function BattleUI:getFxNode() @@ -529,6 +531,46 @@ function BattleUI:refreshSkill(elementMap) end end +-- shakeType: 奇数是水平震动 偶数是垂直震动 +function BattleUI:shakeScreen(shakeType, duration) + self.battleRoot:setLocalPosition(0, 0, 0) + if self.shakeTween == nil then + local length = ConfigManager:getConfig("const")["shake_level_" .. math.ceil(shakeType / 2)].value + if shakeType % 2 == 0 then + CacheVector2.x = 0 + CacheVector2.y = length + self.shakeTween = self.battleRoot:getTransform():DOShakeAnchorPos(duration, CacheVector2, 100, 90, false, false) + else + CacheVector2.x = length + CacheVector2.y = 0 + self.shakeTween = self.battleRoot:getTransform():DOShakeAnchorPos(duration, CacheVector2, 100, 90, false, false) + end + self.shakeTween:SetIntId(GConst.DOTWEEN_IDS.BATTLE) + self.shakeTween:SetAutoKill(false) + self.shakeType = shakeType + self.shakeDuration = duration + elseif self.shakeType == shakeType and self.shakeDuration == duration then + self.shakeTween:Restart() + else + self.shakeTween:Kill() + local length = ConfigManager:getConfig("config")["shake_level_" .. math.ceil(shakeType / 2)].value / 100 + if shakeType % 2 == 0 then + CacheVector2.x = 0 + CacheVector2.y = length + self.shakeTween = self.battleRoot:getTransform():DOShakeAnchorPos(duration, CacheVector2, 100, 90, false, false) + else + CacheVector2.x = length + CacheVector2.y = 0 + self.shakeTween = self.battleRoot:getTransform():DOShakeAnchorPos(duration, CacheVector2, 100, 90, false, false) + end + self.shakeTween:SetIntId(GConst.DOTWEEN_IDS.BATTLE) + self.shakeTween:SetAutoKill(false) + self.shakeType = shakeType + self.shakeDuration = duration + end + self.shakeTween.timeScale = DataManager.BattleData:getTimeScale() +end + function BattleUI:initGridCell() if self.root.gridCells then self.gridCells = self.root.gridCells @@ -1109,6 +1151,10 @@ function BattleUI:clear() self.bgMoveTween:Kill() self.bgMoveTween = nil end + if self.shakeTween then + self.shakeTween:Kill() + self.shakeTween = nil + end if self.battleNumberNode then self.battleNumberNode:removeAllChildren() end diff --git a/lua/app/userdata/battle/skill/battle_skill_entity.lua b/lua/app/userdata/battle/skill/battle_skill_entity.lua index 38d464e5..109af92a 100644 --- a/lua/app/userdata/battle/skill/battle_skill_entity.lua +++ b/lua/app/userdata/battle/skill/battle_skill_entity.lua @@ -184,6 +184,14 @@ function BattleSkillEntity:getFxTargetDelay() return self.skillInfo.fx_target_delay end +function BattleSkillEntity:getShakeType() + return self.skillInfo.shake_type +end + +function BattleSkillEntity:getShakeTime() + return self.skillInfo.shake_time +end + function BattleSkillEntity:getRecordData(name) if self.recordData == nil then self.recordData = {}