Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

Commit

Permalink
feat: widescreen (ParadiseSS13/Paradise#20861) (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
larentoun authored and Furrior committed Jun 27, 2023
1 parent 9c15ce4 commit 135e88a
Show file tree
Hide file tree
Showing 25 changed files with 205 additions and 116 deletions.
1 change: 1 addition & 0 deletions SQL/paradise_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ CREATE TABLE `player` (
`discord_id` varchar(32) NULL DEFAULT NULL,
`discord_name` varchar(32) NULL DEFAULT NULL,
`keybindings` longtext COLLATE 'utf8mb4_unicode_ci' DEFAULT NULL,
`viewrange` VARCHAR(5) NOT NULL DEFAULT '19x15' COLLATE 'utf8mb4_general_ci',
PRIMARY KEY (`id`),
UNIQUE KEY `ckey` (`ckey`),
KEY `lastseen` (`lastseen`),
Expand Down
4 changes: 4 additions & 0 deletions SQL/updates/29-30.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Updating SQL from 29 to 30 -AffectedArc07
# Add new viewrange toggle
ALTER TABLE `player`
ADD COLUMN `viewrange` VARCHAR(5) NOT NULL DEFAULT '19x15' AFTER `keybindings`;
16 changes: 11 additions & 5 deletions code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@
#define in_range(source, user) (get_dist(source, user) <= 1)

#define RANGE_TURFS(RADIUS, CENTER) \
block( \
locate(max(CENTER.x-(RADIUS),1), max(CENTER.y-(RADIUS),1), CENTER.z), \
locate(min(CENTER.x+(RADIUS),world.maxx), min(CENTER.y+(RADIUS),world.maxy), CENTER.z) \
)
RECT_TURFS(RADIUS, RADIUS, CENTER)

#define RECT_TURFS(H_RADIUS, V_RADIUS, CENTER) \
block( \
locate(max(CENTER.x-(H_RADIUS),1), max(CENTER.y-(V_RADIUS),1), CENTER.z), \
locate(min(CENTER.x+(H_RADIUS),world.maxx), min(CENTER.y+(V_RADIUS),world.maxy), CENTER.z) \
)

/// Returns the turfs on the edge of a square with CENTER in the middle and with the given RADIUS. If used near the edge of the map, will still work fine.
// order of the additions: top edge + bottom edge + left edge + right edge
Expand Down Expand Up @@ -382,7 +385,7 @@
#define EXPLOSION_BLOCK_PROC -1

// The SQL version required by this version of the code
#define SQL_VERSION 29
#define SQL_VERSION 30

// Vending machine stuff
#define CAT_NORMAL 1
Expand Down Expand Up @@ -516,3 +519,6 @@
#define TTS_SEED_DEFAULT_FEMALE "tyrande"
#define TTS_SEED_DEFAULT_MALE "arthas"
#define TTS_SEED_ANNOUNCER "anubarak"

// This isnt in client_defines due to scoping issues
#define DEFAULT_CLIENT_VIEWSIZE "19x15"
5 changes: 3 additions & 2 deletions code/__DEFINES/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@
#define PREFTOGGLE_2_SEE_ITEM_OUTLINES 512
// Yes I know this being an "enable to disable" is misleading, but it avoids having to tweak all existing pref entries
#define PREFTOGGLE_2_REVERB_DISABLE 1024
#define PREFTOGGLE_2_WIDESCREEN 2048

#define TOGGLES_2_TOTAL 2047 // If you add or remove a preference toggle above, make sure you update this define with the total value of the toggles combined.
#define TOGGLES_2_TOTAL 4095 // If you add or remove a preference toggle above, make sure you update this define with the total value of the toggles combined.

#define TOGGLES_2_DEFAULT (PREFTOGGLE_2_FANCYUI|PREFTOGGLE_2_ITEMATTACK|PREFTOGGLE_2_WINDOWFLASHING|PREFTOGGLE_2_RUNECHAT|PREFTOGGLE_2_DEATHMESSAGE|PREFTOGGLE_2_SEE_ITEM_OUTLINES)
#define TOGGLES_2_DEFAULT (PREFTOGGLE_2_FANCYUI|PREFTOGGLE_2_ITEMATTACK|PREFTOGGLE_2_WINDOWFLASHING|PREFTOGGLE_2_RUNECHAT|PREFTOGGLE_2_DEATHMESSAGE|PREFTOGGLE_2_SEE_ITEM_OUTLINES|PREFTOGGLE_2_WIDESCREEN)

// Sanity checks
#if TOGGLES_TOTAL > 16777215
Expand Down
9 changes: 0 additions & 9 deletions code/_onclick/hud/hud.dm
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,6 @@
if(display_hud_version > HUD_VERSIONS) //If the requested version number is greater than the available versions, reset back to the first version
display_hud_version = 1

if(mymob.client.view < world.view)
if(mymob.client.view < ARBITRARY_VIEWRANGE_NOHUD)
to_chat(mymob, "<span class='notice'>HUD is unavailable with this view range.</span>")
display_hud_version = HUD_STYLE_NOHUD
else
if(display_hud_version == HUD_STYLE_STANDARD)
to_chat(mymob, "<span class='notice'>Standard HUD mode is unavailable with a smaller-than-normal view range.</span>")
display_hud_version = HUD_STYLE_REDUCED

switch(display_hud_version)
if(HUD_STYLE_STANDARD) //Default HUD
hud_shown = TRUE //Governs behavior of other procs
Expand Down
21 changes: 14 additions & 7 deletions code/_onclick/hud/parallax.dm
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,24 @@
/obj/screen/parallax_layer/proc/update_o(view)
if(!view)
view = world.view
var/list/new_overlays = list()
var/count = CEILING(view/(480/world.icon_size), 1)+1
for(var/x in -count to count)
for(var/y in -count to count)

var/static/parallax_scaler = world.icon_size / 480

// Turn the view size into a grid of correctly scaled overlays
var/list/viewscales = getviewsize(view)
var/countx = CEILING((viewscales[1] / 2) * parallax_scaler, 1) + 1
var/county = CEILING((viewscales[2] / 2) * parallax_scaler, 1) + 1
var/list/new_overlays = new
for(var/x in -countx to countx)
for(var/y in -county to county)
if(x == 0 && y == 0)
continue
var/mutable_appearance/texture_overlay = mutable_appearance(icon, icon_state)
texture_overlay.transform = matrix(1, 0, x*480, 0, 1, y*480)
texture_overlay.transform = matrix(1, 0, x * 480, 0, 1, y * 480)
new_overlays += texture_overlay

overlays = new_overlays
cut_overlays()
add_overlay(new_overlays)
// Cache this
view_sized = view

/obj/screen/parallax_layer/proc/update_status(mob/M)
Expand Down
2 changes: 1 addition & 1 deletion code/game/gamemodes/miniantags/slaughter/slaughter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@

/datum/action/innate/demon/whisper/proc/choose_targets(mob/user = usr)//yes i am copying from telepathy..hush...
var/list/validtargets = list()
for(var/mob/living/M in view(user.client.view, get_turf(user)))
for(var/mob/living/M in view(user.client.maxview(), get_turf(user)))
if(M && M.mind && M.stat != DEAD)
if(M == user)
continue
Expand Down
15 changes: 9 additions & 6 deletions code/game/objects/items/blueprints.dm
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,22 @@
set_viewer(usr)

attack_self(usr)
/obj/item/areaeditor/blueprints/proc/get_images(turf/T, viewsize)

/obj/item/areaeditor/blueprints/proc/get_images(turf/central_turf, viewsize)
. = list()
for(var/tt in RANGE_TURFS(viewsize, T))
var/turf/TT = tt
if(TT.blueprint_data)
. += TT.blueprint_data
var/list/dimensions = getviewsize(viewsize)
var/horizontal_radius = dimensions[1] / 2
var/vertical_radius = dimensions[2] / 2
for(var/turf/nearby_turf as anything in RECT_TURFS(horizontal_radius, vertical_radius, central_turf))
if(nearby_turf.blueprint_data)
. += nearby_turf.blueprint_data

/obj/item/areaeditor/blueprints/proc/set_viewer(mob/user, message = "")
if(user && user.client)
if(viewing)
clear_viewer()
viewing = user.client
showing = get_images(get_turf(user), viewing.view)
showing = get_images(get_turf(viewing.eye || user), viewing.view)
viewing.images |= showing
if(message)
to_chat(user, message)
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/devices/lightreplacer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
return
if(!isturf(T))
return
if(get_dist(src, T) >= (U.client.view + 2)) // To prevent people from using it over cameras
if(get_dist(src, T) >= (U.client.maxview() + 2)) // To prevent people from using it over cameras
return

var/used = FALSE
Expand Down
2 changes: 2 additions & 0 deletions code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@

/turf/proc/add_blueprints(atom/movable/AM)
var/image/I = new
I.plane = GAME_PLANE
I.layer = OBJ_LAYER
I.appearance = AM.appearance
I.appearance_flags = RESET_COLOR|RESET_ALPHA|RESET_TRANSFORM
I.loc = src
Expand Down
2 changes: 1 addition & 1 deletion code/modules/client/client_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

preload_rsc = 0 // This is 0 so we can set it to an URL once the player logs in and have them download the resources from a different server.

var/global/obj/screen/click_catcher/void
var/obj/screen/click_catcher/void

var/karma = 0
var/karma_spent = 0
Expand Down
70 changes: 48 additions & 22 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@
GLOB.preferences_datums[ckey] = prefs
else
prefs.parent = src

// Setup widescreen
view = prefs.viewrange

prefs.init_keybindings(prefs.keybindings_overrides) //The earliest sane place to do it where prefs are not null, if they are null you can't do crap at lobby
prefs.last_ip = address //these are gonna be used for banning
prefs.last_id = computer_id //these are gonna be used for banning
Expand Down Expand Up @@ -350,6 +354,10 @@
winset(src, null, "command=\".configure graphics-hwmode off\"")
winset(src, null, "command=\".configure graphics-hwmode on\"")

// Try doing this before mob login
generate_clickcatcher()
apply_clickcatcher()

connection_time = world.time
connection_realtime = world.realtime
connection_timeofday = world.timeofday
Expand Down Expand Up @@ -381,9 +389,6 @@
else
to_chat(src,"<span class='notice'>You have enabled karma gains.")

generate_clickcatcher()
apply_clickcatcher()

if(show_update_prompt)
show_update_notice()

Expand Down Expand Up @@ -426,6 +431,7 @@
GLOB.panic_bunker_enabled = FALSE
message_admins("Panic bunker has been automatically disabled due to playercount dropping below [threshold]")


/client/proc/is_connecting_from_localhost()
var/localhost_addresses = list("127.0.0.1", "::1") // Adresses
if(!isnull(address) && (address in localhost_addresses))
Expand Down Expand Up @@ -1073,25 +1079,40 @@

/client/verb/fit_viewport()
set name = "Fit Viewport"
set desc = "Fit the size of the map window to match the 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/list/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.mainvsplit;mapwindow", "size"))
var/map_size = splittext(sizes["mapwindow.size"], "x")
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")

