From ef4e59528e6b8ae57582b0b8e5dd36993f4c2f59 Mon Sep 17 00:00:00 2001
From: "p.kosyh"
Date: Tue, 21 Sep 2010 13:55:03 +0000
Subject: [PATCH] delimiters
---
src/sdl-instead/game.c | 51 ++++++++++++++----------------------------
stead/gui.lua | 26 +++++++++++++++------
2 files changed, 36 insertions(+), 41 deletions(-)
diff --git a/src/sdl-instead/game.c b/src/sdl-instead/game.c
index a41a11b..fc97e1f 100644
--- a/src/sdl-instead/game.c
+++ b/src/sdl-instead/game.c
@@ -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);
diff --git a/stead/gui.lua b/stead/gui.lua
index ca2d97b..568b222 100644
--- a/stead/gui.lua
+++ b/stead/gui.lua
@@ -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 ''..str..'';
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