obj/scrobj
MouseDrag()//needs to be created so that you can drag objects on the screen where you want them.
icon='Test.dmi'
var//purpose of this is to simplify repositioning and movement of screen objects in game.
scr_x=1
scr_y=1
scr_xx=0
scr_yy=0
scr_dir1="SOUTH"
scr_dir2="WEST"
scr_type=2//type 2 is the default.
can_move=1//if the object can be repositioned, mostly for dragging purposes.
proc
SetScr()//used to set and update the screen position based on screen obj type.
switch(scr_type)
if(1)
screen_loc="[scr_dir1]+[scr_x]:[scr_xx],[scr_dir2]+[scr_y]:[scr_yy]"
if(2)
screen_loc="[scr_x]:[scr_xx],[scr_y]:[scr_yy]"
if(3)
screen_loc="1:[scr_xx],1:[scr_yy]"//bottom left. uses the scr_xx to place.
GetAbs()
var/xx=round((scr_x*32)+scr_xx)//,1:[scr_yy]"//bottom left. uses the scr_xx to place.
var/yy=round((scr_y*32)+scr_yy)
world<<"[xx] by [yy]"
AbsX()
if(scr_type==3)scr_x=0
return round((scr_x*32)+scr_xx)
AbsY()
return round((scr_y*32)+scr_yy)
Shift(var/xx_amt=0,var/yy_amt=0,var/x_amt=0,var/y_amt=0)
switch(scr_type)
if(1)
scr_x+=x_amt
scr_y+=y_amt
scr_xx+=xx_amt
scr_yy+=yy_amt
screen_loc="[scr_dir1]+[scr_x]:[scr_xx],[scr_dir2]+[scr_y]:[scr_yy]"
if(2)
scr_x+=x_amt
scr_y+=y_amt
scr_xx+=xx_amt
scr_yy+=yy_amt
screen_loc="[scr_x]:[scr_xx],[scr_y]:[scr_yy]"
if(3)
scr_xx+=xx_amt
scr_yy+=yy_amt
screen_loc="0:[scr_xx],0:[scr_yy]"
ConvertPerc(wh)
if(istext(wh))
.//forgot what i was going to do here.
else
var/xx=(wh+1)*32
var/yy=(wh+1)*32
var/x_perc=AbsX()/xx
world<<"[x_perc]%"
mob
verb
AddScr()
var/obj/scrobj/j=new
j.SetScr()
client.screen+=j
ShiftLeft()
for(var/obj/scrobj/x in client.screen)
x.Shift(-32,0,0,0)
usr<<"[x.GetAbs()]"
ShiftRight()
for(var/obj/scrobj/x in client.screen)
x.Shift(32,0,0,0)
usr<<"[x.GetAbs()]"
ShiftUp()
for(var/obj/scrobj/x in client.screen)
x.Shift(0,32,0,0)
usr<<"[x.GetAbs()]"
ShiftDown()
for(var/obj/scrobj/x in client.screen)
x.Shift(0,-32,0,0)
usr<<"[x.GetAbs()]"
SeePercentX()
for(var/obj/scrobj/x in client.screen)
x.ConvertPerc(client.view)
Problem description:
End goal of this will be to re-position screen objects on re-size of the window by way of calculating the % position of the object on the screen.
F Ex: I have a 10x10 view, and my health hud resides at 1,8, then the x% is 10% while the y% is 80%.
This set of code will grab the new maximized window size, convert it into %age, then "reset" the screen objects to the percent they should be at.
//F Ex 2:
860 = 8.6 pixels =1%, 86 px = 10%
And if needed apply scaling (but that's pretty simple to implement thus saving it for last)
This method is for games where a uniform view among all players isn't necessary.But it could also be used for stretch to sh*t--err fit, games as well.
If anyone would like to modify the MouseDrag so that you can drag objs around the screen without a ton of trouble(or at all), I say go for it.
Edit:
Also, I'm not looking for alternative links on how to solve this problem, I've already seen most of them, they just seem needlessly complex--I'm simply interested in examples on how this can be used to mousedrag screen objects.
If you like or want to use the above code, feel free as well.