Skip to content

Commit

Permalink
refactor: move title screens to assets, move Fix Lobby Screen verb …
Browse files Browse the repository at this point in the history
…to `Special Verbs` category
  • Loading branch information
Gaxeer committed Jan 27, 2024
1 parent 6e61e38 commit 68ce905
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 38 deletions.
1 change: 1 addition & 0 deletions modular_ss220/title_screen/_title_screen.dme
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "code/_title_screen_defines.dm"
#include "code/dead.dm"
#include "code/living.dm"
#include "code/asset_lobby.dm"
#include "code/mob.dm"
#include "code/new_player.dm"
#include "code/title_screen_controls.dm"
Expand Down
2 changes: 1 addition & 1 deletion modular_ss220/title_screen/code/_title_screen_defines.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define DEFAULT_TITLE_SCREEN_IMAGE 'modular_ss220/title_screen/icons/default.dmi'
#define DEFAULT_TITLE_SCREEN_IMAGE "default.gif"

#define DEFAULT_TITLE_HTML {"
<html>
Expand Down
19 changes: 19 additions & 0 deletions modular_ss220/title_screen/code/asset_lobby.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/datum/asset/group/lobby
children = list(
/datum/asset/simple/lobby_fonts,
/datum/asset/simple/lobby_title_screen_images
)

/datum/asset/simple/lobby_fonts
assets = list(
"FixedsysExcelsior3.01Regular.ttf" = 'modular_ss220/title_screen/html/browser/FixedsysExcelsior3.01Regular.ttf',
)

/datum/asset/simple/lobby_title_screen_images
assets = list(
DEFAULT_TITLE_SCREEN_IMAGE = 'modular_ss220/title_screen/icons/default.gif'
)

/datum/asset/simple/lobby_title_screen_images/register()
assets += SStitle.get_title_screens()
return ..()
26 changes: 4 additions & 22 deletions modular_ss220/title_screen/code/mob.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define TITLE_SCREEN_BG_FILE_NAME "bg_file_name"

/**
* Shows the titlescreen to a new player.
*/
Expand All @@ -9,17 +7,17 @@
winset(src, "title_browser", "is-disabled=true;is-visible=true")
winset(src, "status_bar", "is-visible=false")

var/datum/asset/assets = get_asset_datum(/datum/asset/simple/lobby) //Sending pictures to the client
assets.send(src)
var/datum/asset/lobby_asset = get_asset_datum(/datum/asset/group/lobby)
lobby_asset.send(src)

update_title_screen()
src << browse(get_title_html(), "window=title_browser")

/**
* Get the HTML of title screen.
*/
/mob/proc/get_title_html()
var/dat = SStitle.title_html
dat += {"<img src="[TITLE_SCREEN_BG_FILE_NAME]" class="bg" alt="">"}
dat += {"<img src="[SSassets.transport.get_asset_url(SStitle.get_current_title_screen())]" class="bg" alt="">"}

