|
From: Tapio V. <aa...@us...> - 2010-08-02 20:59:04
|
Module: performous
Branch: joinmenu
Commit: 2489bb8dd85212d2f24f251ce49387f66152bead
Author: Tapio Vierros <tap...@gm...>
Date: Mon Aug 2 23:55:40 2010 +0300
Instrument menu items are selected with frets.
* Color is shown next to the item for clarity.
* Strum+start alternative navigation disabled.
* Assumes there are max 5 options in the menu.
* Dance uses old navigation.
---
game/guitargraph.cc | 44 +++++++++++++++-----------------------------
game/guitargraph.hh | 2 --
game/instrumentgraph.cc | 34 +++++++++++++++++++++++++++++++---
game/instrumentgraph.hh | 4 ++++
game/menu.cc | 5 +++++
game/menu.hh | 2 ++
6 files changed, 57 insertions(+), 34 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 117b1dc..5a47ce7 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -59,7 +59,6 @@ namespace {
GuitarGraph::GuitarGraph(Audio& audio, Song const& song, bool drums, int number, bool practmode):
InstrumentGraph(audio, song, drums ? input::DRUMS : input::GUITAR),
- m_button(getThemePath("button.svg")),
m_tail(getThemePath("tail.svg")),
m_tail_glow(getThemePath("tail_glow.svg")),
m_tail_drumfill(getThemePath("tail_drumfill.svg")),
@@ -181,6 +180,7 @@ void GuitarGraph::changeTrack(int dir) {
difficultyAuto(true);
updateNeck();
setupJoinMenu();
+ m_menu.select(1); // Restore selection to the track menu item
}
/// Set specific track
@@ -190,6 +190,7 @@ void GuitarGraph::setTrack(const std::string& track) {
difficultyAuto(true);
updateNeck();
setupJoinMenu();
+ m_menu.select(1); // Restore selection to the track menu item
}
/// Get the difficulty as displayable string
@@ -284,7 +285,7 @@ void GuitarGraph::engine() {
if (ev.type == input::Event::WHAMMY) whammy = (1.0 + ev.button + 2.0*(rand()/double(RAND_MAX))) / 4.0;
} else {
// Handle drum lefty-mode
- if (m_leftymode.b() && ev.button > 0) ev.button = m_pads - ev.button;
+ if (m_leftymode.b() && ev.button > 0 && !menuOpen()) ev.button = m_pads - ev.button;
}
// Keypress anims
if (ev.type == input::Event::PRESS) m_pressed_anim[!m_drums + ev.button].setValue(1.0);
@@ -292,17 +293,19 @@ void GuitarGraph::engine() {
// Menu keys
if (menuOpen()) {
// Check first regular keys
- if (ev.type == input::Event::PRESS && ev.button == 0) m_menu.action(1);
- else if (ev.type == input::Event::PRESS && ev.button == (m_drums ? 4 : 1)) m_menu.action(-1);
- else if (ev.type == input::Event::PRESS && ev.button == (m_drums ? 1 : 2)) m_menu.move(1);
- else if (ev.type == input::Event::PRESS && ev.button == (m_drums ? 2 : 3)) m_menu.move(-1);
- // Strum (strum of keyboard as guitar doesn't generate nav-events)
- else if (ev.type == input::Event::PICK && ev.button == 0) m_menu.move(1);
- else if (ev.type == input::Event::PICK && ev.button == 1) m_menu.move(-1);
- else { // Try nav keys (arrows)
- if (ev.nav == input::DOWN || ev.nav == input::RIGHT) m_menu.move(1);
- else if (ev.nav == input::UP || ev.nav == input::LEFT) m_menu.move(-1);
+ if (ev.type == input::Event::PRESS && ev.button >= 0 && ev.button < 5) {
+ int sel = m_drums ? ((ev.button + 5 - 1) % 5) : ev.button;
+ m_menu.select(sel);
+ m_menu.action();
}
+ // Strum (strum of keyboard as guitar doesn't generate nav-events)
+ //else if (ev.type == input::Event::PICK && ev.button == 0) m_menu.move(1);
+ //else if (ev.type == input::Event::PICK && ev.button == 1) m_menu.move(-1);
+ //else { // Try nav keys (arrows)
+ // if (ev.nav == input::START) m_menu.action();
+ // else if (ev.nav == input::DOWN || ev.nav == input::RIGHT) m_menu.move(1);
+ // else if (ev.nav == input::UP || ev.nav == input::LEFT) m_menu.move(-1);
+ //}
// See if anything changed
if (m_selectedTrack.s() != getTrack()) setTrack(m_selectedTrack.s());
else if (m_selectedDifficulty.i() != m_level) difficulty(Difficulty(m_selectedDifficulty.i()));
@@ -692,23 +695,6 @@ void GuitarGraph::guitarPlay(double time, input::Event const& ev) {
}
}
-/// Get a color based on fret index
-glutil::Color const& GuitarGraph::color(int fret) const {
- static glutil::Color fretColors[5] = {
- glutil::Color(0.0f, 0.9f, 0.0f),
- glutil::Color(0.9f, 0.0f, 0.0f),
- glutil::Color(0.9f, 0.9f, 0.0f),
- glutil::Color(0.0f, 0.0f, 1.0f),
- glutil::Color(0.9f, 0.4f, 0.0f)
- };
- if (fret < 0 || fret >= m_pads) throw std::logic_error("Invalid fret number in GuitarGraph::getColor");
- if (m_drums) {
- if (fret == 0) fret = 4;
- else if (fret == 4) fret = 0;
- }
- return fretColors[fret];
-}
-
/// Modify color based on things like GodMode and solos
glutil::Color const GuitarGraph::colorize(glutil::Color c, double time) const {
const static glutil::Color godmodeC(0.5f, 0.5f, 1.0f); // Color for full GodMode
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index 2a69547..5c2a06b 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -79,7 +79,6 @@ class GuitarGraph: public InstrumentGraph {
void guitarPlay(double time, input::Event const& ev);
// Media
- Surface m_button;
Texture m_tail;
Texture m_tail_glow;
Texture m_tail_drumfill;
@@ -121,7 +120,6 @@ class GuitarGraph: public InstrumentGraph {
unsigned m_holds[max_panels]; /// active hold notes
// Graphics functions
- glutil::Color const& color(int fret) const;
glutil::Color const colorize(glutil::Color c, double time) const;
void drawBar(double time, float h);
void drawNote(int fret, glutil::Color, float tBeg, float tEnd, float whammy = 0, bool tappable = false, bool hit = false, double hitAnim = 0.0, double releaseTime = 0.0);
diff --git a/game/instrumentgraph.cc b/game/instrumentgraph.cc
index b6e1443..6d25b26 100644
--- a/game/instrumentgraph.cc
+++ b/game/instrumentgraph.cc
@@ -18,6 +18,7 @@ InstrumentGraph::InstrumentGraph(Audio& audio, Song const& song, input::DevType
m_stream(),
m_cx(0.0, 0.2), m_width(0.5, 0.4),
m_menu(),
+ m_button(getThemePath("button.svg")),
m_text(getThemePath("sing_timetxt.svg"), config["graphic/text_lod"].f()),
m_selectedTrack(""),
m_selectedDifficulty(0),
@@ -65,17 +66,27 @@ void InstrumentGraph::drawMenu() {
double w = m_menu.dimensions.w();
const double offsetX = 0.5f * (dimensions.x1() + dimensions.x2());
const float txth = th.option.h();
+ const float button_margin = 0.05f;
const float step = txth * 0.7f;
const float h = m_menu.getOptions().size() * step + step;
float y = -h * .5f + step;
- float x = -w * .5f + step + offsetX;
+ float x = -w * .5f + step + offsetX + button_margin * 1.5f;
// Background
th.bg.dimensions.middle(offsetX).center(0).stretch(w, h);
th.bg.draw();
// Loop through menu items
w = 0;
- for (MenuOptions::const_iterator it = m_menu.begin(); it != m_menu.end(); ++it) {
+ int i = 0;
+ for (MenuOptions::const_iterator it = m_menu.begin(); it != m_menu.end(); ++it, ++i) {
SvgTxtTheme* txt = &th.option;
+ // Draw the key hints
+ if (getGraphType() != input::DANCEPAD) {
+ int fret = (getGraphType() == input::DRUMS ? ((i + 1) % 5) : i);
+ glColor4fv(color(fret));
+ m_button.dimensions.middle(x - button_margin).center(y).stretch(0.05, 0.05);
+ m_button.draw();
+ }
+ // Selected item?
if (cur == it) {
//th.back_h.dimensions.middle(0.05 + offsetX).center(y);
//th.back_h.draw();
@@ -83,7 +94,7 @@ void InstrumentGraph::drawMenu() {
}
txt->dimensions.middle(x).center(y);
txt->draw(it->getName());
- w = std::max(w, txt->w() + 2 * step); // Calculate the widest entry
+ w = std::max(w, txt->w() + 2 * step + button_margin * 2); // Calculate the widest entry
y += step;
}
if (cur->getComment() != "") {
@@ -112,3 +123,20 @@ void InstrumentGraph::handleCountdown(double time, double beginTime) {
--m_countdown;
}
}
+
+
+glutil::Color const& InstrumentGraph::color(int fret) const {
+ static glutil::Color fretColors[5] = {
+ glutil::Color(0.0f, 0.9f, 0.0f),
+ glutil::Color(0.9f, 0.0f, 0.0f),
+ glutil::Color(0.9f, 0.9f, 0.0f),
+ glutil::Color(0.0f, 0.0f, 1.0f),
+ glutil::Color(0.9f, 0.4f, 0.0f)
+ };
+ if (fret < 0 || fret >= m_pads) throw std::logic_error("Invalid fret number in InstrumentGraph::color");
+ if (getGraphType() == input::DRUMS) {
+ if (fret == 0) fret = 4;
+ else if (fret == 4) fret = 0;
+ }
+ return fretColors[fret];
+}
diff --git a/game/instrumentgraph.hh b/game/instrumentgraph.hh
index 0489814..5d853b3 100644
--- a/game/instrumentgraph.hh
+++ b/game/instrumentgraph.hh
@@ -121,7 +121,11 @@ class InstrumentGraph {
void drawPopups(double offsetX);
void handleCountdown(double time, double beginTime);
+ // Functions not really shared, but needed here
+ glutil::Color const& color(int fret) const;
+
// Media
+ Surface m_button;
SvgTxtTheme m_text;
boost::scoped_ptr<SvgTxtThemeSimple> m_popupText;
boost::scoped_ptr<ThemeInstrumentMenu> m_menuTheme;
diff --git a/game/menu.cc b/game/menu.cc
index 7d44b35..3081598 100644
--- a/game/menu.cc
+++ b/game/menu.cc
@@ -78,6 +78,11 @@ void Menu::move(int dir) {
else if (dir < 0 && selection_stack.back() > 0) --selection_stack.back();
}
+void Menu::select(unsigned sel) {
+ if (sel < menu_stack.back()->size())
+ selection_stack.back() = sel;
+}
+
void Menu::action(int dir) {
switch (current().type) {
case MenuOption::OPEN_SUBMENU:
diff --git a/game/menu.hh b/game/menu.hh
index a2be1c2..a04a11b 100644
--- a/game/menu.hh
+++ b/game/menu.hh
@@ -59,6 +59,8 @@ struct Menu {
void add(MenuOption opt);
/// move the selection
void move(int dir = 1);
+ /// set selection
+ void select(unsigned sel);
/// adjust the selected value
void action(int dir = 1);
/// clear items
|