Skip to content

Commit 94c5b32

Browse files
Absolucysan7890GoldenAlpharexhry-ghJohnFulpWillard
authored
UI scaling fixes for 516 (+ command bar typing indicators) (#6280)
Co-authored-by: san7890 <[email protected]> Co-authored-by: GoldenAlpharex <[email protected]> Co-authored-by: harry <[email protected]> Co-authored-by: harryob <[email protected]> Co-authored-by: John Willard <[email protected]>
1 parent 7e69648 commit 94c5b32

File tree

45 files changed

+733
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+733
-373
lines changed

code/__DEFINES/traits/declarations.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
11631163
#define TRAIT_HAS_LABEL "labeled"
11641164

11651165
/// Trait given to a mob that is currently thinking (giving off the "thinking" icon), used in an IC context
1166-
/* #define TRAIT_THINKING_IN_CHARACTER "currently_thinking_IC" */
1166+
#define TRAIT_THINKING_IN_CHARACTER "currently_thinking_IC"
11671167

11681168
///without a human having this trait, they speak as if they have no tongue.
11691169
#define TRAIT_SPEAKS_CLEARLY "speaks_clearly"

code/_globalvars/traits/_traits.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ GLOBAL_LIST_INIT(traits_by_type, list(
487487
"TRAIT_TENTACLE_IMMUNE" = TRAIT_TENTACLE_IMMUNE,
488488
"TRAIT_TESLA_SHOCKIMMUNE" = TRAIT_TESLA_SHOCKIMMUNE,
489489
"TRAIT_THERMAL_VISION" = TRAIT_THERMAL_VISION,
490+
"TRAIT_THINKING_IN_CHARACTER" = TRAIT_THINKING_IN_CHARACTER,
490491
"TRAIT_THROWINGARM" = TRAIT_THROWINGARM,
491492
"TRAIT_TIME_STOP_IMMUNE" = TRAIT_TIME_STOP_IMMUNE,
492493
"TRAIT_TOWER_OF_BABEL" = TRAIT_TOWER_OF_BABEL,

code/datums/brain_damage/imaginary_friend.dm

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,8 @@
388388
INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(flick_overlay_global), visual, group_clients(), 2.5 SECONDS)
389389
animate(visual, pixel_x = (tile.x - our_tile.x) * world.icon_size + pointed_atom.pixel_x, pixel_y = (tile.y - our_tile.y) * world.icon_size + pointed_atom.pixel_y, time = 1.7, easing = EASE_OUT)
390390

391-
// monkestation edit start
392-
/* original
393391
/mob/camera/imaginary_friend/create_thinking_indicator()
394-
if(active_thinking_indicator || active_typing_indicator || !thinking_IC)
392+
if(active_thinking_indicator || active_typing_indicator || !HAS_TRAIT(src, TRAIT_THINKING_IN_CHARACTER))
395393
return FALSE
396394
active_thinking_indicator = image('icons/mob/effects/talk.dmi', src, "[bubble_icon]3", TYPING_LAYER)
397395
add_image_to_clients(active_thinking_indicator, group_clients())
@@ -403,7 +401,7 @@
403401
active_thinking_indicator = null
404402

405403
/mob/camera/imaginary_friend/create_typing_indicator()
406-
if(active_typing_indicator || active_thinking_indicator || !thinking_IC)
404+
if(active_typing_indicator || active_thinking_indicator || !HAS_TRAIT(src, TRAIT_THINKING_IN_CHARACTER))
407405
return FALSE
408406
active_typing_indicator = image('icons/mob/effects/talk.dmi', src, "[bubble_icon]0", TYPING_LAYER)
409407
add_image_to_clients(active_typing_indicator, group_clients())
@@ -415,16 +413,9 @@
415413
active_typing_indicator = null
416414

417415
/mob/camera/imaginary_friend/remove_all_indicators()
418-
thinking_IC = FALSE
416+
REMOVE_TRAIT(src, TRAIT_THINKING_IN_CHARACTER, CURRENTLY_TYPING_TRAIT)
419417
remove_thinking_indicator()
420418
remove_typing_indicator()
421-
*/
422-
/mob/camera/imaginary_friend/add_typing_overlay(image)
423-
add_image_to_clients(image, group_clients())
424-
425-
/mob/camera/imaginary_friend/remove_typing_overlay(image)
426-
remove_image_from_clients(image, group_clients())
427-
// monkestation edit end
428419

429420
/mob/camera/imaginary_friend/Move(NewLoc, Dir = 0)
430421
if(world.time < move_delay)

code/datums/browser.dm

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
var/content = ""
1515

1616
/datum/browser/New(nuser, nwindow_id, ntitle = 0, nwidth = 0, nheight = 0, atom/nref = null)
17-
user = nuser
17+
if(IS_CLIENT_OR_MOCK(nuser))
18+
var/client/client_user = nuser
19+
user = client_user.mob
20+
else
21+
user = nuser
1822
RegisterSignal(user, COMSIG_QDELETING, PROC_REF(user_deleted))
1923
window_id = nwindow_id
2024
if (ntitle)
@@ -65,6 +69,14 @@
6569
for (file in stylesheets)
6670
head_content += "<link rel='stylesheet' type='text/css' href='[SSassets.transport.get_asset_url(file)]'>"
6771

72+
if(user.client?.window_scaling && user.client?.window_scaling != 1 && !user.client?.prefs.read_preference(/datum/preference/toggle/ui_scale) && width && height)
73+
head_content += {"
74+
<style>
75+
body {
76+
zoom: [100 / user.client?.window_scaling]%;
77+
}
78+
</style>
79+
"}
6880

6981
for (file in scripts)
7082
head_content += "<script type='text/javascript' src='[SSassets.transport.get_asset_url(file)]'></script>"
@@ -102,15 +114,19 @@
102114
to_chat(user, span_userdanger("The [title] browser you tried to open failed a sanity check! Please report this on github!"))
103115
return
104116
var/window_size = ""
105-
if (width && height)
106-
window_size = "size=[width]x[height];"
117+
if(width && height)
118+
if(user.client?.prefs?.read_preference(/datum/preference/toggle/ui_scale))
119+
var/scaling = user.client.window_scaling
120+
window_size = "size=[width * scaling]x[height * scaling];"
121+
else
122+
window_size = "size=[width]x[height];"
107123
var/datum/asset/simple/namespaced/common/common_asset = get_asset_datum(/datum/asset/simple/namespaced/common)
108124
common_asset.send(user)
109125
if (stylesheets.len)
110126
SSassets.transport.send_assets(user, stylesheets)
111127
if (scripts.len)
112128
SSassets.transport.send_assets(user, scripts)
113-
user << browse(get_content(), "window=[window_id];[window_size][window_options]")
129+
DIRECT_OUTPUT(user, browse(get_content(), "window=[window_id];[window_size][window_options]"))
114130
if (use_onclose)
115131
setup_onclose()
116132

code/modules/admin/player_panel.dm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
log_admin("[key_name(usr)] checked the player panel.")
55
var/dat = "<html><head><meta http-equiv='X-UA-Compatible' content='IE=edge' charset='UTF-8'/><title>Player Panel</title></head>"
66

7+
var/ui_scale = owner.prefs.read_preference(/datum/preference/toggle/ui_scale)
8+
79
//javascript, the part that does most of the work~
810
dat += {"
911

1012
<head>
13+
[!ui_scale && owner.window_scaling ? "<style>body {zoom: [100 / owner.window_scaling]%;}</style>" : ""]
14+
1115
<script type='text/javascript'>
1216

1317
var locked_tabs = new Array();
@@ -329,4 +333,8 @@
329333
</body></html>
330334
"}
331335

332-
usr << browse(dat, "window=players;size=600x480")
336+
var/window_size = "size=600x480"
337+
if(owner.window_scaling && ui_scale)
338+
window_size = "size=[600 * owner.window_scaling]x[400 * owner.window_scaling]"
339+
340+
usr << browse(dat, "window=players;[window_size]")

code/modules/admin/view_variables/view_variables.dm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ ADMIN_VERB_AND_CONTEXT_MENU(debug_variables, R_NONE, "View Variables", "View the
116116

117117
sleep(1 TICKS)
118118

119+
var/ui_scale = prefs?.read_preference(/datum/preference/toggle/ui_scale)
120+
119121
var/list/variable_html = list()
120122
if(islist)
121123
var/list/list_value = thing
@@ -137,6 +139,7 @@ ADMIN_VERB_AND_CONTEXT_MENU(debug_variables, R_NONE, "View Variables", "View the
137139
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
138140
<title>[title]</title>
139141
<link rel="stylesheet" type="text/css" href="[SSassets.transport.get_asset_url("view_variables.css")]">
142+
[!ui_scale && window_scaling ? "<style>body {zoom: [100 / window_scaling]%;}</style>" : ""]
140143
</head>
141144
<body onload='selectTextField()' onkeydown='return handle_keydown()' onkeyup='handle_keyup()'>
142145
<script type="text/javascript">
@@ -305,7 +308,11 @@ datumrefresh=[refid];[HrefToken()]'>Refresh</a>
305308
</body>
306309
</html>
307310
"}
308-
src << browse(html, "window=variables[refid];size=475x650")
311+
var/size_string = "size=475x650";
312+
if(ui_scale && window_scaling)
313+
size_string = "size=[475 * window_scaling]x[650 * window_scaling]"
314+
315+
src << browse(html, "window=variables[refid];[size_string]")
309316

310317
/client/proc/vv_update_display(datum/thing, span, content)
311318
src << output("[span]:[content]", "variables[REF(thing)].browser:replace_span")

code/modules/client/client_defines.dm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,6 @@
274274

275275
/// Does this client have typing indicators enabled?
276276
var/typing_indicators = FALSE
277+
278+
/// The DPI scale of the client. 1 is equivalent to 100% window scaling, 2 will be 200% window scaling
279+
var/window_scaling

code/modules/client/client_procs.dm

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
116116
no_tgui_adminhelp(input(src, "Enter your ahelp", "Ahelp") as null|message)
117117
return
118118

119+
if(href_list["commandbar_typing"])
120+
handle_commandbar_typing(href_list)
121+
119122
//Monkestation Edit Begin
120123
if(mentor_friend(href_list))
121124
return
@@ -246,6 +249,8 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
246249

247250
tgui_say = new(src, "tgui_say")
248251

252+
initialize_commandbar_spy()
253+
249254
set_right_click_menu_mode()
250255

251256
GLOB.ahelp_tickets.ClientLogin(src)
@@ -384,6 +389,8 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
384389
)
385390
addtimer(CALLBACK(src, PROC_REF(check_panel_loaded)), 30 SECONDS)
386391

392+
INVOKE_ASYNC(src, PROC_REF(acquire_dpi))
393+
387394
// Initialize tgui panel
388395
tgui_panel.initialize()
389396

@@ -527,7 +534,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
527534
if(CONFIG_GET(flag/aggressive_changelog))
528535
changelog()
529536
else
530-
winset(src, "infowindow.changelog", "font-style=bold")
537+
winset(src, "infobuttons.changelog", "font-style=bold")
531538

532539
if(ckey in GLOB.clientmessages)
533540
for(var/message in GLOB.clientmessages[ckey])
@@ -1415,6 +1422,14 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
14151422

14161423
send2adminchat("Server", jointext(message_to_send, " "))
14171424

1425+
/// This grabs the DPI of the user per their skin
1426+
/client/proc/acquire_dpi()
1427+
if(byond_version < 516) // why won't you update
1428+
return
1429+
window_scaling = text2num(winget(src, null, "dpi"))
1430+
1431+
debug_admins("scalies: [window_scaling]")
1432+
14181433
#undef ADMINSWARNED_AT
14191434
#undef CURRENT_MINUTE
14201435
#undef CURRENT_SECOND

code/modules/client/preferences/tgui.dm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,21 @@
5757

5858
/datum/preference/toggle/tgui_say_light_mode/apply_to_client(client/client)
5959
client.tgui_say?.load()
60+
61+
/datum/preference/toggle/ui_scale
62+
category = PREFERENCE_CATEGORY_GAME_PREFERENCES
63+
savefile_key = "ui_scale"
64+
savefile_identifier = PREFERENCE_PLAYER
65+
default_value = TRUE
66+
67+
/datum/preference/toggle/ui_scale/apply_to_client(client/client, value)
68+
if(!istype(client))
69+
return
70+
71+
INVOKE_ASYNC(client, TYPE_VERB_REF(/client, refresh_tgui))
72+
client.tgui_say?.load()
73+
74+
/datum/preference/toggle/ui_scale/is_accessible(datum/preferences/preferences)
75+
if(preferences?.parent?.byond_version < 516)
76+
return FALSE
77+
return ..()

code/modules/client/verbs/typing.dm

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#define IC_VERBS list("say", "me", "whisper")
2+
3+
/client/var/commandbar_thinking = FALSE
4+
/client/var/commandbar_typing = FALSE
5+
6+
/client/proc/initialize_commandbar_spy()
7+
src << output('html/typing_indicator.html', "commandbar_spy")
8+
9+
/client/proc/handle_commandbar_typing(href_list)
10+
if (!typing_indicators) //check pref
11+
return
12+
if (length(href_list["verb"]) < 1 || !(LOWER_TEXT(href_list["verb"]) in IC_VERBS) || text2num(href_list["argument_length"]) < 1)
13+
if (commandbar_typing)
14+
commandbar_typing = FALSE
15+
stop_typing()
16+
17+
if (commandbar_thinking)
18+
commandbar_thinking = FALSE
19+
stop_thinking()
20+
return
21+
22+
if (!commandbar_thinking)
23+
commandbar_thinking = TRUE
24+
start_thinking()
25+
26+
if (!commandbar_typing)
27+
commandbar_typing = TRUE
28+
start_typing()
29+
30+
31+
/** Sets the mob as "thinking" - with indicator and the TRAIT_THINKING_IN_CHARACTER trait */
32+
/client/proc/start_thinking()
33+
if(!typing_indicators)
34+
return FALSE
35+
/// Special exemptions
36+
if(isabductor(mob) && !HAS_TRAIT(mob, TRAIT_SIGN_LANG)) // monkestation edit: allow abductors to sign
37+
return FALSE
38+
ADD_TRAIT(mob, TRAIT_THINKING_IN_CHARACTER, CURRENTLY_TYPING_TRAIT)
39+
mob.create_thinking_indicator()
40+
41+
/** Removes typing/thinking indicators and flags the mob as not thinking */
42+
/client/proc/stop_thinking()
43+
mob?.remove_all_indicators()
44+
45+
/**
46+
* Handles the user typing. After a brief period of inactivity,
47+
* signals the client mob to revert to the "thinking" icon.
48+
*/
49+
/client/proc/start_typing()
50+
var/mob/client_mob = mob
51+
client_mob.remove_thinking_indicator()
52+
if(!typing_indicators || !HAS_TRAIT(client_mob, TRAIT_THINKING_IN_CHARACTER))
53+
return FALSE
54+
client_mob.create_typing_indicator()
55+
addtimer(CALLBACK(src, PROC_REF(stop_typing)), 5 SECONDS, TIMER_UNIQUE | TIMER_OVERRIDE | TIMER_STOPPABLE)
56+
57+
/**
58+
* Callback to remove the typing indicator after a brief period of inactivity.
59+
* If the user was typing IC, the thinking indicator is shown.
60+
*/
61+
/client/proc/stop_typing()
62+
if(isnull(mob))
63+
return FALSE
64+
var/mob/client_mob = mob
65+
client_mob.remove_typing_indicator()
66+
if(!typing_indicators || !HAS_TRAIT(client_mob, TRAIT_THINKING_IN_CHARACTER))
67+
return FALSE
68+
client_mob.create_thinking_indicator()
69+
70+
#undef IC_VERBS

0 commit comments

Comments
 (0)