if(SStitle.current_notice)
dat += {"
Expand All @@ -32,26 +30,10 @@

return dat

/**
* Hard updates the title screen HTML, it causes visual glitches if used.
*/
/mob/proc/update_title_screen()
var/dat = get_title_html()

src << browse(SStitle.current_title_screen, "file=[TITLE_SCREEN_BG_FILE_NAME];display=0")
src << browse(dat, "window=title_browser")

/datum/asset/simple/lobby
assets = list(
"FixedsysExcelsior3.01Regular.ttf" = 'modular_ss220/title_screen/html/browser/FixedsysExcelsior3.01Regular.ttf',
)

/**
* Removes the titlescreen entirely from a mob.
*/
/mob/proc/hide_title_screen()
if(client?.mob)
winset(client, "title_browser", "is-disabled=true;is-visible=false")
winset(client, "status_bar", "is-visible=true")

#undef TITLE_SCREEN_BG_FILE_NAME
2 changes: 1 addition & 1 deletion modular_ss220/title_screen/code/title_screen_controls.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/client/verb/fix_title_screen()
set name = "Fix Lobby Screen"
set desc = "Lobbyscreen broke? Press this."
set category = "OOC"
set category = "Special Verbs"

if(istype(mob, /mob/new_player))
mob.show_title_screen()
Expand Down
64 changes: 50 additions & 14 deletions modular_ss220/title_screen/code/title_screen_subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
var/current_notice
/// The preamble html that includes all styling and layout.
var/title_html
/// The list of possible title screens to rotate through, as file path texts.
var/title_screens = list()
/// The list of possible title screens to rotate through, as: title_screen_name -> title_screen_path
var/list/title_screens = list()

/datum/controller/subsystem/title/Initialize()
if(!fexists("config/title_html.txt"))
Expand All @@ -19,17 +19,7 @@
else
title_html = file2text("config/title_html.txt")

var/list/local_title_screens = list()
for(var/screen in flist(TITLE_SCREENS_LOCATION))
var/list/screen_name_parts = splittext(screen, "+")
if((LAZYLEN(screen_name_parts) == 1 && (screen_name_parts[1] != "exclude" && screen_name_parts[1] != "blank.png")))
local_title_screens += screen

for(var/title_screen in local_title_screens)
var/file_path = "[TITLE_SCREENS_LOCATION][title_screen]"
ASSERT(fexists(file_path))
title_screens += fcopy_rsc(file_path)

load_title_screens()
change_title_screen()

/datum/controller/subsystem/title/Recover()
Expand All @@ -38,6 +28,52 @@
title_html = SStitle.title_html
title_screens = SStitle.title_screens

/**
* Iterates over all files in `TITLE_SCREENS_LOCATION` and loads all valid title screens to `title_screens` var.
*/
/datum/controller/subsystem/title/proc/load_title_screens()
var/list/valid_title_screens = list()
for(var/screen in flist(TITLE_SCREENS_LOCATION))
if(validate_title_screen(screen))
valid_title_screens += screen

for(var/title_screen_name in valid_title_screens)
var/file_path = "[TITLE_SCREENS_LOCATION][title_screen_name]"
ASSERT(fexists(file_path))
title_screens[title_screen_name] = fcopy_rsc(file_path)

/**
* Checks wheter passed title is valid
* Currently validates extension and checks whether it's special image like default title screen etc.
*/
/datum/controller/subsystem/title/proc/validate_title_screen(title_screen_to_validate)
var/static/list/title_screens_to_ignore = list("blank.png", DEFAULT_TITLE_SCREEN_IMAGE)
if(title_screen_to_validate in title_screens_to_ignore)
return FALSE

var/list/name_parts = splittext(title_screen_to_validate, ".")
if(length(name_parts) < 2)
return FALSE

var/static/list/supported_extensions = list("gif", "jpg", "jpeg","png", "svg")
var/extension = name_parts[length(name_parts)]
return (extension in supported_extensions)

/**
* Returns the list of all loaded title screens, if no title screens present, tries to load them.
*/
/datum/controller/subsystem/title/proc/get_title_screens()
if(!length(title_screens))
load_title_screens()

return title_screens.Copy()

/**
* Returns current title screen or if null, default one.
*/
/datum/controller/subsystem/title/proc/get_current_title_screen()
return current_title_screen || DEFAULT_TITLE_SCREEN_IMAGE

/**
* Show the title screen to all new players.
*/
Expand All @@ -59,7 +95,7 @@
if(new_screen)
current_title_screen = new_screen
else
if(LAZYLEN(title_screens))
if(length(title_screens))
current_title_screen = pick(title_screens)
else
current_title_screen = DEFAULT_TITLE_SCREEN_IMAGE
Expand Down
Binary file removed modular_ss220/title_screen/icons/default.dmi
Binary file not shown.
Binary file added modular_ss220/title_screen/icons/default.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 68ce905

Please sign in to comment.