diff --git a/modular_ss220/title_screen/_title_screen.dme b/modular_ss220/title_screen/_title_screen.dme index e7740ff637de..c74fb84de9bb 100644 --- a/modular_ss220/title_screen/_title_screen.dme +++ b/modular_ss220/title_screen/_title_screen.dme @@ -3,7 +3,8 @@ #include "code/_title_screen_defines.dm" #include "code/dead.dm" #include "code/living.dm" -#include "code/mob.dm" +#include "code/asset_lobby.dm" +#include "code/title_screen_datum.dm" #include "code/new_player.dm" #include "code/title_screen_controls.dm" #include "code/title_screen_subsystem.dm" diff --git a/modular_ss220/title_screen/code/_title_screen_defines.dm b/modular_ss220/title_screen/code/_title_screen_defines.dm index 02bb9871eb24..e9961e1391a8 100644 --- a/modular_ss220/title_screen/code/_title_screen_defines.dm +++ b/modular_ss220/title_screen/code/_title_screen_defines.dm @@ -1,4 +1,4 @@ -#define DEFAULT_TITLE_SCREEN_IMAGE 'modular_ss220/title_screen/icons/default.dmi' +#define DEFAULT_TITLE_SCREEN_IMAGE_PATH 'modular_ss220/title_screen/icons/default.gif' #define DEFAULT_TITLE_HTML {" diff --git a/modular_ss220/title_screen/code/asset_lobby.dm b/modular_ss220/title_screen/code/asset_lobby.dm new file mode 100644 index 000000000000..8475ba529038 --- /dev/null +++ b/modular_ss220/title_screen/code/asset_lobby.dm @@ -0,0 +1,4 @@ +/datum/asset/simple/lobby_fonts + assets = list( + "FixedsysExcelsior3.01Regular.ttf" = 'modular_ss220/title_screen/html/browser/FixedsysExcelsior3.01Regular.ttf', + ) diff --git a/modular_ss220/title_screen/code/dead.dm b/modular_ss220/title_screen/code/dead.dm index ab33d670ae81..fcf61c94c3ab 100644 --- a/modular_ss220/title_screen/code/dead.dm +++ b/modular_ss220/title_screen/code/dead.dm @@ -1,3 +1,3 @@ /mob/dead/Login() . = ..() - hide_title_screen() + SStitle.hide_title_screen_from(client) diff --git a/modular_ss220/title_screen/code/living.dm b/modular_ss220/title_screen/code/living.dm index 9b96cbd348d0..4383fe0e3a02 100644 --- a/modular_ss220/title_screen/code/living.dm +++ b/modular_ss220/title_screen/code/living.dm @@ -1,3 +1,3 @@ /mob/living/Login() . = ..() - hide_title_screen() + SStitle.hide_title_screen_from(client) diff --git a/modular_ss220/title_screen/code/mob.dm b/modular_ss220/title_screen/code/mob.dm deleted file mode 100644 index 316772269203..000000000000 --- a/modular_ss220/title_screen/code/mob.dm +++ /dev/null @@ -1,57 +0,0 @@ -#define TITLE_SCREEN_BG_FILE_NAME "bg_file_name" - -/** - * Shows the titlescreen to a new player. - */ -/mob/proc/show_title_screen() - if(!client) - return - 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) - - update_title_screen() - -/** - * Get the HTML of title screen. - */ -/mob/proc/get_title_html() - var/dat = SStitle.title_html - dat += {""} - - if(SStitle.current_notice) - dat += {" -
- -
- "} - - dat += "" - - 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 diff --git a/modular_ss220/title_screen/code/new_player.dm b/modular_ss220/title_screen/code/new_player.dm index 8dc07b7195a0..4b32f04fd989 100644 --- a/modular_ss220/title_screen/code/new_player.dm +++ b/modular_ss220/title_screen/code/new_player.dm @@ -1,3 +1,3 @@ /mob/new_player/Login() . = ..() - show_title_screen() + SStitle.show_title_screen_to(client) diff --git a/modular_ss220/title_screen/code/title_screen_controls.dm b/modular_ss220/title_screen/code/title_screen_controls.dm index 579cba432ff5..7f923533e2e3 100644 --- a/modular_ss220/title_screen/code/title_screen_controls.dm +++ b/modular_ss220/title_screen/code/title_screen_controls.dm @@ -16,9 +16,10 @@ var/file = input(usr) as icon|null if(!file) return - SStitle.change_title_screen(file) + + SStitle.set_title_image(file) if("Reset") - SStitle.change_title_screen() + SStitle.set_title_image() if("Cancel") return @@ -49,12 +50,12 @@ /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() + SStitle.show_title_screen_to(src) else - mob.hide_title_screen() + SStitle.hide_title_screen_from(src) /** * An admin debug command that enables you to change the HTML on the go. @@ -74,7 +75,6 @@ if(!new_html) return - SStitle.title_html = new_html - SStitle.show_title_screen() + SStitle.set_title_html(new_html) message_admins("[key_name_admin(usr)] has changed the title screen HTML.") diff --git a/modular_ss220/title_screen/code/title_screen_datum.dm b/modular_ss220/title_screen/code/title_screen_datum.dm new file mode 100644 index 000000000000..675c28b3ced3 --- /dev/null +++ b/modular_ss220/title_screen/code/title_screen_datum.dm @@ -0,0 +1,61 @@ +/datum/title_screen + /// The preamble html that includes all styling and layout. + var/title_html = DEFAULT_TITLE_HTML + /// The current notice text, or null. + var/notice + /// The current title screen being displayed, as `/datum/asset_cache_item` + var/datum/asset_cache_item/screen_image + +/datum/title_screen/New(title_html = DEFAULT_TITLE_HTML, notice, screen_image_file) + src.title_html = title_html + src.notice = notice + set_screen_image(screen_image_file) + +/datum/title_screen/proc/set_screen_image(screen_image_file) + if(!screen_image_file) + return + + if(!isfile(screen_image_file)) + screen_image_file = fcopy_rsc(screen_image_file) + + screen_image = SSassets.transport.register_asset("[screen_image_file]", screen_image_file) + +/datum/title_screen/proc/show_to(client/viewer) + if(!viewer) + return + + winset(viewer, "title_browser", "is-disabled=true;is-visible=true") + winset(viewer, "status_bar", "is-visible=false") + + var/datum/asset/lobby_asset = get_asset_datum(/datum/asset/simple/lobby_fonts) + lobby_asset.send(viewer) + + SSassets.transport.send_assets(viewer, screen_image.name) + + viewer << browse(get_title_html(), "window=title_browser") + +/datum/title_screen/proc/hide_from(client/viewer) + if(viewer?.mob) + winset(viewer, "title_browser", "is-disabled=true;is-visible=false") + winset(viewer, "status_bar", "is-visible=true") + +/** + * Get the HTML of title screen. + */ +/datum/title_screen/proc/get_title_html() + var/list/html = list(title_html) + + var/screen_image_url = SSassets.transport.get_asset_url(asset_cache_item = screen_image) + if(screen_image_url) + html += {""} + + if(notice) + html += {" +
+ +
+ "} + + html += "" + + return html.Join() diff --git a/modular_ss220/title_screen/code/title_screen_subsystem.dm b/modular_ss220/title_screen/code/title_screen_subsystem.dm index bf3288137af6..6879ab130661 100644 --- a/modular_ss220/title_screen/code/title_screen_subsystem.dm +++ b/modular_ss220/title_screen/code/title_screen_subsystem.dm @@ -3,67 +3,136 @@ /datum/controller/subsystem/title flags = SS_NO_FIRE init_order = INIT_ORDER_TITLE - /// The current title screen being displayed, as a file path text. - var/current_title_screen - /// The current notice text, or null. - 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() + /// Currently set title screen + var/datum/title_screen/current_title_screen + /// The list of image files available to be picked for title screen + var/list/title_images_pool = list() /datum/controller/subsystem/title/Initialize() - if(!fexists("config/title_html.txt")) - error(span_boldwarning("Unable to read title_html.txt, reverting to backup title html, please check your server config and ensure this file exists.")) - title_html = DEFAULT_TITLE_HTML - else - title_html = file2text("config/title_html.txt") + fill_title_images_pool() + current_title_screen = new(title_html = get_title_html(), screen_image_file = pick_title_image()) + show_title_screen_to_all_new_players() - 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 +/datum/controller/subsystem/title/Recover() + current_title_screen = SStitle.current_title_screen + title_images_pool = SStitle.title_images_pool - 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) +/** + * Iterates over all files in `TITLE_SCREENS_LOCATION` and loads all valid title screens to `title_screens` var. + */ +/datum/controller/subsystem/title/proc/fill_title_images_pool() + for(var/file_name in flist(TITLE_SCREENS_LOCATION)) + if(validate_filename(file_name)) + var/file_path = "[TITLE_SCREENS_LOCATION][file_name]" + title_images_pool += fcopy_rsc(file_path) - change_title_screen() +/** + * 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_filename(filename) + var/static/list/title_screens_to_ignore = list("blank.png") + if(filename in title_screens_to_ignore) + return FALSE -/datum/controller/subsystem/title/Recover() - current_title_screen = SStitle.current_title_screen - current_notice = SStitle.current_notice - title_html = SStitle.title_html - title_screens = SStitle.title_screens + var/static/list/supported_extensions = list("gif", "jpg", "jpeg", "png", "svg") + var/extstart = findlasttext(filename, ".") + if(!extstart) + return FALSE + + var/extension = copytext(filename, extstart + 1) + return (extension in supported_extensions) /** * Show the title screen to all new players. */ -/datum/controller/subsystem/title/proc/show_title_screen() - for(var/mob/new_player/new_player in GLOB.player_list) - INVOKE_ASYNC(new_player, TYPE_PROC_REF(/mob/new_player, show_title_screen)) +/datum/controller/subsystem/title/proc/show_title_screen_to_all_new_players() + if(!current_title_screen) + return + + for(var/mob/new_player/viewer in GLOB.player_list) + show_title_screen_to(viewer.client) + +/** + * Show the title screen to specific client. + */ +/datum/controller/subsystem/title/proc/show_title_screen_to(client/viewer) + if(!viewer || !current_title_screen) + return + + INVOKE_ASYNC(current_title_screen, TYPE_PROC_REF(/datum/title_screen, show_to), viewer) + +/** + * Hide the title screen from specific client. + */ +/datum/controller/subsystem/title/proc/hide_title_screen_from(client/viewer) + if(!viewer || !current_title_screen) + return + + INVOKE_ASYNC(current_title_screen, TYPE_PROC_REF(/datum/title_screen, hide_from), viewer) /** * Adds a notice to the main title screen in the form of big red text! */ -/datum/controller/subsystem/title/proc/set_notice(new_title) - current_notice = new_title ? sanitize_text(new_title) : null - show_title_screen() +/datum/controller/subsystem/title/proc/set_notice(new_notice) + new_notice = new_notice ? sanitize_text(new_notice) : null + + if(!current_title_screen) + if(!new_notice) + return + + current_title_screen = new(notice = new_notice) + else + current_title_screen.notice = new_notice + + show_title_screen_to_all_new_players() /** - * Changes the title screen to a new image. + * Replaces html of title screen */ -/datum/controller/subsystem/title/proc/change_title_screen(new_screen) - if(new_screen) - current_title_screen = new_screen +/datum/controller/subsystem/title/proc/set_title_html(new_html) + if(!new_html) + return + + if(!current_title_screen) + current_title_screen = new(title_html = new_html) + else + current_title_screen.title_html = new_html + + show_title_screen_to_all_new_players() + +/** + * Changes title image to desired + */ +/datum/controller/subsystem/title/proc/set_title_image(desired_image_file) + if(desired_image_file) + if(!isfile(desired_image_file)) + CRASH("Not a file passed to `/datum/controller/subsystem/title/proc/set_title_image`") + else + desired_image_file = pick_title_image() + + if(!current_title_screen) + current_title_screen = new(screen_image_file = desired_image_file) else - if(LAZYLEN(title_screens)) - current_title_screen = pick(title_screens) - else - current_title_screen = DEFAULT_TITLE_SCREEN_IMAGE + current_title_screen.set_screen_image(desired_image_file) - show_title_screen() + show_title_screen_to_all_new_players() + +/** + * Picks title image from `title_images_pool` list. If the list is empty, `DEFAULT_TITLE_HTML` is returned + */ +/datum/controller/subsystem/title/proc/pick_title_image() + return length(title_images_pool) ? pick(title_images_pool) : DEFAULT_TITLE_SCREEN_IMAGE_PATH + + +/** + * Tries to read title html from config, if none found - backups to `DEFAULT_TITLE_HTML` + */ +/datum/controller/subsystem/title/proc/get_title_html() + if(!fexists("config/title_html.txt")) + error(span_boldwarning("Unable to read title_html.txt, reverting to backup title html, please check your server config and ensure this file exists.")) + return DEFAULT_TITLE_HTML + else + return file2text("config/title_html.txt") #undef TITLE_SCREENS_LOCATION diff --git a/modular_ss220/title_screen/icons/default.dmi b/modular_ss220/title_screen/icons/default.dmi deleted file mode 100644 index e8ede9793036..000000000000 Binary files a/modular_ss220/title_screen/icons/default.dmi and /dev/null differ diff --git a/modular_ss220/title_screen/icons/default.gif b/modular_ss220/title_screen/icons/default.gif new file mode 100644 index 000000000000..6b7519f1b5a9 Binary files /dev/null and b/modular_ss220/title_screen/icons/default.gif differ