#define INTERACT_NONE 0
#define INTERACT_CLICK 1
#define INTERACT_DBLCLICK 2
#define INTERACT_MOUSEHOLD 4
#define INTERACT_MOUSEHOVER 8
#define INTERACT_MOUSEDRAG 16
#define INTERACT_MOUSEDROP 32
#define INTERACT_MOUSEMOVE 64
#define INTERACT_MOUSEWHEEL 128
#define INTERACT_KEYBOARD 256
#define INTERACT_ALL 511
#define KEYBINDS 4
#define TAP_THRESHOLD 2.5
#define bind2dir(b) __dirs[b]
#define bind2opp(b) __invdirs[b]
#define dir2opp(d) __oppdirs[d]
var/list/__dirs = list(NORTH,SOUTH,EAST,WEST)
var/list/__invdirs = list(SOUTH,NORTH,WEST,EAST)
var/list/__oppdirs = list(SOUTH,NORTH,NORTH|SOUTH,WEST,SOUTHWEST,NORTHWEST,NORTHWEST|SOUTH,EAST,SOUTHEAST,NORTHEAST,NORTHEAST|SOUTH,EAST|WEST,SOUTHEAST|WEST,NORTHEAST|WEST,NORTHEAST|SOUTHWEST)
client
var
list/key_binds = list("W"=1,"S"=2,"D"=3,"A"=4)
list/key_state[KEYBINDS]
list/key_taps[KEYBINDS]
list/key_time[KEYBINDS]
last_key = 0
verb
keyPress(key as text)
set instant = 1
set hidden = 1
var/bind = key_binds[key]
if(bind)
var/olk = last_key
last_key = bind
if(++key_state[bind]==1)
var/otime = key_time[bind]
var/ntime = ACCURATE_TIME
var/tdelta = ntime-otime
var/taps = key_taps[bind]
if(olk==bind&&tdelta<=TAP_THRESHOLD)
taps++
else
taps = 1
key_time[bind] = ntime
key_taps[bind] = taps
mob.onKeyPress(bind,taps,ntime,tdelta)
keyRelease(key as text)
set instant = 1
set hidden = 1
var/bind = key_binds[key]
if(bind)
var/ks = --key_state[bind]
var/olk = last_key
last_key = bind
if(!ks)
var/otime = key_time[bind]
var/ntime = ACCURATE_TIME
var/tdelta = ntime-otime
var/taps = key_taps[bind]
if(olk!=bind||tdelta>TAP_THRESHOLD)
key_taps[bind] = 1
key_time[bind] = ntime
mob.onKeyRelease(bind,taps,ntime,tdelta)
else if(ks<0)
key_state[bind] = 0
Click(hudobj/object,location,control,params)
mob.onClick(object,location,control,params)
DblClick(hudobj/object,location,control,params)
mob.onDblClick(object,location,control,params)
MouseDown(hudobj/object,location,control,params)
var/list/l = params2list(params)
cursor_pos = l["screen-loc"]
mouse_state |= (l["left"]=="1" ? MOUSE_LEFT : 0) + (l["right"]=="1" ? MOUSE_RIGHT : 0) + (l["middle"]=="1" ? MOUSE_MIDDLE : 0)
mob.onMouseDown(object,location,control,params)
MouseUp(hudobj/object,location,control,params)
var/list/l = params2list(params)
cursor_pos = l["screen-loc"]
mouse_state &= ~((l["left"]=="1" ? MOUSE_LEFT : 0) + (l["right"]=="1" ? MOUSE_RIGHT : 0) + (l["middle"]=="1" ? MOUSE_MIDDLE : 0))
mob.onMouseUp(object,location,control,params)
MouseEntered(hudobj/object,location,control,params)
mob.onMouseEntered(object,location,control,params)
MouseExited(hudobj/object,location,control,params)
mob.onMouseExited(object,location,control,params)
MouseMove(hudobj/object,location,control,params)
var/list/l = params2list(params)
cursor_pos = l["screen-loc"]
mob.onMouseMove(object,location,control,params)
MouseDrag(hudobj/object,atom/over_object,src_location,over_location,src_control,over_control,params)
var/list/l = params2list(params)
cursor_pos = l["screen-loc"]
mob.onMouseDrag(object,over_object,src_location,over_location,src_control,over_control,params)
MouseDrop(hudobj/object,atom/over_object,src_location,over_location,src_control,over_control,params)
var/list/l = params2list(params)
cursor_pos = l["screen-loc"]
mob.onMouseDrop(object,over_object,src_location,over_location,src_control,over_control,params)
MouseWheel(hudobj/object,delta_x,delta_y,location,control,params)
mob.onMouseWheel(object,delta_x,delta_y,location,control,params)
North()
South()
East()
West()
Southeast()
Northeast()
Southwest()
Northwest()
Center()
mob
var/tmp
interface/control_focus
move_keys
move_dir
proc
onKeyPress(bind,taps,time,delta)
if(!control_focus||!(control_focus.control_flags&INTERACT_KEYBOARD)||!control_focus.keyPress(bind,taps,time,delta))
switch(bind)
if(1 to 4)
var/d = bind2dir(bind)
var/opp = bind2opp(bind)
move_keys |= d
move_dir |= d
if(move_keys&opp)
move_dir &= ~opp
onKeyRelease(bind,taps,time,delta)
if(!control_focus||!(control_focus.control_flags&INTERACT_KEYBOARD)||!control_focus.keyRelease(bind,taps,time,delta))
switch(bind)
if(1 to 4)
var/d = bind2dir(bind)
var/opp = bind2opp(bind)
move_keys &= ~d
move_dir &= ~d
if(move_keys&opp)
move_dir |= opp
MoveLoop()
set waitfor = 0
while(client)
if(loc&&move_dir)
step(src,move_dir)
sleep(world.tick_lag)
setFocus(interface/nfocus)
var/interface/ofocus = control_focus
if(ofocus)
ofocus.Unfocus(nfocus)
else if(nfocus)
Unfocus(nfocus)
control_focus = nfocus
if(nfocus)
nfocus.Focus(ofocus)
else if(ofocus)
Focus(ofocus)
Focus(interface/ofocus)
var/list/ks = client.key_state
var/list/kt = client.key_time
var/mk
var/md
if(ks[1])
if(ks[2])
mk += 3
if(kt[2]>kt[1])
md += 2
else
md += 1
else
mk += 1
md += 1
else if(ks[2])
mk += 2
md += 2
if(ks[3])
if(ks[4])
mk += 12
if(kt[4]>kt[3])
md += 8
else
md += 4
else
mk += 4
md += 4
else if(ks[4])
mk += 8
md += 8
move_keys = mk
move_dir = md
Unfocus(interface/nfocus)
move_keys = 0
move_dir = 0
onClick(atom/object,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_CLICK)||!control_focus.Click(object,location,control,params))
object.Click(location,control,params)
onDblClick(atom/object,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_DBLCLICK)||!control_focus.DblClick(object,location,control,params))
object.DblClick(location,control,params)
onMouseDown(atom/object,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEHOLD)||!control_focus.MouseDown(object,location,control,params))
object.MouseDown(location,control,params)
onMouseUp(atom/object,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEHOLD)||!control_focus.MouseUp(object,location,control,params))
object.MouseUp(location,control,params)
onMouseEntered(atom/object,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEHOVER)||!control_focus.MouseEntered(object,location,control,params))
object.MouseEntered(location,control,params)
onMouseExited(atom/object,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEHOVER)||!control_focus.MouseExited(object,location,control,params))
object.MouseExited(location,control,params)
onMouseMove(atom/object,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEMOVE)||!control_focus.MouseMove(object,location,control,params))
object.MouseMove(location,control,params)
onMouseDrag(atom/object,atom/over_object,src_location,over_location,src_control,over_control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEDRAG)||!control_focus.MouseDrag(object,over_object,src_location,over_location,src_control,over_control,params))
object.MouseDrag(over_object,src_location,over_location,src_control,over_control,params)
onMouseDrop(atom/object,atom/over_object,src_location,over_location,src_control,over_control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEDROP)||!control_focus.MouseDrop(object,over_object,src_location,over_location,src_control,over_control,params))
object.MouseDrop(over_object,src_location,over_location,src_control,over_control,params)
onMouseWheel(atom/object,delta_x,delta_y,location,control,params)
if(!control_focus||!(control_focus.control_flags&INTERACT_MOUSEDRAG)||!control_focus.MouseWheel(object,delta_x,delta_y,location,control,params))
object.MouseWheel(delta_x,delta_y,location,control,params)
ID:2142090
Sep 1 2016, 10:02 pm
|
|