// Looks like we didn't 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])
var/desired_width = round(height * aspect_ratio)
if (text2num(map_size[1]) == desired_width)
// Nothing to do
if(text2num(map_size[1]) == desired_width)
// Nothing to do.
return

var/split_size = splittext(sizes["mainwindow.mainvsplit.size"], "x")
var/list/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
Expand All @@ -1102,20 +1123,20 @@
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])
var/produced_width = text2num(map_size[1])

if (got_width == desired_width)
// success
if(produced_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]")
else if(isnull(delta))
// Calculate a probably delta based on the difference
delta = 100 * (desired_width - produced_width) / split_width
else if((delta > 0 && produced_width > desired_width) || (delta < 0 && produced_width < desired_width))
// If we overshot, halve the delta and reverse direction
delta = -delta / 2

pct += delta
winset(src, "mainwindow.mainvsplit", "splitter=[pct]")

/client/verb/fitviewport() // wrapper for mainwindow
set hidden = 1
Expand Down Expand Up @@ -1354,6 +1375,11 @@
// If we are here, they have not accepted, and need to read it
return FALSE

/// Returns the biggest number from client.view so we can do easier maths
/client/proc/maxview()
var/list/screensize = getviewsize(view)
return max(screensize[1], screensize[2])

#undef LIMITER_SIZE
#undef CURRENT_SECOND
#undef SECOND_COUNT
Expand Down
23 changes: 22 additions & 1 deletion code/modules/client/preference/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
var/list/datum/keybindings = list()
/// Keybinding overrides ("name" => ["key"...])
var/list/keybindings_overrides = null
/// View range preference for this client
var/viewrange = DEFAULT_CLIENT_VIEWSIZE

