nb token
This commit is contained in:
parent
6ab2bc8106
commit
071b2c0003
|
@ -1671,14 +1671,14 @@ static int is_delim(int c)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int word_img(const char *p, char **eptr)
|
||||
static int process_word_token(const char *p, char **eptr, char ch)
|
||||
{
|
||||
int len = 0;
|
||||
if (eptr)
|
||||
*eptr = (char*)p;
|
||||
if (!p)
|
||||
return 0;
|
||||
if (p[0] != '<' || p[1] != 'g' || p[2] != ':')
|
||||
if (p[0] != '<' || p[1] != ch || p[2] != ':')
|
||||
return 0;
|
||||
p += 3;
|
||||
len = strcspn(p, ">");
|
||||
|
@ -1689,6 +1689,16 @@ static int word_img(const char *p, char **eptr)
|
|||
return len + 1;
|
||||
}
|
||||
|
||||
static int word_img(const char *p, char **eptr)
|
||||
{
|
||||
return process_word_token(p, eptr, 'g');
|
||||
}
|
||||
|
||||
static int word_token(const char *p, char **eptr)
|
||||
{
|
||||
return process_word_token(p, eptr, 'w');
|
||||
}
|
||||
|
||||
|
||||
static const char *lookup_token_or_sp(const char *ptr)
|
||||
{
|
||||
|
@ -1709,6 +1719,10 @@ static const char *lookup_token_or_sp(const char *ptr)
|
|||
if (p == ptr) /* first one */
|
||||
p = eptr;
|
||||
return p;
|
||||
} else if (word_token(p, &eptr)) {
|
||||
if (p == ptr) /* first one */
|
||||
p = eptr;
|
||||
return p;
|
||||
}
|
||||
p ++;
|
||||
continue;
|
||||
|
@ -1745,6 +1759,9 @@ static char *get_word(const char *ptr, char **eptr, int *sp)
|
|||
o[sz] = 0;
|
||||
|
||||
sz = word_img(ptr, eptr);
|
||||
if (sz)
|
||||
return o;
|
||||
sz = word_token(ptr, eptr);
|
||||
if (sz)
|
||||
return o;
|
||||
*eptr = (char*)ep;
|
||||
|
@ -2215,7 +2232,6 @@ void txt_layout_update_links(layout_t layout, int x, int y, clear_fn clear)
|
|||
// gfx_noclip();
|
||||
}
|
||||
|
||||
|
||||
img_t get_img(struct layout *layout, char *p)
|
||||
{
|
||||
int len;
|
||||
|
@ -2251,6 +2267,19 @@ out:
|
|||
return img;
|
||||
}
|
||||
|
||||
char *get_word_token(char *p)
|
||||
{
|
||||
int len;
|
||||
char *r;
|
||||
len = word_token(p, NULL);
|
||||
if (!len)
|
||||
return p;
|
||||
p[len - 1 + 3] = 0;
|
||||
r = strdup((p + 3));
|
||||
free(p);
|
||||
return r;
|
||||
}
|
||||
|
||||
char *process_token(char *ptr, struct layout *layout, struct line *line, struct xref **xref, int *sp)
|
||||
{
|
||||
|
||||
|
@ -2337,7 +2366,7 @@ int get_unbrakable_len(struct layout *layout, const char *ptr)
|
|||
if (!p)
|
||||
return w;
|
||||
|
||||
if (sp || !*p || word_img(p, NULL)) {
|
||||
if (sp || !*p || word_img(p, NULL) || word_token(p, NULL)) {
|
||||
free(p);
|
||||
return w;
|
||||
}
|
||||
|
@ -2435,6 +2464,7 @@ void _txt_layout_add(layout_t lay, char *txt)
|
|||
w = gfx_img_w(img);
|
||||
h = gfx_img_h(img);
|
||||
} else {
|
||||
p = get_word_token(p);
|
||||
TTF_SizeUTF8((TTF_Font *)(layout->fn), p, &w, &h);
|
||||
if (!*p && line->h)
|
||||
h = 0;
|
||||
|
|
|
@ -1,61 +1,67 @@
|
|||
game.hinting = true;
|
||||
game.showlast = true;
|
||||
|
||||
iface.img = function(self, str)
|
||||
return "<g:"..str..">";
|
||||
end;
|
||||
|
||||
iface.xref = function(self, str, obj)
|
||||
local o = ref(obj);
|
||||
local cmd=''
|
||||
local o = ref(obj);
|
||||
local cmd=''
|
||||
|
||||
if not isObject(o) or isStatus(o) or not o.id then
|
||||
return str;
|
||||
end
|
||||
if not isObject(o) or isStatus(o) or not o.id then
|
||||
return str;
|
||||
end
|
||||
|
||||
if ref(ways():srch(obj)) then
|
||||
cmd = 'go ';
|
||||
elseif isMenu(o) then
|
||||
cmd = 'act ';
|
||||
elseif isSceneUse(o) then
|
||||
cmd = 'use ';
|
||||
end
|
||||
if ref(ways():srch(obj)) then
|
||||
cmd = 'go ';
|
||||
elseif isMenu(o) then
|
||||
cmd = 'act ';
|
||||
elseif isSceneUse(o) then
|
||||
cmd = 'use ';
|
||||
end
|
||||
|
||||
return cat('<a:'..cmd..'0'..tostring(o.id)..'>',str,'</a>');
|
||||
return cat('<a:'..cmd..'0'..tostring(o.id)..'>',str,'</a>');
|
||||
end;
|
||||
|
||||
iface.title = function(self, str)
|
||||
return nil
|
||||
return nil
|
||||
end;
|
||||
|
||||
iface.img = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return "<g:"..str..">";
|
||||
end;
|
||||
|
||||
iface.nb = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return "<w:"..str..">";
|
||||
end;
|
||||
|
||||
iface.under = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return cat('<u>',str,'</u>');
|
||||
if str == nil then return nil; end;
|
||||
return cat('<u>',str,'</u>');
|
||||
end;
|
||||
|
||||
iface.em = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return cat('<i>',str,'</i>');
|
||||
if str == nil then return nil; end;
|
||||
return cat('<i>',str,'</i>');
|
||||
end;
|
||||
|
||||
iface.right = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return cat('<r>',str,'</r>');
|
||||
if str == nil then return nil; end;
|
||||
return cat('<r>',str,'</r>');
|
||||
end;
|
||||
|
||||
iface.left = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return cat('<l>',str,'</l>');
|
||||
if str == nil then return nil; end;
|
||||
return cat('<l>',str,'</l>');
|
||||
end;
|
||||
|
||||
iface.center = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return cat('<c>',str,'</c>');
|
||||
if str == nil then return nil; end;
|
||||
return cat('<c>',str,'</c>');
|
||||
end;
|
||||
|
||||
iface.bold = function(self, str)
|
||||
if str == nil then return nil; end;
|
||||
return cat('<b>',str,'</b>');
|
||||
if str == nil then return nil; end;
|
||||
return cat('<b>',str,'</b>');
|
||||
end;
|
||||
|
||||
iface.inv = function(self, str)
|
||||
|
|
|
@ -131,6 +131,11 @@ function cat(v,...)
|
|||
return res;
|
||||
end
|
||||
|
||||
function txtnb(v)
|
||||
if type(v) ~= 'string' then return nil; end
|
||||
return iface:nb(v);
|
||||
end
|
||||
|
||||
function img(v)
|
||||
if type(v) ~= 'string' then return nil; end;
|
||||
return iface:img(v);
|
||||
|
@ -1529,6 +1534,9 @@ iface = {
|
|||
img = function(self, str)
|
||||
return '';
|
||||
end,
|
||||
nb = function(self, str)
|
||||
return str;
|
||||
end,
|
||||
em = function(self, str)
|
||||
return str;
|
||||
end,
|
||||
|
|
Reference in a new issue