|
From: Tapio V. <aa...@us...> - 2009-12-11 12:44:19
|
Module: performous
Branch: dance
Commit: 4c630be35e72e75e98fd33e992f0662431e15739
Author: Miguel Sánchez de León Peque <msd...@gm...>
Date: Wed Dec 2 02:10:11 2009 +0100
OptionMenu struct created in menu.cc/hh; applied to Main Menu.
---
game/menu.cc | 9 +++++++
game/menu.hh | 16 +++++++++++++
game/screen_intro.cc | 37 ++++++++-----------------------
game/screen_intro.hh | 2 +
game/theme.cc | 4 ---
game/theme.hh | 8 -------
themes/default/configuration_value.svg | 17 +++++++-------
7 files changed, 46 insertions(+), 47 deletions(-)
diff --git a/game/menu.cc b/game/menu.cc
new file mode 100755
index 0000000..63eac83
--- /dev/null
+++ b/game/menu.cc
@@ -0,0 +1,9 @@
+#include "menu.hh"
+
+#include "fs.hh"
+#include "configuration.hh"
+
+MenuOption::MenuOption()
+{}
+MenuOption::MenuOption(const std::string scrn, const std::string img) : screen(scrn), image(getThemePath(img))
+{}
diff --git a/game/menu.hh b/game/menu.hh
new file mode 100755
index 0000000..a1ae00b
--- /dev/null
+++ b/game/menu.hh
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "opengl_text.hh"
+#include "surface.hh"
+#include <boost/noncopyable.hpp>
+#include <string>
+
+/// struct for menu options
+struct MenuOption {
+ MenuOption();
+ MenuOption(const std::string scrn, const std::string img);
+ /// screen to activate when option is pressed
+ std::string screen;
+ /// image to show when option is selected
+ Surface image;
+};
diff --git a/game/screen_intro.cc b/game/screen_intro.cc
old mode 100644
new mode 100755
index 885912c..5fdadd0
--- a/game/screen_intro.cc
+++ b/game/screen_intro.cc
@@ -4,7 +4,12 @@
#include "audio.hh"
#include "record.hh"
-ScreenIntro::ScreenIntro(std::string const& name, Audio& audio, Capture& capture): Screen(name), m_audio(audio), m_capture(capture), selected() {}
+ScreenIntro::ScreenIntro(std::string const& name, Audio& audio, Capture& capture): Screen(name), m_audio(audio), m_capture(capture), selected() {
+ m_menuOptions.push_back(new MenuOption("Songs", "intro_sing.svg"));
+ m_menuOptions.push_back(new MenuOption("Practice", "intro_practice.svg"));
+ m_menuOptions.push_back(new MenuOption("Configuration", "intro_configure.svg"));
+ m_menuOptions.push_back(new MenuOption("", "intro_quit.svg"));
+}
void ScreenIntro::enter() {
m_audio.playMusic(getThemePath("menu.ogg"), true);
@@ -20,20 +25,6 @@ void ScreenIntro::exit() {
m_dialog.reset();
}
-/*
-Tronic's note on making the menu more generic:
-
-struct MenuOption {
- std::string screen;
- Surface image;
-};
-
-In ScreenIntro:
-std::vector<MenuOption> m_menuOptions;
-
-This should avoid all if-elses for testing selected == 1, ...
-*/
-
void ScreenIntro::manageEvent(SDL_Event event) {
ScreenManager* sm = ScreenManager::getSingletonPtr();
if (event.type == SDL_KEYDOWN) {
@@ -47,14 +38,9 @@ void ScreenIntro::manageEvent(SDL_Event event) {
if (selected > 0) selected--;
else selected = 3;
} else if (key == SDLK_RETURN) {
- if (selected == 0) sm->activateScreen("Songs");
- else if (selected == 1) sm->activateScreen("Practice");
- else if (selected == 2) sm->activateScreen("Configuration");
- else if (selected == 3) sm->finished();
- } else if (key == SDLK_s) sm->activateScreen("Songs");
- else if (key == SDLK_c) sm->activateScreen("Configuration");
- else if (key == SDLK_p) sm->activateScreen("Practice");
- else if (key == SDLK_SPACE || key == SDLK_PAUSE) m_audio.togglePause();
+ if (selected != 3) sm->activateScreen(m_menuOptions[selected].screen);
+ else sm->finished();
+ } else if (key == SDLK_SPACE || key == SDLK_PAUSE) m_audio.togglePause();
} else if (event.type == SDL_JOYBUTTONDOWN) {
int button = event.jbutton.button;
if (button == 9) sm->activateScreen("Songs");
@@ -64,10 +50,7 @@ void ScreenIntro::manageEvent(SDL_Event event) {
void ScreenIntro::draw() {
theme->bg.draw();
- if (selected == 0) theme->sing.draw();
- else if (selected == 1) theme->practice.draw();
- else if (selected == 2) theme->configure.draw();
- else if (selected == 3) theme->quit.draw();
+ m_menuOptions[selected].image.draw();
theme->top.draw();
if (m_dialog) m_dialog->draw();
}
diff --git a/game/screen_intro.hh b/game/screen_intro.hh
old mode 100644
new mode 100755
index c67ec33..7906f14
--- a/game/screen_intro.hh
+++ b/game/screen_intro.hh
@@ -3,6 +3,7 @@
#include "dialog.hh"
#include "screen.hh"
#include "theme.hh"
+#include "menu.hh"
#include <boost/scoped_ptr.hpp>
class Audio;
@@ -22,6 +23,7 @@ class ScreenIntro : public Screen {
Audio& m_audio;
Capture& m_capture;
boost::scoped_ptr<ThemeIntro> theme;
+ boost::ptr_vector<MenuOption> m_menuOptions;
boost::scoped_ptr<Dialog> m_dialog;
unsigned int selected;
};
diff --git a/game/theme.cc b/game/theme.cc
index 4ce64a7..026f8e6 100644
--- a/game/theme.cc
+++ b/game/theme.cc
@@ -42,9 +42,5 @@ ThemeConfiguration::ThemeConfiguration():
ThemeIntro::ThemeIntro():
Theme(getThemePath("intro_bg.svg")),
- sing(getThemePath("intro_sing.svg")),
- practice(getThemePath("intro_practice.svg")),
- configure(getThemePath("intro_configure.svg")),
- quit(getThemePath("intro_quit.svg")),
top(getThemePath("intro_top.svg"))
{}
diff --git a/game/theme.hh b/game/theme.hh
index 225162a..dbb49bd 100644
--- a/game/theme.hh
+++ b/game/theme.hh
@@ -62,14 +62,6 @@ struct ThemeConfiguration: Theme {
/// theme for intro screen
struct ThemeIntro: Theme {
ThemeIntro();
- /// sing option
- Surface sing;
- /// practice option
- Surface practice;
- /// configuration option
- Surface configure;
- /// quit option
- Surface quit;
/// top layer
Surface top;
};
diff --git a/themes/default/configuration_value.svg b/themes/default/configuration_value.svg
index fbdd01c..9c28453 100644
--- a/themes/default/configuration_value.svg
+++ b/themes/default/configuration_value.svg
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Sodipodi ("http://www.sodipodi.com/") -->
+
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
@@ -15,9 +16,8 @@
height="600.000000"
id="svg559"
sodipodi:version="0.32"
- inkscape:version="0.46"
+ inkscape:version="0.47pre4 r22446"
sodipodi:docname="configuration_value.svg"
- sodipodi:docbase="/home/yoda/UltraStar/sf/UltraStar-ng/themes/lima"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs2522">
@@ -41,7 +41,7 @@
</rdf:RDF>
</metadata>
<sodipodi:namedview
- inkscape:window-height="797"
+ inkscape:window-height="724"
inkscape:window-width="1081"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
@@ -52,13 +52,14 @@
bordercolor="#666666"
pagecolor="#ffffff"
id="base"
- inkscape:zoom="0.63"
- inkscape:cx="382.28027"
- inkscape:cy="304.78209"
+ inkscape:zoom="2.52"
+ inkscape:cx="395.84082"
+ inkscape:cy="267.82124"
inkscape:window-x="5"
- inkscape:window-y="73"
+ inkscape:window-y="25"
inkscape:current-layer="svg559"
- showgrid="false" />
+ showgrid="false"
+ inkscape:window-maximized="0" />
<text
x="400"
y="330"
|