Compare commits
2 Commits
6b6d563780
...
c48a9deb66
Author | SHA1 | Date | |
---|---|---|---|
c48a9deb66 | |||
0d1d5e3e3e |
BIN
excel/anim.xlsx
Normal file
BIN
excel/anim.xlsx
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,6 +6,10 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
--> Dependencies
|
||||
local EffectDispatcher = require(ReplicatedStorage.Modules.EffectDispatcher)
|
||||
local Utils = require(ReplicatedStorage.Tools.Utils)
|
||||
|
||||
--> Json
|
||||
local JsonAnimation = require(ReplicatedStorage.Json.Animation)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -19,15 +23,51 @@ function BehaviourClient:Init(CasterPlayer: Player, CastInfo: table, DelayTime:
|
||||
self.ShowTask = nil
|
||||
self.EffectDispatcher = EffectDispatcher
|
||||
|
||||
self.Animations = {}
|
||||
return self
|
||||
end
|
||||
|
||||
function BehaviourClient:LoadAnimationByName(AnimationName: string)
|
||||
local AnimationData = Utils:GetSpecialKeyDataFromJson(JsonAnimation, "name", AnimationName)
|
||||
if not AnimationData then warn("Animation not found") return end
|
||||
|
||||
-- 如果已经加载过,则直接返回
|
||||
if self.Animations[AnimationName] then return self.Animations[AnimationName] end
|
||||
|
||||
local Humanoid = self.Character:FindFirstChild("Humanoid")
|
||||
if not Humanoid then warn("Humanoid not found") return end
|
||||
local Animator = Humanoid:FindFirstChild("Animator")
|
||||
if not Animator then warn("Animator not found") return end
|
||||
|
||||
local Animation = Instance.new("Animation")
|
||||
Animation.AnimationId = "rbxassetid://" .. AnimationData.rbxId
|
||||
|
||||
local AnimationTrack = Animator:LoadAnimation(Animation)
|
||||
AnimationTrack.Priority = Enum.AnimationPriority[AnimationData.priority]
|
||||
|
||||
self.Animations[AnimationName] = AnimationTrack
|
||||
Animation:Destroy()
|
||||
|
||||
return AnimationTrack
|
||||
end
|
||||
|
||||
function BehaviourClient:GetAnimationByName(AnimationName: string)
|
||||
return self.Animations[AnimationName]
|
||||
end
|
||||
|
||||
function BehaviourClient:Show(CasterPlayer: Player, CastInfo: table, DelayTime: number, CastState: boolean)
|
||||
|
||||
end
|
||||
|
||||
-- 销毁
|
||||
function BehaviourClient:Destroy()
|
||||
if self.Animations then
|
||||
for _, AnimationTrack in self.Animations do
|
||||
AnimationTrack:Destroy()
|
||||
end
|
||||
self.Animations = nil
|
||||
end
|
||||
|
||||
if self.ShowTask then
|
||||
task.cancel(self.ShowTask)
|
||||
self.ShowTask = nil
|
||||
|
@ -58,18 +58,34 @@ function UIList:SetData(Data: table)
|
||||
self:Refresh()
|
||||
end
|
||||
|
||||
function UIList:AddData(data: table)
|
||||
self.Data[#self.Data + 1] = data
|
||||
self:SetSingleInstance(#self.Data, data)
|
||||
-- 列表添加单个数据
|
||||
function UIList:AddData(key: string, data: table)
|
||||
self.Data[key] = data
|
||||
self:SetSingleInstance(key, data)
|
||||
end
|
||||
|
||||
function UIList:RemoveData(data: table)
|
||||
for i, v in pairs(self.Data) do
|
||||
if Utils:CompareTableJson(v, data) then
|
||||
self.Instances[i]:Destroy()
|
||||
table.remove(self.Data, i)
|
||||
return i
|
||||
-- 列表清除单个数据
|
||||
function UIList:RemoveData(key)
|
||||
if self.Data[key] then
|
||||
for k, v in pairs(self.Instances) do
|
||||
if v.Data == self.Data[key] then
|
||||
for _, connection in pairs(v.Connections) do
|
||||
connection:Disconnect()
|
||||
end
|
||||
v.Connections = nil
|
||||
if v.UIRoot then v.UIRoot:Destroy() end
|
||||
if v.Destroy then v:Destroy() end
|
||||
if type(key) == "number" then
|
||||
table.remove(self.Instances, k)
|
||||
else
|
||||
self.Instances[k] = nil
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
self.Data[key] = nil
|
||||
else
|
||||
warn("UIList:RemoveData() 数据不存在", key, self.Data)
|
||||
end
|
||||
end
|
||||
|
||||
@ -161,6 +177,7 @@ function UIList:Destroy()
|
||||
self.SignalConnections = nil
|
||||
self.Connections = nil
|
||||
self.Org:Destroy()
|
||||
if self.UIRoot then self.UIRoot:Destroy() end
|
||||
self = nil
|
||||
end
|
||||
|
||||
|
@ -13,6 +13,8 @@ local Utils = require(ReplicatedStorage.Tools.Utils)
|
||||
|
||||
local LocalPlayer = game.Players.LocalPlayer
|
||||
local FolderPlayerGui = LocalPlayer:WaitForChild("PlayerGui")
|
||||
local FolderStarterPlayerScripts = game.StarterPlayer:WaitForChild("StarterPlayerScripts")
|
||||
local FolderUIInstanceScripts = FolderStarterPlayerScripts:WaitForChild("UI"):WaitForChild("InstanceScripts")
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -46,6 +48,7 @@ function UIWindow:AutoInjectVariables()
|
||||
if typeof(varName) == "string" then
|
||||
local firstChar = string.sub(varName, 1, 1)
|
||||
local sixChar = string.sub(varName, 1, 6)
|
||||
local sevenChar = string.sub(varName, 1, 7)
|
||||
local target
|
||||
|
||||
if firstChar == "_" then
|
||||
@ -53,6 +56,11 @@ function UIWindow:AutoInjectVariables()
|
||||
local prefab = Utils:FindInDescendantsUI(self.UIRoot, varName)
|
||||
target = UIList:Init(prefab)
|
||||
target.TopUI = self
|
||||
elseif sevenChar == "__money" then
|
||||
target = Utils:FindInDescendantsUI(self.UIRoot, varName)
|
||||
-- 把脚本放到预制体下
|
||||
local newScript = FolderUIInstanceScripts:FindFirstChild("Money"):Clone()
|
||||
newScript.Parent = target
|
||||
else
|
||||
-- _开头,递归查找
|
||||
target = Utils:FindInDescendantsUI(self.UIRoot, varName)
|
||||
@ -75,7 +83,6 @@ function UIWindow:OnOpenWindow()
|
||||
-- 创建UI根节点
|
||||
self.UIRoot = FolderWindows:FindFirstChild(self.UIRootName):Clone()
|
||||
self.UIRoot.Parent = FolderPlayerGui:WaitForChild(self.UIParentName)
|
||||
print("节点", self.UIRoot, self.UIParentName, FolderPlayerGui, FolderPlayerGui:FindFirstChild(self.UIParentName))
|
||||
else
|
||||
self.UIRoot.Visible = true
|
||||
self:Refresh()
|
||||
|
3
src/ReplicatedStorage/Json/Animation.json
Normal file
3
src/ReplicatedStorage/Json/Animation.json
Normal file
@ -0,0 +1,3 @@
|
||||
[
|
||||
{"id":1,"name":"SwordWave","rbxId":"133335766636767","priority":"Action"}
|
||||
]
|
@ -1,18 +1,18 @@
|
||||
[
|
||||
{"id":40000,"type":1,"name":40000,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40001,"type":1,"name":40001,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40002,"type":1,"name":40002,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40003,"type":1,"name":40003,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40004,"type":1,"name":40004,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40005,"type":1,"name":40005,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40006,"type":1,"name":40006,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40007,"type":1,"name":40007,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40008,"type":1,"name":40008,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40009,"type":1,"name":40009,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40010,"type":1,"name":40010,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40011,"type":1,"name":40011,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40012,"type":1,"name":40012,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40013,"type":1,"name":40013,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40014,"type":1,"name":40014,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10},
|
||||
{"id":40015,"type":1,"name":40015,"attributes":[14,200,10,15,200,10,16,100,0],"recycle":10}
|
||||
{"id":40000,"type":1,"name":40000,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40001,"type":1,"name":40001,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40002,"type":1,"name":40002,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40003,"type":1,"name":40003,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40004,"type":1,"name":40004,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40005,"type":1,"name":40005,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40006,"type":1,"name":40006,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40007,"type":1,"name":40007,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40008,"type":1,"name":40008,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40009,"type":1,"name":40009,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40010,"type":1,"name":40010,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40011,"type":1,"name":40011,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40012,"type":1,"name":40012,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40013,"type":1,"name":40013,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40014,"type":1,"name":40014,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10},
|
||||
{"id":40015,"type":1,"name":40015,"attributes":[14,200,10,15,200,10,16,100,0],"modelName":"Zeus","recycle":10}
|
||||
]
|
@ -1,5 +1,6 @@
|
||||
[
|
||||
{"id":1,"key":"quality_bonus","intValue":null,"stringValue":null,"intArray":[100,125,150,200,275,375]},
|
||||
{"id":2,"key":"level_get_bonus","intValue":null,"stringValue":null,"intArray":[5,2]},
|
||||
{"id":3,"key":"mob_died_get","intValue":null,"stringValue":null,"intArray":[2,10]}
|
||||
{"id":3,"key":"mob_died_get","intValue":null,"stringValue":null,"intArray":[2,10]},
|
||||
{"id":4,"key":"default_weapon","intValue":null,"stringValue":"Sword","intArray":[]}
|
||||
]
|
@ -20,12 +20,16 @@ function SwordWave:Init(CasterPlayer: Player, CastInfo: table, DelayTime: number
|
||||
local self = BehaviourClient:Init(CasterPlayer, CastInfo, DelayTime, CastState)
|
||||
setmetatable(self, SwordWave)
|
||||
|
||||
-- 加载动画
|
||||
self:LoadAnimationByName("SwordWave")
|
||||
return self
|
||||
end
|
||||
|
||||
function SwordWave:Show(CasterPlayer: Player, CastInfo: table, DelayTime: number, CastState: boolean)
|
||||
self.ShowTask, self.Projectile, self.Tween = self.EffectDispatcher:ShowProjectile(self.Player, DelayTime,
|
||||
0, CastInfo.StartPos, CastInfo.EndPos, CastInfo.Duration, Prefab_SwordWave, Enum.EasingStyle.Linear)
|
||||
|
||||
self.EffectDispatcher:ShowAnimation(self.Player, DelayTime, self:GetAnimationByName("SwordWave"))
|
||||
end
|
||||
|
||||
function SwordWave:Destroy()
|
||||
|
@ -26,7 +26,6 @@ function EffectDispatcher:ShowProjectile(Caster: Player, DelayTime: number, PreT
|
||||
Projectile.CanCollide = false
|
||||
Projectile.Anchored = true
|
||||
|
||||
|
||||
-- Tween动画
|
||||
local tweenInfo = TweenInfo.new(Duration, EasingStyle or Enum.EasingStyle.Linear)
|
||||
local direction = (EndPos - StartPos).Unit
|
||||
@ -43,4 +42,8 @@ function EffectDispatcher:ShowProjectile(Caster: Player, DelayTime: number, PreT
|
||||
return projectileTask, Projectile, tween
|
||||
end
|
||||
|
||||
function EffectDispatcher:ShowAnimation(Caster: Player, DelayTime: number, AnimationTrack: AnimationTrack)
|
||||
AnimationTrack:Play()
|
||||
end
|
||||
|
||||
return EffectDispatcher
|
@ -39,7 +39,7 @@ end
|
||||
|
||||
-- 获取图片Id数据
|
||||
function Localization:GetImageData(Id: number)
|
||||
if not Id then return end
|
||||
if not Id then return "" end
|
||||
local data = Utils:GetIdDataFromJson(JsonImage, Id)
|
||||
if not data then return "" end
|
||||
return data.sourceId
|
||||
|
@ -11,6 +11,13 @@ local PlayerDataFolder = ReplicatedStorage:WaitForChild("PlayerData")
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
function Utils:WaitPlayerDataFolder(Player: Player)
|
||||
local pData = PlayerDataFolder:WaitForChild(Player.UserId)
|
||||
if pData then return pData end
|
||||
warn("玩家数据不存在: " .. Player.Name)
|
||||
return nil
|
||||
end
|
||||
|
||||
function Utils:GetPlayerDataFolder(Player: Player)
|
||||
local pData = PlayerDataFolder:FindFirstChild(Player.UserId)
|
||||
if pData then return pData end
|
||||
@ -65,7 +72,7 @@ function Utils:GetIdDataFromJson(JsonData: table, id: number)
|
||||
-- 遍历JsonData,查找id字段等于目标id的项
|
||||
for _, item in ipairs(JsonData) do
|
||||
if item.id == id then
|
||||
return item
|
||||
return Utils:DeepCopyTable(item)
|
||||
end
|
||||
end
|
||||
return nil -- 没有找到对应id
|
||||
@ -215,9 +222,23 @@ end
|
||||
|
||||
-- 合并表(加法合并)
|
||||
function Utils:MergeTable(t1: table, t2: table)
|
||||
-- 检查是否为空表
|
||||
local t1Empty = next(t1) == nil
|
||||
local t2Empty = next(t2) == nil
|
||||
|
||||
-- 如果其中一个为空表,返回不为空的表
|
||||
if t1Empty and not t2Empty then
|
||||
return t2
|
||||
elseif not t1Empty and t2Empty then
|
||||
return t1
|
||||
elseif t1Empty and t2Empty then
|
||||
return t1 -- 全为空表,返回t1
|
||||
end
|
||||
|
||||
-- 正常合并逻辑
|
||||
for k, v in pairs(t2) do
|
||||
if type(v) == "number" then
|
||||
t1[k] = t1[k] + v
|
||||
t1[k] = (t1[k] or 0) + v
|
||||
end
|
||||
end
|
||||
return t1
|
||||
|
@ -34,11 +34,14 @@ function Character.new(Player: Player, CharacterModel: Model, CharacterData: tab
|
||||
Attributes.Name = "Attributes"
|
||||
Attributes.Parent = self.Instance
|
||||
for attributeKey, attributeValue in self.Config do
|
||||
Attributes:SetAttribute(attributeKey, attributeValue)
|
||||
-- 设置限制值
|
||||
if table.find(LIMIT_ATTRIBUTE, attributeKey) then
|
||||
self.Config["max" .. attributeKey] = attributeValue
|
||||
Attributes:SetAttribute("max" .. attributeKey, attributeValue)
|
||||
-- 只设置非表类型的属性值
|
||||
if type(attributeValue) ~= "table" then
|
||||
Attributes:SetAttribute(attributeKey, attributeValue)
|
||||
-- 设置限制值
|
||||
if table.find(LIMIT_ATTRIBUTE, attributeKey) then
|
||||
self.Config["max" .. attributeKey] = attributeValue
|
||||
Attributes:SetAttribute("max" .. attributeKey, attributeValue)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,7 +47,7 @@ local function ChangeValue(Player: Player, EquipmentUniqueId: number, KeyName: s
|
||||
local ValueInstance = GetPlayerEquipmentFolder(Player):FindFirstChild(EquipmentUniqueId)
|
||||
if not ValueInstance then warn("ValueInstance not found", KeyName) return end
|
||||
|
||||
ArchiveProxy.pData[Player.UserId][EquipmentUniqueId][KeyName] = Value
|
||||
ArchiveProxy.pData[Player.UserId][STORE_NAME][EquipmentUniqueId][KeyName] = Value
|
||||
ValueInstance:SetAttribute(KeyName, Value)
|
||||
end
|
||||
|
||||
@ -281,6 +281,11 @@ function EquipmentProxy:WearEquipment(Player: Player, EquipmentId: number, Slot:
|
||||
|
||||
-- 更新玩家数据
|
||||
PlayerFightProxy:UpdatePlayerFightData(Player)
|
||||
|
||||
-- 给前端的提示(模型穿戴)
|
||||
if Slot == 1 then
|
||||
RE_WearEquipment:FireClient(Player, true, EquipmentId, Slot)
|
||||
end
|
||||
end
|
||||
|
||||
-- 卸下装备
|
||||
@ -288,15 +293,20 @@ function EquipmentProxy:UnwearEquipment(Player: Player, EquipmentId: number)
|
||||
local pData = Utils:GetPlayerDataFolder(Player)
|
||||
if not pData then return end
|
||||
|
||||
-- TODO :卸下装备时再关闭模型
|
||||
|
||||
-- 卸下装备
|
||||
local EquipmentData = ArchiveProxy.pData[Player.UserId][STORE_NAME][EquipmentId]
|
||||
if not EquipmentData then return end
|
||||
|
||||
-- 给前端的提示(模型卸下)
|
||||
if EquipmentData.wearing == 1 then
|
||||
RE_WearEquipment:FireClient(Player, false, EquipmentId, EquipmentData.wearing)
|
||||
end
|
||||
|
||||
ChangeValue(Player, EquipmentId, "wearing", 0)
|
||||
|
||||
-- 更新玩家数据
|
||||
PlayerFightProxy:UpdatePlayerFightData(Player)
|
||||
|
||||
end
|
||||
|
||||
-- 获取穿戴中的装备UniqueId
|
||||
@ -363,7 +373,6 @@ RE_WearEquipment.OnServerEvent:Connect(function(Player: Player, EquipmentUniqueI
|
||||
if Unwear then
|
||||
EquipmentProxy:UnwearEquipment(Player, EquipmentUniqueId)
|
||||
else
|
||||
print(Player, EquipmentUniqueId, SlotId)
|
||||
EquipmentProxy:WearEquipment(Player, EquipmentUniqueId, SlotId)
|
||||
end
|
||||
end)
|
||||
|
@ -124,13 +124,19 @@ function PlayerFightProxy:UpdatePlayerFightData(Player: Player)
|
||||
|
||||
-- 计算角色基础属性值 + 装备属性值 + 宝石属性值,赋值属性
|
||||
local PlayerInfoAttributes = PlayerInfoProxy:GetPlayerAttributes(Player)
|
||||
AttributesData = Utils:MergeTable(AttributesData, PlayerInfoAttributes)
|
||||
if PlayerInfoAttributes.UpgradeAttributes then
|
||||
Utils:TableSafeAddTableValue(AttributesData, PlayerInfoAttributes.UpgradeAttributes)
|
||||
end
|
||||
|
||||
local EquipmentAttributes = EquipmentProxy:GetPlayerAttributes(Player)
|
||||
AttributesData = Utils:MergeTable(AttributesData, EquipmentAttributes)
|
||||
if EquipmentAttributes then
|
||||
Utils:TableSafeAddTableValue(AttributesData, EquipmentAttributes)
|
||||
end
|
||||
|
||||
local GemAttributes = GemProxy:GetPlayerAttributes(Player)
|
||||
AttributesData = Utils:MergeTable(AttributesData, GemAttributes)
|
||||
if GemAttributes.GemWearingAttributes then
|
||||
Utils:TableSafeAddTableValue(AttributesData, GemAttributes.GemWearingAttributes)
|
||||
end
|
||||
|
||||
-- 角色基础数据
|
||||
local PlayerRole = self:GetPlayerRole(Player)
|
||||
@ -172,7 +178,7 @@ function PlayerFightProxy:UpdatePlayerFightData(Player: Player)
|
||||
for _, behaviourName in behaviourNameList do
|
||||
playerAI:AddBehaviour(behaviourName)
|
||||
end
|
||||
playerAI:AddBehaviour("Move")
|
||||
-- playerAI:AddBehaviour("Move")
|
||||
playerAI:AddBehaviour("SwordWave")
|
||||
|
||||
|
||||
|
@ -335,7 +335,6 @@ end)
|
||||
|
||||
RE_UpgradeAttributes.OnServerEvent:Connect(function(Player: Player, AttributeId: number)
|
||||
PlayerInfoProxy:UpgradeAttribute(Player, AttributeId)
|
||||
print(ArchiveProxy.pData[Player.UserId][STORE_NAME].AttributesUpgrade)
|
||||
end)
|
||||
|
||||
return PlayerInfoProxy
|
6
src/StarterPlayerScripts/ClientMain/DefaultUIClose.luau
Normal file
6
src/StarterPlayerScripts/ClientMain/DefaultUIClose.luau
Normal file
@ -0,0 +1,6 @@
|
||||
local StarterGui = game:GetService("StarterGui")
|
||||
|
||||
-- Disable default health bar and backpack
|
||||
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
|
||||
|
||||
return {}
|
@ -9,85 +9,88 @@
|
||||
fighting any enemy with a melee weapon, especially on platforms like mobile, where shift lock may not be a feature.
|
||||
]]
|
||||
|
||||
--> Services
|
||||
local CollectionService = game:GetService("CollectionService")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local RunService = game:GetService("RunService")
|
||||
local Players = game:GetService("Players")
|
||||
-- 临时关闭(原参考demo代码)
|
||||
return {}
|
||||
|
||||
--> Player
|
||||
local Player = Players.LocalPlayer
|
||||
-- --> Services
|
||||
-- local CollectionService = game:GetService("CollectionService")
|
||||
-- local UserInputService = game:GetService("UserInputService")
|
||||
-- local RunService = game:GetService("RunService")
|
||||
-- local Players = game:GetService("Players")
|
||||
|
||||
--> Variables
|
||||
local Focus: Model?
|
||||
-- --> Player
|
||||
-- local Player = Players.LocalPlayer
|
||||
|
||||
--> Configuration
|
||||
local Enabled = true
|
||||
-- --> Variables
|
||||
-- local Focus: Model?
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- --> Configuration
|
||||
-- local Enabled = true
|
||||
|
||||
if not Enabled then
|
||||
return {}
|
||||
end
|
||||
-- --------------------------------------------------------------------------------
|
||||
|
||||
local function GetNearestMob()
|
||||
local Character = Player.Character
|
||||
if not Character then return end
|
||||
-- if not Enabled then
|
||||
-- return {}
|
||||
-- end
|
||||
|
||||
-- local function GetNearestMob()
|
||||
-- local Character = Player.Character
|
||||
-- if not Character then return end
|
||||
|
||||
local Closest = {MobInstance = nil, Distance = math.huge}
|
||||
-- local Closest = {MobInstance = nil, Distance = math.huge}
|
||||
|
||||
for _, MobInstance in CollectionService:GetTagged("Mob") do
|
||||
local MobConfig = MobInstance:FindFirstChild("MobConfig") and require(MobInstance.MobConfig)
|
||||
local Enemy = MobInstance:FindFirstChild("Enemy")
|
||||
if not MobConfig or not Enemy or Enemy.Health == 0 then continue end
|
||||
-- for _, MobInstance in CollectionService:GetTagged("Mob") do
|
||||
-- local MobConfig = MobInstance:FindFirstChild("MobConfig") and require(MobInstance.MobConfig)
|
||||
-- local Enemy = MobInstance:FindFirstChild("Enemy")
|
||||
-- if not MobConfig or not Enemy or Enemy.Health == 0 then continue end
|
||||
|
||||
local Distance = (Character:GetPivot().Position - MobInstance:GetPivot().Position).Magnitude
|
||||
local MaxDistance = MobConfig.FollowDistance
|
||||
-- local Distance = (Character:GetPivot().Position - MobInstance:GetPivot().Position).Magnitude
|
||||
-- local MaxDistance = MobConfig.FollowDistance
|
||||
|
||||
if (Distance < MaxDistance) and (Distance < Closest.Distance) then
|
||||
Closest.MobInstance = MobInstance
|
||||
Closest.Distance = Distance
|
||||
end
|
||||
end
|
||||
-- if (Distance < MaxDistance) and (Distance < Closest.Distance) then
|
||||
-- Closest.MobInstance = MobInstance
|
||||
-- Closest.Distance = Distance
|
||||
-- end
|
||||
-- end
|
||||
|
||||
return Closest.MobInstance
|
||||
end
|
||||
-- return Closest.MobInstance
|
||||
-- end
|
||||
|
||||
task.defer(function()
|
||||
while true do
|
||||
task.wait(1/5)
|
||||
Focus = GetNearestMob()
|
||||
end
|
||||
end)
|
||||
-- task.defer(function()
|
||||
-- while true do
|
||||
-- task.wait(1/5)
|
||||
-- Focus = GetNearestMob()
|
||||
-- end
|
||||
-- end)
|
||||
|
||||
RunService:BindToRenderStep("MeleeLock", Enum.RenderPriority.Character.Value + 1, function(DeltaTime: number)
|
||||
local Character = Player.Character
|
||||
local Humanoid = Character and Character:FindFirstChild("Humanoid") :: Humanoid?
|
||||
local HumanoidRootPart = Character and Character:FindFirstChild("HumanoidRootPart") :: BasePart?
|
||||
if not Humanoid or not HumanoidRootPart then return end
|
||||
-- RunService:BindToRenderStep("MeleeLock", Enum.RenderPriority.Character.Value + 1, function(DeltaTime: number)
|
||||
-- local Character = Player.Character
|
||||
-- local Humanoid = Character and Character:FindFirstChild("Humanoid") :: Humanoid?
|
||||
-- local HumanoidRootPart = Character and Character:FindFirstChild("HumanoidRootPart") :: BasePart?
|
||||
-- if not Humanoid or not HumanoidRootPart then return end
|
||||
|
||||
local Success = false
|
||||
-- local Success = false
|
||||
|
||||
if Focus and UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
|
||||
local Tool = Character:FindFirstChildOfClass("Tool")
|
||||
local ItemConfig = Tool and require(Tool:FindFirstChild("ItemConfig"))
|
||||
-- if Focus and UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
|
||||
-- local Tool = Character:FindFirstChildOfClass("Tool")
|
||||
-- local ItemConfig = Tool and require(Tool:FindFirstChild("ItemConfig"))
|
||||
|
||||
if ItemConfig and ItemConfig.WeaponType == "Melee" then
|
||||
local CurrentRotation = HumanoidRootPart.CFrame.Rotation
|
||||
local GoalRotation = CFrame.lookAt(HumanoidRootPart.Position, Focus:GetPivot().Position).Rotation
|
||||
local _, Y, _ = CurrentRotation:Lerp(GoalRotation, DeltaTime * 30):ToOrientation()
|
||||
local X, _, Z = CurrentRotation:ToOrientation()
|
||||
-- if ItemConfig and ItemConfig.WeaponType == "Melee" then
|
||||
-- local CurrentRotation = HumanoidRootPart.CFrame.Rotation
|
||||
-- local GoalRotation = CFrame.lookAt(HumanoidRootPart.Position, Focus:GetPivot().Position).Rotation
|
||||
-- local _, Y, _ = CurrentRotation:Lerp(GoalRotation, DeltaTime * 30):ToOrientation()
|
||||
-- local X, _, Z = CurrentRotation:ToOrientation()
|
||||
|
||||
Humanoid.AutoRotate = false
|
||||
HumanoidRootPart.CFrame = CFrame.Angles(X, Y, Z) + HumanoidRootPart.Position
|
||||
-- Humanoid.AutoRotate = false
|
||||
-- HumanoidRootPart.CFrame = CFrame.Angles(X, Y, Z) + HumanoidRootPart.Position
|
||||
|
||||
Success = true
|
||||
end
|
||||
end
|
||||
-- Success = true
|
||||
-- end
|
||||
-- end
|
||||
|
||||
if not Success then
|
||||
Humanoid.AutoRotate = true
|
||||
end
|
||||
end)
|
||||
-- if not Success then
|
||||
-- Humanoid.AutoRotate = true
|
||||
-- end
|
||||
-- end)
|
||||
|
||||
return {}
|
||||
-- return {}
|
@ -115,5 +115,6 @@ end)
|
||||
|
||||
-- 打开默认界面
|
||||
UIManager:OpenWindow("MainWindow")
|
||||
UIManager:OpenWindow("TipsWindow")
|
||||
|
||||
return PerformanceClient
|
85
src/StarterPlayerScripts/ClientMain/WeaponModel.luau
Normal file
85
src/StarterPlayerScripts/ClientMain/WeaponModel.luau
Normal file
@ -0,0 +1,85 @@
|
||||
local WeaponModel = {}
|
||||
|
||||
--> Services
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Utils = require(ReplicatedStorage.Tools.Utils)
|
||||
|
||||
--> Json
|
||||
local JsonEquipment = require(ReplicatedStorage.Json.Equipment)
|
||||
local JsonParam = require(ReplicatedStorage.Json.Param)
|
||||
|
||||
--> Events
|
||||
local RE_WearEquipment = ReplicatedStorage.Events.RE_WearEquipment
|
||||
|
||||
--> Variables
|
||||
local LocalPlayer = game.Players.LocalPlayer
|
||||
local Character = LocalPlayer.Character
|
||||
local LastWeaponName
|
||||
|
||||
-- 如果角色不存在,等待角色加载
|
||||
if not Character then
|
||||
Character = LocalPlayer.CharacterAdded:Wait()
|
||||
end
|
||||
|
||||
local FolderEquipment = Utils:WaitPlayerDataFolder(LocalPlayer):WaitForChild("Equipment")
|
||||
local FolderPrefabEquipments = ReplicatedStorage.Prefabs.Equipments
|
||||
local FolderBackpack = LocalPlayer.Backpack
|
||||
|
||||
function WeaponModel:SetWeaponModel(WeaponInstance: Instance)
|
||||
local WeaponData = Utils:GetIdDataFromJson(JsonEquipment, tonumber(WeaponInstance:GetAttribute("orgId")))
|
||||
if not WeaponData then warn("WeaponData not found") return end
|
||||
|
||||
local WeaponModel = FolderPrefabEquipments:FindFirstChild(WeaponData.modelName)
|
||||
if not WeaponModel then warn("WeaponModel not found") return end
|
||||
|
||||
local newWeapon = WeaponModel:Clone()
|
||||
newWeapon.Parent = LocalPlayer.Backpack
|
||||
Character:FindFirstChild("Humanoid"):EquipTool(newWeapon)
|
||||
return newWeapon.Name
|
||||
end
|
||||
|
||||
function WeaponModel:SetDefaultWeaponModel()
|
||||
local modelName = Utils:GetIdDataFromJson(JsonParam, 4).stringValue
|
||||
local WeaponModel = FolderPrefabEquipments:FindFirstChild(modelName)
|
||||
if not WeaponModel then warn("DefaultWeaponModel not found") return end
|
||||
|
||||
local newWeapon = WeaponModel:Clone()
|
||||
newWeapon.Parent = LocalPlayer.Backpack
|
||||
|
||||
Character:FindFirstChild("Humanoid"):EquipTool(newWeapon)
|
||||
return newWeapon.Name
|
||||
end
|
||||
|
||||
-- 初始化
|
||||
local instance
|
||||
for _, WeaponInstance in FolderEquipment:GetChildren() do
|
||||
if WeaponInstance:GetAttribute("wearing") == 1 then
|
||||
instance = WeaponInstance
|
||||
break
|
||||
end
|
||||
end
|
||||
-- 设置初始化武器
|
||||
if instance then
|
||||
LastWeaponName = WeaponModel:SetWeaponModel(instance)
|
||||
else
|
||||
LastWeaponName = WeaponModel:SetDefaultWeaponModel()
|
||||
end
|
||||
|
||||
-- 穿戴装备
|
||||
RE_WearEquipment.OnClientEvent:Connect(function(IsWear: boolean, EquipmentId: number, Slot: number)
|
||||
local oldWeaponName = LastWeaponName
|
||||
if IsWear then
|
||||
local newInstance = FolderEquipment:FindFirstChild(EquipmentId)
|
||||
if not newInstance then warn("newInstance not found") return end
|
||||
LastWeaponName = WeaponModel:SetWeaponModel(newInstance)
|
||||
else
|
||||
LastWeaponName = WeaponModel:SetDefaultWeaponModel()
|
||||
end
|
||||
for _, child in FolderBackpack:GetChildren() do
|
||||
if child.Name == oldWeaponName then
|
||||
child:Destroy()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return WeaponModel
|
@ -0,0 +1,57 @@
|
||||
-- 检查父级是否为Frame类型,如果不是则退出脚本
|
||||
if typeof(script.Parent) ~= "Instance" or not script.Parent:IsA("Frame") then return end
|
||||
|
||||
-- 必须读取内容
|
||||
local CheckMoneyId = script.Parent:GetAttribute("CheckMoneyId")
|
||||
local tmpValue = script.Parent:FindFirstChild("_tmpValue")
|
||||
local imgIcon = script.Parent:FindFirstChild("_imgIcon")
|
||||
if not CheckMoneyId or not tmpValue or not imgIcon then warn("Money实例内容初始化失败") return end
|
||||
|
||||
--> Server
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
--> Modules
|
||||
local Utils = require(ReplicatedStorage.Tools.Utils)
|
||||
local Localization = require(ReplicatedStorage.Tools.Localization)
|
||||
|
||||
--> Json
|
||||
local JsonItemProp = require(ReplicatedStorage.Json.ItemProp)
|
||||
|
||||
-- 临时变量
|
||||
local LocalPlayer = game.Players.LocalPlayer
|
||||
local connection, connectionFolder
|
||||
|
||||
local PlayerDataFolder = Utils:GetPlayerDataFolder(LocalPlayer)
|
||||
if not PlayerDataFolder then warn("无法获取玩家数据文件夹") return end
|
||||
|
||||
local PlayerInfo = PlayerDataFolder:FindFirstChild("PlayerInfo")
|
||||
if not PlayerInfo then warn("无法获取玩家信息文件夹") return end
|
||||
|
||||
local MoneyFolder = PlayerInfo:FindFirstChild("Items")
|
||||
if not MoneyFolder then warn("无法获取物品文件夹") return end
|
||||
|
||||
local InstanceMoney = MoneyFolder:FindFirstChild(CheckMoneyId)
|
||||
|
||||
local ItemData = Utils:GetIdDataFromJson(JsonItemProp, tonumber(CheckMoneyId))
|
||||
imgIcon.Image = Localization:GetImageData(ItemData.iconId)
|
||||
|
||||
if not InstanceMoney then
|
||||
tmpValue.Text = "0"
|
||||
connectionFolder = MoneyFolder.ChildAdded:Connect(function(child)
|
||||
if child.Name == tostring(CheckMoneyId) then
|
||||
tmpValue.Text = child.Value
|
||||
InstanceMoney = child
|
||||
connectionFolder:Disconnect()
|
||||
end
|
||||
end)
|
||||
else
|
||||
tmpValue.Text = InstanceMoney.Value
|
||||
connection = InstanceMoney.Changed:Connect(function(newValue)
|
||||
tmpValue.Text = newValue
|
||||
end)
|
||||
end
|
||||
|
||||
script.Destroying:Once(function()
|
||||
if connectionFolder then connectionFolder:Disconnect() end
|
||||
if connection then connection:Disconnect() end
|
||||
end)
|
@ -0,0 +1,123 @@
|
||||
local AttributeLvupShow = {}
|
||||
AttributeLvupShow.__index = AttributeLvupShow
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Utils = require(ReplicatedStorage.Tools.Utils)
|
||||
local Localization = require(ReplicatedStorage.Tools.Localization)
|
||||
local JsonAttributesUpgrade = require(ReplicatedStorage.Json.AttributesUpgrade)
|
||||
local JsonAttributes = require(ReplicatedStorage.Json.Attributes)
|
||||
|
||||
local RE_UpgradeAttributes = ReplicatedStorage.Events.RE_UpgradeAttributes
|
||||
|
||||
local LocalPlayer = game:GetService("Players").LocalPlayer
|
||||
|
||||
function AttributeLvupShow:Init(data: table)
|
||||
local self = {}
|
||||
self.Data = data
|
||||
self.Variables = {
|
||||
["_imgIcon"] = 0,
|
||||
["_tmpAttributeName"] = 0,
|
||||
["_tmpValue"] = 0,
|
||||
["_tmpLv"] = 0,
|
||||
["_btnUpgrade"] = 0,
|
||||
}
|
||||
self.Connections = {}
|
||||
setmetatable(self, AttributeLvupShow)
|
||||
return self
|
||||
end
|
||||
|
||||
function AttributeLvupShow:GetNowLv()
|
||||
local attributeFolder = Utils:GetPlayerDataFolder(LocalPlayer):FindFirstChild("PlayerInfo"):FindFirstChild("AttributesUpgrade")
|
||||
local instance = attributeFolder:FindFirstChild(tostring(self.Data.id))
|
||||
local nowLv = 0
|
||||
if instance then nowLv = instance.Value end
|
||||
return nowLv
|
||||
end
|
||||
|
||||
function AttributeLvupShow:Refresh()
|
||||
-- 如果有实例,,并且之前有监听,则断开添加监听
|
||||
if self.instance then
|
||||
if self.folderCon then
|
||||
self.folderCon:Disconnect()
|
||||
self.folderCon = nil
|
||||
end
|
||||
end
|
||||
|
||||
if self.instance and not self.instanceCon then
|
||||
local instanceCon = self.instance.Changed:Connect(function()
|
||||
self:Refresh()
|
||||
end)
|
||||
self.instanceCon = instanceCon
|
||||
end
|
||||
|
||||
local attributeData = Utils:GetIdDataFromJson(JsonAttributes, self.Data.id)
|
||||
self.Variables._imgIcon.Image = Localization:GetImageData(attributeData.iconId)
|
||||
self.Variables._tmpAttributeName.Text = self.Data.id
|
||||
|
||||
local nowLv = self:GetNowLv()
|
||||
self.Variables._tmpLv.Text = "Lv." .. nowLv
|
||||
|
||||
-- 花费按钮显示
|
||||
if self.Data.maxLv then
|
||||
self.Variables._btnUpgrade.Text = nowLv >= self.Data.maxLv and "满级" or self.Data.cost[2] + self.Data.cost[3] * (self.Data.maxLv - 1)
|
||||
|
||||
-- 属性值显示
|
||||
local caculateValue = self.Data.lvAdd[1] + self.Data.lvAdd[2] * (self.Data.maxLv - 1)
|
||||
self.Variables._tmpValue.Text = string.format("%.2f%%", caculateValue / 100)
|
||||
else
|
||||
self.Variables._btnUpgrade.Text = self.Data.cost[2] + self.Data.cost[3] * nowLv
|
||||
-- 属性值显示(下一级)
|
||||
self.Variables._tmpValue.Text = self.Data.lvAdd[1] + self.Data.lvAdd[2] * nowLv
|
||||
end
|
||||
end
|
||||
|
||||
function AttributeLvupShow:OnInitFinish()
|
||||
local con = self.Variables._btnUpgrade.MouseButton1Click:Connect(function()
|
||||
if self.Data.maxLv then
|
||||
if self:GetNowLv() >= self.Data.maxLv then
|
||||
-- TODO: 之后做提示弹窗
|
||||
else
|
||||
RE_UpgradeAttributes:FireServer(self.Data.id)
|
||||
end
|
||||
else
|
||||
-- TODO: 检查货币是否充足
|
||||
RE_UpgradeAttributes:FireServer(self.Data.id)
|
||||
end
|
||||
end)
|
||||
table.insert(self.Connections, con)
|
||||
|
||||
-- 没有实例时,监听文件夹,有实例时,监听实例
|
||||
if not self.instance then
|
||||
local attributeFolder = Utils:GetPlayerDataFolder(LocalPlayer):FindFirstChild("PlayerInfo"):FindFirstChild("AttributesUpgrade")
|
||||
local attributeInst = attributeFolder:FindFirstChild(tostring(self.Data.id))
|
||||
if attributeInst then
|
||||
self.instance = attributeInst
|
||||
else
|
||||
local folderCon = attributeFolder.ChildAdded:Connect(function(child)
|
||||
if child.Name == tostring(self.Data.id) then
|
||||
self.instance = child
|
||||
self:Refresh()
|
||||
end
|
||||
end)
|
||||
self.folderCon = folderCon
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AttributeLvupShow:Destroy()
|
||||
if self.instanceCon then
|
||||
self.instanceCon:Disconnect()
|
||||
self.instanceCon = nil
|
||||
end
|
||||
if self.folderCon then
|
||||
self.folderCon:Disconnect()
|
||||
self.folderCon = nil
|
||||
end
|
||||
for k, v in pairs(self) do
|
||||
self[k] = nil
|
||||
end
|
||||
self = nil
|
||||
end
|
||||
|
||||
return AttributeLvupShow
|
@ -0,0 +1,79 @@
|
||||
--> Services
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
--> Dependencies
|
||||
local UIWindow = require(ReplicatedStorage.Base.UIWindow)
|
||||
local UIEnums = require(ReplicatedStorage.Base.UIEnums)
|
||||
local Utils = require(ReplicatedStorage.Tools.Utils)
|
||||
|
||||
--> Components
|
||||
local AttributeLvupShow = require(script.AttributeLvupShow)
|
||||
|
||||
--> Json
|
||||
local JsonAttributesUpgrade = require(ReplicatedStorage.Json.AttributesUpgrade)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local AttributeLvupWindow = {}
|
||||
AttributeLvupWindow.__index = AttributeLvupWindow
|
||||
setmetatable(AttributeLvupWindow, {__index = UIWindow})
|
||||
|
||||
function AttributeLvupWindow:Init(UIManager: table, Data: table?)
|
||||
local self = UIWindow:Init(UIManager, Data)
|
||||
setmetatable(self, AttributeLvupWindow)
|
||||
self.Variables = {
|
||||
["_goSpecaialPanel"] = 0,
|
||||
["_goBasePanel"] = 0,
|
||||
["__listSpecialAttributes"] = 0,
|
||||
["__listBaseAttributes"] = 0,
|
||||
["_tmpSpecialTitle"] = 0,
|
||||
["_tmpBaseTitle"] = 0,
|
||||
|
||||
["__moneyCoin"] = 0,
|
||||
|
||||
["_btnClose"] = 0,
|
||||
["_btnBgClose"] = 0,
|
||||
}
|
||||
self.UIRootName = "ui_w_attribute_lvup"
|
||||
self.UIParentName = UIEnums.UIParent.UIRoot
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function AttributeLvupWindow:OnOpenWindow()
|
||||
UIWindow.OnOpenWindow(self)
|
||||
|
||||
local orgData = Utils:DeepCopyTable(JsonAttributesUpgrade)
|
||||
local data = {
|
||||
Special = {},
|
||||
Base = {},
|
||||
}
|
||||
|
||||
for key, value in pairs(orgData) do
|
||||
local secondKey = "Base"
|
||||
if value.type == 2 then secondKey = "Special" end
|
||||
table.insert(data[secondKey], value)
|
||||
end
|
||||
|
||||
self:SetData(data)
|
||||
|
||||
|
||||
self.Variables["__listSpecialAttributes"]:AddComponent(AttributeLvupShow)
|
||||
self.Variables["__listBaseAttributes"]:AddComponent(AttributeLvupShow)
|
||||
self.Variables["__listSpecialAttributes"]:SetData(self.Data.Special)
|
||||
self.Variables["__listBaseAttributes"]:SetData(self.Data.Base)
|
||||
self.Variables["__listSpecialAttributes"]:SetLayoutOrder("id")
|
||||
self.Variables["__listBaseAttributes"]:SetLayoutOrder("id")
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
|
||||
return AttributeLvupWindow
|
@ -19,6 +19,7 @@ function PackageShow:Init(data: table)
|
||||
self.Connections = {}
|
||||
|
||||
setmetatable(self, PackageShow)
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@ -38,6 +39,21 @@ function PackageShow:OnInitFinish()
|
||||
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()
|
||||
|
@ -49,6 +49,21 @@ function WearingShow:OnInitFinish()
|
||||
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 WearingShow:Destroy()
|
||||
|
@ -48,20 +48,51 @@ function ChaWindow:ShowDetailData(uniqueId: number)
|
||||
self.UIManager:OpenWindow("EquipmentDetailWindow", data)
|
||||
end
|
||||
|
||||
function ChaWindow:WearRefresh(data: table)
|
||||
local newSlot = data.instance:GetAttribute("wearing")
|
||||
self.Variables["__listWeaing"]:RemoveData("slot"..newSlot)
|
||||
self.Variables["__listWeaponPackage"]:RemoveData(tostring(data.id))
|
||||
|
||||
-- 更新穿戴数据,要不再点击前端就不好使了
|
||||
data.wearing = newSlot
|
||||
self.Variables["__listWeaing"]:AddData("slot"..newSlot, data)
|
||||
|
||||
-- 关闭装备详情窗口
|
||||
self.UIManager:CloseWindow("EquipmentDetailWindow")
|
||||
end
|
||||
|
||||
function ChaWindow:UnwearRefresh(data: table)
|
||||
local oldSlot = data.wearing
|
||||
self.Variables["__listWeaing"]:RemoveData("slot"..oldSlot)
|
||||
data.wearing = 0
|
||||
self.Variables["__listWeaponPackage"]:AddData(tostring(data.id), data)
|
||||
self.Data.Wearing["slot"..oldSlot] = {
|
||||
wearing = oldSlot,
|
||||
}
|
||||
self.Variables["__listWeaing"]:AddData("slot"..oldSlot, self.Data.Wearing["slot"..oldSlot])
|
||||
|
||||
-- 关闭装备详情窗口
|
||||
self.UIManager:CloseWindow("EquipmentDetailWindow")
|
||||
end
|
||||
|
||||
function ChaWindow:AddInstanceData(configInstance: Instance, Data: table?)
|
||||
local data = self.Data
|
||||
if Data then data = Data end
|
||||
local attributes = configInstance:GetAttributes()
|
||||
|
||||
-- 归类是否是穿戴的装备
|
||||
local parentName = "Package"
|
||||
if attributes.wearing ~= 0 then parentName = "Wearing" end
|
||||
data[parentName][configInstance.Name] = {}
|
||||
local parentName, secondName = "Package", configInstance.Name
|
||||
if attributes.wearing ~= 0 then
|
||||
parentName = "Wearing"
|
||||
secondName = "slot"..attributes.wearing
|
||||
end
|
||||
data[parentName][secondName] = {}
|
||||
|
||||
for attributeKey, attributeValue in attributes do
|
||||
data[parentName][configInstance.Name][attributeKey] = attributeValue
|
||||
data[parentName][secondName][attributeKey] = attributeValue
|
||||
end
|
||||
return data[parentName][configInstance.Name], parentName
|
||||
data[parentName][secondName].instance = configInstance
|
||||
return data[parentName][secondName], parentName
|
||||
end
|
||||
|
||||
function ChaWindow:OnOpenWindow()
|
||||
@ -97,9 +128,9 @@ function ChaWindow:OnOpenWindow()
|
||||
local addCon = DataFolder.ChildAdded:Connect(function(child)
|
||||
local data, parentName = self:AddInstanceData(child, data)
|
||||
if parentName == "Wearing" then
|
||||
self.Variables["__listWeaing"]:AddData(data)
|
||||
self.Variables["__listWeaing"]:AddData("slot"..data.wearing, data)
|
||||
else
|
||||
self.Variables["__listWeaponPackage"]:AddData(data)
|
||||
self.Variables["__listWeaponPackage"]:AddData(child.Name, data)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -17,6 +17,7 @@ function MainWindow:Init(UIManager: table, Data: table?)
|
||||
self.Variables = {
|
||||
["_btnMainCreate"] = 0,
|
||||
["_btnMainCha"] = 0,
|
||||
["_btnMainAttributeUpgrade"] = 0,
|
||||
}
|
||||
self.UIRootName = "ui_w_main"
|
||||
self.UIParentName = UIEnums.UIParent.UIRoot
|
||||
@ -33,9 +34,13 @@ function MainWindow:OnOpenWindow()
|
||||
local chaCon = self.Variables["_btnMainCha"].Activated:Connect(function()
|
||||
self.UIManager:OpenWindow("ChaWindow")
|
||||
end)
|
||||
local attributeUpgradeCon = self.Variables["_btnMainAttributeUpgrade"].Activated:Connect(function()
|
||||
self.UIManager:OpenWindow("AttributeLvupWindow")
|
||||
end)
|
||||
|
||||
table.insert(self.Connections, createCon)
|
||||
table.insert(self.Connections, chaCon)
|
||||
table.insert(self.Connections, attributeUpgradeCon)
|
||||
end
|
||||
|
||||
|
||||
|
63
src/StarterPlayerScripts/UI/Windows/TipsWindow/init.luau
Normal file
63
src/StarterPlayerScripts/UI/Windows/TipsWindow/init.luau
Normal file
@ -0,0 +1,63 @@
|
||||
--> Services
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
--> Dependencies
|
||||
local UIWindow = require(ReplicatedStorage.Base.UIWindow)
|
||||
local UIEnums = require(ReplicatedStorage.Base.UIEnums)
|
||||
local Tween = require(ReplicatedStorage.Modules.Tween)
|
||||
|
||||
--> Components
|
||||
|
||||
--> Events
|
||||
local RE_PlayerTip = ReplicatedStorage.Events.RE_PlayerTip
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local TipsWindow = {}
|
||||
TipsWindow.__index = TipsWindow
|
||||
setmetatable(TipsWindow, {__index = UIWindow})
|
||||
|
||||
function TipsWindow:Init(UIManager: table, Data: table?)
|
||||
local self = UIWindow:Init(UIManager, Data)
|
||||
setmetatable(self, TipsWindow)
|
||||
self.Variables = {
|
||||
["__goPanel1"] = 0,
|
||||
}
|
||||
self.UIRootName = "ui_w_tips"
|
||||
self.UIParentName = UIEnums.UIParent.UIRoot
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function TipsWindow:ShowPanel1(text: string)
|
||||
local newPanel = self.Variables["__goPanel1"]:Clone()
|
||||
newPanel.Parent = self.UIRoot
|
||||
newPanel.Visible = true
|
||||
newPanel:FindFirstChild("_tmpContent").Text = text or ""
|
||||
|
||||
-- 设置初始位置(向下偏移)
|
||||
|
||||
-- 创建向上移动的tween动画
|
||||
local tween = Tween:Play(newPanel, {2, "Circular", "Out"}, {
|
||||
Position = newPanel.Position + UDim2.new(0, 0, 0, -80)
|
||||
})
|
||||
|
||||
-- 动画完成后自动销毁面板
|
||||
tween.Completed:Once(function()
|
||||
task.delay(0.5, function()
|
||||
newPanel:Destroy()
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
function TipsWindow:OnOpenWindow()
|
||||
UIWindow.OnOpenWindow(self)
|
||||
|
||||
self.Variables["__goPanel1"].Visible = false
|
||||
local con = RE_PlayerTip.OnClientEvent:Connect(function(data)
|
||||
self:ShowPanel1(data)
|
||||
end)
|
||||
table.insert(self.Connections, con)
|
||||
end
|
||||
|
||||
return TipsWindow
|
Loading…
x
Reference in New Issue
Block a user