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 (#947)

## Что этот PR делает

Рефактор способа доставки лобби картинок пользователю с использованием
`datum/asset`.

## Почему это хорошо для игры

Должно исправить проблему, когда картинку в лобби пытается отобразить до
того, как она будет получена пользователем.

## Тестирование
Протестировали с другим игрком, картинка отобразилась нормально.
Следующий этап тестирования уже на лайв серверах.

## Changelog

:cl:
tweak: `Fix Lobby Screen` в стат панельке был перенесен в категорию
`Special Verbs`
fix: Картинка лобби скрина теперь должна подгружаться без проблем и
черный экран вместо неё не должен отображаться
/:cl:
  • Loading branch information
Gaxeer authored Jan 31, 2024
1 parent 9c1cbcb commit a0eb341
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 112 deletions.
3 changes: 2 additions & 1 deletion modular_ss220/title_screen/_title_screen.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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_PATH 'modular_ss220/title_screen/icons/default.gif'

#define DEFAULT_TITLE_HTML {"
<html>
Expand Down
4 changes: 4 additions & 0 deletions modular_ss220/title_screen/code/asset_lobby.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/datum/asset/simple/lobby_fonts
assets = list(
"FixedsysExcelsior3.01Regular.ttf" = 'modular_ss220/title_screen/html/browser/FixedsysExcelsior3.01Regular.ttf',
)
2 changes: 1 addition & 1 deletion modular_ss220/title_screen/code/dead.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/mob/dead/Login()
. = ..()
hide_title_screen()
SStitle.hide_title_screen_from(client)
2 changes: 1 addition & 1 deletion modular_ss220/title_screen/code/living.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/mob/living/Login()
. = ..()
hide_title_screen()
SStitle.hide_title_screen_from(client)
57 changes: 0 additions & 57 deletions modular_ss220/title_screen/code/mob.dm

This file was deleted.

2 changes: 1 addition & 1 deletion modular_ss220/title_screen/code/new_player.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/mob/new_player/Login()
. = ..()
show_title_screen()
SStitle.show_title_screen_to(client)
14 changes: 7 additions & 7 deletions modular_ss220/title_screen/code/title_screen_controls.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand All @@ -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.")
61 changes: 61 additions & 0 deletions modular_ss220/title_screen/code/title_screen_datum.dm
Original file line number Diff line number Diff line change
@@ -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 += {"<img src="[screen_image_url]" class="bg" alt="">"}

if(notice)
html += {"
<div class="container_notice">
<p class="menu_notice">[notice]</p>
</div>
"}

html += "</body></html>"

return html.Join()
155 changes: 112 additions & 43 deletions modular_ss220/title_screen/code/title_screen_subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 a0eb341

Please sign in to comment.