delimiters

This commit is contained in:
p.kosyh 2010-09-21 13:55:03 +00:00
parent 192519beef
commit ef4e59528e
2 changed files with 36 additions and 41 deletions

View file

@ -1356,41 +1356,25 @@ void game_sound_player(void)
snd_play(w, chan, loop - 1); snd_play(w, chan, loop - 1);
} }
char *horiz_inv(char *invstr) char *norm_inv(char *invstr)
{ {
char *p = invstr; char *ni;
char *ns; struct instead_args args[] = {
char *np; { .val = NULL, .type = INSTEAD_STR },
int item = 0; { .val = NULL, .type = INSTEAD_BOOL },
if (!p || !(*p)) { .val = NULL, },
};
if (!invstr || !(*invstr))
return invstr; return invstr;
args[0].val = invstr;
np = ns = malloc((strlen(p) + 2) * 3); args[1].val = (INV_MODE(game_theme.inv_mode) == INV_MODE_HORIZ)?"true":"false";
instead_function("normalize_inv", args);
if (!np) ni = instead_retval(0);
return invstr; instead_clear();
while (*p) { if (ni) {
if (*p == '\n') { free(invstr);
if (p[strspn(p, " \n\t")]) { invstr = ni;
if (item) {
*(np++) = ' ';
*(np++) = '|';
}
*(np) = ' ';
item = 0;
} else
break;
} else {
item = 1;
*np = *p;
}
p ++;
np ++;
} }
*(np++) = '\n';
*np = 0;
free(invstr);
invstr = ns;
return invstr; return invstr;
} }
@ -1613,8 +1597,7 @@ inv:
invstr = instead_cmd("inv"); instead_clear(); invstr = instead_cmd("inv"); instead_clear();
if (invstr && INV_MODE(game_theme.inv_mode) == INV_MODE_HORIZ) invstr = norm_inv(invstr);
invstr = horiz_inv(invstr);
off = txt_box_off(el_box(el_inv)); off = txt_box_off(el_box(el_inv));
txt_layout_set(txt_box_layout(el_box(el_inv)), invstr); txt_layout_set(txt_box_layout(el_box(el_inv)), invstr);

View file

@ -1,6 +1,12 @@
game.hinting = true; game.hinting = true;
game.showlast = true; game.showlast = true;
game.gui = { fading = 4; }
game.gui = {
fading = 4;
ways_delim = ' | ';
inv_delim = '\n';
hinv_delim = ' | ';
}
iface.xref = function(self, str, obj, ...) iface.xref = function(self, str, obj, ...)
local o = ref(obj); local o = ref(obj);
@ -96,24 +102,30 @@ iface.middle = function(self, str)
end; end;
iface.inv = function(self, str) iface.inv = function(self, str)
if str then
str = stead.string.gsub(str, '\\'..stead.delim, '<&delim;>');
str = stead.string.gsub(str, stead.delim, '^');
str = stead.string.gsub(str, '<&delim;>', stead.delim);
end
return str return str
end; end;
iface.ways = function(self, str) iface.ways = function(self, str)
if str then if str then
str = stead.string.gsub(str, '\\'..stead.delim, '<&delim;>'); str = stead.string.gsub(str, '\\'..stead.delim, '<&delim;>');
str = stead.string.gsub(str, stead.delim, ' | '); str = stead.string.gsub(str, stead.delim, game.gui.ways_delim);
str = stead.string.gsub(str, '<&delim;>', stead.delim); str = stead.string.gsub(str, '<&delim;>', stead.delim);
return '<c>'..str..'</c>'; return '<c>'..str..'</c>';
end end
return str return str
end; end;
function normalize_inv(str, horiz)
str = stead.string.gsub(str, '\\'..stead.delim, '<&delim;>'):gsub(stead.delim..'$', '')
if not horiz then
str = stead.string.gsub(str, stead.delim, game.gui.inv_delim);
else
str = stead.string.gsub(str, stead.delim, game.gui.hinv_delim);
end
str = stead.string.gsub(str, '<&delim;>', stead.delim);
return str
end
function get_title() function get_title()
local s local s
if stead.api_version >= "1.2.0" then if stead.api_version >= "1.2.0" then