-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodservercreationmain.lua
More file actions
205 lines (182 loc) · 7.44 KB
/
Copy pathmodservercreationmain.lua
File metadata and controls
205 lines (182 loc) · 7.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
local menv = env
GLOBAL.setfenv(1, GLOBAL)
local eventname = "fe_unload_".. menv.modname
local iconname = menv.modname .. "_dynamic_icon"
local UIAnim = require("widgets/uianim")
if not rawget(_G, "EventTimerFePatches") then
_G.EventTimerFePatches = {}
end
menv.FrontEndAssets = {
Asset("ANIM", "anim/global_events_timer_dynamic_icon.zip"),
}
local function DoFnForCurrentScreen(fn)
scheduler:ExecuteInTime(0, function()
for _, screen in ipairs(TheFrontEnd.screenstack) do
if screen.name == "ServerCreationScreen" then
fn(screen)
break
end
end
end)
end
local function AddDynamicIcon(self, root, s, x, y)
if self[iconname] then
return
end
self[iconname] = self[root]:AddChild(UIAnim())
self[iconname]:GetAnimState():SetBuild("global_events_timer_dynamic_icon")
self[iconname]:GetAnimState():SetBank("global_events_timer_dynamic_icon")
self[iconname]:GetAnimState():PlayAnimation("global_events_timer_dynamic_icon", true)
-- self[iconname]:GetAnimState():PushAnimation("", true)
-- self[iconname]:GetAnimState():SetTime(22 * FRAMES)
self[iconname]:SetPosition(x or 0, y or 0)
if s then
self[iconname]:SetScale(s)
end
self[iconname].inst:ListenForEvent(eventname, function()
self[iconname]:Kill()
self[iconname] = nil
end, TheGlobalInstance)
end
local function PatchModDetails(self)
if not _G.EventTimerFePatches.DynamicIconEnabled then return end
if self.currentmodname == menv.modname then
AddDynamicIcon(self, "detailimage", 0.55, 3, 2.5)
elseif self[iconname] then
self[iconname]:Kill()
self[iconname] = nil
end
end
local function PatchModIcon(widget, data)
if not _G.EventTimerFePatches.DynamicIconEnabled then return end
local opt = widget.moditem
local mod_data = (data or widget.data)
if mod_data and mod_data.mod and mod_data.mod.modname == menv.modname then
-- Fox: It seems that it triggers too fast if we change world tabs
if not data and opt[iconname] then
opt[iconname]:Kill()
opt[iconname] = nil
end
AddDynamicIcon(opt, "image", 0.45, 3, 0)
elseif opt[iconname] then
opt[iconname]:Kill()
opt[iconname] = nil
end
end
if not _G.EventTimerFePatches["HookedFrontendUnloadMod_" .. menv.modname] then
local _FrontendUnloadMod = ModManager.FrontendUnloadMod
ModManager.FrontendUnloadMod = function(self, unloaded_modname, ...)
if not unloaded_modname or unloaded_modname == menv.modname then
TheGlobalInstance:PushEvent(eventname)
end
return _FrontendUnloadMod(self, unloaded_modname, ...)
end
_G.EventTimerFePatches["HookedFrontendUnloadMod_" .. menv.modname] = true
end
local function PreLoad(self)
local _update_fn
local mods_page
if self.mods_tab then -- 创建世界的模组列表页面
mods_page = self.mods_tab
else
return
end
if mods_page.mods_scroll_list then
for i, widget in ipairs(mods_page.mods_scroll_list:GetListWidgets()) do
PatchModIcon(widget)
end
end
if not mods_page[menv.modname .. "_hooked_mods_page"] then
local _ShowModDetails = mods_page.ShowModDetails
mods_page.ShowModDetails = function(self, idx, ...)
_ShowModDetails(self, idx, ...)
PatchModDetails(self)
end
if mods_page.mods_scroll_list.update_fn and not _update_fn then
_update_fn = mods_page.mods_scroll_list.update_fn
mods_page.mods_scroll_list.update_fn = function(context, widget, data, index, ...)
_update_fn(context, widget, data, index, ...)
PatchModIcon(widget, data)
end
end
mods_page[menv.modname .. "_hooked_mods_page"] = true
end
TheGlobalInstance:ListenForEvent(eventname, function()
-- mods_page.mods_scroll_list.update_fn = _update_fn
-- mods_page.ShowModDetails = _ShowModDetails
_G.EventTimerFePatches.DynamicIconEnabled = false
ModUnloadFrontEndAssets(menv.modname)
end)
_G.EventTimerFePatches.DynamicIconEnabled = true
PatchModDetails(mods_page)
end
if rawget(_G, "TheFrontEnd") then
menv.ReloadFrontEndAssets()
DoFnForCurrentScreen(PreLoad)
-- 尝试自动开启依赖模组
local basementmod = rawget(_G, "BBGOAT_utils") and BBGOAT_utils.server_folder_name
if basementmod and not KnownModIndex:IsModEnabledAny(basementmod) then
KnownModIndex:Enable(basementmod)
elseif not basementmod then -- 麻烦呐
local _languages = {
zh = true, --Chinese for Steam
zhr = true, --Chinese for WeGame
ch = true, --Chinese mod
chs = true, --Chinese mod
sc = true, --simple Chinese
chinese = true, --Chinese mod
zht = true, --traditional Chinese for Steam
tc = true, --traditional Chinese
cht = true, --Chinese mod
}
local lang = LanguageTranslator and LanguageTranslator.defaultlang
local isCH = lang and _languages[lang]
local PopupDialogScreen = require "screens/redux/popupdialog"
TheFrontEnd:PushScreen(PopupDialogScreen(
menv.modinfo.name,
isCH and "模组基础运行库缺失!\n你缺少了模组基础运行库,你必须去订阅才能继续使用本模组" or
"Mod Runtime Library Missing!\nYou are missing the required runtime library for this mod. Please subscribe to it before continuing to use this mod.",
{
{
text = isCH and "订阅/启用运行库模组" or "Subscribe/Enable mod",
cb = function()
local modname = "workshop-3750536829"
if table.contains(TheSim:GetModDirectoryNames(), modname) then
KnownModIndex:Enable(modname)
KnownModIndex:Save()
TheGlobalInstance:DoTaskInTime(0.5, function()
TheNet:Disconnect(true)
TheSim:ResetError()
StartNextInstance()
end)
else
TheSim:SubscribeToMod("workshop-3750536829")
TheFrontEnd:PopScreen()
TheFrontEnd:PushScreen(PopupDialogScreen(
isCH and "已订阅" or "Subscribed",
isCH and "请前往客户端模组列表启用【冰冰羊的模组运行库】模组" or "Please go to the client mods list to enable the runtime library mod named\n\"BBGOAT Utils\"",
{
{
text = isCH and "好的" or "OK",
cb = function()
TheFrontEnd:PopScreen()
c_reset()
end
}
}
))
end
end
},
{
text = isCH and "返回" or "Back",
cb = function()
KnownModIndex:Disable(menv.modname)
TheGlobalInstance:PushEvent(eventname) -- 取消注册模组动态图标
TheFrontEnd:PopScreen()
end
},
}
))
end
end