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

View file

@ -1,6 +1,12 @@
game.hinting = 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, ...)
local o = ref(obj);
@ -96,24 +102,30 @@ iface.middle = function(self, str)
end;
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
end;
iface.ways = 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, stead.delim, game.gui.ways_delim);
str = stead.string.gsub(str, '<&delim;>', stead.delim);
return '<c>'..str..'</c>';
end
return str
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()
local s
if stead.api_version >= "1.2.0" then