mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
[MIRROR] Add fit viewport verb and automatic pref (#8952)
Co-authored-by: Heroman3003 <31296024+Heroman3003@users.noreply.github.com> Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
This commit is contained in:
@@ -176,3 +176,6 @@
|
||||
var/last_move_dir_pressed = NONE
|
||||
|
||||
#endif
|
||||
|
||||
/// If this client has been fully initialized or not
|
||||
var/fully_created = FALSE
|
||||
|
||||
@@ -309,6 +309,8 @@
|
||||
X << 'sound/voice/bcriminal.ogg' //ChompEDIT - back to beepsky
|
||||
window_flash(X)
|
||||
//VOREStation Edit end.
|
||||
fully_created = TRUE
|
||||
attempt_auto_fit_viewport()
|
||||
|
||||
//////////////
|
||||
//DISCONNECT//
|
||||
@@ -646,6 +648,7 @@
|
||||
winset(usr, "mainwindow", "can-resize=true")
|
||||
winset(usr, "mainwindow", "is-maximized=false")
|
||||
winset(usr, "mainwindow", "on-size=attempt_auto_fit_viewport") // The attempt_auto_fit_viewport() proc is not implemented yet
|
||||
attempt_auto_fit_viewport()
|
||||
|
||||
/*CHOMPRemove Start, we use TGPanel
|
||||
/client/verb/toggle_verb_panel()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/datum/preference/toggle/auto_fit_viewport
|
||||
category = PREFERENCE_CATEGORY_GAME_PREFERENCES
|
||||
savefile_key = "auto_fit_viewport"
|
||||
savefile_identifier = PREFERENCE_PLAYER
|
||||
|
||||
/datum/preference/toggle/auto_fit_viewport/apply_to_client_updated(client/client, value)
|
||||
INVOKE_ASYNC(client, /client/verb/fit_viewport)
|
||||
@@ -195,10 +195,90 @@
|
||||
if(eyeobj)
|
||||
return eyeobj
|
||||
return src
|
||||
|
||||
//CHOMPEdit Begin
|
||||
/client/verb/fix_stat_panel()
|
||||
set name = "Fix Stat Panel"
|
||||
set hidden = TRUE
|
||||
|
||||
init_verbs()
|
||||
//CHOMPEdit End
|
||||
|
||||
/client/verb/fit_viewport()
|
||||
set name = "Fit Viewport"
|
||||
set category = "OOC.Client Settings" //CHOMPEdit
|
||||
set desc = "Fit the width of the map window to match the viewport"
|
||||
|
||||
// Fetch aspect ratio
|
||||
var/view_size = getviewsize(view)
|
||||
var/aspect_ratio = view_size[1] / view_size[2]
|
||||
|
||||
// Calculate desired pixel width using window size and aspect ratio
|
||||
var/list/sizes = params2list(winget(src, "mainwindow.mainvsplit;mapwindow", "size"))
|
||||
|
||||
// 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 = 0 // 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
|
||||
|
||||
var/split_size = splittext(sizes["mainwindow.mainvsplit.size"], "x")
|
||||
var/split_width = text2num(split_size[1])
|
||||
|
||||
// Avoid auto-resizing the statpanel and chat into nothing.
|
||||
desired_width = min(desired_width, split_width - 300)
|
||||
|
||||
// Calculate and apply a best estimate
|
||||
// +4 pixels are for the width of the splitter's handle
|
||||
var/pct = 100 * (desired_width + 4) / split_width
|
||||
winset(src, "mainwindow.mainvsplit", "splitter=[pct]")
|
||||
|
||||
// Apply an ever-lowering offset until we finish or fail
|
||||
var/delta
|
||||
for(var/safety in 1 to 10)
|
||||
var/after_size = winget(src, "mapwindow", "size")
|
||||
map_size = splittext(after_size, "x")
|
||||
var/got_width = text2num(map_size[1])
|
||||
|
||||
if (got_width == desired_width)
|
||||
// success
|
||||
return
|
||||
else if (isnull(delta))
|
||||
// calculate a probable delta value based on the difference
|
||||
delta = 100 * (desired_width - got_width) / split_width
|
||||
else if ((delta > 0 && got_width > desired_width) || (delta < 0 && got_width < desired_width))
|
||||
// if we overshot, halve the delta and reverse direction
|
||||
delta = -delta/2
|
||||
|
||||
pct += delta
|
||||
winset(src, "mainwindow.mainvsplit", "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))
|
||||
|
||||
Reference in New Issue
Block a user