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/gui.lua

337 lines
6.9 KiB
Lua
Raw Normal View History

2009-09-20 13:21:11 +03:00
game.hinting = true;
game.showlast = true;
2010-09-21 16:55:03 +03:00
game.gui = {
fading = 4;
ways_delim = ' | ';
2010-11-04 10:20:40 +02:00
inv_delim = '\n';
2010-09-21 16:55:03 +03:00
hinv_delim = ' | ';
}
2009-09-20 13:21:11 +03:00
2010-06-24 12:33:59 +03:00
iface.xref = function(self, str, obj, ...)
2011-07-27 16:11:29 +03:00
local o = stead.ref(obj);
2010-01-25 16:53:33 +02:00
local cmd=''
2009-10-06 21:22:52 +03:00
2010-09-16 12:09:02 +03:00
if not isObject(o) or isStatus(o) or (not o.id and not isXaction(o)) then
2010-01-25 16:53:33 +02:00
return str;
end
2009-10-06 21:22:52 +03:00
2011-07-27 16:11:29 +03:00
if stead.ref(ways():srch(obj)) then
2010-01-25 16:53:33 +02:00
cmd = 'go ';
elseif isMenu(o) then
cmd = 'act ';
elseif isSceneUse(o) then
2010-09-16 12:09:02 +03:00
cmd = 'use ';
2010-10-02 15:52:03 +03:00
elseif isXaction(o) and not o.id then
2010-09-16 12:09:02 +03:00
cmd = 'act ';
2010-01-25 16:53:33 +02:00
end
2010-06-24 12:33:59 +03:00
local a = ''
local i
2011-02-23 12:11:27 +02:00
local varg = {...}
for i = 1, stead.table.maxn(varg) do
a = a..','..varg[i]
2010-06-24 12:33:59 +03:00
end
2010-09-16 12:09:02 +03:00
if isXaction(o) and not o.id then
2011-07-27 16:11:29 +03:00
return stead.cat('<a:'..cmd..stead.deref(obj)..a..'>',str,'</a>');
2010-09-16 12:09:02 +03:00
end
2010-06-24 12:33:59 +03:00
return stead.cat('<a:'..cmd..'0'..tostring(o.id)..a..'>',str,'</a>');
2009-09-20 13:21:11 +03:00
end;
2010-01-26 11:25:01 +02:00
iface.enum = function(self, n, str)
if str == nil or n == nil then return nil; end;
return n..self:nb(' - ')..str;
end
2009-09-20 13:21:11 +03:00
iface.title = function(self, str)
2010-01-25 16:53:33 +02:00
return nil
end;
iface.img = function(self, str)
if str == nil then return nil; end;
return "<g:"..str..">";
end;
2010-10-30 15:54:41 +03:00
iface.imgl = function(self, str)
if str == nil then return nil; end;
2011-03-07 15:39:06 +02:00
return "<g:"..str.."\\|left>";
2010-10-30 15:54:41 +03:00
end;
iface.imgr = function(self, str)
2010-01-25 16:53:33 +02:00
if str == nil then return nil; end;
2011-03-07 15:39:06 +02:00
return "<g:"..str.."\\|right>";
2010-10-30 15:54:41 +03:00
end;
iface.nb = function(self, str)
if type(str) ~= 'string' then return nil end
2011-07-26 20:06:01 +03:00
return "<w:"..str:gsub("\\", "\\\\\\"):gsub(">","\\>"):gsub("%^","\\%^")..">";
2009-09-20 13:21:11 +03:00
end;
iface.under = function(self, str)
2010-01-25 16:53:33 +02:00
if str == nil then return nil; end;
2010-06-16 22:31:15 +03:00
return stead.cat('<u>',str,'</u>');
2009-09-20 13:21:11 +03:00
end;
iface.em = function(self, str)
2010-01-25 16:53:33 +02:00
if str == nil then return nil; end;
2010-06-16 22:31:15 +03:00
return stead.cat('<i>',str,'</i>');
2009-09-20 13:21:11 +03:00
end;
2010-10-08 11:32:41 +03:00
iface.st = function(self, str)
if str == nil then return nil; end;
return stead.cat('<s>',str,'</s>');
end;
2009-09-20 13:21:11 +03:00
iface.right = function(self, str)
2010-01-25 16:53:33 +02:00
if str == nil then return nil; end;
2010-06-16 22:31:15 +03:00
return stead.cat('<r>',str,'</r>');
2009-09-20 13:21:11 +03:00
end;
iface.left = function(self, str)
2010-01-25 16:53:33 +02:00
if str == nil then return nil; end;
2010-06-16 22:31:15 +03:00
return stead.cat('<l>',str,'</l>');
2009-09-20 13:21:11 +03:00
end;
iface.center = function(self, str)
2010-01-25 16:53:33 +02:00
if str == nil then return nil; end;
2010-06-16 22:31:15 +03:00
return stead.cat('<c>',str,'</c>');
2009-09-20 13:21:11 +03:00
end;
2010-10-31 17:06:54 +02:00
iface.just = function(self, str)
if str == nil then return nil; end;
return stead.cat('<j>',str,'</j>');
end;
2010-11-08 10:20:37 +02:00
iface.tab = function(self, str, al)
2010-11-01 15:52:42 +02:00
if tonumber(str) then
str = tostring(str)
end
2010-11-08 10:20:37 +02:00
if type(str) ~= 'string' then
return nil;
end
if al == 'right' then
str = str .. ",right"
elseif al == 'center' then
str = str .. ",center"
end
2010-11-01 15:52:42 +02:00
return '<x:'..str..'>'
end;
2009-09-20 13:21:11 +03:00
iface.bold = function(self, str)
2010-01-25 16:53:33 +02:00
if str == nil then return nil; end;
2010-06-16 22:31:15 +03:00
return stead.cat('<b>',str,'</b>');
2009-09-20 13:21:11 +03:00
end;
2010-09-02 11:03:06 +03:00
iface.top = function(self, str)
if str == nil then return nil; end;
return stead.cat('<t>',str,'</t>');
end;
iface.bottom = function(self, str)
if str == nil then return nil; end;
return stead.cat('<d>',str,'</d>');
end;
iface.middle = function(self, str)
if str == nil then return nil; end;
return stead.cat('<m>',str,'</m>');
end;
2009-09-20 13:21:11 +03:00
iface.inv = function(self, str)
return str
end;
iface.ways = function(self, str)
2010-09-22 13:15:23 +03:00
return str
end;
function get_inv(horiz)
2010-11-04 08:32:43 +02:00
local str = iface:cmd("inv");
2009-09-20 13:21:11 +03:00
if str then
2010-09-22 13:15:23 +03:00
str = stead.string.gsub(str, '\n$','');
if not horiz then
2010-11-04 10:20:40 +02:00
str = stead.string.gsub(str, '\\?['.. stead.delim ..']',
{ [stead.delim] = game.gui.inv_delim, ['\\'..stead.delim] = stead.delim });
2010-09-22 13:15:23 +03:00
else
2010-11-04 10:20:40 +02:00
str = stead.string.gsub(str, '\\?['.. stead.delim ..']',
{ [stead.delim] = game.gui.hinv_delim, ['\\'..stead.delim] = stead.delim });
2010-09-22 13:15:23 +03:00
end
2009-09-20 13:21:11 +03:00
end
return str
2010-09-22 13:15:23 +03:00
end
instead.get_inv = get_inv;
2009-09-20 13:21:11 +03:00
2010-09-22 13:15:23 +03:00
function get_ways()
2010-11-04 08:32:43 +02:00
local str = iface:cmd("way");
2010-10-30 15:54:41 +03:00
if str and str ~= '' then
2010-09-22 13:15:23 +03:00
str = stead.string.gsub(str, '\n$','');
2010-11-04 10:20:40 +02:00
str = stead.string.gsub(str, '\\?['..stead.delim ..']',
{ [stead.delim] = game.gui.ways_delim, [ '\\'..stead.delim ] = stead.delim });
2010-09-22 13:15:23 +03:00
return iface:center(str);
2010-09-21 16:55:03 +03:00
end
return str
end
2010-09-22 13:15:23 +03:00
instead.get_ways = get_ways;
2010-09-21 16:55:03 +03:00
2010-02-16 20:05:36 +02:00
function get_title()
2010-08-31 19:48:22 +03:00
local s
if stead.api_version >= "1.2.0" then
2011-07-27 13:21:20 +03:00
s = stead.call(here(), 'disp');
2010-08-31 19:48:22 +03:00
end
if type(s) ~= 'string' then
2011-07-27 13:21:20 +03:00
s = stead.call(here(), 'nam');
2010-08-31 19:48:22 +03:00
end
2010-10-30 15:54:41 +03:00
if type(s) == 'string' and s ~= '' then
2010-11-04 14:46:25 +02:00
stead.state = false
s = "<c><b>"..stead.fmt(s).."</b></c>";
2010-11-04 19:45:46 +02:00
s = stead.string.gsub(s, '\\'..stead.delim, stead.delim);
2010-07-08 20:54:29 +03:00
end
return s
2010-02-16 20:05:36 +02:00
end
2010-09-22 13:15:23 +03:00
instead.get_title = get_title;
instead.get_picture = get_picture;
instead.get_music = get_music;
instead.get_sound = get_sound;
instead.set_sound = set_sound;
instead.get_autosave = get_autosave;
instead.get_music_loop = get_music_loop;
instead.dec_music_loop = dec_music_loop;
instead.isEnableSave = isEnableSave;
instead.isEnableAutosave = isEnableAutosave;
instead.autosave = autosave;
2009-09-20 13:21:11 +03:00
-- here is gui staff only
function stat(v)
v.status_type = true
return obj(v);
end
function isStatus(v)
if type(v) ~= 'table' then
return false
end
if v.status_type then
return true
end
return false
end
function menu_save(self, name, h, need)
local dsc;
if need then
2010-07-03 15:38:27 +03:00
print ("Warning: menu "..name.." can not be saved!");
return
2009-09-20 13:21:11 +03:00
end
stead.savemembers(h, self, name, need);
2009-09-20 13:21:11 +03:00
end
2009-09-25 11:21:58 +03:00
MENU_TAG_ID = 10000
2009-09-20 13:21:11 +03:00
function menu(v)
v.menu_type = true
2009-09-20 13:37:00 +03:00
if v.inv == nil then
v.inv = function(s)
2010-06-05 18:02:10 +03:00
local r,v
2011-07-27 13:21:20 +03:00
r,v = stead.call(s, 'menu');
2010-06-05 18:02:10 +03:00
if v == nil then v = true end
2009-09-25 12:00:15 +03:00
if r == nil then
obj_tag(me(), MENU_TAG_ID); -- retag menu field
end
2010-06-05 18:02:10 +03:00
return r, v
2009-09-20 13:37:00 +03:00
end
end
2009-10-02 22:04:34 +03:00
if v.act == nil then
v.act = function(s)
2010-06-05 18:02:10 +03:00
local r,v
2011-07-27 13:21:20 +03:00
r,v = stead.call(s, 'menu');
2010-06-05 18:02:10 +03:00
if v == nil then v = true end
2009-10-02 22:04:34 +03:00
if r == nil then
obj_tag(me(), MENU_TAG_ID); -- retag menu field
end
2010-06-05 18:02:10 +03:00
return r, v
2009-10-02 22:04:34 +03:00
end
end
2009-09-20 13:21:11 +03:00
if v.save == nil then
v.save = menu_save;
end
return obj(v);
end
function isMenu(v)
if type(v) ~= 'table' then
return false
end
2011-07-27 21:43:21 +03:00
if v.menu_type then
2009-09-20 13:21:11 +03:00
return true
end
return false
end
2009-10-15 10:06:45 +03:00
2010-06-16 22:31:15 +03:00
fmt = function(...)
2010-06-16 21:29:11 +03:00
local i, res
2011-02-23 12:11:27 +02:00
local a={...}
for i=1,stead.table.maxn(a) do
if type(a[i]) == 'string' then
local s = stead.string.gsub(a[i],'\t', ' '):gsub('[\n]+', ' ');
2010-11-04 14:46:25 +02:00
s = stead.string.gsub(s, '\\?[\\^]', { ['^'] = '\n', ['\\^'] = '^',
['\\\\'] = '\\' });
2010-06-21 22:33:38 +03:00
res = stead.par('', res, s);
2010-06-16 21:29:11 +03:00
end
end
return res
end
2010-06-16 22:31:15 +03:00
stead.fmt = fmt
2010-07-06 13:15:27 +03:00
2010-07-10 09:39:29 +03:00
game.fading = function(s)
local rc = false
2011-07-27 13:21:20 +03:00
local p = stead.call(here(), 'pic');
2010-07-10 09:39:29 +03:00
if stead.cmd == 'load' then
2010-07-11 13:20:04 +03:00
game.lastpic = p;
2010-07-10 09:39:29 +03:00
return true
end
if not stead.state then --only for states!!!
return false
end
if game._time == 1 then -- first cmd
2010-08-28 18:48:17 +03:00
game.lastpic = p;
2010-07-10 09:39:29 +03:00
return true
end
if PLAYER_MOVED or game.lastpic ~= p then
rc = true
end
game.lastpic = p
return rc
end
function isFading() --to check fading from sdl gui
local r,g,v
local h = here()
if not isRoom(h) then
return false
end
2011-07-27 13:21:20 +03:00
r,v = stead.call_value(h, 'fading');
if r then
2010-11-03 09:50:33 +02:00
if tonumber(r) and v == nil then
return true, tonumber(r)
end
2011-07-27 08:33:42 +03:00
return r, v
2010-07-10 09:39:29 +03:00
end
2011-07-27 13:21:20 +03:00
g,v = stead.call_value(game, 'fading', h);
2010-11-03 09:50:33 +02:00
if tonumber(g) and v == nil then
2011-07-27 08:33:42 +03:00
return true, tonumber(g)
2010-11-03 09:50:33 +02:00
end
2011-07-27 08:33:42 +03:00
return g, v
2010-07-10 09:39:29 +03:00
end
2010-09-22 13:15:23 +03:00
instead.get_fading = function()
2010-07-10 09:39:29 +03:00
local r, v
r, v = isFading()
2011-07-27 08:33:42 +03:00
if v == nil and r then v = game.gui.fading end
2010-07-10 09:39:29 +03:00
return r,v
end
2010-07-06 13:15:27 +03:00
-- vim:ts=4