|
From: Johnny O. <js...@us...> - 2010-10-28 21:13:06
|
Module: performous
Branch: opengl2
Commit: 65c4e3a911817f9b76fa2d3b1f0a39cbce54f81c
Author: Tapio Vierros <tap...@gm...>
Date: Thu Oct 28 18:14:38 2010 +0300
Use Cachemap for join and pause menu option texts.
---
game/instrumentgraph.cc | 51 ++++++++++++++++++++++++++++++----------------
game/screen_sing.cc | 10 ++++----
game/theme.cc | 7 +++++-
game/theme.hh | 6 +++-
4 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/game/instrumentgraph.cc b/game/instrumentgraph.cc
index 8044c2e..c657636 100644
--- a/game/instrumentgraph.cc
+++ b/game/instrumentgraph.cc
@@ -83,7 +83,7 @@ void InstrumentGraph::drawMenu() {
// We need to multiply offset by inverse scale factor to keep it always constant
// All these vars are ultimately affected by the scaling matrix
const double offsetX = 0.5f * (dimensions.x1() + dimensions.x2()) / s;
- const float txth = th.option.h();
+ const float txth = th.option_selected.h();
const float button_margin = m_arrow_up.dimensions.w()
* (m_input.isKeyboard() && getGraphType() != input::DANCEPAD ? 2.0f : 1.0f);
const float step = txth * 0.7f;
@@ -98,9 +98,14 @@ void InstrumentGraph::drawMenu() {
w = 0;
unsigned i = 0;
for (MenuOptions::const_iterator it = m_menu.begin(); it != m_menu.end(); ++it, ++i) {
- SvgTxtTheme* txt = &th.option;
- // Selected item?
- if (cur == it) {
+ std::string menutext = it->getName();
+ SvgTxtTheme* txt = &th.option_selected; // Default: font for selected menu item
+
+ if (cur != it) { // Unselected menuoption
+ txt = &(th.getCachedOption(menutext));
+
+ // Selected item
+ } else {
// Left/right Icons
if (getGraphType() == input::DRUMS) {
// Drum colors are mirrored
@@ -129,27 +134,37 @@ void InstrumentGraph::drawMenu() {
if (m_input.isKeyboard() && getGraphType() != input::DANCEPAD) {
float leftx = x - button_margin*0.75f;
float rightx = xx + button_margin*0.25f;
- txt->dimensions.left(leftx).center(y);
- txt->draw(getGraphType() == input::GUITAR ? (m_leftymode.b() ? "Z" : "1") : "U");
- txt->dimensions.right(rightx).center(y);
- txt->draw(getGraphType() == input::GUITAR ? (m_leftymode.b() ? "X" : "2") : "P");
+ {
+ std::string hintletter = (getGraphType() == input::GUITAR ? (m_leftymode.b() ? "Z" : "1") : "U");
+ SvgTxtTheme& hintfont = th.getCachedOption(hintletter);
+ hintfont.dimensions.left(leftx).center(y);
+ hintfont.draw(hintletter);
+ }{
+ std::string hintletter = (getGraphType() == input::GUITAR ? (m_leftymode.b() ? "X" : "2") : "P");
+ SvgTxtTheme& hintfont = th.getCachedOption(hintletter);
+ hintfont.dimensions.right(rightx).center(y);
+ hintfont.draw(hintletter);
+ }
// Only drums has up/down
if (getGraphType() == input::DRUMS) {
- txt->dimensions.left(leftx).center(y - step);
- if (i > 0) txt->draw("I"); // Up
- txt->dimensions.left(leftx).center(y + step);
- if (m_menu.getOptions().size()-1) txt->draw("O"); // Down
+ if (i > 0) { // Up
+ SvgTxtTheme& hintfont = th.getCachedOption("I");
+ hintfont.dimensions.left(leftx).center(y - step);
+ hintfont.draw("I");
+ }
+ if (m_menu.getOptions().size()-1) { // Down
+ SvgTxtTheme& hintfont = th.getCachedOption("O");
+ hintfont.dimensions.left(leftx).center(y + step);
+ hintfont.draw("O");
+ }
}
}
- //th.back_h.dimensions.middle(0.05 + offsetX).center(y);
- //th.back_h.draw();
- // Switch to the "selected" font
- txt = &th.option_selected;
}
+ // Finally we are at the actual menu item text drawing
txt->dimensions.middle(x).center(y);
- txt->draw(it->getName(), it->isActive() ? 1.0f : 0.5f);
+ txt->draw(menutext, it->isActive() ? 1.0f : 0.5f);
w = std::max(w, txt->w() + 2 * step + button_margin * 2); // Calculate the widest entry
- y += step;
+ y += step; // Move draw position down for the next option
}
// Draw comment text
if (cur->getComment() != "") {
diff --git a/game/screen_sing.cc b/game/screen_sing.cc
index 6b8c35c..525f035 100644
--- a/game/screen_sing.cc
+++ b/game/screen_sing.cc
@@ -532,7 +532,7 @@ void ScreenSing::drawMenu() {
ThemeInstrumentMenu& th = *m_menuTheme;
MenuOptions::const_iterator cur = static_cast<MenuOptions::const_iterator>(&m_menu.current());
double w = m_menu.dimensions.w();
- const float txth = th.option.h();
+ const float txth = th.option_selected.h();
const float step = txth * 0.85f;
const float h = m_menu.getOptions().size() * step + step;
float y = -h * .5f + step;
@@ -543,10 +543,10 @@ void ScreenSing::drawMenu() {
// Loop through menu items
w = 0;
for (MenuOptions::const_iterator it = m_menu.begin(); it != m_menu.end(); ++it) {
- SvgTxtTheme* txt = &th.option;
- if (cur == it) {
- txt = &th.option_selected;
- }
+ // Pick the font object
+ SvgTxtTheme* txt = &th.option_selected;
+ if (cur != it) txt = &(th.getCachedOption(it->getName()));
+ // Set dimensions and draw
txt->dimensions.middle(x).center(y);
txt->draw(it->getName());
w = std::max(w, txt->w() + 2 * step); // Calculate the widest entry
diff --git a/game/theme.cc b/game/theme.cc
index ef02ae1..dbaab57 100644
--- a/game/theme.cc
+++ b/game/theme.cc
@@ -60,7 +60,7 @@ ThemeIntro::ThemeIntro():
ThemeInstrumentMenu::ThemeInstrumentMenu():
Theme(getThemePath("instrumentmenu_bg.svg")),
back_h(getThemePath("instrumentmenu_back_highlight.svg")),
- option(getThemePath("instrumentmenu_option.svg"), config["graphic/text_lod"].f()),
+ options(30),
option_selected(getThemePath("instrumentmenu_option_selected.svg"), config["graphic/text_lod"].f()),
comment(getThemePath("instrumentmenu_comment.svg"), config["graphic/text_lod"].f())
//comment_bg(getThemePath("menu_comment_bg.svg"))
@@ -68,3 +68,8 @@ ThemeInstrumentMenu::ThemeInstrumentMenu():
back_h.dimensions.fixedHeight(0.08f);
comment.setAlign(SvgTxtTheme::CENTER);
}
+
+SvgTxtTheme& ThemeInstrumentMenu::getCachedOption(const std::string& text) {
+ if (options.contains(text)) return options[text];
+ return *options.insert(text, new SvgTxtTheme(getThemePath("instrumentmenu_option.svg"), config["graphic/text_lod"].f()))->second;
+}
diff --git a/game/theme.hh b/game/theme.hh
index 285b023..8b77f32 100644
--- a/game/theme.hh
+++ b/game/theme.hh
@@ -97,12 +97,14 @@ struct ThemeInstrumentMenu: Theme {
ThemeInstrumentMenu();
/// back highlight for selected option
Surface back_h;
- /// menu option text
- SvgTxtTheme option;
+ /// menu option texts
+ Cachemap<std::string, SvgTxtTheme> options;
/// menu selected option text
SvgTxtTheme option_selected;
/// menu comment text
SvgTxtTheme comment;
/// menu comment background
//Surface comment_bg;
+ /// get a cached option test
+ SvgTxtTheme& getCachedOption(const std::string& text);
};
|