Attached Files |
0001-Improve-handling-of-menu-titles-in-WebTiles.patch [^] (11,768 bytes) 2013-06-07 07:29 [Show Content] [Hide Content]From d06fb2d94bc8ea6d294154d06b457a16842d7620 Mon Sep 17 00:00:00 2001
From: Pekka Lampila <pekka.lampila@iki.fi>
Date: Fri, 7 Jun 2013 07:23:27 +0300
Subject: [PATCH] Improve handling of menu titles in WebTiles
---
crawl-ref/source/menu.cc | 81 ++++++++++++++--------
crawl-ref/source/menu.h | 7 ++
crawl-ref/source/shopping.cc | 15 ++--
crawl-ref/source/stash.cc | 32 ++++++---
.../source/webserver/game_data/static/menu.js | 17 +++--
.../source/webserver/game_data/static/style.css | 4 --
6 files changed, 101 insertions(+), 55 deletions(-)
diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc
index defdb1b..d8fde47 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
diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h
index b8e4a5d..135ac4c 100644
--- a/crawl-ref/source/menu.h
+++ b/crawl-ref/source/menu.h
@@ -431,6 +431,9 @@ protected:
virtual void draw_stock_item(int index, const MenuEntry *me) const;
#ifdef USE_TILE_WEB
+ void webtiles_set_title(const formatted_string title);
+ void webtiles_set_suffix(const formatted_string title);
+
void webtiles_update_item(int index) const;
void webtiles_update_title() const;
void webtiles_update_scroll_pos() const;
@@ -443,6 +446,10 @@ protected:
int _webtiles_section_start;
int _webtiles_section_end;
+ bool _webtiles_title_changed;
+ formatted_string _webtiles_title;
+ formatted_string _webtiles_suffix;
+
inline int webtiles_section_start() const
{
return _webtiles_section_start == -1 ? 0 : _webtiles_section_start;
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index 4876be4..d7f3862 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -2940,11 +2940,16 @@ void ShoppingListMenu::draw_title()
const int total_cost = you.props[SHOPPING_LIST_COST_KEY];
cgotoxy(1, 1);
- textcolor(title->colour);
- cprintf("%d %s%s, total cost %d gp",
- title->quantity, title->text.c_str(),
- title->quantity > 1? "s" : "",
- total_cost);
+ formatted_string fs = formatted_string(title->colour);
+ fs.cprintf("%d %s%s, total cost %d gp",
+ title->quantity, title->text.c_str(),
+ title->quantity > 1? "s" : "",
+ total_cost);
+ fs.display();
+
+#ifdef USE_TILE_WEB
+ webtiles_set_title(fs);
+#endif
const char *verb = menu_action == ACT_EXECUTE ? "travel" :
menu_action == ACT_EXAMINE ? "examine" :
diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc
index 9444235..8b2e540 100644
--- a/crawl-ref/source/stash.cc
+++ b/crawl-ref/source/stash.cc
@@ -460,20 +460,20 @@ void StashMenu::draw_title()
if (title)
{
cgotoxy(1, 1);
- textcolor(title->colour);
- cprintf("%s", title->text.c_str());
+ formatted_string fs = formatted_string(title->colour);
+ fs.cprintf("%s", title->text.c_str());
if (title->quantity)
{
- cprintf(", %d item%s", title->quantity,
- title->quantity == 1? "" : "s");
+ fs.cprintf(", %d item%s", title->quantity,
+ title->quantity == 1? "" : "s");
}
- cprintf(")");
+ fs.cprintf(")");
if (action_cycle == Menu::CYCLE_TOGGLE)
{
- cprintf(" [a-z: %s ?/!: %s]",
- menu_action == ACT_EXAMINE ? "examine" : "shopping",
- menu_action == ACT_EXAMINE ? "shopping" : "examine");
+ fs.cprintf(" [a-z: %s ?/!: %s]",
+ menu_action == ACT_EXAMINE ? "examine" : "shopping",
+ menu_action == ACT_EXAMINE ? "shopping" : "examine");
}
if (can_travel)
@@ -488,8 +488,13 @@ void StashMenu::draw_title()
flags |= MF_ALWAYS_SHOW_MORE;
}
else
- cprintf(" [ENTER: travel]");
+ fs.cprintf(" [ENTER: travel]");
}
+ fs.display();
+
+#ifdef USE_TILE_WEB
+ webtiles_set_title(fs);
+#endif
}
}
@@ -1865,11 +1870,16 @@ void StashSearchMenu::draw_title()
if (title)
{
cgotoxy(1, 1);
- textcolor(title->colour);
- cprintf("%d %s%s, %s %s",
+ formatted_string fs = formatted_string(title->colour);
+ fs.cprintf("%d %s%s, %s %s",
title->quantity, title->text.c_str(),
title->quantity > 1? "es" : "",
stack_style, sort_style);
+ fs.display();
+
+#ifdef USE_TILE_WEB
+ webtiles_set_title(fs);
+#endif
draw_title_suffix(formatted_string::parse_string(make_stringf(
"<lightgrey> [<w>a-z</w>: %s"
diff --git a/crawl-ref/source/webserver/game_data/static/menu.js b/crawl-ref/source/webserver/game_data/static/menu.js
index a04b960..38857ed 100644
--- a/crawl-ref/source/webserver/game_data/static/menu.js
+++ b/crawl-ref/source/webserver/game_data/static/menu.js
@@ -78,11 +78,8 @@ function ($, comm, client, enums, dungeon_renderer, cr, util) {
}
// Normal menu
- if (menu.title && menu.title.text)
- {
- menu_div.prepend("<div id='menu_title'>");
- update_title();
- }
+ menu_div.prepend("<div id='menu_title'>");
+ update_title();
var content_div= $("<div id='menu_contents'>");
content_div.css({
@@ -398,8 +395,14 @@ function ($, comm, client, enums, dungeon_renderer, cr, util) {
function update_title()
{
- set_item_contents(menu.title, $("#menu_title"));
- if (menu.suffix)
+ $("#menu_title").html(util.formatted_string_to_html(menu.title.text));
+
+ if (menu.title.suffix)
+ {
+ $("#menu_title").append(" <span id='menu_suffix'>"
+ + util.formatted_string_to_html(menu.title.suffix) + "</span>");
+ }
+ else if (menu.suffix) // support old versions
{
$("#menu_title").append(" <span id='menu_suffix'>"
+ menu.suffix
diff --git a/crawl-ref/source/webserver/game_data/static/style.css b/crawl-ref/source/webserver/game_data/static/style.css
index 1012468..bd757f2 100644
--- a/crawl-ref/source/webserver/game_data/static/style.css
+++ b/crawl-ref/source/webserver/game_data/static/style.css
@@ -288,10 +288,6 @@ body {
white-space: pre;
}
-#menu_suffix {
- float: right;
-}
-
#menu_more {
white-space: pre;
}
--
1.8.1.2
|