diff --git a/excel/Rune.xlsx b/excel/Rune.xlsx index 73fe200..7198895 100644 Binary files a/excel/Rune.xlsx and b/excel/Rune.xlsx differ diff --git a/excel/cha.xlsx b/excel/cha.xlsx index 2419450..bb9ab02 100644 Binary files a/excel/cha.xlsx and b/excel/cha.xlsx differ diff --git a/excel/item.xlsx b/excel/item.xlsx index 28081fa..86c23a9 100644 Binary files a/excel/item.xlsx and b/excel/item.xlsx differ diff --git a/excel/language.xlsx b/excel/language.xlsx index f2a2d9c..593768c 100644 Binary files a/excel/language.xlsx and b/excel/language.xlsx differ diff --git a/src/ReplicatedStorage/Base/UIWindow.luau b/src/ReplicatedStorage/Base/UIWindow.luau index 9db46c1..8510c96 100644 --- a/src/ReplicatedStorage/Base/UIWindow.luau +++ b/src/ReplicatedStorage/Base/UIWindow.luau @@ -70,7 +70,7 @@ function UIWindow:AutoInjectVariables() end if not target then - error("自动注入失败:未找到UI节点 " .. varName) + error("自动注入失败:未找到UI节点 "..self.UIRootName.." "..varName) end self.Variables[varName] = target diff --git a/src/ReplicatedStorage/Data/SignalEnum.luau b/src/ReplicatedStorage/Data/SignalEnum.luau index 92e1547..c5c5217 100644 --- a/src/ReplicatedStorage/Data/SignalEnum.luau +++ b/src/ReplicatedStorage/Data/SignalEnum.luau @@ -3,6 +3,7 @@ local SignalEnum = {} SignalEnum = { SHOW_ABILITY = "SHOW_ABILITY", CHALLENGE_LEVEL_END = "CHALLENGE_LEVEL_END", + SELECT_RUNE_INLAY_EQUIPMENT = "SELECT_RUNE_INLAY_EQUIPMENT", } return SignalEnum \ No newline at end of file diff --git a/src/ReplicatedStorage/Json/Attributes.json b/src/ReplicatedStorage/Json/Attributes.json index 2ad9f6e..1786872 100644 --- a/src/ReplicatedStorage/Json/Attributes.json +++ b/src/ReplicatedStorage/Json/Attributes.json @@ -29,5 +29,6 @@ {"id":52,"type":1,"specialType":null,"effectAttribute":"extraAttributeNumber","battleValue":[1,10],"iconId":28,"nameId":252}, {"id":53,"type":1,"specialType":null,"effectAttribute":"elementNumber","battleValue":[1,10],"iconId":29,"nameId":253}, {"id":54,"type":1,"specialType":null,"effectAttribute":"elementDefNumber","battleValue":[1,10],"iconId":30,"nameId":254}, -{"id":55,"type":1,"specialType":null,"effectAttribute":"gemNumber","battleValue":[1,10],"iconId":31,"nameId":255} +{"id":55,"type":1,"specialType":null,"effectAttribute":"gemNumber","battleValue":[1,10],"iconId":31,"nameId":255}, +{"id":56,"type":1,"specialType":null,"effectAttribute":"runeNumber","battleValue":[1,10],"iconId":31,"nameId":256} ] \ No newline at end of file diff --git a/src/ReplicatedStorage/Json/AttributesUpgrade.json b/src/ReplicatedStorage/Json/AttributesUpgrade.json index 5a73d9f..020bcfb 100644 --- a/src/ReplicatedStorage/Json/AttributesUpgrade.json +++ b/src/ReplicatedStorage/Json/AttributesUpgrade.json @@ -9,5 +9,5 @@ {"id":12,"type":2,"effectAttribute":"extraAttributeNumber","cost":[1,300,0],"lvAdd":[1,1],"battleValueLimit":[5,20],"maxLv":3}, {"id":13,"type":2,"effectAttribute":"elementNumber","cost":[1,300,0],"lvAdd":[1,1],"battleValueLimit":[5,20],"maxLv":3}, {"id":14,"type":2,"effectAttribute":"elementDefNumber","cost":[1,300,0],"lvAdd":[1,1],"battleValueLimit":[5,20],"maxLv":3}, -{"id":15,"type":2,"effectAttribute":"gemNumber","cost":[1,300,0],"lvAdd":[1,1],"battleValueLimit":[5,20],"maxLv":3} +{"id":15,"type":2,"effectAttribute":"runeNumber","cost":[1,300,0],"lvAdd":[1,1],"battleValueLimit":[5,20],"maxLv":4} ] \ No newline at end of file diff --git a/src/ReplicatedStorage/Json/ItemProp.json b/src/ReplicatedStorage/Json/ItemProp.json index c5bd145..19221b5 100644 --- a/src/ReplicatedStorage/Json/ItemProp.json +++ b/src/ReplicatedStorage/Json/ItemProp.json @@ -96,5 +96,7 @@ {"id":50013,"type":3,"typeArgs":[],"quality":14,"iconId":14,"nameId":50013,"textId":70013,"buyPrice":[],"sellPrice":[],"use":[],"showPackage":null}, {"id":50014,"type":3,"typeArgs":[],"quality":15,"iconId":15,"nameId":50014,"textId":70014,"buyPrice":[],"sellPrice":[],"use":[],"showPackage":null}, {"id":50015,"type":3,"typeArgs":[],"quality":16,"iconId":16,"nameId":50015,"textId":70015,"buyPrice":[],"sellPrice":[],"use":[],"showPackage":null}, -{"id":60000,"type":7,"typeArgs":[],"quality":1,"iconId":60000,"nameId":60000,"textId":80000,"buyPrice":[],"sellPrice":[],"use":[],"showPackage":null} +{"id":60000,"type":7,"typeArgs":[],"quality":4,"iconId":60000,"nameId":60000,"textId":80000,"buyPrice":[],"sellPrice":[],"use":[],"showPackage":null}, +{"id":61000,"type":7,"typeArgs":[],"quality":5,"iconId":61000,"nameId":61000,"textId":61000,"buyPrice":[],"sellPrice":[],"use":[],"showPackage":null}, +{"id":62000,"type":7,"typeArgs":[],"quality":6,"iconId":62000,"nameId":62000,"textId":62000,"buyPrice":[],"sellPrice":[],"use":[],"showPackage":null} ] \ No newline at end of file diff --git a/src/ReplicatedStorage/Json/Language_En_US.json b/src/ReplicatedStorage/Json/Language_En_US.json index 7d76d47..64793e2 100644 --- a/src/ReplicatedStorage/Json/Language_En_US.json +++ b/src/ReplicatedStorage/Json/Language_En_US.json @@ -45,6 +45,7 @@ {"id":1011,"text":"祝福:出现{0}属性的概率+{1}"}, {"id":1012,"text":"祝福:出现{0}技能的概率+{1}"}, {"id":1013,"text":"祝福:出现{0}晶石的概率+{1}"}, +{"id":1200,"text":"该装备无符文槽位"}, {"id":20000,"text":"普攻"}, {"id":20001,"text":"剑气"}, {"id":40000,"text":"测试装备1"}, @@ -62,5 +63,8 @@ {"id":40012,"text":"测试装备13"}, {"id":40013,"text":"测试装备14"}, {"id":40014,"text":"测试装备15"}, -{"id":40015,"text":"测试装备16"} +{"id":40015,"text":"测试装备16"}, +{"id":60000,"text":"火焰伤害符文"}, +{"id":61000,"text":"冰棺符文"}, +{"id":62000,"text":"测试符文"} ] \ No newline at end of file diff --git a/src/ReplicatedStorage/Json/Language_Zh_CN.json b/src/ReplicatedStorage/Json/Language_Zh_CN.json index 7d76d47..64793e2 100644 --- a/src/ReplicatedStorage/Json/Language_Zh_CN.json +++ b/src/ReplicatedStorage/Json/Language_Zh_CN.json @@ -45,6 +45,7 @@ {"id":1011,"text":"祝福:出现{0}属性的概率+{1}"}, {"id":1012,"text":"祝福:出现{0}技能的概率+{1}"}, {"id":1013,"text":"祝福:出现{0}晶石的概率+{1}"}, +{"id":1200,"text":"该装备无符文槽位"}, {"id":20000,"text":"普攻"}, {"id":20001,"text":"剑气"}, {"id":40000,"text":"测试装备1"}, @@ -62,5 +63,8 @@ {"id":40012,"text":"测试装备13"}, {"id":40013,"text":"测试装备14"}, {"id":40014,"text":"测试装备15"}, -{"id":40015,"text":"测试装备16"} +{"id":40015,"text":"测试装备16"}, +{"id":60000,"text":"火焰伤害符文"}, +{"id":61000,"text":"冰棺符文"}, +{"id":62000,"text":"测试符文"} ] \ No newline at end of file diff --git a/src/ReplicatedStorage/Json/Rune.json b/src/ReplicatedStorage/Json/Rune.json index 2da4fae..320bce9 100644 --- a/src/ReplicatedStorage/Json/Rune.json +++ b/src/ReplicatedStorage/Json/Rune.json @@ -1,3 +1,5 @@ [ -{"id":60000,"type":1,"icon":1,"nameId":20000,"behaviourName":"Attack","recycle":[]} +{"id":60000,"quality":1,"type":1,"icon":1,"nameId":60000,"runeName":"RuneFireDamage","behaviorName":null,"recycle":[],"isInPool":1}, +{"id":61000,"quality":2,"type":1,"icon":1,"nameId":61000,"runeName":"RuneIceCoffin","behaviorName":"IceCoffin","recycle":[],"isInPool":1}, +{"id":62000,"quality":3,"type":1,"icon":1,"nameId":62000,"runeName":null,"behaviorName":null,"recycle":[],"isInPool":1} ] \ No newline at end of file diff --git a/src/ReplicatedStorage/Tools/Utils.luau b/src/ReplicatedStorage/Tools/Utils.luau index 4ed273f..4798de8 100644 --- a/src/ReplicatedStorage/Tools/Utils.luau +++ b/src/ReplicatedStorage/Tools/Utils.luau @@ -50,6 +50,16 @@ function Utils:GenUniqueId(t: table) return min_id end + +function Utils:GenUniqueIdString(t: table) + local min_id = 1 + while t[tostring(min_id)] ~= nil do + min_id = min_id + 1 + end + return tostring(min_id) +end + + function Utils:GenUniqueIdPlayerAI(LastTime: number, Counter: number) local now = os.time() -- 或 tick(),精度更高 if now ~= LastTime then diff --git a/src/ServerStorage/Proxy/ItemProxy.luau b/src/ServerStorage/Proxy/ItemProxy.luau index 971daad..ea20f23 100644 --- a/src/ServerStorage/Proxy/ItemProxy.luau +++ b/src/ServerStorage/Proxy/ItemProxy.luau @@ -28,6 +28,9 @@ function ItemProxy:AddItem(Player: Player, ItemId: number, ItemCount: number) elseif ItemData.type == 3 then local BookProxy = require(script.Parent.BookProxy) BookProxy:UnlockBook(Player, ItemId - 10000) + elseif ItemData.type == 7 then + local RuneProxy = require(script.Parent.RuneProxy) + RuneProxy:AddRune(Player, ItemId) else PlayerInfoProxy:ChangeItemCount(Player, ItemId, ItemCount) end diff --git a/src/ServerStorage/Proxy/RuneProxy/init.luau b/src/ServerStorage/Proxy/RuneProxy/init.luau index d7a5596..e0d43f2 100644 --- a/src/ServerStorage/Proxy/RuneProxy/init.luau +++ b/src/ServerStorage/Proxy/RuneProxy/init.luau @@ -17,6 +17,8 @@ local JsonRune = require(ReplicatedStorage.Json.Rune) --> Events local RE_PlayerTip = ReplicatedStorage.Events.RE_PlayerTip local RE_RuneInlay = ReplicatedStorage.Events.RE_RuneInlay +local RE_RuneCombine = ReplicatedStorage.Events.RE_RuneCombine + --> SubFunctions local RuneCalculation = require(script.RuneCalculation) @@ -65,7 +67,7 @@ function RuneProxy:AddRune(Player: Player, RuneId: number) local RuneData = Utils:GetIdDataFromJson(JsonRune, RuneId) if not RuneData then return end - local UniqueId = Utils:GenUniqueId(ArchiveProxy.pData[Player.UserId][STORE_NAME]) + local UniqueId = Utils:GenUniqueIdString(ArchiveProxy.pData[Player.UserId][STORE_NAME]) -- 配置表内容 local ResultData = {} for key, value in pairs(RuneData) do @@ -86,11 +88,22 @@ function RuneProxy:AddRune(Player: Player, RuneId: number) end -- 合成符文 -function RuneProxy:CombineRune(Player: Player, RuneData: table) +function RuneProxy:CombineRune(Player: Player, RuneIds: table) local pData = Utils:GetPlayerDataFolder(Player) if not pData then return end - if #RuneData ~= 3 then warn('符文合成数量不正确', Player.Name, RuneData) return end + if #RuneIds ~= 3 then warn('符文合成数量不正确', Player.Name, RuneIds) return end + + -- 查看符文id是否相同,相同则返回 + if RuneIds[1] == RuneIds[2] and RuneIds[2] == RuneIds[3] then warn('符文id相同', Player.Name, RuneIds) return end + + local RuneData = {} + for _, RuneId in RuneIds do + RuneId = tostring(RuneId) + local RuneInstance = GetPlayerRuneFolder(Player):FindFirstChild(RuneId) + if not RuneInstance then warn('符文实例不存在', Player.Name, RuneId) return end + table.insert(RuneData, RuneInstance:GetAttributes()) + end -- 获取合成符文数据 local sameQuality = true @@ -110,20 +123,24 @@ function RuneProxy:CombineRune(Player: Player, RuneData: table) -- 添加合成符文 local newRuneId = self:GetRandomRuneIdByQuality(higherQuality) if not newRuneId then warn('合成符文不存在', Player.Name, RuneData) return end - self:AddRune(Player, newRuneId) + local newRuneData, newRuneInstance = self:AddRune(Player, newRuneId) -- 销毁符文 for _, rune in RuneData do self:DestroyRune(Player, rune.id) end + + -- 发送给前端结果信息 + RE_RuneCombine:FireClient(Player, newRuneData.id, newRuneData.orgId) end -- 销毁符文 function RuneProxy:DestroyRune(Player: Player, UniqueId: number) local pData = Utils:GetPlayerDataFolder(Player) if not pData then return end + UniqueId = tostring(UniqueId) -- 获取符文实例存储数据 - local UniqueData = ArchiveProxy.pData[Player.UserId][UniqueId] - if not UniqueData then return end + local UniqueData = ArchiveProxy.pData[Player.UserId][STORE_NAME][UniqueId] + if not UniqueData then warn('UniqueData不存在', Player.Name, UniqueId) return end -- 检查是否有符文实例 local RuneInstance = GetPlayerRuneFolder(Player):FindFirstChild(UniqueId) @@ -131,7 +148,7 @@ function RuneProxy:DestroyRune(Player: Player, UniqueId: number) -- 销毁 RuneInstance:Destroy() - ArchiveProxy.pData[Player.UserId][UniqueId] = nil + ArchiveProxy.pData[Player.UserId][STORE_NAME][UniqueId] = nil end -- 穿戴符文 @@ -292,4 +309,8 @@ RE_RuneInlay.OnServerEvent:Connect(function(Player: Player, RuneUniqueId: number RuneProxy:WearRune(Player, RuneUniqueId, EquipmentUniqueId) end) +RE_RuneCombine.OnServerEvent:Connect(function(Player: Player, RuneData: table) + RuneProxy:CombineRune(Player, RuneData) +end) + return RuneProxy \ No newline at end of file diff --git a/src/StarterPlayerScripts/ClientMain/Helper.luau b/src/StarterPlayerScripts/ClientMain/Helper.luau index a4b0056..0812cca 100644 --- a/src/StarterPlayerScripts/ClientMain/Helper.luau +++ b/src/StarterPlayerScripts/ClientMain/Helper.luau @@ -22,6 +22,9 @@ UserInputService.InputBegan:Connect(function(input, gameProcessed) elseif input.KeyCode == Enum.KeyCode.K then -- RE_UpgradeAttributes:FireServer(1) RE_PlayerHelper:FireServer("AddItem", {2, 1000}) + RE_PlayerHelper:FireServer("AddItem", {60000, 1}) + RE_PlayerHelper:FireServer("AddItem", {61000, 1}) + RE_PlayerHelper:FireServer("AddItem", {62000, 1}) elseif input.KeyCode == Enum.KeyCode.L then RE_UpgradeAttributes:FireServer(2) elseif input.KeyCode == Enum.KeyCode.M then diff --git a/src/StarterPlayerScripts/UI/Common/EquipmentModelDetail.luau b/src/StarterPlayerScripts/UI/Common/EquipmentModelDetail.luau new file mode 100644 index 0000000..790813c --- /dev/null +++ b/src/StarterPlayerScripts/UI/Common/EquipmentModelDetail.luau @@ -0,0 +1,42 @@ +local EquipmentModelDetail = {} + +--> Services +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +--> Json +local JsonEquipment = require(ReplicatedStorage.Json.Equipment) + +--> Components +local Utils = require(ReplicatedStorage.Tools.Utils) + +--> Prefabs +local FolderEquipmentPrefabs = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") + +function EquipmentModelDetail:ShowDetail(prefab: Instance, orgId: number, isRotation: boolean?) + -- 模型展示 + local equipmentData = Utils:GetIdDataFromJson(JsonEquipment, orgId) + local part = FolderEquipmentPrefabs:FindFirstChild(equipmentData.modelName):Clone() + part.Handle.Position = Vector3.new(0, 0, 0) + part.Handle.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), 0, 0) + part.Parent = prefab + + -- 相机 + local viewportCamera = Instance.new("Camera") + prefab.CurrentCamera = viewportCamera + viewportCamera.Parent = prefab + viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 6), part.Handle.Position) + + local taskRotation = nil + if isRotation then + taskRotation = task.spawn(function() + while true do + part.Handle.CFrame = part.Handle.CFrame * CFrame.Angles(0, 0, 0.01) + task.wait(0.01) + end + end) + end + + return taskRotation, part, viewportCamera +end + +return EquipmentModelDetail \ No newline at end of file diff --git a/src/StarterPlayerScripts/UI/Windows/ChaWindow/PackageShow.luau b/src/StarterPlayerScripts/UI/Windows/ChaWindow/PackageShow.luau index 874f2cc..8be550f 100644 --- a/src/StarterPlayerScripts/UI/Windows/ChaWindow/PackageShow.luau +++ b/src/StarterPlayerScripts/UI/Windows/ChaWindow/PackageShow.luau @@ -10,6 +10,13 @@ local JsonItemProp = require(ReplicatedStorage.Json.ItemProp) local FolderEquipment = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") +--> Variables +local LocalPlayer = game.Players.LocalPlayer + +--> Components +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + function PackageShow:Init(data: table) local self = {} self.Data = data @@ -34,20 +41,8 @@ function PackageShow:Refresh() self.Variables._tmpQuality.Text = Localization:GetColoredEquipmentQualityDesc(self.Data.quality) self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId) - local equipmentData = Utils:GetIdDataFromJson(JsonEquipment, self.Data.orgId) - -- 模型 - local part = FolderEquipment:FindFirstChild(equipmentData.modelName):Clone() - part.Handle.Position = Vector3.new(0, 0, 0) - part.Handle.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), 0, 0) - part.Parent = self.Variables["_imgView"] - self.Prefab = part - - -- 相机 - local viewportCamera = Instance.new("Camera") - self.Variables["_imgView"].CurrentCamera = viewportCamera - viewportCamera.Parent = self.Variables["_imgView"] - viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 6), part.Handle.Position) - self.ViewCamera = viewportCamera + -- 模型展示 + EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], self.Data.orgId, false) end function PackageShow:OnInitFinish() diff --git a/src/StarterPlayerScripts/UI/Windows/ChaWindow/WearingShow.luau b/src/StarterPlayerScripts/UI/Windows/ChaWindow/WearingShow.luau index 0367b0b..a02bda6 100644 --- a/src/StarterPlayerScripts/UI/Windows/ChaWindow/WearingShow.luau +++ b/src/StarterPlayerScripts/UI/Windows/ChaWindow/WearingShow.luau @@ -10,6 +10,11 @@ local JsonItemProp = require(ReplicatedStorage.Json.ItemProp) local FolderEquipment = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") +local LocalPlayer = game.Players.LocalPlayer + +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + function WearingShow:Init(data: table) local self = {} self.Data = data @@ -43,21 +48,8 @@ function WearingShow:Refresh() self.Variables._tmpQuality.Text = Localization:GetColoredEquipmentQualityDesc(self.Data.quality) self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId) - - local equipmentData = Utils:GetIdDataFromJson(JsonEquipment, self.Data.orgId) - -- 模型 - local part = FolderEquipment:FindFirstChild(equipmentData.modelName):Clone() - part.Handle.Position = Vector3.new(0, 0, 0) - part.Handle.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), 0, 0) - part.Parent = self.Variables["_imgView"] - self.Prefab = part - - -- 相机 - local viewportCamera = Instance.new("Camera") - self.Variables["_imgView"].CurrentCamera = viewportCamera - viewportCamera.Parent = self.Variables["_imgView"] - viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 6), part.Handle.Position) - self.ViewCamera = viewportCamera + -- 模型展示 + EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], self.Data.orgId, false) end end diff --git a/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/PackageShow.luau b/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/PackageShow.luau new file mode 100644 index 0000000..6074749 --- /dev/null +++ b/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/PackageShow.luau @@ -0,0 +1,54 @@ +local PackageShow = {} +PackageShow.__index = PackageShow + +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +local Utils = require(ReplicatedStorage.Tools.Utils) +local Localization = require(ReplicatedStorage.Tools.Localization) +local JsonRune = require(ReplicatedStorage.Json.Rune) +local JsonItemProp = require(ReplicatedStorage.Json.ItemProp) + +function PackageShow:Init(data: table) + local self = {} + self.Data = data + self.Variables = { + ["_btnClick"] = 0, + ["_imgIcon"] = 0, + ["_tmpName"] = 0, + ["_imgView"] = 0, + } + self.Connections = {} + + setmetatable(self, PackageShow) + + return self +end + +function PackageShow:Refresh() + local itemData = Utils:GetIdDataFromJson(JsonItemProp, self.Data.orgId) + local runeData = Utils:GetIdDataFromJson(JsonRune, self.Data.orgId) + + self.Variables._imgIcon.Image = Localization:GetImageData(runeData.icon) + self.Variables._imgIcon.BackgroundColor3 = Localization:GetRuneQualityBgColor(runeData.quality) + self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId) +end + +function PackageShow:OnInitFinish() + local con = self.Variables._btnClick.MouseButton1Click:Connect(function() + if self.Data == {} then + -- TODO: 之后做提示弹窗 + else + self.TopUI:WearRefresh(self.Data) + end + end) + table.insert(self.Connections, con) +end + +function PackageShow:Destroy() + for k, v in pairs(self) do + self[k] = nil + end + self = nil +end + +return PackageShow \ No newline at end of file diff --git a/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/WearingShow.luau b/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/WearingShow.luau new file mode 100644 index 0000000..6883c94 --- /dev/null +++ b/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/WearingShow.luau @@ -0,0 +1,60 @@ +local WearingShow = {} +WearingShow.__index = WearingShow + +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +local Utils = require(ReplicatedStorage.Tools.Utils) +local Localization = require(ReplicatedStorage.Tools.Localization) +local JsonRune = require(ReplicatedStorage.Json.Rune) +local JsonItemProp = require(ReplicatedStorage.Json.ItemProp) + +function WearingShow:Init(data: table) + local self = {} + self.Data = data + self.Variables = { + ["_btnClick"] = 0, + ["_imgIcon"] = 0, + ["_tmpName"] = 0, + ["_imgView"] = 0, + } + self.Connections = {} + + setmetatable(self, WearingShow) + + return self +end + +function WearingShow:Refresh() + if self.Data.instance then + local itemData = Utils:GetIdDataFromJson(JsonItemProp, self.Data.orgId) + local runeData = Utils:GetIdDataFromJson(JsonRune, self.Data.orgId) + + self.Variables._imgIcon.Image = Localization:GetImageData(runeData.icon) + self.Variables._imgIcon.BackgroundColor3 = Localization:GetRuneQualityBgColor(runeData.quality) + self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId) + self.Variables._imgIcon.Visible = true + else + self.Variables._imgIcon.Image = "" + self.Variables._tmpName.Text = "" + self.Variables._imgIcon.Visible = false + end +end + +function WearingShow:OnInitFinish() + local con = self.Variables._btnClick.MouseButton1Click:Connect(function() + if self.Data.instance then + self.TopUI:UnwearRefresh(self.Data) + end + end) + table.insert(self.Connections, con) +end + +function WearingShow:Destroy() + print("Destroy WearingShow") + for k, v in pairs(self) do + self[k] = nil + end + self = nil +end + +return WearingShow \ No newline at end of file diff --git a/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/init.luau b/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/init.luau new file mode 100644 index 0000000..74f51e1 --- /dev/null +++ b/src/StarterPlayerScripts/UI/Windows/CombineRuneWindow/init.luau @@ -0,0 +1,300 @@ +--> Services +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +--> Dependencies +local UIWindow = require(ReplicatedStorage.Base.UIWindow) +local UIEnums = require(ReplicatedStorage.Base.UIEnums) + +--> Components +local WearingShow = require(script.WearingShow) +local PackageShow = require(script.PackageShow) +--> Dependencies +local Utils = require(ReplicatedStorage.Tools.Utils) +local Localization = require(ReplicatedStorage.Tools.Localization) + +--> Json +local JsonAttributesUpgrade = require(ReplicatedStorage.Json.AttributesUpgrade) +local JsonRune = require(ReplicatedStorage.Json.Rune) +local JsonEquipment = require(ReplicatedStorage.Json.Equipment) + +--> Events +local RE_RuneCombine = ReplicatedStorage.Events.RE_RuneCombine + +--> Variables +local LocalPlayer = game.Players.LocalPlayer + +--> Prefabs +local FolderEquipmentPrefabs = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") +local EquipmentFolder = Utils:WaitPlayerDataFolder(LocalPlayer):WaitForChild("Equipment") +local DataFolder = Utils:WaitPlayerDataFolder(LocalPlayer):WaitForChild("Rune") + +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + +-------------------------------------------------------------------------------- + +local CombineRuneWindow = {} +CombineRuneWindow.__index = CombineRuneWindow +setmetatable(CombineRuneWindow, {__index = UIWindow}) + +local MAX_RUNE_COMBINE_NUMBER = 3 + +function CombineRuneWindow:Init(UIManager: table, Data: table?) + local self = UIWindow:Init(UIManager, Data) + setmetatable(self, CombineRuneWindow) + self.Variables = { + ["_goRunePanel"] = 0, + ["__listRunePackage"] = 0, + ["__listRuneCombine"] = 0, + ["_tmpCombatValue"] = 0, + ["_imgIcon"] = 0, + + ["_bgNewSelectFrame"] = 0, + ["_imgNewRune"] = 0, + ["_tmpNewRuneName"] = 0, + + ["_btnClose"] = 0, + ["_btnBgClose"] = 0, + ["_btnCombineRune"] = 0, + } + self.UIRootName = "ui_w_combine_rune" + self.UIParentName = UIEnums.UIParent.UIRoot + + return self +end + +function CombineRuneWindow:ShowCombineRuneResult(uniqueId: number, orgId: number) + if uniqueId then + local runeData = Utils:GetIdDataFromJson(JsonRune, orgId) + self.Variables["_tmpNewRuneName"].Text = Localization:GetLanguageData(runeData.nameId) + self.Variables["_imgNewRune"].Image = Localization:GetImageData(runeData.icon) + self.Variables["_imgNewRune"].BackgroundColor3 = Localization:GetRuneQualityBgColor(runeData.quality) + self.Variables["_imgNewRune"].Transparency = 0 + else + self.NowSelectRuneId = nil + self.Variables["_tmpNewRuneName"].Text = "" + self.Variables["_imgNewRune"].Image = "" + self.Variables["_imgNewRune"].BackgroundColor3 = Color3.fromRGB(0, 0, 0) + self.Variables["_imgNewRune"].Transparency = 1 + end +end + +function CombineRuneWindow:WearRefresh(data: table) + -- 清除之前的显示内容 + self:ShowCombineRuneResult() + + -- 选择符文排查 + local newSlot = self:GetEmptySlot() + if newSlot == 0 then warn("没有空槽位") return end + local isExist, isNotSameQuality = false, false + for i = 1, MAX_RUNE_COMBINE_NUMBER do + if self.Data.SelectRune["slot"..i].instance == data.instance then + isExist = true + break + elseif self.Data.SelectRune["slot"..i].quality then + if self.Data.SelectRune["slot"..i].quality ~= data.quality then + isNotSameQuality = true + break + end + end + end + if isExist then warn("槽位上已经存在该符文") return end + if isNotSameQuality then warn("符文品质不同无法穿戴") return end + + -- 是否为相同品质且品质<3的符文 + if data.quality >= 3 then warn("品质大于等于3的符文不能穿戴") return end + self.Variables["__listRuneCombine"]:RemoveData("slot"..newSlot) + self.Variables["__listRunePackage"]:RemoveData(tostring(data.id)) + + data.wearingSlot = newSlot + self.Variables["__listRuneCombine"]:AddData("slot"..newSlot, data) +end + +function CombineRuneWindow:UnwearRefresh(data: table) + local oldSlot = data.wearingSlot + self.Variables["__listRuneCombine"]:RemoveData("slot"..oldSlot) + self.Variables["__listRunePackage"]:AddData(tostring(data.id), data) + self.Data.SelectRune["slot"..oldSlot] = { + wearingSlot = oldSlot, + } + self.Variables["__listRuneCombine"]:AddData("slot"..oldSlot, self.Data.SelectRune["slot"..oldSlot]) +end + +function CombineRuneWindow:CombineRune() + local combineRuneIds = {} + for i = 1, MAX_RUNE_COMBINE_NUMBER do + if not self.Data.SelectRune["slot"..i].instance then + warn("符文槽位"..i.."为空") + return + else + table.insert(combineRuneIds, self.Data.SelectRune["slot"..i].id) + end + end + RE_RuneCombine:FireServer(combineRuneIds) +end + +function CombineRuneWindow:GetEmptySlot() + for i = 1, MAX_RUNE_COMBINE_NUMBER do + if self.Data.SelectRune["slot"..i].instance == nil then + return i + end + end + return 0 +end + +function CombineRuneWindow:AddInstanceData(configInstance: Instance, Data: table?, isSelect: boolean?) + local data = self.Data + if Data then data = Data end + local attributes = configInstance:GetAttributes() + + -- 归类是否是穿戴的装备 + local parentName, secondName = "PackageRune", configInstance.Name + if attributes.wearing == self.ShowEquipmentId then + parentName = "SelectRune" + secondName = "slot"..attributes.wearingSlot + end + if isSelect then + parentName = "SelectRune" + -- 是否有空槽位判断 + local notHasEmptySlot = true + for i = 1, MAX_RUNE_COMBINE_NUMBER do + if self.Data.SelectRune["slot"..i].instance == nil then + notHasEmptySlot = false + secondName = "slot"..i + break + end + end + if notHasEmptySlot then warn("没有空槽位") return end + end + data[parentName][secondName] = {} + + for attributeKey, attributeValue in attributes do + data[parentName][secondName][attributeKey] = attributeValue + end + data[parentName][secondName].instance = configInstance + return data[parentName][secondName], parentName +end + +function CombineRuneWindow:RemoveInstanceData(configInstance: Instance, Data: table?) + for key, data in pairs(self.Data.SelectRune) do + if data.instance == configInstance then + return tostring(key), "SelectRune" + end + end + for key, data in pairs(self.Data.PackageRune) do + if data.instance == configInstance then + return tostring(key), "PackageRune" + end + end + return nil +end + +function CombineRuneWindow:CleanSelectData() + for i = 1, MAX_RUNE_COMBINE_NUMBER do + self.Data.SelectRune["slot" .. i] = { + wearingSlot = i, + wearing = 0, + } + end +end + +function CombineRuneWindow:ShowWearingSlot() + -- 清除旧数据 + if self.Data then + if self.Data.SelectRune then + self.Data.SelectRune = nil + end + if self.Data.PackageRune then + self.Data.PackageRune = nil + end + end + self.Data = { + SelectRune = {}, + PackageRune = {}, + } + + -- 添加符文数据 + for _, child in DataFolder:GetChildren() do + self:AddInstanceData(child, self.Data) + end + -- 补充空槽位 + for i = 1, MAX_RUNE_COMBINE_NUMBER do + local isExist = false + for k, data in pairs(self.Data.SelectRune) do + if data.wearingSlot == 0 and data.wearing == 0 then + isExist = true + break + end + end + if not isExist then + self.Data.SelectRune["slot" .. i] = { + wearingSlot = i, + wearing = 0, + } + end + end + + self:SetData(self.Data) + self.Variables["__listRunePackage"]:SetData(self.Data.PackageRune) + self.Variables["__listRuneCombine"]:SetData(self.Data.SelectRune) +end + +function CombineRuneWindow:OnOpenWindow() + UIWindow.OnOpenWindow(self) + self.Variables["__listRunePackage"]:AddComponent(PackageShow) + self.Variables["__listRuneCombine"]:AddComponent(WearingShow) + + local bgCloseCon = self.Variables["_btnBgClose"].Activated:Connect(function() + self.UIManager:CloseWindow(script.Name) + end) + local closeCon = self.Variables["_btnClose"].Activated:Connect(function() + self.UIManager:CloseWindow(script.Name) + end) + + table.insert(self.Connections, bgCloseCon) + table.insert(self.Connections, closeCon) + + self:ShowWearingSlot() + + local addCon = DataFolder.ChildAdded:Connect(function(child) + local data, parentName = self:AddInstanceData(child, self.Data) + if parentName == "SelectRune" then + self.Variables["__listRuneCombine"]:AddData("slot"..data.wearingSlot, data) + else + self.Variables["__listRunePackage"]:AddData(child.Name, data) + end + end) + + local removeCon = DataFolder.ChildRemoved:Connect(function(child) + -- TODO: 这里清除逻辑不清晰,之后优化 + local key, parentName = self:RemoveInstanceData(child, self.Data) + if parentName == "SelectRune" then + local removeIndex = self.Variables["__listRuneCombine"]:RemoveData(key) + else + local removeIndex = self.Variables["__listRunePackage"]:RemoveData(key) + end + end) + + table.insert(self.Connections, addCon) + table.insert(self.Connections, removeCon) + + self.Variables["__listRuneCombine"]:SetLayoutOrder("wearingSlot") + + local combineCon = self.Variables["_btnCombineRune"].Activated:Connect(function() + self:CombineRune() + end) + table.insert(self.Connections, combineCon) + + local combineResultCon = RE_RuneCombine.OnClientEvent:Connect(function(uniqueId, orgId) + self:ShowCombineRuneResult(uniqueId, orgId) + end) + table.insert(self.Connections, combineResultCon) +end + +function CombineRuneWindow:OnCloseWindow() + UIWindow.OnCloseWindow(self) +end + + + +return CombineRuneWindow \ No newline at end of file diff --git a/src/StarterPlayerScripts/UI/Windows/CreateWindow/WeaponItem.luau b/src/StarterPlayerScripts/UI/Windows/CreateWindow/WeaponItem.luau index f5ea701..24e0933 100644 --- a/src/StarterPlayerScripts/UI/Windows/CreateWindow/WeaponItem.luau +++ b/src/StarterPlayerScripts/UI/Windows/CreateWindow/WeaponItem.luau @@ -12,6 +12,10 @@ local JsonEquipment = require(ReplicatedStorage.Json.Equipment) local FolderEquipment = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") +local LocalPlayer = game.Players.LocalPlayer +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + function WeaponItem:Init(data: table) local self = {} self.Data = data @@ -40,21 +44,10 @@ function WeaponItem:Refresh() self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId) self.Variables._tmpQuality.Text = Localization:GetColoredEquipmentQualityDesc(self.Data.Quality) - local equipmentData = Utils:GetIdDataFromJson(JsonEquipment, self.Data.OrgId) - -- 模型 - local part = FolderEquipment:FindFirstChild(equipmentData.modelName):Clone() - part.Handle.Position = Vector3.new(0, 0, 0) - part.Handle.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), 0, 0) - part.Parent = self.Variables["_imgView"] + -- 模型展示 + local taskRotation, part = EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], self.Data.OrgId, false) self.Prefab = part - -- 相机 - local viewportCamera = Instance.new("Camera") - self.Variables["_imgView"].CurrentCamera = viewportCamera - viewportCamera.Parent = self.Variables["_imgView"] - viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 6), part.Handle.Position) - self.ViewCamera = viewportCamera - -- 如果图鉴没有,就设置成黑色的 if self.Data.Timestamp == 0 then part.Handle.Mesh.TextureId = Localization:GetBlackTexture() diff --git a/src/StarterPlayerScripts/UI/Windows/CreateWindow/init.luau b/src/StarterPlayerScripts/UI/Windows/CreateWindow/init.luau index 067ef97..5ec7f59 100644 --- a/src/StarterPlayerScripts/UI/Windows/CreateWindow/init.luau +++ b/src/StarterPlayerScripts/UI/Windows/CreateWindow/init.luau @@ -22,6 +22,10 @@ local RE_Forge = ReplicatedStorage.Events.RE_Forge local LocalPlayer = game.Players.LocalPlayer +--> Components +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + -------------------------------------------------------------------------------- @@ -70,6 +74,7 @@ function CreateWindow:Init(UIManager: table, Data: table?) -- 详情面板 ["_btnCreate"] = 0, ["_btnMult"] = 0, + ["_imgView"] = 0, ["_imgIcon"] = 0, ["_tmpName"] = 0, ["_tmpQuality"] = 0, @@ -84,6 +89,9 @@ function CreateWindow:Init(UIManager: table, Data: table?) self.UIRootName = "ui_w_create" self.UIParentName = UIEnums.UIParent.UIRoot + self.OldPrefab = nil + self.OldViewportCamera = nil + self.LastActiveItem = nil return self @@ -94,10 +102,21 @@ function CreateWindow:ShowDetailInfo(data: table?) self.Variables["_imgIcon"].Image = Localization:GetImageData(Utils:GetIdDataFromJson(JsonItemProp, data.OrgId).iconId) self.Variables["_tmpName"].Text = Localization:GetLanguageData(Utils:GetIdDataFromJson(JsonItemProp, data.OrgId).nameId) self.Variables["_tmpQuality"].Text = Localization:GetColoredEquipmentQualityDesc(data.Quality) + + local taskRotation, part, viewportCamera = EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], data.OrgId, false) + self.OldPrefab = part + self.OldViewportCamera = viewportCamera else self.Variables["_imgIcon"].Image = "" self.Variables["_tmpName"].Text = "" self.Variables["_tmpQuality"].Text = "" + + if self.OldPrefab then + self.OldPrefab:Destroy() + self.OldViewportCamera:Destroy() + self.OldPrefab = nil + self.OldViewportCamera = nil + end end end diff --git a/src/StarterPlayerScripts/UI/Windows/EquipmentDetailWindow/init.luau b/src/StarterPlayerScripts/UI/Windows/EquipmentDetailWindow/init.luau index be2a9f7..0a0950b 100644 --- a/src/StarterPlayerScripts/UI/Windows/EquipmentDetailWindow/init.luau +++ b/src/StarterPlayerScripts/UI/Windows/EquipmentDetailWindow/init.luau @@ -27,6 +27,7 @@ local LocalPlayer = game.Players.LocalPlayer --> Common local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") local SpecialShow = require(CommonFolder:WaitForChild("SpecialShow")) +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) local FolderEquipment = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") @@ -203,21 +204,12 @@ function EquipmentDetailWindow:OnOpenWindow() self.Variables["_tmpQuality"].Text = Localization:GetColoredEquipmentQualityDesc(equipmentInstance:GetAttribute("quality")) self.Variables["_tmpCombatValue"].Text = 0 - local equipmentData = Utils:GetIdDataFromJson(JsonEquipment, equipmentInstance:GetAttribute("orgId")) - -- 模型 - local part = FolderEquipment:FindFirstChild(equipmentData.modelName):Clone() - part.Handle.Position = Vector3.new(0, 0, 0) - part.Handle.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), 0, 0) - part.Parent = self.Variables["_imgView"] + local taskRotation, part, viewportCamera = EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], equipmentInstance:GetAttribute("orgId"), false) + self.TaskRotation = taskRotation self.Prefab = part - - -- 相机 - local viewportCamera = Instance.new("Camera") - self.Variables["_imgView"].CurrentCamera = viewportCamera - viewportCamera.Parent = self.Variables["_imgView"] - viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 6), part.Handle.Position) self.ViewCamera = viewportCamera + -- 穿戴状态按钮显示 self.Variables["_btnUnwear"].Visible = self.Data.base.wearing ~= 0 diff --git a/src/StarterPlayerScripts/UI/Windows/GetEquipmentsWindow/EquipmentShow.luau b/src/StarterPlayerScripts/UI/Windows/GetEquipmentsWindow/EquipmentShow.luau index 511dd7a..72a10e5 100644 --- a/src/StarterPlayerScripts/UI/Windows/GetEquipmentsWindow/EquipmentShow.luau +++ b/src/StarterPlayerScripts/UI/Windows/GetEquipmentsWindow/EquipmentShow.luau @@ -11,6 +11,10 @@ local JsonAttributes = require(ReplicatedStorage.Json.Attributes) local FolderEquipment = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") +local LocalPlayer = game.Players.LocalPlayer +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + function EquipmentShow:Init(data: table) local self = {} self.Data = data @@ -25,29 +29,11 @@ function EquipmentShow:Init(data: table) end function EquipmentShow:Refresh() - local equipmentData = Utils:GetIdDataFromJson(JsonEquipment, self.Data["orgId"]) - - -- 模型 - local part = FolderEquipment:FindFirstChild(equipmentData.modelName):Clone() - part.Handle.Position = Vector3.new(0, 0, 0) - part.Handle.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(90), 0, 0) - part.Parent = self.Variables["_imgView"] + local taskRotation, part, viewportCamera = EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], self.Data.orgId, true) + self.TaskRotation = taskRotation self.Prefab = part - - -- 相机 - local viewportCamera = Instance.new("Camera") - self.Variables["_imgView"].CurrentCamera = viewportCamera - viewportCamera.Parent = self.Variables["_imgView"] - viewportCamera.CFrame = CFrame.new(Vector3.new(0, 0, 6), part.Handle.Position) self.ViewCamera = viewportCamera - - -- 旋转 - self.taskRotation = task.spawn(function() - while true do - self.Prefab.Handle.CFrame = self.Prefab.Handle.CFrame * CFrame.Angles(0, 0, 0.01) - task.wait(0.01) - end - end) + print(taskRotation, part, viewportCamera) end function EquipmentShow:OnInitFinish() @@ -64,9 +50,10 @@ function EquipmentShow:Destroy() v:Disconnect() end end - if self.taskRotation then - task.cancel(self.taskRotation) - self.taskRotation = nil + + if self.TaskRotation then + task.cancel(self.TaskRotation) + self.TaskRotation = nil end for k, v in pairs(self) do self[k] = nil diff --git a/src/StarterPlayerScripts/UI/Windows/MainWindow/init.luau b/src/StarterPlayerScripts/UI/Windows/MainWindow/init.luau index c9207be..adfc700 100644 --- a/src/StarterPlayerScripts/UI/Windows/MainWindow/init.luau +++ b/src/StarterPlayerScripts/UI/Windows/MainWindow/init.luau @@ -88,6 +88,7 @@ function MainWindow:Init(UIManager: table, Data: table?) ["_btnStartChallenge"] = 0, ["_btnBlessing"] = 0, ["_btnRune"] = 0, + ["_btnRuneCombine"] = 0, -- 锻造条 ["_goForgeBar"] = 0, @@ -158,6 +159,9 @@ function MainWindow:OnOpenWindow() local runeCon = self.Variables["_btnRune"].Activated:Connect(function() self.UIManager:OpenWindow("RuneWindow") end) + local combineRuneCon = self.Variables["_btnRuneCombine"].Activated:Connect(function() + self.UIManager:OpenWindow("CombineRuneWindow") + end) table.insert(self.Connections, createCon) table.insert(self.Connections, chaCon) @@ -165,6 +169,7 @@ function MainWindow:OnOpenWindow() table.insert(self.Connections, startChallengeCon) table.insert(self.Connections, blessingCon) table.insert(self.Connections, runeCon) + table.insert(self.Connections, combineRuneCon) local challengeLevelEndCon = challengeLevelEndSignal:Connect(function(result: boolean) self.Variables["_btnStartChallenge"].Visible = true diff --git a/src/StarterPlayerScripts/UI/Windows/RuneWindow/PackageShow.luau b/src/StarterPlayerScripts/UI/Windows/RuneWindow/PackageShow.luau index 8007b7e..e621cc5 100644 --- a/src/StarterPlayerScripts/UI/Windows/RuneWindow/PackageShow.luau +++ b/src/StarterPlayerScripts/UI/Windows/RuneWindow/PackageShow.luau @@ -38,7 +38,7 @@ function PackageShow:OnInitFinish() if self.Data == {} then -- TODO: 之后做提示弹窗 else - self.TopUI:ShowDetailData(self.Data.id) + self.TopUI:ShowDetailData(self.Data.id, self.Data.orgId) end end) table.insert(self.Connections, con) diff --git a/src/StarterPlayerScripts/UI/Windows/RuneWindow/init.luau b/src/StarterPlayerScripts/UI/Windows/RuneWindow/init.luau index 49d4d7f..1d26773 100644 --- a/src/StarterPlayerScripts/UI/Windows/RuneWindow/init.luau +++ b/src/StarterPlayerScripts/UI/Windows/RuneWindow/init.luau @@ -8,22 +8,33 @@ local UIEnums = require(ReplicatedStorage.Base.UIEnums) --> Components local WearingShow = require(script.WearingShow) local PackageShow = require(script.PackageShow) - --> Dependencies local Utils = require(ReplicatedStorage.Tools.Utils) local Localization = require(ReplicatedStorage.Tools.Localization) --> Json -local JsonAttributesUpgrade = require(ReplicatedStorage.Json.AttributesUpgrade) local JsonRune = require(ReplicatedStorage.Json.Rune) +local JsonItem = require(ReplicatedStorage.Json.ItemProp) +local JsonEquipment = require(ReplicatedStorage.Json.Equipment) --> Events local RE_RuneInlay = ReplicatedStorage.Events.RE_RuneInlay - --> Variables local LocalPlayer = game.Players.LocalPlayer +--> Prefabs +local FolderEquipmentPrefabs = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") +local EquipmentFolder = Utils:WaitPlayerDataFolder(LocalPlayer):WaitForChild("Equipment") +local DataFolder = Utils:WaitPlayerDataFolder(LocalPlayer):WaitForChild("Rune") + +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + +--> Signals +local Signal = require(ReplicatedStorage.Tools.Signal) +local selectRuneInlayEquipmentSignal = Signal.new(Signal.ENUM.SELECT_RUNE_INLAY_EQUIPMENT) + -------------------------------------------------------------------------------- local RuneWindow = {} @@ -37,29 +48,35 @@ function RuneWindow:Init(UIManager: table, Data: table?) ["_goRunePanel"] = 0, ["__listRunePackage"] = 0, ["__listRuneWearing"] = 0, - ["_tmpCombatValue"] = 0, + ["_tmpName"] = 0, + ["_tmpQuality"] = 0, ["_imgIcon"] = 0, ["_bgNowSelectFrame"] = 0, ["_imgNowRune"] = 0, ["_tmpNowRuneName"] = 0, + ["_tmpMaxRuneEmpty"] = 0, + ["_imgView"] = 0, ["_btnClose"] = 0, ["_btnBgClose"] = 0, ["_btnInlay"] = 0, + ["_btnChangeEquipment"] = 0, } self.UIRootName = "ui_w_rune" self.UIParentName = UIEnums.UIParent.UIRoot self.ShowEquipmentId = nil self.NowSelectRuneId = nil + self.NowMaxRuneNumber = 0 return self end -function RuneWindow:ShowDetailData(uniqueId: number) +function RuneWindow:ShowDetailData(uniqueId: number, orgId: number) if uniqueId then + if self.NowMaxRuneNumber == 0 then warn("当前最大符文数量为0") return end self.NowSelectRuneId = uniqueId - local runeData = Utils:GetIdDataFromJson(JsonRune, uniqueId) + local runeData = Utils:GetIdDataFromJson(JsonRune, orgId) self.Variables["_tmpNowRuneName"].Text = Localization:GetLanguageData(runeData.nameId) self.Variables["_imgNowRune"].Image = Localization:GetImageData(runeData.icon) self.Variables["_imgNowRune"].BackgroundColor3 = Localization:GetRuneQualityBgColor(runeData.quality) @@ -73,6 +90,18 @@ function RuneWindow:ShowDetailData(uniqueId: number) end end +function RuneWindow:RefreshEquipmentName() + if self.ShowEquipmentId then + local equipmentInstance = EquipmentFolder:FindFirstChild(self.ShowEquipmentId) + local itemData = Utils:GetIdDataFromJson(JsonItem, equipmentInstance:GetAttribute("orgId")) + self.Variables["_tmpName"].Text = Localization:GetLanguageData(itemData.nameId) + self.Variables["_tmpQuality"].Text = Localization:GetColoredEquipmentQualityDesc(equipmentInstance:GetAttribute("quality")) + else + self.Variables["_tmpName"].Text = "" + self.Variables["_tmpQuality"].Text = "" + end +end + function RuneWindow:WearRefresh(data: table) local newSlot = data.instance:GetAttribute("wearing") self.Variables["__listRuneWearing"]:RemoveData("slot"..newSlot) @@ -101,7 +130,7 @@ function RuneWindow:InlayRune() if self.NowSelectRuneId and self.ShowEquipmentId then RE_RuneInlay:FireClient(self.NowSelectRuneId, self.ShowEquipmentId) end -end +end function RuneWindow:AddInstanceData(configInstance: Instance, Data: table?) local data = self.Data @@ -137,6 +166,65 @@ function RuneWindow:RemoveInstanceData(configInstance: Instance, Data: table?) return nil end +function RuneWindow:ShowWearingSlot() + -- 清除旧数据 + if self.Data then + if self.Data.WearingRune then + self.Data.WearingRune = nil + end + if self.Data.PackageRune then + self.Data.PackageRune = nil + end + end + self.Data = { + WearingRune = {}, + PackageRune = {}, + } + + local equipmentInstance = EquipmentFolder:FindFirstChild(self.ShowEquipmentId) + local maxRuneNumber = equipmentInstance:GetAttribute("maxRuneNumber") + self.NowMaxRuneNumber = maxRuneNumber + self:RefreshEquipmentName() + + -- 模型展示 + EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], equipmentInstance:GetAttribute("orgId"), false) + + -- 如果当前最大槽位数为0,刷新至空显示 + if maxRuneNumber <= 0 then + self:ShowDetailData() + self.Variables["_bgNowSelectFrame"].Visible = false + self.Variables["_tmpMaxRuneEmpty"].Text = Localization:GetLanguageData(1200) + self.Variables["_tmpMaxRuneEmpty"].Visible = true + else + self.Variables["_bgNowSelectFrame"].Visible = true + self.Variables["_tmpMaxRuneEmpty"].Visible = false + end + + -- 补充空槽位 + for i = 1, self.NowMaxRuneNumber do + local isExist = false + for k, data in pairs(self.Data.WearingRune) do + if data.wearingSlot == i then + isExist = true + break + end + end + if not isExist then + self.Data.WearingRune["slot" .. i] = { + wearingSlot = i, + } + end + end + + -- 添加符文数据 + for _, child in DataFolder:GetChildren() do + self:AddInstanceData(child, self.Data) + end + self:SetData(self.Data) + self.Variables["__listRunePackage"]:SetData(self.Data.PackageRune) + self.Variables["__listRuneWearing"]:SetData(self.Data.WearingRune) +end + function RuneWindow:OnOpenWindow() UIWindow.OnOpenWindow(self) self.Variables["__listRunePackage"]:AddComponent(PackageShow) @@ -151,16 +239,8 @@ function RuneWindow:OnOpenWindow() table.insert(self.Connections, bgCloseCon) table.insert(self.Connections, closeCon) - - -- 自己进行数据处理 - local DataFolder = Utils:WaitPlayerDataFolder(LocalPlayer):FindFirstChild("Rune") - local data = { - WearingRune = {}, - PackageRune = {}, - } -- 找到当前穿戴的装备 - local EquipmentFolder = Utils:WaitPlayerDataFolder(LocalPlayer):FindFirstChild("Equipment") for _, child in EquipmentFolder:GetChildren() do if child:GetAttribute("wearing") ~= 0 then self.ShowEquipmentId = child.Name @@ -170,6 +250,7 @@ function RuneWindow:OnOpenWindow() -- 如果当前没有穿戴的装备,并且没有装备,则报错提示, 并返回内容 if not self.ShowEquipmentId and #EquipmentFolder:GetChildren() == 0 then warn("没有找到当前穿戴的装备") + self.NowMaxRuneNumber = 0 return end @@ -177,41 +258,10 @@ function RuneWindow:OnOpenWindow() if not self.ShowEquipmentId then self.ShowEquipmentId = EquipmentFolder:GetChildren()[1].Name end - - local equipmentInstance = EquipmentFolder:FindFirstChild(self.ShowEquipmentId) - local maxRuneNumber = equipmentInstance:GetAttribute("maxRuneNumber") - - -- 如果当前最大槽位数为0,刷新至空显示 - if maxRuneNumber <= 0 then - self.Variables["__listRuneWearing"]:SetData({}) - self:ShowDetailData() - return - end - - -- 添加符文数据 - for _, child in DataFolder:GetChildren() do - self:AddInstanceData(child, data) - end - self:SetData(data) - - -- 补充空槽位 - for i = 1, maxRuneNumber do - local isExist = false - for k, data in pairs(self.Data.WearingRune) do - if data.wearingSlot == i then - isExist = true - break - end - end - if not isExist then - self.Data.WearingRune["slot" .. i] = { - wearingSlot = i, - } - end - end + self:ShowWearingSlot() local addCon = DataFolder.ChildAdded:Connect(function(child) - local data, parentName = self:AddInstanceData(child, data) + local data, parentName = self:AddInstanceData(child, self.Data) if parentName == "WearingRune" then self.Variables["__listRuneWearing"]:AddData("slot"..data.wearingSlot, data) else @@ -229,14 +279,29 @@ function RuneWindow:OnOpenWindow() end end) - table.insert(self.Connections, addCon) table.insert(self.Connections, removeCon) - print(self.Variables["__listRunePackage"], self.Variables["__listRuneWearing"]) - self.Variables["__listRunePackage"]:SetData(self.Data.PackageRune) - self.Variables["__listRuneWearing"]:SetData(self.Data.WearingRune) self.Variables["__listRuneWearing"]:SetLayoutOrder("wearingSlot") + + local inlayCon = self.Variables["_btnInlay"].Activated:Connect(function() + self:InlayRune() + end) + table.insert(self.Connections, inlayCon) + + local changeEquipmentCon = self.Variables["_btnChangeEquipment"].Activated:Connect(function() + self.UIManager:OpenWindow("SelectEquipmentWindow", { + ExpectIds = {tostring(self.ShowEquipmentId)}, + }) + end) + table.insert(self.Connections, changeEquipmentCon) + + local selectRuneInlayEquipmentCon = selectRuneInlayEquipmentSignal:Connect(function(id) + self.ShowEquipmentId = id + self:RefreshEquipmentName() + self:ShowWearingSlot() + end) + table.insert(self.Connections, selectRuneInlayEquipmentCon) end function RuneWindow:OnCloseWindow() diff --git a/src/StarterPlayerScripts/UI/Windows/SelectEquipmentWindow/PackageShow.luau b/src/StarterPlayerScripts/UI/Windows/SelectEquipmentWindow/PackageShow.luau new file mode 100644 index 0000000..83f1765 --- /dev/null +++ b/src/StarterPlayerScripts/UI/Windows/SelectEquipmentWindow/PackageShow.luau @@ -0,0 +1,81 @@ +local PackageShow = {} +PackageShow.__index = PackageShow + +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +local Utils = require(ReplicatedStorage.Tools.Utils) +local Localization = require(ReplicatedStorage.Tools.Localization) +local JsonEquipment = require(ReplicatedStorage.Json.Equipment) +local JsonItemProp = require(ReplicatedStorage.Json.ItemProp) + +local FolderEquipment = ReplicatedStorage:WaitForChild("Prefabs"):WaitForChild("Equipments") + +--> Variables +local LocalPlayer = game.Players.LocalPlayer + +--> Components +local CommonFolder = LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("UI"):WaitForChild("Common") +local EquipmentModelDetail = require(CommonFolder:WaitForChild("EquipmentModelDetail")) + +function PackageShow:Init(data: table) + local self = {} + self.Data = data + self.Variables = { + ["_btnClick"] = 0, + ["_imgIcon"] = 0, + ["_tmpQuality"] = 0, + ["_tmpName"] = 0, + ["_imgView"] = 0, + } + self.Connections = {} + + setmetatable(self, PackageShow) + + return self +end + +function PackageShow:Refresh() + local itemData = Utils:GetIdDataFromJson(JsonItemProp, self.Data.orgId) + self.Variables._imgIcon.Image = Localization:GetImageData(itemData.iconId) + self.Variables._imgIcon.Visible = false + self.Variables._tmpQuality.Text = Localization:GetColoredEquipmentQualityDesc(self.Data.quality) + self.Variables._tmpName.Text = Localization:GetLanguageData(itemData.nameId) + + -- 模型展示 + EquipmentModelDetail:ShowDetail(self.Variables["_imgView"], self.Data.orgId, false) +end + +function PackageShow:OnInitFinish() + local con = self.Variables._btnClick.MouseButton1Click:Connect(function() + if self.Data == {} then + -- TODO: 之后做提示弹窗 + else + self.TopUI:SetSelectId(self.Data.id) + end + end) + table.insert(self.Connections, con) + + if self.Data.instance then + local wearingCon = self.Data.instance:GetAttributeChangedSignal("wearing"):Connect(function() + local oldWearing = self.Data.wearing + local newWearing = self.Data.instance:GetAttribute("wearing") + if oldWearing ~= newWearing then + if newWearing > 0 then + self.TopUI:WearRefresh(self.Data) + else + self.TopUI:UnwearRefresh(self.Data) + end + end + end) + table.insert(self.Connections, wearingCon) + end +end + +function PackageShow:Destroy() + for k, v in pairs(self) do + self[k] = nil + end + self = nil +end + +return PackageShow \ No newline at end of file diff --git a/src/StarterPlayerScripts/UI/Windows/SelectEquipmentWindow/init.luau b/src/StarterPlayerScripts/UI/Windows/SelectEquipmentWindow/init.luau new file mode 100644 index 0000000..cf35dc3 --- /dev/null +++ b/src/StarterPlayerScripts/UI/Windows/SelectEquipmentWindow/init.luau @@ -0,0 +1,78 @@ +--> Services +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +--> Dependencies +local UIWindow = require(ReplicatedStorage.Base.UIWindow) +local UIEnums = require(ReplicatedStorage.Base.UIEnums) + +--> Components +local PackageShow = require(script.PackageShow) + +--> Dependencies +local Utils = require(ReplicatedStorage.Tools.Utils) + +--> Variables +local LocalPlayer = game.Players.LocalPlayer +local Signal = require(ReplicatedStorage.Tools.Signal) +local selectRuneInlayEquipmentSignal = Signal.new(Signal.ENUM.SELECT_RUNE_INLAY_EQUIPMENT) + +-------------------------------------------------------------------------------- + +local SelectEquipmentWindow = {} +SelectEquipmentWindow.__index = SelectEquipmentWindow +setmetatable(SelectEquipmentWindow, {__index = UIWindow}) + +function SelectEquipmentWindow:Init(UIManager: table, Data: table?) + local self = UIWindow:Init(UIManager, Data) + setmetatable(self, SelectEquipmentWindow) + self.Variables = { + ["__listWeaponPackage"] = 0, + ["_btnClose"] = 0, + ["_btnBgClose"] = 0, + } + self.UIRootName = "ui_w_select_equipment" + self.UIParentName = UIEnums.UIParent.UIRoot + + return self +end + +function SelectEquipmentWindow:SetSelectId(id: number) + selectRuneInlayEquipmentSignal:Fire(id) + self.UIManager:CloseWindow(script.Name) +end + +function SelectEquipmentWindow:OnOpenWindow() + UIWindow.OnOpenWindow(self) + + -- 自己进行数据处理 + local DataFolder = Utils:WaitPlayerDataFolder(LocalPlayer):FindFirstChild("Equipment") + self.Data.ShowData = {} + for _, child in DataFolder:GetChildren() do + if not table.find(self.Data.ExpectIds, child.Name) then + local newData = child:GetAttributes() + newData.instance = child + table.insert(self.Data.ShowData, newData) + end + end + print(self.Data) + + local bgCloseCon = self.Variables["_btnBgClose"].Activated:Connect(function() + self.UIManager:CloseWindow(script.Name) + end) + local closeCon = self.Variables["_btnClose"].Activated:Connect(function() + self.UIManager:CloseWindow(script.Name) + end) + table.insert(self.Connections, bgCloseCon) + table.insert(self.Connections, closeCon) + + self.Variables["__listWeaponPackage"]:AddComponent(PackageShow) + self.Variables["__listWeaponPackage"]:SetData(self.Data.ShowData) +end + +function SelectEquipmentWindow:OnCloseWindow() + UIWindow.OnCloseWindow(self) +end + + + +return SelectEquipmentWindow \ No newline at end of file