Skip to content

Commit 025678f

Browse files
committed
Main menu stuff
1 parent f829c5a commit 025678f

4 files changed

Lines changed: 52 additions & 16 deletions

File tree

api/connection.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ local _connection = nil
2828
local _ready = false
2929
local _ready_callbacks = {}
3030
local _last_opts = nil
31+
local _state_change_callbacks = {}
3132

3233
local SERVER_DEFAULTS = {
3334
api_url = 'http://localhost:8788',
@@ -55,6 +56,10 @@ MPAPI.on_loaded = function(fn)
5556
_ready_callbacks[#_ready_callbacks + 1] = fn
5657
end
5758

59+
MPAPI.on_connection_state_change = function(fn)
60+
_state_change_callbacks[#_state_change_callbacks + 1] = fn
61+
end
62+
5863
MPAPI.connect = function(opts)
5964
opts = opts or {}
6065
_last_opts = opts
@@ -293,6 +298,13 @@ connection_on_state_change = function(new_state, context)
293298
end
294299

295300
run_new_state_user_callbacks(new_state, context)
301+
302+
for _, fn in ipairs(_state_change_callbacks) do
303+
local ok, err = pcall(fn, new_state, context)
304+
if not ok then
305+
MPAPI.sendWarnMessage('on_connection_state_change callback error: ' .. tostring(err))
306+
end
307+
end
296308
end
297309

298310
log_state_update = function(new_state, context)

api/mod_registry.lua

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ MPAPI.register_mod = function(opts)
4747
return
4848
end
4949

50+
local hide_logo = opts.hide_logo == true
51+
5052
local existing = _registered_mods[opts.id]
5153
if existing and existing.is_official then
5254
existing.main_menu_ui = opts.main_menu_ui
5355
existing.server_config = opts.server_config
56+
existing.hide_logo = hide_logo
5457
if opts.name then
5558
existing.name = opts.name
5659
end
@@ -65,6 +68,7 @@ MPAPI.register_mod = function(opts)
6568
server_config = opts.server_config,
6669
main_menu_ui = opts.main_menu_ui,
6770
download_url = opts.download_url,
71+
hide_logo = hide_logo,
6872
is_official = false,
6973
}
7074
_mod_order[#_mod_order + 1] = opts.id
@@ -119,7 +123,7 @@ MPAPI._internal.activate_mod = function(id)
119123

120124
_active_mod = id
121125

122-
replace_main_menu(mod.main_menu_ui)
126+
replace_main_menu(mod.main_menu_ui, mod.hide_logo)
123127
update_account_button()
124128
end
125129

@@ -160,10 +164,25 @@ update_account_button = function()
160164
end
161165
end
162166

163-
replace_main_menu = function(build_fn)
167+
replace_main_menu = function(build_fn, hide_logo)
164168
if G.MAIN_MENU_UI then
165169
G.MAIN_MENU_UI:remove()
166170
end
171+
if G.PROFILE_BUTTON then
172+
G.PROFILE_BUTTON:remove()
173+
G.PROFILE_BUTTON = nil
174+
end
175+
if hide_logo then
176+
if G.SPLASH_LOGO then
177+
G.SPLASH_LOGO.states.visible = false
178+
end
179+
if G.title_top then
180+
G.title_top.states.visible = false
181+
for _, card in ipairs(G.title_top.cards or {}) do
182+
card.states.visible = false
183+
end
184+
end
185+
end
167186
G.MAIN_MENU_UI = UIBox({
168187
definition = build_fn(),
169188
config = { align = 'bmi', offset = { x = 0, y = 10 }, major = G.ROOM_ATTACH, bond = 'Weak' },
@@ -172,10 +191,23 @@ replace_main_menu = function(build_fn)
172191
G.MAIN_MENU_UI:align_to_major()
173192
end
174193

194+
MPAPI._internal.replace_main_menu = function(build_fn, hide_logo)
195+
replace_main_menu(build_fn, hide_logo)
196+
end
197+
175198
restore_main_menu = function()
176199
if G.MAIN_MENU_UI then
177200
G.MAIN_MENU_UI:remove()
178201
end
202+
if G.SPLASH_LOGO then
203+
G.SPLASH_LOGO.states.visible = true
204+
end
205+
if G.title_top then
206+
G.title_top.states.visible = true
207+
for _, card in ipairs(G.title_top.cards or {}) do
208+
card.states.visible = true
209+
end
210+
end
179211
if _original_set_main_menu_UI then
180212
_original_set_main_menu_UI()
181213
end

localization/en-us.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ return {
2222
k_unlink_discord = 'Unlink Discord',
2323
b_open_download_page = 'Open Download Page',
2424
b_retry_connection = 'Retry Connection',
25+
b_create_lobby_cap = { 'CREATE', 'LOBBY' },
26+
b_join_lobby_cap = 'JOIN LOBBY',
27+
b_by_code_cap = 'BY CODE',
28+
b_from_clipboard_cap = 'FROM CLIPBOARD',
29+
b_find_game_cap = 'FIND GAME',
2530
},
2631
},
2732
}

ui/main_menu.lua

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
-- Forward declarations for helper functions
22
local build_mod_buttons
33
local build_mod_button
4-
local set_modded_main_menu_ui
54
local attach_account_button
65

76
-----------------------------
@@ -140,18 +139,6 @@ build_mod_button = function(mod, inner_width)
140139
}
141140
end
142141

143-
set_modded_main_menu_ui = function(mod)
144-
if G.MAIN_MENU_UI then
145-
G.MAIN_MENU_UI:remove()
146-
end
147-
G.MAIN_MENU_UI = UIBox({
148-
definition = mod.main_menu_ui(),
149-
config = { align = 'bmi', offset = { x = 0, y = 10 }, major = G.ROOM_ATTACH, bond = 'Weak' },
150-
})
151-
G.MAIN_MENU_UI.alignment.offset.y = 0
152-
G.MAIN_MENU_UI:align_to_major()
153-
end
154-
155142
attach_account_button = function()
156143
G.E_MANAGER:add_event(Event({
157144
blockable = false,
@@ -207,7 +194,7 @@ set_main_menu_UI = function()
207194
local active = MPAPI.get_active_mod_data()
208195

209196
if active and active.main_menu_ui then
210-
set_modded_main_menu_ui(active)
197+
MPAPI._internal.replace_main_menu(active.main_menu_ui, active.hide_logo)
211198
else
212199
_set_main_menu_UI_ref()
213200
end

0 commit comments

Comments
 (0)