Skip to content

Commit d30b012

Browse files
authored
Refactor title screen and music spinner (#786)
* Refactor title screen and music spinner * Don't need that * Ah yes
1 parent 0b207d9 commit d30b012

14 files changed

Lines changed: 126 additions & 109 deletions

File tree

code/_onclick/hud/new_player.dm

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
///Whether the menu is currently on the client's screen or not
88
var/menu_hud_status = TRUE
99

10+
1011
/datum/hud/new_player/New(mob/owner)
1112
. = ..()
1213

@@ -29,6 +30,9 @@
2930
if (istype(lobbyscreen, /atom/movable/screen/lobby/button))
3031
var/atom/movable/screen/lobby/button/lobby_button = lobbyscreen
3132
lobby_button.owner = REF(owner)
33+
34+
static_inventory += new /atom/movable/screen/lobby_init_text(our_hud = src)
35+
static_inventory += new /atom/movable/screen/lobby_music(our_hud = src)
3236
add_station_trait_buttons()
3337

3438
/// Display buttons for relevant station traits
@@ -585,3 +589,63 @@
585589
#undef SHUTTER_MOVEMENT_DURATION
586590
#undef SHUTTER_WAIT_DURATION
587591
#undef MAX_STATION_TRAIT_BUTTONS_VERTICAL
592+
593+
/atom/movable/screen/lobby_init_text
594+
maptext_height = 500
595+
maptext_width = 225
596+
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
597+
plane = SPLASHSCREEN_PLANE
598+
screen_loc = "LEFT+0.25,BOTTOM+0.25"
599+
600+
/atom/movable/screen/lobby_init_text/New(loc, datum/hud/our_hud, ...)
601+
src.hud = our_hud
602+
return ..()
603+
604+
/atom/movable/screen/lobby_init_text/Initialize(mapload, datum/hud/hud_owner)
605+
. = ..()
606+
if(SStitle.stats_faded || !hud?.mymob?.client?.prefs?.read_preference(/datum/preference/toggle/show_init_stats))
607+
alpha = 0 // we still need to init it incase they turn it back on
608+
609+
/atom/movable/screen/lobby_music
610+
icon = 'maplestation_modules/icons/hud/lobby_spinner.dmi'
611+
icon_state = "spinner"
612+
maptext_height = 100
613+
maptext_width = 225
614+
maptext_y = -10
615+
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
616+
plane = SPLASHSCREEN_PLANE
617+
screen_loc = "LEFT+0.25,TOP-0.25"
618+
/// World time when the current song started playing for this player
619+
var/start_time
620+
/// World time when the current song will stop playing for this player
621+
var/end_time
622+
623+
/atom/movable/screen/lobby_music/New(loc, datum/hud/our_hud, ...)
624+
src.hud = our_hud
625+
return ..()
626+
627+
/atom/movable/screen/lobby_music/Initialize(mapload, datum/hud/hud_owner)
628+
. = ..()
629+
if(!hud?.mymob?.client?.prefs?.read_preference(/datum/preference/toggle/sound_lobby))
630+
alpha = 0 // we still need to init it incase they turn it back on
631+
632+
/atom/movable/screen/lobby_music/proc/start_tracking()
633+
animate(src)
634+
alpha = 255
635+
start_time = world.time
636+
end_time = start_time + SSticker.login_length
637+
START_PROCESSING(SSlobby_music_player, src)
638+
639+
/atom/movable/screen/lobby_music/process(seconds_per_tick)
640+
maptext = "[SStitle.music_maptext]<br>[MAPTEXT("\u25B6 [time2text(min(world.time - start_time, SSticker.login_length), "mm:ss", 0)] / [time2text(SSticker.login_length, "mm:ss", 0)]s")]"
641+
if(world.time >= end_time)
642+
animate(src, alpha = 0, time = 5 SECONDS)
643+
return PROCESS_KILL
644+
645+
/atom/movable/screen/lobby_music/proc/cancel_tracking()
646+
STOP_PROCESSING(SSlobby_music_player, src)
647+
animate(src, alpha = 0, time = 1 SECONDS)
648+
649+
/atom/movable/screen/lobby_music/Destroy()
650+
STOP_PROCESSING(SSlobby_music_player, src)
651+
return ..()

code/controllers/master.dm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ ADMIN_VERB(cmd_controller_view_ui, R_SERVER|R_DEBUG, "Controller Overview", "Vie
444444
Master.StartProcessing(0)
445445

446446
var/time = (REALTIMEOFDAY - start_timeofday) / (1 SECONDS)
447-
SStitle.total_init_time = time
447+
SStitle.total_init_time = round(time, 0.01)
448448
log_world("Initializations complete within [time] second\s!")
449449

450450
if(world.system_type == MS_WINDOWS && CONFIG_GET(flag/toast_notification_on_init) && !length(GLOB.clients))
@@ -1021,4 +1021,3 @@ ADMIN_VERB(cmd_controller_view_ui, R_SERVER|R_DEBUG, "Controller Overview", "Vie
10211021
return FALSE
10221022
last_profiled = REALTIMEOFDAY
10231023
SSprofiler.DumpFile(allow_yield = FALSE)
1024-
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// Updates lobby music hud elements
2+
PROCESSING_SUBSYSTEM_DEF(lobby_music_player)
3+
name = "Lobby Music Player"
4+
flags = SS_NO_INIT|SS_BACKGROUND|SS_KEEP_TIMING
5+
runlevels = ALL
6+
wait = 1 SECONDS

code/controllers/subsystem/ticker.dm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ SUBSYSTEM_DEF(ticker)
1818
/// Boolean to track and check if our subsystem setup is done.
1919
var/setup_done = FALSE
2020

21-
var/login_music //music played in pregame lobby
21+
/// Music played in pregame lobby
22+
var/login_music
23+
/// Length of the music in deciseconds
24+
var/login_length
25+
2226
var/round_end_sound //music/jingle played when the world reboots
2327
var/round_end_sound_sent = TRUE //If all clients have loaded it
2428

@@ -782,6 +786,7 @@ SUBSYSTEM_DEF(ticker)
782786
return
783787

784788
login_music = new_music
789+
login_length = rustg_sound_length(new_music)
785790
var/list/music_file_components = splittext(new_music, "/")
786791
var/music_file_name = length(music_file_components) && music_file_components[length(music_file_components)] || new_music
787792
var/list/music_name_components = splittext(music_file_name, "+")

code/controllers/subsystem/title.dm

Lines changed: 30 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ SUBSYSTEM_DEF(title)
1010
var/icon/previous_icon
1111
/// Reference to the turf in the lobby, which is where we hold the title screen
1212
var/turf/closed/indestructible/splashscreen/splash_turf
13-
/// A holder for maptext that displays initialization information on the title screen
14-
var/obj/effect/abstract/maptext_holder/init/init_stat_holder
15-
/// A holder for maptext that displays the playing music on the title screen
16-
var/obj/effect/abstract/maptext_holder/music/music_holder
13+
/// Holds the maptext that displays initialization information on the title screen
14+
var/init_stat_maptext
15+
/// Tracks when stats have been faded out for everyone
16+
var/stats_faded = FALSE
17+
/// Holds the maptext that displays the playing music on the title screen
18+
var/music_maptext
1719

1820
/// A list of initialization information
1921
var/list/init_infos = list()
@@ -89,18 +91,13 @@ SUBSYSTEM_DEF(title)
8991
return
9092
if(!music_string)
9193
return
92-
if(!music_holder)
93-
if(!splash_turf)
94-
return
95-
music_holder = new(splash_turf)
96-
97-
music_holder.pixel_x = initial(music_holder.pixel_x) - (length(music_string) * 8)
98-
music_holder.maptext = ""
99-
music_holder.maptext += "<span class='maptext'>"
100-
music_holder.maptext += "<span class='big'>"
101-
music_holder.maptext += "Now playing: [music_string]"
102-
music_holder.maptext += "</span>"
103-
music_holder.maptext += "</span>"
94+
95+
music_maptext = ""
96+
music_maptext += "<span class='maptext'>"
97+
music_maptext += "<span class='big'>"
98+
music_maptext += "Now playing: [music_string]"
99+
music_maptext += "</span>"
100+
music_maptext += "</span>"
104101

105102
/// Max number of init entries to display
106103
/// If this is exceeded, the oldest entry will be removed (but it generally should not be exceeded)
@@ -119,6 +116,8 @@ SUBSYSTEM_DEF(title)
119116
* * major_update: Indicates this init text is a major update, which will update a "dot" animation.
120117
*/
121118
/datum/controller/subsystem/title/proc/add_init_text(init_category, name, stage, seconds, override = FALSE, major_update = FALSE)
119+
if(isnum(seconds))
120+
seconds = round(seconds, 0.1)
122121
if(override || !init_infos[init_category])
123122
init_infos[init_category] = list(name, stage, seconds)
124123
else
@@ -139,13 +138,8 @@ SUBSYSTEM_DEF(title)
139138

140139
/// Updates the displayed initialization text according to all initialization information
141140
/datum/controller/subsystem/title/proc/update_init_text()
142-
if(!init_stat_holder)
143-
if(!splash_turf)
144-
return
145-
init_stat_holder = new(splash_turf)
146-
147-
init_stat_holder.maptext = "<span class='maptext'>"
148-
init_stat_holder.maptext += "<span class='big'>"
141+
init_stat_maptext = "<span class='maptext'>"
142+
init_stat_maptext += "<span class='big'>"
149143
if(SSticker?.current_state == GAME_STATE_PREGAME)
150144
var/total_time_formatted = "[total_init_time]s"
151145
switch(total_init_time)
@@ -156,83 +150,26 @@ SUBSYSTEM_DEF(title)
156150
if(120 to INFINITY)
157151
total_time_formatted = "<font color='red'>[total_init_time]s</font>"
158152

159-
init_stat_holder.maptext += "Game Ready! ([total_time_formatted])"
153+
init_stat_maptext += "Game Ready! ([total_time_formatted])"
160154
else
161-
init_stat_holder.maptext += "Initializing game"
155+
init_stat_maptext += "Initializing game"
162156
for(var/i in 1 to num_dots)
163-
init_stat_holder.maptext += "."
164-
init_stat_holder.maptext += "</span><br>"
157+
init_stat_maptext += "."
158+
init_stat_maptext += "</span><br>"
165159
for(var/sstype in init_infos)
166160
var/list/init_data = init_infos[sstype]
167161
var/init_name = init_data[1]
168162
var/init_stage = init_data[2]
169163
var/init_time = isnum(init_data[3]) ? "([init_data[3]]s)" : ""
170-
init_stat_holder.maptext += "<br>[init_name] [init_stage] [init_time]"
171-
init_stat_holder.maptext += "<br></span>"
164+
init_stat_maptext += "<br>[init_name] [init_stage] [init_time]"
165+
init_stat_maptext += "<br></span>"
166+
for(var/mob/dead/new_player/lobbyguy as anything in GLOB.new_player_list)
167+
for(var/atom/movable/screen/lobby_init_text/text in lobbyguy.hud_used?.static_inventory)
168+
text.maptext = SStitle.init_stat_maptext
172169

173170
/// Simply fades out the initialization text
174171
/datum/controller/subsystem/title/proc/fade_init_text()
175-
update_init_text()
176-
animate(init_stat_holder, alpha = 0, time = 8 SECONDS)
177-
178-
/// Abstract holder for maptext on the lobby screen
179-
/obj/effect/abstract/maptext_holder
180-
icon = null
181-
icon_state = null
182-
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
183-
plane = SPLASHSCREEN_PLANE
184-
/// Conceals the holder from clients who don't want to see it
185-
var/image/hide_me
186-
187-
/obj/effect/abstract/maptext_holder/Initialize(mapload)
188-
. = ..()
189-
for(var/mob/dead/new_player/lobby_goer as anything in GLOB.new_player_list)
190-
check_client(lobby_goer.client)
191-
192-
/// Check if the client should see or should not see the initialization information. Updates accordingly.
193-
/obj/effect/abstract/maptext_holder/proc/check_client(client/seer)
194-
if(isnull(seer))
195-
return
196-
if(!check_preferences(seer))
197-
hide_from_client(seer)
198-
return
199-
show_to_client(seer)
200-
201-
/// Return TRUE if this maptext holder should be visible to the client
202-
/obj/effect/abstract/maptext_holder/proc/check_preferences(client/seer)
203-
// default check for widescreen, because elements at the edge of the screen are cut off and i'm too lazy to fix it
204-
return seer.prefs.read_preference(/datum/preference/toggle/widescreen)
205-
206-
/// Hides the initialization information from the client
207-
/obj/effect/abstract/maptext_holder/proc/hide_from_client(client/seer)
208-
if(isnull(hide_me))
209-
hide_me = image(loc = src)
210-
hide_me.override = TRUE
211-
seer?.images |= hide_me
212-
213-
/// Shows the initialization information to the client (if already hidden, otherwise nothing happens)
214-
/obj/effect/abstract/maptext_holder/proc/show_to_client(client/seer)
215-
seer?.images -= hide_me
216-
217-
/obj/effect/abstract/maptext_holder/init
218-
maptext_height = 500
219-
maptext_width = 200
220-
maptext_x = 12
221-
maptext_y = 12
222-
pixel_x = -64
223-
224-
/obj/effect/abstract/maptext_holder/init/check_preferences(client/seer)
225-
return ..() && seer.prefs.read_preference(/datum/preference/toggle/show_init_stats)
226-
227-
/obj/effect/abstract/maptext_holder/music
228-
icon = 'maplestation_modules/icons/hud/lobby_spinner.dmi'
229-
icon_state = "spinner"
230-
maptext_height = 64
231-
maptext_width = 200
232-
maptext_x = 36
233-
maptext_y = 6
234-
pixel_y = 6
235-
pixel_x = 420
236-
237-
/obj/effect/abstract/maptext_holder/music/check_preferences(client/seer)
238-
return ..() && seer.prefs.read_preference(/datum/preference/toggle/sound_lobby)
172+
for(var/mob/dead/new_player/lobbyguy as anything in GLOB.new_player_list)
173+
for(var/atom/movable/screen/lobby_init_text/text in lobbyguy.hud_used?.static_inventory)
174+
animate(text, alpha = 0, time = 8 SECONDS)
175+
stats_faded = TRUE

code/game/machinery/digital_clock.dm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
density = FALSE
1010
layer = ABOVE_WINDOW_LAYER
1111
custom_materials = list(/datum/material/iron = SHEET_MATERIAL_AMOUNT * 7, /datum/material/glass = SHEET_MATERIAL_AMOUNT * 4)
12+
subsystem_type = /datum/controller/subsystem/processing/digital_clock
1213

1314
/obj/item/wallframe/digital_clock
1415
name = "digital clock frame"
@@ -79,13 +80,8 @@
7980

8081
/obj/machinery/digital_clock/Initialize(mapload)
8182
. = ..()
82-
START_PROCESSING(SSdigital_clock, src)
8383
find_and_hang_on_wall()
8484

85-
/obj/machinery/digital_clock/Destroy()
86-
STOP_PROCESSING(SSdigital_clock, src)
87-
return ..()
88-
8985
/obj/machinery/digital_clock/process(seconds_per_tick)
9086
if(machine_stat & NOPOWER)
9187
return

code/game/sound.dm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@
194194

195195
if(prefs && (prefs.read_preference(/datum/preference/toggle/sound_lobby)) && !CONFIG_GET(flag/disallow_title_music))
196196
SEND_SOUND(src, sound(SSticker.login_music, repeat = 0, wait = 0, volume = vol, channel = CHANNEL_LOBBYMUSIC)) // MAD JAMS
197+
for(var/atom/movable/screen/lobby_music/text in mob.hud_used?.static_inventory)
198+
text.start_tracking()
199+
200+
/client/proc/stoptitlemusic()
201+
mob.stop_sound_channel(CHANNEL_LOBBYMUSIC)
202+
for(var/atom/movable/screen/lobby_music/text in mob.hud_used?.static_inventory)
203+
text.cancel_tracking()
197204

198205
///get a random frequency.
199206
/proc/get_rand_frequency()

code/modules/client/preferences/init_stats.dm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
default_value = TRUE
66

77
/datum/preference/toggle/show_init_stats/apply_to_client_updated(client/client, value)
8-
if(isnewplayer(client.mob))
9-
SStitle?.init_stat_holder?.check_client(client)
8+
for(var/atom/movable/screen/lobby_init_text/text in client.mob?.hud_used?.static_inventory)
9+
if(!value)
10+
text.alpha = 0 // go away instantly
11+
else if(!SStitle.stats_faded)
12+
text.alpha = 255 // show instantly if possible

code/modules/client/preferences/sounds.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
if (value && isnewplayer(client.mob))
9090
client.playtitlemusic()
9191
else
92-
client.mob.stop_sound_channel(CHANNEL_LOBBYMUSIC)
92+
client.stoptitlemusic()
9393

9494
/// Controls hearing admin music
9595
/datum/preference/toggle/sound_midi

code/modules/mob/dead/new_player/login.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@
5353
return
5454

5555
if(SSticker.current_state < GAME_STATE_SETTING_UP)
56-
SStitle?.init_stat_holder?.check_client(client)
5756
var/tl = SSticker.GetTimeLeft()
5857
to_chat(src, "Please set up your character and select \"Ready\". The game will start [tl > 0 ? "in about [DisplayTimeText(tl)]" : "soon"].")

0 commit comments

Comments
 (0)