diff --git a/lua/app/ui/battle/battle_result_ui.lua b/lua/app/ui/battle/battle_result_ui.lua index 34b2617f..c8d0a314 100644 --- a/lua/app/ui/battle/battle_result_ui.lua +++ b/lua/app/ui/battle/battle_result_ui.lua @@ -90,21 +90,43 @@ function BattleResultUI:refreshDefeatNode() end function BattleResultUI:refreshRewards() - if self.scrollRect then - self.scrollRect:updateAllCell() + if self.scrollRectComp then + self.scrollRectComp:updateAllCell() return end local uiMap = self.root:genAllChildren() - self.scrollRect = uiMap["battle_result_ui.scroll_rect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) - self.scrollRect:addInitCallback(function() + local scrollRect = uiMap["battle_result_ui.scroll_rect"] + self.scrollRectComp = scrollRect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) + self.scrollRectComp:addInitCallback(function() return GConst.TYPEOF_LUA_CLASS.REWARD_CELL end) - self.scrollRect:addRefreshCallback(function(index, cell) + self.scrollRectComp:addRefreshCallback(function(index, cell) cell:refresh(self.rewards[index]) end) - self.scrollRect:clearCells() - self.scrollRect:refillCells(#self.rewards) + self.scrollRectComp:setFadeArgs(0.05, 0.3) + self.scrollRectComp:clearCells() + local rewardCount = #self.rewards + if rewardCount > 10 then + local comp = scrollRect:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_SCROLL_RECT) + comp.movementType = CS.UnityEngine.UI.ScrollRect.MovementType.Elastic + self.scrollRectComp:setPerLineNum(5) + scrollRect:setSizeDeltaX(560) + else + local comp = scrollRect:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_SCROLL_RECT) + comp.movementType = CS.UnityEngine.UI.ScrollRect.MovementType.Clamped + if rewardCount >= 5 then + self.scrollRectComp:setPerLineNum(5) + scrollRect:setSizeDeltaX(560) + elseif rewardCount <= 0 then + self.scrollRectComp:setPerLineNum(1) + scrollRect:setSizeDeltaX(560) + else + self.scrollRectComp:setPerLineNum(rewardCount) + scrollRect:setSizeDeltaX(112*rewardCount) + end + end + self.scrollRectComp:refillCells(rewardCount, true) end function BattleResultUI:refreshUnitInfo()