|
From: Tapio V. <aa...@us...> - 2010-10-26 15:08:52
|
Module: performous
Branch: master
Commit: 94a4a40ff684814c875ef7cc1ee0b6937e48903e
Author: Tapio Vierros <tap...@gm...>
Date: Tue Oct 26 18:07:58 2010 +0300
Use Cachemap for screen_intro menu option text objects.
---
game/cachemap.hh | 4 ++++
game/screen_intro.cc | 13 ++++++++++---
game/screen_intro.hh | 2 ++
game/theme.cc | 2 +-
game/theme.hh | 7 ++++---
5 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/game/cachemap.hh b/game/cachemap.hh
index 7a59dc0..6e42b3a 100644
--- a/game/cachemap.hh
+++ b/game/cachemap.hh
@@ -28,6 +28,10 @@ template <typename Key, typename Value> class Cachemap {
if (it == m_map.end()) it = insert(key, new Value(key)); else access(key);
return *it->second;
}
+ /// does it have a certain key
+ bool contains(Key const& key) const {
+ return m_map.find(key) != m_map.end();
+ }
/// clears history and cachemap
void clear() {
m_history.clear();
diff --git a/game/screen_intro.cc b/game/screen_intro.cc
index 84e9a7a..3d624a9 100644
--- a/game/screen_intro.cc
+++ b/game/screen_intro.cc
@@ -97,9 +97,11 @@ void ScreenIntro::draw_menu_options() {
// Regular option (not selected)
} else {
- theme->option.dimensions.left(x).center(start_y + ii*0.08);
- theme->option.draw(opt.getName(), submenuanim * (opt.isActive() ? 1.0f : 0.5f));
- wcounter = std::max(wcounter, theme->option.w() + 2 * sel_margin); // Calculate the widest entry
+ std::string title = opt.getName();
+ SvgTxtTheme& txt = getTextObject(title);
+ txt.dimensions.left(x).center(start_y + ii*0.08);
+ txt.draw(title, submenuanim * (opt.isActive() ? 1.0f : 0.5f));
+ wcounter = std::max(wcounter, txt.w() + 2 * sel_margin); // Calculate the widest entry
}
}
m_menu.dimensions.stretch(wcounter, 1);
@@ -125,6 +127,11 @@ void ScreenIntro::draw() {
draw_menu_options();
}
+SvgTxtTheme& ScreenIntro::getTextObject(std::string const& txt) {
+ if (theme->options.contains(txt)) return theme->options[txt];
+ return *theme->options.insert(txt, new SvgTxtTheme(getThemePath("mainmenu_option.svg"), config["graphic/text_lod"].f()))->second;
+}
+
void ScreenIntro::populateMenu() {
m_menu.clear();
boost::shared_ptr<Surface> config_bg(new Surface(getThemePath("intro_configure.svg")));
diff --git a/game/screen_intro.hh b/game/screen_intro.hh
index 917e602..2f1e572 100644
--- a/game/screen_intro.hh
+++ b/game/screen_intro.hh
@@ -7,6 +7,7 @@
class Audio;
class ThemeIntro;
+class SvgTxtTheme;
class MenuOption;
/// intro screen
@@ -24,6 +25,7 @@ class ScreenIntro : public Screen {
private:
void populateMenu();
+ SvgTxtTheme& getTextObject(std::string const& txt);
Audio& m_audio;
boost::scoped_ptr<ThemeIntro> theme;
diff --git a/game/theme.cc b/game/theme.cc
index b549d0d..ef02ae1 100644
--- a/game/theme.cc
+++ b/game/theme.cc
@@ -47,7 +47,7 @@ ThemeAudioDevices::ThemeAudioDevices():
ThemeIntro::ThemeIntro():
Theme(getThemePath("intro_bg.svg")),
back_h(getThemePath("mainmenu_back_highlight.svg")),
- option(getThemePath("mainmenu_option.svg"), config["graphic/text_lod"].f()),
+ options(30),
option_selected(getThemePath("mainmenu_option_selected.svg"), config["graphic/text_lod"].f()),
comment(getThemePath("mainmenu_comment.svg"), config["graphic/text_lod"].f()),
short_comment(getThemePath("mainmenu_short_comment.svg"), config["graphic/text_lod"].f()),
diff --git a/game/theme.hh b/game/theme.hh
index 35607f2..285b023 100644
--- a/game/theme.hh
+++ b/game/theme.hh
@@ -2,6 +2,7 @@
#include "opengl_text.hh"
#include "surface.hh"
+#include "cachemap.hh"
#include <boost/noncopyable.hpp>
#include <string>
@@ -77,9 +78,9 @@ public:
ThemeIntro();
/// back highlight for selected option
Surface back_h;
- /// menu option text
- SvgTxtTheme option;
- /// menu selected option text
+ /// menu option texts
+ Cachemap<std::string, SvgTxtTheme> options;
+ /// selected menu option text
SvgTxtTheme option_selected;
/// menu comment text
SvgTxtTheme comment;
|