-
Notifications
You must be signed in to change notification settings - Fork 12
/
modservercreationmain.lua
68 lines (58 loc) · 3.09 KB
/
modservercreationmain.lua
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
local modname = modname
local modimport = modimport
GLOBAL.setfenv(1, GLOBAL)
modimport("main/toolutil")
modimport("main/strings")
modimport("modfrontendmain")
modimport("modcustomizeitems")
local TEMPLATES = require("widgets/redux/templates")
local PopupDialogScreen = require("screens/redux/popupdialog")
local ChooseWorldSreen = require("widgets/redux/chooseworldscreen")
local world_locations = {
[1] = {FOREST = true, PORKLAND = true, CAVE = true},
[2] = {CAVE = true}
}
local function SetLevelLocations(servercreationscreen, location, i)
local server_level_locations = {}
server_level_locations[i] = location
server_level_locations[3 - i] = SERVER_LEVEL_LOCATIONS[3 - i]
servercreationscreen:SetLevelLocations(server_level_locations)
local text = servercreationscreen.world_tabs[i]:GetLocationTabName()
servercreationscreen.world_config_tabs.menu.items[i + 1]:SetText(text)
end
local function OnWorldButton(world_tab, i)
if world_tab:GetParentScreen() then
world_tab:GetParentScreen().last_focus = TheFrontEnd:GetFocusWidget()
end
local currentworld = world_tab:GetLocation()
local chooseworldscreen = ChooseWorldSreen(world_tab, currentworld, i, SetLevelLocations, world_locations)
TheFrontEnd:PushScreen(chooseworldscreen)
end
scheduler:ExecuteInTime(0, function() -- Delay a frame so we can get ServerCreationScreen when entering a existing world
local servercreationscreen = TheFrontEnd:GetOpenScreenOfType("ServerCreationScreen")
if not (KnownModIndex:IsModEnabled(modname) and servercreationscreen and servercreationscreen.world_tabs and servercreationscreen.world_tabs[1]) then
return
end
for i, world_tab in ipairs(servercreationscreen.world_tabs) do
if world_tab:GetLocation() ~= SERVER_LEVEL_LOCATIONS[i] and servercreationscreen:CanResume() then -- and servercreationscreen:CanResume()
SERVER_LEVEL_LOCATIONS[i] = world_tab:GetLocation()
servercreationscreen.world_tabs[i]:RefreshOptionItems()
local text = servercreationscreen.world_tabs[i]:GetLocationTabName()
servercreationscreen.world_config_tabs.menu.items[i + 1]:SetText(text)
end
if world_tab.settings_widget:IsNewShard() then
if not world_tab.choose_world_button then
world_tab.choose_world_button = world_tab.settings_root:AddChild(TEMPLATES.StandardButton(function() OnWorldButton(world_tab, i) end, STRINGS.UI.SANDBOXMENU.CHOOSEWORLD))
world_tab.choose_world_button.image:SetScale(.47)
world_tab.choose_world_button.text:SetColour(0, 0, 0, 1)
world_tab.choose_world_button:SetTextSize(19.6)
world_tab.choose_world_button:SetPosition(320, 285)
elseif not world_tab.choose_world_button.shown then
world_tab.choose_world_button:Show()
end
end
end
-- if not servercreationscreen:CanResume() then -- Only when first time creating the world
SetLevelLocations(servercreationscreen, "porkland", 1) -- Automatically try switching to the porkland preset
-- end
end)