This repository has been archived on 2019-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
adventin/stead/click.lua

95 lines
1.9 KiB
Lua
Raw Normal View History

require "theme"
2010-11-07 14:04:18 +02:00
click = {
nam = 'click';
object_type = true;
system_type = true;
bg = false;
2011-04-15 12:17:34 +03:00
press = false;
2011-04-15 17:20:25 +03:00
button = false;
2010-11-07 14:04:18 +02:00
save = function(self, name, h, need)
local s = stead.tostring(self.bg)
h:write(stead.string.format("click[%q] = %s;\n", 'bg', s))
2011-04-15 12:17:34 +03:00
s = stead.tostring(self.press)
h:write(stead.string.format("click[%q] = %s;\n", 'press', s))
2011-04-15 17:20:25 +03:00
s = stead.tostring(self.button)
h:write(stead.string.format("click[%q] = %s;\n", 'button', s))
2010-11-07 14:04:18 +02:00
end;
}
2010-07-22 13:39:48 +03:00
stead.module_init(function()
input.click = stead.hook(input.click,
function(f, s, press, mb, x, y, px, py, ...)
2010-11-07 14:04:18 +02:00
local cmd = 'click '
2011-04-15 17:20:25 +03:00
local act = false
2011-04-15 19:46:36 +03:00
if ( press or click.press ) and ( mb == 1 or click.button ) then
2011-04-15 17:20:25 +03:00
cmd = cmd..tostring(press)..','..tostring(mb);
2011-04-15 12:17:34 +03:00
if click.bg or theme.get 'scr.gfx.mode' == 'direct' then
2011-04-15 17:20:25 +03:00
act = true
cmd = cmd .. ',' .. x .. ','.. y
2010-11-07 14:04:18 +02:00
end
2011-04-15 12:17:34 +03:00
2010-11-07 14:04:18 +02:00
if px then
2011-04-15 17:20:25 +03:00
act = true
cmd = cmd .. ',' .. px .. ',' .. py
2010-11-07 14:04:18 +02:00
end
2011-04-15 12:17:34 +03:00
2011-04-15 17:20:25 +03:00
if act then
2010-11-07 14:04:18 +02:00
return cmd
end
2010-07-22 13:39:48 +03:00
end
2011-02-23 12:11:27 +02:00
return f(s, press, mb, x, y, px, py, ...)
2010-07-22 13:39:48 +03:00
end)
2010-06-16 12:41:03 +03:00
end)
2010-06-07 16:53:00 +03:00
2010-06-23 15:09:33 +03:00
game.action = stead.hook(game.action,
2011-04-15 17:20:25 +03:00
function(f, s, cmd, press, mb, x, y, px, py, ...)
2010-06-07 16:53:00 +03:00
if cmd == 'click' then
2010-07-19 09:40:58 +03:00
local r,v
2011-04-12 16:11:58 +03:00
local x2 = px
local y2 = py
2011-04-15 17:20:25 +03:00
if tonumber(mb) then
mb = tonumber(mb)
end
2011-04-12 16:11:58 +03:00
if tonumber(px) then
x2 = tonumber(px)
end
if tonumber(py) then
y2 = tonumber(py)
end
2010-06-09 13:19:11 +03:00
if here().click then
2011-04-15 12:17:34 +03:00
s = here()
end
2011-04-15 17:20:25 +03:00
2011-04-15 12:58:17 +03:00
if press == 'true' then
press = true
else
press = false
end
2011-04-15 17:20:25 +03:00
2011-04-15 12:17:34 +03:00
if s.click then
if click.press then
2011-04-15 17:20:25 +03:00
if click.button then
r,v = call(s, 'click', press, mb, tonumber(x), tonumber(y), x2, y2, ...);
else
r,v = call(s, 'click', press, tonumber(x), tonumber(y), x2, y2, ...);
end
2011-04-15 12:17:34 +03:00
else
2011-04-15 17:20:25 +03:00
if click.button then
r,v = call(s, 'click', mb, tonumber(x), tonumber(y), x2, y2, ...);
else
r,v = call(s, 'click', tonumber(x), tonumber(y), x2, y2, ...);
end
2011-04-15 12:17:34 +03:00
end
2010-06-09 13:19:11 +03:00
end
2010-07-19 09:40:58 +03:00
return r,v
2010-06-07 16:53:00 +03:00
end
2011-04-12 16:11:58 +03:00
return f(s, cmd, x, y, px, py, ...)
2010-06-07 16:53:00 +03:00
end)
2010-07-06 13:15:27 +03:00
-- vim:ts=4