From cb29d15ba58477894f1d46d8dc65ffb2dd041ce7 Mon Sep 17 00:00:00 2001 From: MalorMorfin <95427566+MalorMorfin@users.noreply.github.com> Date: Fri, 6 Dec 2024 21:29:52 +1000 Subject: [PATCH] PortFitViewport (#764) --- code/datums/view.dm | 18 +++++++++++++++--- code/game/verbs/ooc.dm | 27 +++++++++++++++++++++++++-- code/modules/client/client_defines.dm | 3 +++ code/modules/client/client_procs.dm | 4 ++-- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/code/datums/view.dm b/code/datums/view.dm index 60019bc4139..abf28f6726e 100644 --- a/code/datums/view.dm +++ b/code/datums/view.dm @@ -7,6 +7,11 @@ var/height = 0 ///Default view size, formatted as a string var/default = "" + /// This client's current zoom level, if it's not being supressed + /// If it's 0, we autoscale to the size of the window. Otherwise it's treated as the ratio between + /// the pixels on the map and output pixels. Only looks proper nice in increments of whole numbers (iirc) + /// Stored here so other parts of the code have a non blocking way of getting a user's functional zoom + var/zoom = 0 ///Bool that determines whether we want it to ignore any other changes after we applied some changes var/supress_changes = FALSE @@ -18,6 +23,10 @@ chief = owner apply() +/datum/view_data/Destroy() + chief = null + return ..() + ///sets the default view size froma string /datum/view_data/proc/set_default(string) default = string @@ -33,14 +42,17 @@ ///Resets the format type /datum/view_data/proc/assert_format() winset(chief, "mapwindow.map", "zoom=0") + zoom = 0 ///applies the current clients preferred pixel size setting /datum/view_data/proc/update_pixel_format() - winset(chief, "mapwindow.map", "zoom=[chief.prefs.pixel_size]") + zoom = chief?.prefs.pixel_size + winset(chief, "mapwindow.map", "zoom=[zoom]") + chief?.attempt_auto_fit_viewport() // If you change zoom mode, fit the viewport ///applies the preferred clients scaling method /datum/view_data/proc/update_zoom_mode() - winset(chief, "mapwindow.map", "zoom-mode=[chief.prefs.scaling_method]") + winset(chief, "mapwindow.map", "zoom-mode=[chief?.prefs.scaling_method]") ///Returns a boolean if the client has any form of zoom /datum/view_data/proc/is_zooming() @@ -100,7 +112,7 @@ ///applies all current outstanding changes to the client /datum/view_data/proc/apply() - chief.change_view(get_client_view_size()) + chief?.change_view(get_client_view_size()) safe_apply_formatting() ///supresses any further view changes until it is unsupressed diff --git a/code/game/verbs/ooc.dm b/code/game/verbs/ooc.dm index 313ed85745d..97b414a6c35 100644 --- a/code/game/verbs/ooc.dm +++ b/code/game/verbs/ooc.dm @@ -507,8 +507,23 @@ // Calculate desired pixel width using window size and aspect ratio var/sizes = params2list(winget(src, "mainwindow.split;mapwindow", "size")) var/map_size = splittext(sizes["mapwindow.size"], "x") - var/height = text2num(map_size[2]) - var/desired_width = round(height * aspect_ratio) + // Gets the type of zoom we're currently using from our view datum + // If it's 0 we do our pixel calculations based off the size of the mapwindow + // If it's not, we already know how big we want our window to be, since zoom is the exact pixel ratio of the map + var/zoom_value = src.view_size?.zoom || 0 + + var/desired_width = 0 + if(zoom_value) + desired_width = round(view_size[1] * zoom_value * world.icon_size) + else + + // Looks like we expect mapwindow.size to be "ixj" where i and j are numbers. + // If we don't get our expected 2 outputs, let's give some useful error info. + if(length(map_size) != 2) + CRASH("map_size of incorrect length --- map_size var: [map_size] --- map_size length: [length(map_size)]") + var/height = text2num(map_size[2]) + desired_width = round(height * aspect_ratio) + if (text2num(map_size[1]) == desired_width) // Nothing to do return @@ -541,6 +556,14 @@ pct += delta winset(src, "mainwindow.split", "splitter=[pct]") +/// Attempt to automatically fit the viewport, assuming the user wants it +/client/proc/attempt_auto_fit_viewport() + if (!prefs.auto_fit_viewport) + return + if(fully_created) + INVOKE_ASYNC(src, .verb/fit_viewport) + else //Delayed to avoid wingets from Login calls. + INVOKE_NEXT_TICK(src, VERB_REF(fit_viewport), 1 SECONDS) //Delayed to avoid wingets from Login calls. /client/verb/policy() set name = "Show Policy" diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index afb2c3381cb..75f5c56a2b3 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -139,3 +139,6 @@ /// The direction we WANT to move, based off our keybinds /// Will be udpated to be the actual direction later on var/intended_direction = NONE + + /// If this client has been fully initialized or not + var/fully_created = FALSE diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index a188beb687f..9e7275b0a53 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -364,6 +364,7 @@ Master.UpdateTickRate() + fully_created = TRUE ////////////////// @@ -877,8 +878,7 @@ apply_clickcatcher() mob.reload_fullscreens() - if(prefs.auto_fit_viewport) - INVOKE_NEXT_TICK(src, VERB_REF(fit_viewport), 1 SECONDS) //Delayed to avoid wingets from Login calls. + attempt_auto_fit_viewport() ///Change the fullscreen setting of the client /client/proc/set_fullscreen(fullscreen_mode)