Add "Fit Viewport" verb to automatically size the map window (#38351)

* Add a verb to automatically size the map window

* Add a preference to auto-fit the viewport
This commit is contained in:
Tad Hardesty
2018-06-14 10:03:16 +02:00
committed by AnturK
parent 8faec058c8
commit 75aa8ec4b2
4 changed files with 60 additions and 2 deletions
+2
View File
@@ -773,6 +773,8 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
if (isliving(mob))
var/mob/living/M = mob
M.update_damage_hud()
if (prefs.auto_fit_viewport)
fit_viewport()
/client/proc/generate_clickcatcher()
if(!void)
+9 -2
View File
@@ -114,6 +114,7 @@ GLOBAL_LIST_EMPTY(preferences_datums)
var/parallax
var/ambientocclusion = TRUE
var/auto_fit_viewport = FALSE
var/uplink_spawn_loc = UPLINK_PDA
@@ -157,7 +158,7 @@ GLOBAL_LIST_EMPTY(preferences_datums)
return
update_preview_icon()
user << browse_rsc(preview_icon, "previewicon.png")
var/dat = "<center>"
var/list/dat = list("<center>")
dat += "<a href='?_src_=prefs;preference=tab;tab=0' [current_tab == 0 ? "class='linkOn'" : ""]>Character Settings</a>"
dat += "<a href='?_src_=prefs;preference=tab;tab=1' [current_tab == 1 ? "class='linkOn'" : ""]>Game Preferences</a>"
@@ -512,6 +513,7 @@ GLOBAL_LIST_EMPTY(preferences_datums)
dat += "</a><br>"
dat += "<b>Ambient Occlusion:</b> <a href='?_src_=prefs;preference=ambientocclusion'>[ambientocclusion ? "Enabled" : "Disabled"]</a><br>"
dat += "<b>Fit Viewport:</b> <a href='?_src_=prefs;preference=auto_fit_viewport'>[auto_fit_viewport ? "Auto" : "Manual"]</a><br>"
if (CONFIG_GET(flag/maprotation))
var/p_map = preferred_map
@@ -604,7 +606,7 @@ GLOBAL_LIST_EMPTY(preferences_datums)
dat += "</center>"
var/datum/browser/popup = new(user, "preferences", "<div align='center'>Character Setup</div>", 640, 770)
popup.set_content(dat)
popup.set_content(dat.Join())
popup.open(0)
#undef APPEARANCE_CATEGORY_COLUMN
@@ -1495,6 +1497,11 @@ GLOBAL_LIST_EMPTY(preferences_datums)
var/obj/screen/plane_master/game_world/PM = locate(/obj/screen/plane_master/game_world) in parent.screen
PM.backdrop(parent.mob)
if("auto_fit_viewport")
auto_fit_viewport = !auto_fit_viewport
if(auto_fit_viewport && parent)
parent.fit_viewport()
if("save")
save_preferences()
save_character()
@@ -98,6 +98,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
S["clientfps"] >> clientfps
S["parallax"] >> parallax
S["ambientocclusion"] >> ambientocclusion
S["auto_fit_viewport"] >> auto_fit_viewport
S["menuoptions"] >> menuoptions
S["enable_tips"] >> enable_tips
S["tip_delay"] >> tip_delay
@@ -122,6 +123,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
clientfps = sanitize_integer(clientfps, 0, 1000, 0)
parallax = sanitize_integer(parallax, PARALLAX_INSANE, PARALLAX_DISABLE, null)
ambientocclusion = sanitize_integer(ambientocclusion, 0, 1, initial(ambientocclusion))
auto_fit_viewport = sanitize_integer(auto_fit_viewport, 0, 1, initial(auto_fit_viewport))
ghost_form = sanitize_inlist(ghost_form, GLOB.ghost_forms, initial(ghost_form))
ghost_orbit = sanitize_inlist(ghost_orbit, GLOB.ghost_orbits, initial(ghost_orbit))
ghost_accs = sanitize_inlist(ghost_accs, GLOB.ghost_accs_options, GHOST_ACCS_DEFAULT_OPTION)
@@ -168,6 +170,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
WRITE_FILE(S["clientfps"], clientfps)
WRITE_FILE(S["parallax"], parallax)
WRITE_FILE(S["ambientocclusion"], ambientocclusion)
WRITE_FILE(S["auto_fit_viewport"], auto_fit_viewport)
WRITE_FILE(S["menuoptions"], menuoptions)
WRITE_FILE(S["enable_tips"], enable_tips)
WRITE_FILE(S["tip_delay"], tip_delay)
+46
View File
@@ -298,3 +298,49 @@ GLOBAL_VAR_INIT(normal_ooc_colour, OOC_COLOR)
set desc = "View the last round end report you've seen"
SSticker.show_roundend_report(src, TRUE)
/client/verb/fit_viewport()
set name = "Fit Viewport"
set category = "OOC"
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/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)
if (text2num(map_size[1]) == desired_width)
// Nothing to do
return
var/split_size = splittext(sizes["mainwindow.split.size"], "x")
var/split_width = text2num(split_size[1])
// 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.split", "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.split", "splitter=[pct]")