Mouse Aiming
- Static Camera
- Player-Centric Camera
Relevant Vector Math
Mouse Movement Vector
Changelog
Original:
Easy! You just have to...
// add the mouse-tracking events to /atom...
atom
// when the mouse enters an atom for the first time
// (MouseMove purposely is not called)
MouseEntered(location, control, params)
..()
usr.client.MousePosition(params)
// when the mouse moves around within an atom
// (and no mouse buttons are down)
MouseMove(location, control, params)
..()
usr.client.MousePosition(params)
// when the mouse moves around and at least
// one mouse button is down
MouseDrag(over_object, src_location, over_location, src_control, over_control, params)
..()
usr.client.MousePosition(params)
// to call an extremely simple proc
// to parse the screen-loc from the given params...
client
// this is the screen-loc passed by the mouse events.
var mouse_screen_loc
// (1, 1) is the bottom-left pixel in the screen.
var mouse_x
var mouse_y
proc/MousePosition(params)
var screen_loc = params2list(params)["screen-loc"]
if(!screen_loc) return
// Sometimes we get screen-loc in the form of
// "map:x:px,y:py"
// but we want to just be using the "x:px,y:py" part.
var position = 1
var colons = 0
var first_colon
for(var/_ in 1 to 3)
var colon = findtext(screen_loc, ":", position)
if(colon)
if(!first_colon) first_colon = colon
position = colon + 1
colons ++
else break
if(colons > 2) screen_loc = copytext(screen_loc, first_colon + 1)
// We split "x:px,y:py" into "x:px" and "y:py".
var comma = findtext(screen_loc, ",")
var screen_x = copytext(screen_loc, 1, comma)
var screen_y = copytext(screen_loc, comma + 1)
// Split "x:px" into x and px.
var colon_x = findtext(screen_x, ":")
var x = text2num(copytext(screen_x, 1, colon_x))
var px = text2num(copytext(screen_x, colon_x + 1))
// Split "y:py" into y and py.
var colon_y = findtext(screen_y, ":")
var y = text2num(copytext(screen_y, 1, colon_y))
var py = text2num(copytext(screen_y, colon_y + 1))
// Store them in the client's variables.
// tile_width() and tile_height() are just procs
// that return whatever world.icon_size says,
// because unfortunately it can be a number or text.
mouse_screen_loc = screen_loc
mouse_x = (x - 1) * tile_width() + px
mouse_y = (y - 1) * tile_height() + py
// Call an event that you can easily override.
MouseUpdate()
proc/MouseUpdate()
// But wait, there's more!
// Your mouse won't be tracked on the "void" areas on the map,
// found in the darkness behind opaque objects and past the map edges
// because there are no atoms there.
// To fix this, we add a mouse-catcher to the background.
New()
. = ..()
screen += new /atom/movable {
name = ""
layer = -1.#INF
mouse_opacity = 2
screen_loc = "SOUTHWEST to NORTHEAST"
}
And that's all you need to do! Simple, right?
The new MouseMove event isn't a disappointment, right?
It looks a lot better than the code in Forum_account's Mouse Position library, right?