/datum/preferences/New(client/C)
parent = C
Expand Down Expand Up @@ -540,6 +542,7 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
dat += "<b>Play Lobby Music:</b> <a href='?_src_=prefs;preference=lobby_music'><b>[(sound & SOUND_LOBBY) ? "Yes" : "No"]</b></a><br>"
dat += "<b>Randomized Character Slot:</b> <a href='?_src_=prefs;preference=randomslot'><b>[toggles2 & PREFTOGGLE_2_RANDOMSLOT ? "Yes" : "No"]</b></a><br>"
dat += "<b>Window Flashing:</b> <a href='?_src_=prefs;preference=winflash'>[(toggles2 & PREFTOGGLE_2_WINDOWFLASHING) ? "Yes" : "No"]</a><br>"
dat += "<b>View Range:</b> <a href='?_src_=prefs;preference=setviewrange'>[viewrange]</a><br>"
// RIGHT SIDE OF THE PAGE
dat += "</td><td width='300px' height='300px' valign='top'>"
dat += "<h2>Special Role Settings</h2>"
Expand Down Expand Up @@ -689,7 +692,7 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
dat += "<a href='?_src_=prefs;preference=reset_all'>Reset Setup</a>"
dat += "</center>"

var/datum/browser/popup = new(user, "preferences", "<div align='center'>Character Setup</div>", 820, 660)
var/datum/browser/popup = new(user, "preferences", "<div align='center'>Character Setup</div>", 820, 770)
popup.set_content(dat.Join(""))
popup.open(FALSE)

