ID:2707408
 

//Resize code
client
var
map_width
map_height

view_width
view_height

buffer_height
buffer_width

view_zoom
verb
onMapResize(map as text,default as num,width as num,height as num,zoom as num)
set instant = 1, hidden = 1
world.log << "[map] [default] [width] [height] [zoom]"

if(default)
map_width = width
map_height = height
view_zoom = 0

do
++view_zoom

view_width = ceil(map_width / (TILE_WIDTH * view_zoom))
if(view_width%2==0)
++view_width

view_height = ceil(map_height / (TILE_HEIGHT * view_zoom))
if(view_height%2==0)
++view_height

while(view_width>MAXIMUM_VIEW_WIDTH || view_height> MAXIMUM_VIEW_HEIGHT || view_width*view_height>MAX_VIEW_TILES)

view_width = max(MINIMUM_VIEW_WIDTH,view_width)+EXTRA_VIEW_WIDTH*2
view_height = max(MINIMUM_VIEW_HEIGHT,view_height)+EXTRA_VIEW_HEIGHT*2

buffer_width = floor((view_width*TILE_WIDTH - map_width/view_zoom)/2)
buffer_height = floor((view_height*TILE_HEIGHT - map_height/view_zoom)/2)

mob.tempvars[B_W] = buffer_width
mob.tempvars[B_H] = buffer_height

view = "[view_width]x[view_height]"

// world.log << view
// world.log << buffer_width
// world.log << buffer_height


if(zoom!=view_zoom)
winset(src,"map1","zoom=[view_zoom]")

proc
updateMapSize()
set waitfor = 0
var/v = winget(src,"map1","id;size.x;size.y;zoom")
var/list/params = params2list(v)
onMapResize(params["id"],1,text2num(params["size.x"]),text2num(params["size.y"]),params["zoom"])


//code that adds the HUD objects to the screen
Show(ID, X, Y, TIME)

if(!(ID in hud))
world.log << "could not show hud"
return FALSE

vis_contents |= hud[ID]

for(var/OBJECT in hud[ID])
animate(OBJECT, pixel_x=X,pixel_y=Y, time = TIME)

Problem description: This is currently what I'm using to resize my map and position my huds on the screen. My problem is with repositioning the HUD objects once the map resizes, I think I'm supposed to do it with buffer_width and buffer_height in mind but I'm not exactly sure how. Any help would be appreciated. :(

Also, let me know if what I've provided isn't descriptive enough. First time posting.
Well with a quick glance. It looks like you are doing most things right..

I don't think you have properly couvade your issue though. As it seems like you DO have the resizing down. So I will assume the issue is the hud objects solely.

Setting the screen_loc of the hud object to the bottom left corner will have it positioned correctly where then you can assume that x = screen_x /2 - hud_width / 2, should center it.
Well, what i'm looking to avoid is situations where if the window is resized to funky dimensions the objects don't get cut off like below.

https://i.imgur.com/3hIf9EA.png

mob/var/tmp/screen/myscreen

screen/
parent_type = /obj
appearance_flags = PLANE_MASTER | PIXEL_SCALE | NO_CLIENT_COLOR
screen_loc = "1,1"

var/list/hud

New(client/c)
hud = new
c.screen += src


This is the screen obj i place at 1,1 and then add the hud objects to, which i then move around using the show() proc in the original post.
Sorry if I'm not conveying my issue well enough. ;=;
If your map isn't letterboxed and pixels are being cut off at certain sizes, then you can use screen_loc values of LEFT, TOP, RIGHT, and BOTTOM (and + or -, as well as percentages) to position things based on where the pixels would be cutoff.
Just messed around with using screen_loc values like that and it's definitely easier to position objects on the screen, imo. Saves me from worrying about keeping the objects in the right position after the map resizes.

Are there use cases where you'd rather move an object on the screen with pixel x & y over screen_loc?
In response to Depressedmistake
Draggable/repositionable HUD objects.