summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-24 23:36:31 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-07-24 23:36:31 +0000
commit6a38874fed2ede86cac0ca906c2fa90370432280 (patch)
tree2e397ccd558d5836b12bacb31c076a56a1cb5ddf
parentaefd04b12411ec9df4189696e375ebc2fc70572b (diff)
downloadcrawl-ref-6a38874fed2ede86cac0ca906c2fa90370432280.tar.gz
crawl-ref-6a38874fed2ede86cac0ca906c2fa90370432280.zip
Merge r6653, FR 2017262: add chunk colour to eat prompt.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6676 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/clua.cc70
-rw-r--r--crawl-ref/source/dat/lua/eat.lua4
2 files changed, 65 insertions, 9 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 8ada60d847..55659a1613 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -8,6 +8,7 @@
#include "AppHdr.h"
#include <algorithm>
+#include <sstream>
#include "clua.h"
@@ -1313,18 +1314,44 @@ static int l_item_worn(lua_State *ls)
return (2);
}
+static std::string _item_name(lua_State *ls, item_def* item)
+{
+ description_level_type ndesc = DESC_PLAIN;
+ if (lua_isstring(ls, 2))
+ ndesc = description_type_by_name(lua_tostring(ls, 2));
+ else if (lua_isnumber(ls, 2))
+ ndesc = static_cast<description_level_type>(luaL_checkint(ls, 2));
+ bool terse = lua_toboolean(ls, 3);
+ return (item->name(ndesc, terse));
+}
+
static int l_item_name(lua_State *ls)
{
LUA_ITEM(item, 1);
if (item)
{
- description_level_type ndesc = DESC_PLAIN;
- if (lua_isstring(ls, 2))
- ndesc = description_type_by_name(lua_tostring(ls, 2));
- else if (lua_isnumber(ls, 2))
- ndesc = static_cast<description_level_type>(luaL_checkint(ls, 2));
- bool terse = lua_toboolean(ls, 3);
- lua_pushstring(ls, item->name(ndesc, terse).c_str());
+ std::string name = _item_name(ls, item);
+ lua_pushstring(ls, name.c_str());
+ }
+ else
+ lua_pushnil(ls);
+ return (1);
+}
+
+static int l_item_name_coloured(lua_State *ls)
+{
+ LUA_ITEM(item, 1);
+ if (item)
+ {
+ std::string name = _item_name(ls, item);
+ int col = menu_colour(name, menu_colour_item_prefix(*item));
+ std::string colstr = colour_to_str(col);
+
+ std::ostringstream out;
+
+ out << "<" << colstr << ">" << name << "</" << colstr << ">";
+
+ lua_pushstring(ls, out.str().c_str());
}
else
lua_pushnil(ls);
@@ -1481,6 +1508,7 @@ static const struct luaL_reg item_lib[] =
{ "cursed", l_item_cursed },
{ "worn", l_item_worn },
{ "name", l_item_name },
+ { "name_coloured", l_item_name_coloured },
{ "quantity", l_item_quantity },
{ "inslot", l_item_inslot },
{ "slot", l_item_slot },
@@ -1685,6 +1713,33 @@ static int crawl_mpr(lua_State *ls)
return (0);
}
+static int crawl_formatted_mpr(lua_State *ls)
+{
+ if (!crawl_state.io_inited)
+ return (0);
+
+ const char *message = luaL_checkstring(ls, 1);
+ if (!message)
+ return (0);
+
+ int ch = MSGCH_PLAIN;
+ if (lua_isnumber(ls, 2))
+ ch = luaL_checkint(ls, 2);
+ else
+ {
+ const char *channel = lua_tostring(ls, 2);
+ if (channel)
+ ch = str_to_channel(channel);
+ }
+
+ if (ch < 0 || ch >= NUM_MESSAGE_CHANNELS)
+ ch = MSGCH_PLAIN;
+
+ formatted_mpr(formatted_string::parse_string(message),
+ static_cast<msg_channel_type>(ch));
+ return (0);
+}
+
LUAWRAP(crawl_mesclr, mesclr())
LUAWRAP(crawl_redraw_screen, redraw_screen())
@@ -2067,6 +2122,7 @@ static int crawl_err_trace(lua_State *ls)
static const struct luaL_reg crawl_lib[] =
{
{ "mpr", crawl_mpr },
+ { "formatted_mpr", crawl_formatted_mpr },
{ "mesclr", crawl_mesclr },
{ "random2", crawl_random2 },
{ "one_chance_in", crawl_one_chance_in },
diff --git a/crawl-ref/source/dat/lua/eat.lua b/crawl-ref/source/dat/lua/eat.lua
index f27f69068b..4bd520b9e5 100644
--- a/crawl-ref/source/dat/lua/eat.lua
+++ b/crawl-ref/source/dat/lua/eat.lua
@@ -8,11 +8,11 @@
-- See c_eat in this file if you want to tweak eating behaviour further.
---------------------------------------------------------------------------
function prompt_eat(i)
- local iname = item.name(i, "a")
+ local iname = item.name_coloured(i, "a")
if item.quantity(i) > 1 then
iname = "one of " .. iname
end
- crawl.mpr("Eat " .. iname .. "?", "prompt")
+ crawl.formatted_mpr("Eat " .. iname .. "?", "prompt")
local res
res = crawl.getch()