Expand Down Expand Up @@ -2233,6 +2236,24 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
if("winflash")
toggles2 ^= PREFTOGGLE_2_WINDOWFLASHING

if("setviewrange")
var/list/viewrange_options = list(
"15x15 (Classic)" = "15x15",
"17x15 (Wide)" = "17x15",
"19x15 (Ultrawide)" = "19x15"
)

var/new_range = input(user, "Select a view range") as anything in viewrange_options
var/actual_new_range = viewrange_options[new_range]

viewrange = actual_new_range

if(actual_new_range != parent.view)
parent.view = actual_new_range
// Update the size of the click catcher
var/list/actualview = getviewsize(parent.view)
parent.void.UpdateGreed(actualview[1],actualview[2])

if("afk_watch")
if(!(toggles2 & PREFTOGGLE_2_AFKWATCH))
to_chat(user, "<span class='info'>You will now get put into cryo dorms after [config.auto_cryo_afk] minutes. \
Expand Down
8 changes: 6 additions & 2 deletions code/modules/client/preference/preferences_mysql.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
parallax,
discord_id,
discord_name,
keybindings
keybindings,
viewrange
FROM [format_table_name("player")]
WHERE ckey=:ckey"}, list(
"ckey" = C.ckey
Expand Down Expand Up @@ -51,6 +52,7 @@
discord_id = query.item[17]
discord_name = query.item[18]
keybindings = init_keybindings(raw = query.item[19])
viewrange = query.item[20]

qdel(query)

Expand Down Expand Up @@ -102,7 +104,8 @@
lastchangelog=:lastchangelog,
clientfps=:clientfps,
parallax=:parallax,
keybindings=:keybindings
keybindings=:keybindings,
viewrange=:viewrange
WHERE ckey=:ckey"}, list(
// OH GOD THE PARAMETERS
"ooccolour" = ooccolor,
Expand All @@ -121,6 +124,7 @@
"clientfps" = clientfps,
"parallax" = parallax,
"keybindings" = json_encode(keybindings_overrides),
"viewrange" = viewrange,
"ckey" = C.ckey
)
)
Expand Down
Loading

0 comments on commit 135e88a

Please sign in to comment.