Skip to content

Commit 1614501

Browse files
Datum view and some other things (#51208)
* Datumizes all uses of change_view * Cleanup and helper procs * tweaks values to match the format, hint hint, (value - 0.5) works just fine * And there's the rest * woop, braindamage * and one more * fuck you menu file * woops * we should apply that * fixes tooltip drift, thank you goon coders * you can shake but you can't zoom
1 parent 8e153aa commit 1614501

File tree

30 files changed

+280
-169
lines changed

30 files changed

+280
-169
lines changed

code/__DEFINES/preferences.dm

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
#define PARALLAX_LOW 2
4848
#define PARALLAX_DISABLE 3 //this option must be the highest number
4949

50+
#define PIXEL_SCALING_AUTO 0
51+
#define PIXEL_SCALING_1X 1
52+
#define PIXEL_SCALING_1_2X 1.5
53+
#define PIXEL_SCALING_2X 2
54+
#define PIXEL_SCALING_3X 3
55+
56+
#define SCALING_METHOD_NORMAL "normal"
57+
#define SCALING_METHOD_DISTORT "distort"
58+
#define SCALING_METHOD_BLUR "blur"
59+
5060
#define PARALLAX_DELAY_DEFAULT world.tick_lag
5161
#define PARALLAX_DELAY_MED 1
5262
#define PARALLAX_DELAY_LOW 2

code/__HELPERS/view.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var/viewX
33
var/viewY
44
if(isnum(view))
5-
var/totalviewrange = 1 + 2 * view
5+
var/totalviewrange = (view < 0 ? -1 : 1) + 2 * view
66
viewX = totalviewrange
77
viewY = totalviewrange
88
else

code/datums/components/riding.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
buckled_mob.pixel_x = 0
154154
buckled_mob.pixel_y = 0
155155
if(buckled_mob.client)
156-
buckled_mob.client.change_view(CONFIG_GET(string/default_view))
156+
buckled_mob.client.view_size.resetToDefault()
157157

158158
//MOVEMENT
159159
/datum/component/riding/proc/turf_check(turf/next, turf/current)

code/datums/view.dm

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
//This is intended to be a full wrapper. DO NOT directly modify its values
2+
///Container for client viewsize
3+
/datum/viewData
4+
var/width = 0
5+
var/height = 0
6+
var/default = ""
7+
var/is_suppressed = FALSE
8+
var/client/chief = null
9+
10+
/datum/viewData/New(client/owner, view_string)
11+
default = view_string
12+
chief = owner
13+
apply()
14+
15+
/datum/viewData/proc/setDefault(string)
16+
default = string
17+
apply()
18+
19+
/datum/viewData/proc/safeApplyFormat()
20+
if(isZooming())
21+
assertFormat()
22+
return
23+
resetFormat()
24+
25+
/datum/viewData/proc/assertFormat()//T-Pose
26+
winset(chief, "mapwindow.map", "zoom=0")
27+
28+
/datum/viewData/proc/resetFormat()//Cuck
29+
winset(chief, "mapwindow.map", "zoom=[chief.prefs.pixel_size]")
30+
31+
/datum/viewData/proc/setZoomMode()
32+
winset(chief, "mapwindow.map", "zoom-mode=[chief.prefs.scaling_method]")
33+
34+
/datum/viewData/proc/isZooming()
35+
return (width || height)
36+
37+
/datum/viewData/proc/resetToDefault()
38+
width = 0
39+
height = 0
40+
apply()
41+
42+
/datum/viewData/proc/add(toAdd)
43+
width += toAdd
44+
height += toAdd
45+
apply()
46+
47+
/datum/viewData/proc/addTo(toAdd)
48+
var/list/shitcode = getviewsize(toAdd)
49+
width += shitcode[1]
50+
height += shitcode[2]
51+
apply()
52+
53+
/datum/viewData/proc/setTo(toAdd)
54+
var/list/shitcode = getviewsize(toAdd) //Backward compatability to account
55+
width = shitcode[1] //for a change in how sizes get calculated. we used to include world.view in
56+
height = shitcode[2] //this, but it was jank, so I had to move it
57+
apply()
58+
59+
/datum/viewData/proc/setBoth(wid, hei)
60+
width = wid
61+
height = hei
62+
apply()
63+
64+
/datum/viewData/proc/setWidth(wid)
65+
width = wid
66+
apply()
67+
68+
/datum/viewData/proc/setHeight(hei)
69+
width = hei
70+
apply()
71+
72+
/datum/viewData/proc/addToWidth(toAdd)
73+
width += toAdd
74+
apply()
75+
76+
/datum/viewData/proc/addToHeight(screen, toAdd)
77+
height += toAdd
78+
apply()
79+
80+
/datum/viewData/proc/apply()
81+
chief.change_view(getView())
82+
safeApplyFormat()
83+
if(chief.prefs.auto_fit_viewport)
84+
chief.fit_viewport()
85+
86+
/datum/viewData/proc/supress()
87+
is_suppressed = TRUE
88+
apply()
89+
90+
/datum/viewData/proc/unsupress()
91+
is_suppressed = FALSE
92+
apply()
93+
94+
/datum/viewData/proc/getView()
95+
var/list/temp = getviewsize(default)
96+
if(is_suppressed)
97+
return "[temp[1]]x[temp[2]]"
98+
return "[width + temp[1]]x[height + temp[2]]"
99+
100+
/datum/viewData/proc/zoomIn()
101+
resetToDefault()
102+
animate(chief, pixel_x = 0, pixel_y = 0, 0, FALSE, LINEAR_EASING, ANIMATION_END_NOW)
103+
104+
/datum/viewData/proc/zoomOut(radius = 0, offset = 0, direction = FALSE)
105+
if(direction)
106+
var/_x = 0
107+
var/_y = 0
108+
switch(direction)
109+
if(NORTH)
110+
_y = offset
111+
if(EAST)
112+
_x = offset
113+
if(SOUTH)
114+
_y = -offset
115+
if(WEST)
116+
_x = -offset
117+
animate(chief, pixel_x = world.icon_size*_x, pixel_y = world.icon_size*_y, 0, FALSE, LINEAR_EASING, ANIMATION_END_NOW)
118+
//Ready for this one?
119+
setTo(radius)
120+
121+
/proc/getScreenSize(widescreen)
122+
if(widescreen)
123+
return CONFIG_GET(string/default_view)
124+
return CONFIG_GET(string/default_view_square)

code/game/machinery/computer/camera_advanced.dm

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
current_user = null
7878
user.unset_machine()
79+
user.client.view_size.unsupress()
7980
playsound(src, 'sound/machines/terminal_off.ogg', 25, FALSE)
8081

8182
/obj/machinery/computer/camera_advanced/check_eye(mob/user)
@@ -161,6 +162,7 @@
161162
user.remote_control = eyeobj
162163
user.reset_perspective(eyeobj)
163164
eyeobj.setLoc(eyeobj.loc)
165+
user.client.view_size.supress()
164166

165167
/mob/camera/aiEye/remote
166168
name = "Inactive Camera Eye"

code/game/mecha/mecha.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@
10801080

10811081
if(L && L.client)
10821082
L.update_mouse_pointer()
1083-
L.client.change_view(CONFIG_GET(string/default_view))
1083+
L.client.view_size.resetToDefault()
10841084
zoom_mode = 0
10851085

10861086
/////////////////////////

code/game/mecha/mecha_actions.dm

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@
215215
chassis.log_message("Toggled zoom mode.", LOG_MECHA)
216216
chassis.occupant_message("<font color='[chassis.zoom_mode?"blue":"red"]'>Zoom mode [chassis.zoom_mode?"en":"dis"]abled.</font>")
217217
if(chassis.zoom_mode)
218-
owner.client.change_view(12)
218+
owner.client.view_size.setTo(4.5)
219219
SEND_SOUND(owner, sound('sound/mecha/imag_enh.ogg',volume=50))
220220
else
221-
owner.client.change_view(CONFIG_GET(string/default_view)) //world.view - default mob view size
221+
owner.client.view_size.resetToDefault() //Let's not let this stack shall we?
222222
UpdateButtonIcon()
223223

224224
/datum/action/innate/mecha/mech_switch_damtype

code/game/objects/items/binoculars.dm

+17-29
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
slot_flags = ITEM_SLOT_BELT
99
w_class = WEIGHT_CLASS_SMALL
1010
var/mob/listeningTo
11-
var/zoom_out_amt = 6
11+
var/zoom_out_amt = 5.5
1212
var/zoom_amt = 10
1313

1414
/obj/item/binoculars/Initialize()
@@ -25,41 +25,29 @@
2525
return ..()
2626

2727
/obj/item/binoculars/proc/on_wield(obj/item/source, mob/user)
28-
RegisterSignal(user, COMSIG_MOVABLE_MOVED, .proc/unwield)
28+
RegisterSignal(user, COMSIG_MOVABLE_MOVED, .proc/on_walk)
29+
RegisterSignal(user, COMSIG_ATOM_DIR_CHANGE, .proc/rotate)
2930
listeningTo = user
3031
user.visible_message("<span class='notice'>[user] holds [src] up to [user.p_their()] eyes.</span>", "<span class='notice'>You hold [src] up to your eyes.</span>")
3132
item_state = "binoculars_wielded"
3233
user.regenerate_icons()
33-
if(!user?.client)
34-
return
35-
var/client/C = user.client
36-
var/_x = 0
37-
var/_y = 0
38-
switch(user.dir)
39-
if(NORTH)
40-
_y = zoom_amt
41-
if(EAST)
42-
_x = zoom_amt
43-
if(SOUTH)
44-
_y = -zoom_amt
45-
if(WEST)
46-
_x = -zoom_amt
47-
C.change_view(world.view + zoom_out_amt)
48-
C.pixel_x = world.icon_size*_x
49-
C.pixel_y = world.icon_size*_y
50-
/obj/item/binoculars/proc/on_unwield(obj/item/source, mob/user)
51-
unwield(user)
34+
user.client.view_size.zoomOut(zoom_out_amt, zoom_amt, user.dir)
35+
36+
/obj/item/binoculars/proc/rotate(atom/thing, old_dir, new_dir)
37+
if(ismob(thing))
38+
var/mob/lad = thing
39+
lad.regenerate_icons()
40+
lad.client.view_size.zoomOut(zoom_out_amt, zoom_amt, new_dir)
5241

53-
/obj/item/binoculars/proc/unwield(mob/user)
42+
/obj/item/binoculars/proc/on_walk()
43+
attack_self(listeningTo) //Yes I have sinned, why do you ask?
44+
45+
/obj/item/binoculars/proc/on_unwield(obj/item/source, mob/user)
5446
if(listeningTo)
55-
UnregisterSignal(listeningTo, COMSIG_MOVABLE_MOVED)
47+
UnregisterSignal(user, COMSIG_MOVABLE_MOVED)
48+
UnregisterSignal(user, COMSIG_ATOM_DIR_CHANGE)
5649
listeningTo = null
5750
user.visible_message("<span class='notice'>[user] lowers [src].</span>", "<span class='notice'>You lower [src].</span>")
5851
item_state = "binoculars"
5952
user.regenerate_icons()
60-
if(user && user.client)
61-
user.regenerate_icons()
62-
var/client/C = user.client
63-
C.change_view(CONFIG_GET(string/default_view))
64-
user.client.pixel_x = 0
65-
user.client.pixel_y = 0
53+
user.client.view_size.zoomIn()

code/game/objects/structures/manned_turret.dm

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
max_integrity = 100
1212
buckle_lying = FALSE
1313
layer = ABOVE_MOB_LAYER
14-
var/view_range = 10
14+
var/view_range = 2.5
1515
var/cooldown = 0
1616
var/projectile_type = /obj/projectile/bullet/manned_turret
1717
var/rate_of_fire = 1
@@ -38,7 +38,7 @@
3838
buckled_mob.pixel_x = 0
3939
buckled_mob.pixel_y = 0
4040
if(buckled_mob.client)
41-
buckled_mob.client.change_view(CONFIG_GET(string/default_view))
41+
buckled_mob.client.view_size.resetToDefault()
4242
anchored = FALSE
4343
. = ..()
4444
STOP_PROCESSING(SSfastprocess, src)
@@ -65,7 +65,7 @@
6565
playsound(src,'sound/mecha/mechmove01.ogg', 50, TRUE)
6666
anchored = TRUE
6767
if(M.client)
68-
M.client.change_view(view_range)
68+
M.client.view_size.setTo(view_range)
6969
START_PROCESSING(SSfastprocess, src)
7070

7171
/obj/machinery/manned_turret/process()

code/modules/admin/verbs/randomverbs.dm

+3-3
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,10 @@ Traitors and the like can also be revived with the previous role mostly intact.
715715
set name = "Change View Range"
716716
set desc = "switches between 1x and custom views"
717717

718-
if(view == CONFIG_GET(string/default_view))
719-
change_view(input("Select view range:", "FUCK YE", 7) in list(1,2,3,4,5,6,7,8,9,10,11,12,13,14,128))
718+
if(view_size.getView() == view_size.default)
719+
view_size.setTo(input("Select view range:", "FUCK YE", 7) in list(1,2,3,4,5,6,7,8,9,10,11,12,13,14,128) - 7)
720720
else
721-
change_view(CONFIG_GET(string/default_view))
721+
view_size.resetToDefault(getScreenSize(prefs.widescreenpref))
722722

723723
log_admin("[key_name(usr)] changed their view range to [view].")
724724
//message_admins("\blue [key_name_admin(usr)] changed their view range to [view].") //why? removed by order of XSI

code/modules/antagonists/fugitive/fugitive_ship.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
shuttlePortId = "huntership_custom"
4646
see_hidden = FALSE
4747
jumpto_ports = list("huntership_home" = 1, "whiteship_home" = 1, "syndicate_nw" = 1)
48-
view_range = 12
48+
view_range = 4.5
4949

5050
/obj/structure/closet/crate/eva
5151
name = "EVA crate"

code/modules/client/client_defines.dm

+1
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,4 @@
141141

142142
/// Messages currently seen by this client
143143
var/list/seen_messages
144+
var/datum/viewData/view_size

code/modules/client/client_procs.dm

+6-5
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
447447
if (menuitem)
448448
menuitem.Load_checked(src)
449449

450+
view_size = new(src, getScreenSize(prefs.widescreenpref))
451+
view_size.resetFormat()
452+
view_size.setZoomMode()
453+
fit_viewport()
450454
Master.UpdateTickRate()
451455

452456
//////////////
@@ -881,7 +885,7 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
881885
if ("key")
882886
return FALSE
883887
if("view")
884-
change_view(var_value)
888+
view_size.setDefault(var_value)
885889
return TRUE
886890
. = ..()
887891

@@ -891,7 +895,7 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
891895
var/y = viewscale[2]
892896
x = clamp(x+change, min, max)
893897
y = clamp(y+change, min,max)
894-
change_view("[x]x[y]")
898+
view_size.setDefault("[x]x[y]")
895899

896900
/client/proc/update_movement_keys(datum/preferences/direct_prefs)
897901
var/datum/preferences/D = prefs || direct_prefs
@@ -914,9 +918,6 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
914918
if (isnull(new_size))
915919
CRASH("change_view called without argument.")
916920

917-
if(prefs && !prefs.widescreenpref && new_size == CONFIG_GET(string/default_view))
918-
new_size = CONFIG_GET(string/default_view_square)
919-
920921
view = new_size
921922
apply_clickcatcher()
922923
mob.reload_fullscreen()

0 commit comments

Comments
 (0)