431 lines
12 KiB
Lua
431 lines
12 KiB
Lua
---@class WBP_SettleSave_C:UUserWidget
|
||
---@field ScrollBox_SaveItems UScrollBox
|
||
---@field WBP_WidgetHeader UWBP_WidgetHeader_C
|
||
--Edit Below--
|
||
local WBP_SettleSave = {
|
||
bInitDoOnce = false;
|
||
|
||
-- 存放数组,如果之后需要改变排序,直接改变即可,不需要在计算一遍
|
||
SaveGames = {
|
||
},
|
||
-- 对象池初始化数量
|
||
InitCount = 0,
|
||
FirstOpen = true;
|
||
};
|
||
|
||
function WBP_SettleSave:Construct()
|
||
WBP_SettleSave.SuperClass.Construct(self)
|
||
|
||
self.ScrollBox_SaveItems:ClearChildren()
|
||
end
|
||
|
||
-- function WBP_SettleSave:Tick(MyGeometry, InDeltaTime)
|
||
|
||
-- end
|
||
|
||
-- function WBP_SettleSave:Destruct()
|
||
|
||
-- end
|
||
|
||
function WBP_SettleSave:ShowArchive()
|
||
print(string.format("[WBP_SettleSave:ShowArchive] 进入"))
|
||
if self.FirstOpen == false then
|
||
return
|
||
end
|
||
self.FirstOpen = false;
|
||
-- 这里面就是变化,还是要根据每一个具体显示
|
||
local Results = self:CompareArchive()
|
||
log_tree("[WBP_SettleSave:ShowArchive] Results = ", Results)
|
||
-- 显示存档,根据顺序进行排列
|
||
self:ShowItem_GameClearance(Results.GameClearanceDiff)
|
||
self:ShowItem_Credit(Results.CreditDiff)
|
||
self:ShowItem_EasterEggs(Results.EasterEggsDiff)
|
||
self:ShowItem_Achievement(Results.AchievementDiff)
|
||
self:ShowItem_GameDrop(Results.GameDropDiff)
|
||
self:ShowItem_BossDrop(Results.BossDropDiff)
|
||
print(string.format("[WBP_SettleSave:ShowArchive] 显示完全"))
|
||
-- 设置数据
|
||
self:SetItemInfos();
|
||
print(string.format("[WBP_SettleSave:ShowArchive] 设置完全"))
|
||
end
|
||
|
||
function WBP_SettleSave:SetItemInfos()
|
||
log_tree("[WBP_SettleSave:SetItemInfos] self.SaveGames = ", self.SaveGames)
|
||
local ChildrenCount = self.ScrollBox_SaveItems:GetChildrenCount()
|
||
local SaveGameCount = #self.SaveGames
|
||
if ChildrenCount < SaveGameCount then
|
||
self:InitObjectPool(SaveGameCount - ChildrenCount)
|
||
end
|
||
for i, Info in pairs(self.SaveGames) do
|
||
self.ScrollBox_SaveItems:GetChildAt(i - 1):SetSaveInfo(Info)
|
||
self.ScrollBox_SaveItems:GetChildAt(i - 1):SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||
end
|
||
end
|
||
|
||
--比较前后变化
|
||
function WBP_SettleSave:CompareArchive()
|
||
local BeforeArchive = GameDataManager.GetLocalPlayerState().SavedArchiveData
|
||
local LastArchive = GameDataManager.GetLocalPlayerState().ArchiveData;
|
||
|
||
local Results = {}
|
||
|
||
Results.GameClearanceDiff = self:GameClearanceDiff(BeforeArchive["PlayedGames"], LastArchive["PlayedGames"])
|
||
Results.CreditDiff = self:CreditDiff(BeforeArchive["Score"], LastArchive["Score"])
|
||
Results.EasterEggsDiff = self:EasterEggsDiff(BeforeArchive["EasterEggs"], LastArchive["EasterEggs"])
|
||
|
||
-- 成就类
|
||
Results.AchievementDiff = {}
|
||
Results.AchievementDiff["通关"] = self:AchievementDiff("通关", BeforeArchive.GameClearanceTimes, LastArchive.GameClearanceTimes)
|
||
Results.AchievementDiff["击败"] = self:AchievementDiff("击败", BeforeArchive.TotalBossKilledTimes, LastArchive.TotalBossKilledTimes)
|
||
Results.AchievementDiff["金币"] = self:AchievementDiff("金币", BeforeArchive.TotalCoinPoint / 10000, LastArchive.TotalCoinPoint / 10000)
|
||
Results.AchievementDiff["科技点"] = self:AchievementDiff("科技点", BeforeArchive.TotalKillPoint, LastArchive.TotalKillPoint)
|
||
Results.AchievementDiff["技能"] = self:AchievementDiff("技能", BeforeArchive.TotalSuperSkill, LastArchive.TotalSuperSkill)
|
||
Results.AchievementDiff["配件"] = self:AchievementDiff("配件", BeforeArchive.TotalSuperFitting, LastArchive.TotalSuperFitting)
|
||
Results.AchievementDiff["开箱"] = self:AchievementDiff("开箱", BeforeArchive.TotalUnpackTimes, LastArchive.TotalUnpackTimes)
|
||
|
||
Results.GameDropDiff = self:GameDropDiff(BeforeArchive.GameDropItems, LastArchive.GameDropItems)
|
||
|
||
Results.BossDropDiff = self:BossDropDiff(BeforeArchive.BossDropItems, LastArchive.BossDropItems)
|
||
|
||
-- 精简一下
|
||
for i, v in pairs(Results) do
|
||
if table.isEmpty(v) == true then
|
||
Results[i] = nil;
|
||
end
|
||
end
|
||
|
||
return Results;
|
||
end
|
||
|
||
-- 返回新增的存档,数据结构如下
|
||
-- {
|
||
-- [Difficult] = { Time1 }
|
||
-- }
|
||
--- 例如:
|
||
--- {
|
||
--- [10] = { 3, 5 }
|
||
---}
|
||
function WBP_SettleSave:GameClearanceDiff(InOld, InLast)
|
||
local Results = {}
|
||
-- 记录增量变化
|
||
|
||
-- 去检查一下 ArchiveTable 中当前的存档
|
||
local Func = function(InDiff, InTimes)
|
||
local ValTable = {
|
||
[InDiff] = {}
|
||
}
|
||
ValTable[InDiff] = {}
|
||
for i, v in pairs(ArchiveTable.GameClearanceRewards[InDiff]) do
|
||
if InTimes >= i then
|
||
table.insert(ValTable[InDiff], i);
|
||
end
|
||
end
|
||
return ValTable;
|
||
end
|
||
|
||
-- InTable: Results; InAddTable: [Diff] = { Times }
|
||
local AddResultFunc = function(InAddTable)
|
||
for i, v in pairs(InAddTable) do
|
||
Results[i] = v
|
||
end
|
||
end
|
||
|
||
for Diff, Times in pairs(InLast) do
|
||
if InOld[Diff] == nil then
|
||
-- 说明全部是新的
|
||
local NewAdd = Func(Diff, Times)
|
||
AddResultFunc(NewAdd)
|
||
else
|
||
-- 判断当前已经打到第几个阶段了
|
||
local OldTable = Func(Diff, InOld[Diff])
|
||
local NewTable = Func(Diff, Times)
|
||
-- 做插值
|
||
local DiffTable = table.Diff(OldTable, NewTable)
|
||
AddResultFunc(DiffTable)
|
||
end
|
||
end
|
||
|
||
return Results;
|
||
end
|
||
|
||
function WBP_SettleSave:CreditDiff(InOld, InLast)
|
||
local Results = {}
|
||
|
||
-- 获取积分的最大值
|
||
local Func = function(Val)
|
||
local Max = 0
|
||
for i, v in pairs(ArchiveTable.CreditRewards) do
|
||
if v.Reach >= Val then
|
||
return i - 1
|
||
end
|
||
Max = i;
|
||
end
|
||
return Max;
|
||
end
|
||
|
||
local Old = Func(InOld)
|
||
local New = Func(InLast)
|
||
if Old ~= New then
|
||
for i = Old + 1, New do
|
||
table.insert(Results, i)
|
||
end
|
||
end
|
||
return Results
|
||
end
|
||
|
||
function WBP_SettleSave:EasterEggsDiff(InOld, InLast)
|
||
local Results = {}
|
||
for i, v in pairs(InLast) do
|
||
if v.Active == true and InOld[i].Active == false then
|
||
table.insert(Results, i)
|
||
end
|
||
end
|
||
return Results;
|
||
end
|
||
|
||
-- 成就类型: { Val }
|
||
function WBP_SettleSave:AchievementDiff(InKey, InOld, InLast)
|
||
-- 做成数组
|
||
local MakeArrFunc = function(TheKey)
|
||
local Ret = {}
|
||
for i, v in pairs(ArchiveTable.AchievementRewards[TheKey]) do
|
||
table.insert(Ret, i)
|
||
end
|
||
return Ret;
|
||
end
|
||
local Arr = MakeArrFunc(InKey)
|
||
local Func = function(InArr, Val)
|
||
for i, v in pairs(InArr) do
|
||
if v > Val then
|
||
return i - 1
|
||
end
|
||
end
|
||
return 0
|
||
end
|
||
|
||
local OldMax = Func(Arr, InOld)
|
||
local LastMax = Func(Arr, InLast)
|
||
local Results = {}
|
||
|
||
if OldMax ~= LastMax then
|
||
for i = OldMax + 1, LastMax do
|
||
table.insert(Results, Arr[i])
|
||
end
|
||
end
|
||
return Results;
|
||
end
|
||
|
||
-- 游戏掉落物
|
||
-- { [Diff] = { Type: Count } }
|
||
function WBP_SettleSave:GameDropDiff(InOld, InLast)
|
||
local Results = {}
|
||
for Diff, Table in pairs(InLast) do
|
||
if InOld[Diff] ~= nil then
|
||
for Type, Count in pairs(Table) do
|
||
local OldVal = InOld[Diff][Type]
|
||
if OldVal == nil then
|
||
Results[Diff] = {
|
||
[Type] = Count
|
||
}
|
||
else
|
||
Results[Diff] = {
|
||
[Type] = Count - OldVal
|
||
}
|
||
end
|
||
end
|
||
else
|
||
Results[Diff] = Table;
|
||
end
|
||
end
|
||
return Results;
|
||
end
|
||
|
||
function WBP_SettleSave:BossDropDiff(InOld, InLast)
|
||
-- Table: { Type: Count }
|
||
local Results = {}
|
||
for BossName, Table in pairs(InLast) do
|
||
if InOld[BossName] == nil then
|
||
Results[BossName] = Table
|
||
else
|
||
Results[BossName] = {}
|
||
for Type, Count in pairs(Table) do
|
||
local OldVal = InOld[BossName][Type]
|
||
if OldVal == nil then
|
||
Results[BossName][Type] = Count
|
||
else
|
||
Results[BossName][Type] = Count - OldVal
|
||
end
|
||
end
|
||
end
|
||
end
|
||
return Results
|
||
end
|
||
|
||
function WBP_SettleSave:GetTypeValue(InArchive, InNum)
|
||
local Archive = InArchive
|
||
if InArchive.Type == nil then
|
||
local Val = ''
|
||
for i, v in pairs(InArchive) do
|
||
Val = self:GetTypeValue(v, InNum) .. '\n' .. Val
|
||
end
|
||
return Val
|
||
end
|
||
if InNum == nil then
|
||
InNum = 1
|
||
end
|
||
local Num = Archive.Value * InNum
|
||
|
||
local Type = Archive.Type
|
||
-- 替换掉 %
|
||
if string.find(Type, '%%') ~= nil then
|
||
Type = string.gsub(Type, '%%', '')
|
||
end
|
||
local Unit = ""
|
||
|
||
if Archive.Unit == '%' then
|
||
Unit = '%'
|
||
Num = Num * 100
|
||
end
|
||
|
||
if math.type(Archive.Value) == 'float' then
|
||
Num = string.format("%.2f", Num)
|
||
elseif math.type(Archive.Value) == 'integer' then
|
||
Num = string.format("%d", Archive.Value)
|
||
end
|
||
return string.format('%s + %s', Type, Num .. Unit)
|
||
end
|
||
|
||
function WBP_SettleSave:ShowItem_GameClearance(InData)
|
||
-- 存放到数组中
|
||
if InData == nil then
|
||
return
|
||
end
|
||
for Diff, TimeTable in pairs(InData) do
|
||
for i, Times in pairs(TimeTable) do
|
||
-- 处理 Desc
|
||
local ItemData = {
|
||
Type = ArchiveTable.ArchiveType.GameClearance,
|
||
TextVal = string.format("难%d %d次", Diff, Times),
|
||
Icon = SaveGameConfigs.Icons.GameClearance,
|
||
Desc = self:GetTypeValue(ArchiveTable.GameClearanceRewards[Diff][Times])
|
||
}
|
||
table.insert(self.SaveGames, ItemData)
|
||
end
|
||
end
|
||
end
|
||
|
||
function WBP_SettleSave:ShowItem_Credit(InData)
|
||
if InData == nil then
|
||
return
|
||
end
|
||
for i, CreditRewardsIndex in pairs(InData) do
|
||
local ItemData = {
|
||
Type = ArchiveTable.ArchiveType.Credit,
|
||
TextVal = tostring(ArchiveTable.CreditRewards[CreditRewardsIndex].Reach),
|
||
Icon = SaveGameConfigs.Icons.Score,
|
||
Desc = self:GetTypeValue(ArchiveTable.CreditRewards[CreditRewardsIndex]["Reward"])
|
||
}
|
||
table.insert(self.SaveGames, ItemData)
|
||
end
|
||
end
|
||
|
||
function WBP_SettleSave:ShowItem_EasterEggs(InData)
|
||
if InData == nil then
|
||
return
|
||
end
|
||
for i, v in pairs(InData) do
|
||
local ItemData = {
|
||
Type = ArchiveTable.ArchiveType.EasterEggs,
|
||
Desc = self:GetTypeValue(ArchiveTable.EasterEggs[v]["Reward"]),
|
||
Icon = SaveGameConfigs.Icons.EasterEggs[v],
|
||
TextVal = ArchiveTable.EasterEggs[i].Name,
|
||
}
|
||
table.insert(self.SaveGames, ItemData)
|
||
end
|
||
end
|
||
|
||
function WBP_SettleSave:ShowItem_Achievement(InData)
|
||
if InData == nil then
|
||
return
|
||
end
|
||
for Name, ValTable in pairs(InData) do
|
||
for i, v in pairs(ValTable) do
|
||
local ItemData = {
|
||
Type = ArchiveTable.ArchiveType.Achievement,
|
||
TextVal = ArchiveTable.AchievementRewards[Name][i].Name,
|
||
Icon = SaveGameConfigs.Icons.Achievements[Name][v],
|
||
Desc = self:GetTypeValue(ArchiveTable.AchievementRewards[Name][v].Reward),
|
||
}
|
||
table.insert(self.SaveGames, ItemData)
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 表示新增的
|
||
function WBP_SettleSave:ShowItem_GameDrop(InData)
|
||
if InData == nil then
|
||
return
|
||
end
|
||
-- Diff: 难度;TypeCountTable: 物品:数量
|
||
-- 统计所有的
|
||
for Diff, TypeCountTable in pairs(InData) do
|
||
for Type, Count in pairs(TypeCountTable) do
|
||
local Name = ArchiveTable.DropGameItemIndex[Type]
|
||
--if self.SaveGames.GameDrop[Name] == nil then
|
||
-- self.SaveGames.GameDrop[Name] = {}
|
||
--end
|
||
local ItemData = {
|
||
Type = ArchiveTable.ArchiveType.DropGameItems,
|
||
TextVal = string.format('难%d %s', Diff, Name),
|
||
Desc = self:GetTypeValue(ArchiveTable.DropGameItems[Name], Diff * Count),
|
||
Icon = SaveGameConfigs.Icons.GameDropItems[Name],
|
||
}
|
||
table.insert(self.SaveGames, ItemData)
|
||
end
|
||
end
|
||
end
|
||
|
||
function WBP_SettleSave:ShowItem_BossDrop(InData)
|
||
if InData == nil then
|
||
return
|
||
end
|
||
-- 检查新增
|
||
local Func = function(Index)
|
||
for c, d in pairs(ArchiveTable.BossDropItemIndexs) do
|
||
if Index == d then
|
||
return c
|
||
end
|
||
end
|
||
end
|
||
for BossName, Table in pairs(InData) do
|
||
for i, v in pairs(Table) do
|
||
local ItemData = {
|
||
Desc = self:GetTypeValue(ArchiveTable.BossDropItems[BossName][i].Rewards, v),
|
||
Icon = SaveGameConfigs.Icons.BossDropItems[BossName][i],
|
||
Type = ArchiveTable.ArchiveType.DropBossItems,
|
||
TextVal = string.format('%s之%s', BossName, Func(i))
|
||
}
|
||
table.insert(self.SaveGames, ItemData);
|
||
end
|
||
end
|
||
end
|
||
|
||
-- 初始化对象池
|
||
function WBP_SettleSave:InitObjectPool(InSize)
|
||
if InSize == nil then
|
||
InSize = self.InitCount
|
||
end
|
||
-- 先清空
|
||
self.ScrollBox_SaveItems:ClearChildren()
|
||
local ClassPath = UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/ChildWidgets/WBP_SettlementSaveItem.WBP_SettlementSaveItem_C')
|
||
local ItemClass = UE.LoadClass(ClassPath)
|
||
for i = 1, InSize do
|
||
local Item = UserWidget.NewWidgetObjectBP(UGCGameSystem.GameState, ItemClass)
|
||
-- 添加进去
|
||
self.ScrollBox_SaveItems:AddChild(Item)
|
||
-- 设置隐藏
|
||
Item:SetVisibility(ESlateVisibility.Collapsed)
|
||
end
|
||
end
|
||
|
||
return WBP_SettleSave; |