summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/menu.cc
diff options
context:
space:
mode:
authorPekka Lampila <pekka.lampila@iki.fi>2013-06-07 07:23:27 +0300
committerNeil Moore <neil@s-z.org>2013-06-07 01:59:51 -0400
commitf35a63b0d44ae5deaa2ab246b614d31e08343d02 (patch)
tree8e5fbf432db56ef54eda4c42625bdbee571f95ce /crawl-ref/source/menu.cc
parent0edb3d0cfcadf004b65ba9f222c9f787fc04e1f2 (diff)
downloadcrawl-ref-f35a63b0d44ae5deaa2ab246b614d31e08343d02.tar.gz
crawl-ref-f35a63b0d44ae5deaa2ab246b614d31e08343d02.zip
Improve handling of menu titles in WebTiles
Diffstat (limited to 'crawl-ref/source/menu.cc')
-rw-r--r--crawl-ref/source/menu.cc81
1 files changed, 53 insertions, 28 deletions
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc
index defdb1be97..d8fde47ed2 100644
--- a/crawl-ref/source/menu.cc
+++ b/crawl-ref/source/menu.cc
@@ -313,10 +313,6 @@ vector<MenuEntry *> Menu::show(bool reuse_selections)
if (is_set(MF_START_AT_END))
first_entry = max((int)items.size() - pagesize, 0);
-#ifdef USE_TILE_WEB
- tiles.push_menu(this);
-#endif
-
do_menu();
#ifdef USE_TILE_WEB
@@ -330,9 +326,21 @@ void Menu::do_menu()
{
draw_menu();
+#ifdef USE_TILE_WEB
+ tiles.push_menu(this);
+ _webtiles_title_changed = false;
+#endif
+
alive = true;
while (alive)
{
+#ifdef USE_TILE_WEB
+ if (_webtiles_title_changed)
+ {
+ webtiles_update_title();
+ _webtiles_title_changed = false;
+ }
+#endif
int keyin = getchm(KMC_MENU, getch_ck);
if (!process_key(keyin))
@@ -510,9 +518,6 @@ bool Menu::process_key(int keyin)
select_index(next, num);
get_selected(&sel);
draw_select_count(sel.size());
-#ifdef USE_TILE_WEB
- webtiles_update_title();
-#endif
if (get_cursor() < next)
{
first_entry = 0;
@@ -609,9 +614,6 @@ bool Menu::process_key(int keyin)
return false;
draw_select_count(sel.size());
-#ifdef USE_TILE_WEB
- webtiles_update_title();
-#endif
if (flags & MF_ANYPRINTABLE
&& (!isadigit(keyin) || is_set(MF_NO_SELECT_QTY)))
@@ -654,6 +656,10 @@ bool Menu::draw_title_suffix(const string &s, bool titlefirst)
if (crawl_state.doing_prev_cmd_again)
return true;
+#ifdef USE_TILE_WEB
+ webtiles_set_suffix(formatted_string(s, 0));
+#endif
+
int oldx = wherex(), oldy = wherey();
if (titlefirst)
@@ -680,6 +686,10 @@ bool Menu::draw_title_suffix(const formatted_string &fs, bool titlefirst)
if (crawl_state.doing_prev_cmd_again)
return true;
+#ifdef USE_TILE_WEB
+ webtiles_set_suffix(fs);
+#endif
+
int oldx = wherex(), oldy = wherey();
if (titlefirst)
@@ -1262,10 +1272,6 @@ void Menu::draw_menu()
void Menu::update_title()
{
-#ifdef USE_TILE_WEB
- webtiles_update_title();
-#endif
-
int x = wherex(), y = wherey();
draw_title();
cgotoxy(x, y);
@@ -1296,10 +1302,12 @@ void Menu::write_title()
if (!first)
ASSERT(title2);
- textcolor(item_colour(-1, first ? title : title2));
+ formatted_string fs =
+ formatted_string(item_colour(-1, first ? title : title2));
string text = (first ? title->get_text() : title2->get_text());
- cprintf("%s", text.c_str());
+
+ fs.cprintf("%s", text.c_str());
if (flags & MF_SHOW_PAGENUMBERS)
{
// The total number of pages is well defined, but the current
@@ -1310,8 +1318,13 @@ void Menu::write_title()
int curpage = first_entry / pagesize + 1;
if (in_page(items.size() - 1))
curpage = numpages;
- cprintf(" (page %d of %d)", curpage, numpages);
+ fs.cprintf(" (page %d of %d)", curpage, numpages);
}
+ fs.display();
+
+#ifdef USE_TILE_WEB
+ webtiles_set_title(fs);
+#endif
// Don't clear the next line if the title was exactly as wide as the
// screen; but do clear the current line if the title was empty.
@@ -1489,6 +1502,24 @@ void Menu::webtiles_handle_item_request(int start, int end)
tiles.finish_message();
}
+void Menu::webtiles_set_title(const formatted_string title_)
+{
+ if (title_.to_colour_string() != _webtiles_title.to_colour_string())
+ {
+ _webtiles_title_changed = true;
+ _webtiles_title = title_;
+ }
+}
+
+void Menu::webtiles_set_suffix(const formatted_string suffix)
+{
+ if (suffix.to_colour_string() != _webtiles_suffix.to_colour_string())
+ {
+ _webtiles_title_changed = true;
+ _webtiles_suffix = suffix;
+ }
+}
+
void Menu::webtiles_update_item(int index) const
{
tiles.json_open_object();
@@ -1534,16 +1565,11 @@ void Menu::webtiles_update_scroll_pos() const
void Menu::webtiles_write_title() const
{
- if (!title) return;
- const bool first = (action_cycle == CYCLE_NONE
- || menu_action == ACT_EXECUTE);
- const MenuEntry* me = (first ? title : title2);
-
- tiles.json_write_name("title");
- webtiles_write_item(-1, me);
-
- if (is_set(MF_MULTISELECT))
- tiles.json_write_string("suffix", get_select_count_string(sel.size()));
+ // the title object only exists for backwards compatibility
+ tiles.json_open_object("title");
+ tiles.json_write_string("text", _webtiles_title.to_colour_string());
+ tiles.json_write_string("suffix", _webtiles_suffix.to_colour_string());
+ tiles.json_close_object("title");
}
void Menu::webtiles_write_item(int index, const MenuEntry* me) const
@@ -2079,7 +2105,6 @@ int ToggleableMenu::pre_process(int key)
draw_menu();
#ifdef USE_TILE_WEB
- webtiles_update_title();
for (unsigned int i = 0; i < items.size(); ++i)
webtiles_update_item(i);
#endif