--> Services local ReplicatedStorage = game:GetService("ReplicatedStorage") --> Dependencies local UIWindow = require(ReplicatedStorage.Base.UIWindow) local UIEnums = require(ReplicatedStorage.Base.UIEnums) --> Json local JsonLevel = require(ReplicatedStorage.Json.Level) local Utils = require(ReplicatedStorage.Tools.Utils) local LocalPlayer = game:GetService("Players").LocalPlayer -------------------------------------------------------------------------------- local MainWindow = {} MainWindow.__index = MainWindow setmetatable(MainWindow, {__index = UIWindow}) function MainWindow:Init(UIManager: table, Data: table?) local self = UIWindow:Init(UIManager, Data) setmetatable(self, MainWindow) self.Variables = { ["_btnMainCreate"] = 0, ["_btnMainCha"] = 0, ["_btnMainAttributeUpgrade"] = 0, ["_tmpNowLevel"] = 0, ["_imgBoss"] = 0, } self.UIRootName = "ui_w_main" self.UIParentName = UIEnums.UIParent.UIRoot return self end function MainWindow:SetShowLevel(level: number) self.Variables["_tmpNowLevel"].Text = string.format("第%d关", level) local levelData = Utils:GetIdDataFromJson(JsonLevel, level) if levelData.type == 2 then self.Variables["_imgBoss"].Visible = true else self.Variables["_imgBoss"].Visible = false end end function MainWindow:OnOpenWindow() UIWindow.OnOpenWindow(self) local createCon = self.Variables["_btnMainCreate"].Activated:Connect(function() self.UIManager:OpenWindow("CreateWindow") end) 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) -- TODO: 暂时用主关卡数显示,我记得之前这里主要是记录的,Challenge中才是正在挑战的内容 -- TODO: 之后LevelProxy也应该挪到ReplicatedStorage下,之前可能是因为觉得Challenge是临时的内容所以放在workspace下,但是逻辑做的不统一 local playerDataFolder = game.Workspace:WaitForChild("Level"):WaitForChild(LocalPlayer.UserId) local StatsFolder = playerDataFolder:WaitForChild("Progress") local levelCon = StatsFolder.Main.Changed:Connect(function(newValue) self:SetShowLevel(newValue) end) -- 初始值设置 self:SetShowLevel(StatsFolder.Main.Value) table.insert(self.Connections, levelCon) end return MainWindow