Skip to content

Commit

Permalink
PortFitViewport (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
MalorMorfin authored Dec 6, 2024
1 parent 5705d27 commit cb29d15
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
18 changes: 15 additions & 3 deletions code/datums/view.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions code/game/verbs/ooc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/client_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@

Master.UpdateTickRate()

fully_created = TRUE


//////////////////
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cb29d15

Please sign in to comment.