Skip to content

Commit

Permalink
view fix port
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilDragonfiend committed Apr 10, 2024
1 parent d6a6441 commit 1eb1539
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
4 changes: 4 additions & 0 deletions code/__byond_version_compat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#if DM_VERSION < 515
/// Call by name proc reference, checks if the proc exists on this type or as a global proc
#define PROC_REF(X) (.proc/##X)
/// Call by name verb reference, checks if the proc exists on this type or as a global verb
#define VERB_REF(X) (.verb/##X)
/// Call by name proc reference, checks if the proc exists on given type or as a global proc
#define TYPE_PROC_REF(TYPE, X) (##TYPE.proc/##X)
/// Call by name verb reference, checks if the verb exists on given type or as a global verb
Expand All @@ -51,6 +53,8 @@
#else
/// Call by name proc reference, checks if the proc exists on this type or as a global proc
#define PROC_REF(X) (nameof(.proc/##X))
/// Call by name verb references, checks if the proc exists on this type or as a global verb
#define VERB_REF(X) (nameof(.verb/##X))
/// Call by name proc reference, checks if the proc exists on given type or as a global proc
#define TYPE_PROC_REF(TYPE, X) (nameof(##TYPE.proc/##X))
/// Call by name verb reference, checks if the verb exists on given type or as a global verb
Expand Down
26 changes: 23 additions & 3 deletions code/datums/view.dm
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
//This is intended to be a full wrapper. DO NOT directly modify its values
///Container for client viewsize
/datum/viewData
/// Width offset to apply to the default view string if we're not supressed for some reason
var/width = 0
/// Height offset to apply to the default view string, see above
var/height = 0
/// This client's current "default" view, in the format "WidthxHeight"
/// We add/remove from this when we want to change their window size
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
/// If the view is currently being supressed by some other "monitor"
/// For when you want to own the client's eye without fucking with their viewport
/// Doesn't make sense for a binocoler to effect your view in a camera console
var/is_suppressed = FALSE
/// The client that owns this view packet
var/client/chief = null

/datum/viewData/New(client/owner, view_string)
default = view_string
chief = owner
apply()

/datum/viewData/Destroy()
chief = null
return ..()

/datum/viewData/proc/setDefault(string)
default = string
apply()
Expand All @@ -24,12 +41,15 @@

/datum/viewData/proc/assertFormat()//T-Pose
winset(chief, "mapwindow.map", "zoom=0")
zoom = 0

/datum/viewData/proc/resetFormat()
winset(chief, "mapwindow.map", "zoom=[chief.prefs.read_player_preference(/datum/preference/numeric/pixel_size)]")
zoom = chief?.prefs.read_preference(/datum/preference/numeric/pixel_size)
winset(chief, "mapwindow.map", "zoom=[zoom]")
chief?.attempt_auto_fit_viewport() // If you change zoom mode, fit the viewport

/datum/viewData/proc/setZoomMode()
winset(chief, "mapwindow.map", "zoom-mode=[chief.prefs.read_player_preference(/datum/preference/choiced/scaling_method)]")
winset(chief, "mapwindow.map", "zoom-mode=[chief?.prefs.read_preference(/datum/preference/choiced/scaling_method)]")

/datum/viewData/proc/isZooming()
return (width || height)
Expand Down Expand Up @@ -80,7 +100,7 @@
apply()

/datum/viewData/proc/apply()
chief.change_view(getView())
chief?.change_view(getView())
safeApplyFormat()

/datum/viewData/proc/supress()
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 @@ -8,6 +8,9 @@
//ADMIN THINGS//
////////////////

/// If this client has been fully initialized or not
var/fully_created = FALSE

/// The admin state of the client. If this is null, the client is not an admin.
var/datum/admins/holder = null
var/datum/click_intercept = null // Needs to implement InterceptClickOn(user,params,atom) proc
Expand Down
4 changes: 2 additions & 2 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(

//Load the TGUI stat in case of TGUI subsystem not ready (startup)
mob.UpdateMobStat(TRUE)
fully_created = TRUE

/client/proc/time_to_redirect()
var/redirect_address = CONFIG_GET(string/redirect_address)
Expand Down Expand Up @@ -1045,8 +1046,7 @@ GLOBAL_LIST_INIT(blacklisted_builds, list(
if (isliving(mob))
var/mob/living/M = mob
M.update_damage_hud()
if (prefs?.read_player_preference(/datum/preference/toggle/auto_fit_viewport))
addtimer(CALLBACK(src,.verb/fit_viewport,10)) //Delayed to avoid wingets from Login calls.
attempt_auto_fit_viewport()

/client/proc/generate_clickcatcher()
if(!void)
Expand Down
39 changes: 35 additions & 4 deletions code/modules/client/verbs/ooc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ GLOBAL_VAR_INIT(normal_ooc_colour, "#002eb8")
SSticker.show_roundend_report(src, TRUE)

/client/verb/fit_viewport()
set name = "Fit Viewport"
set name = "Fit Viewport asdfasdf"
set category = "OOC"
set desc = "Fit the width of the map window to match the viewport"

Expand All @@ -249,9 +249,31 @@ GLOBAL_VAR_INIT(normal_ooc_colour, "#002eb8")

// 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)

// Client closed the window? Some other error? This is unexpected behaviour, let's
// CRASH with some info.
if(!sizes["mapwindow.size"])
CRASH("sizes does not contain mapwindow.size key. This means a winget failed to return what we wanted. --- sizes var: [sizes] --- sizes length: [length(sizes)]")

var/list/map_size = splittext(sizes["mapwindow.size"], "x")

// 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 @@ -284,6 +306,15 @@ GLOBAL_VAR_INIT(normal_ooc_colour, "#002eb8")
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.read_preference(/datum/preference/toggle/auto_fit_viewport))
return
if(fully_created)
INVOKE_ASYNC(src, VERB_REF(fit_viewport))
else //Delayed to avoid wingets from Login calls.
addtimer(CALLBACK(src, VERB_REF(fit_viewport), 1 SECONDS))

/client/verb/view_runtimes_minimal()
set name = "View Minimal Runtimes"
set category = "OOC"
Expand Down

0 comments on commit 1eb1539

Please sign in to comment.