Added some code for disabling button visually, but it doesn't quite work
This commit is contained in:
parent
eccc773457
commit
8a4ed42ab1
3
game.cpp
3
game.cpp
|
@ -373,7 +373,8 @@ void Game::mode_changed()
|
|||
cursor != buttons.end(); cursor++)
|
||||
{
|
||||
(*cursor)->set_state(data.get_mode(), data.get_build_type(),
|
||||
data.get_current_vertex());
|
||||
data.get_current_vertex(),
|
||||
data.can_build(data.get_build_type()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ bool MenuButton::init()
|
|||
hover = false;
|
||||
selected = false;
|
||||
visible = true;
|
||||
enabled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -54,7 +55,8 @@ void MenuButton::render(SDL_Surface* display)
|
|||
if (!visible) return;
|
||||
|
||||
int colour_to_use = colour;
|
||||
if (selected) colour_to_use = selected_colour;
|
||||
if (!enabled) colour_to_use = 0xbbbbbb;
|
||||
else if (selected) colour_to_use = selected_colour;
|
||||
else if (hover) colour_to_use = hover_colour;
|
||||
|
||||
SDL_Rect pen = {x, y, 80, 20};
|
||||
|
@ -75,10 +77,12 @@ bool MenuButton::is_at(int test_x, int test_y)
|
|||
}
|
||||
|
||||
|
||||
void MenuButton::set_state(Mode mode, VertexType type, GameVertex* current)
|
||||
void MenuButton::set_state(Mode mode, VertexType type, GameVertex* current,
|
||||
bool can_build)
|
||||
{
|
||||
selected = false;
|
||||
visible = false;
|
||||
enabled = true;
|
||||
|
||||
if (action & BUTTON_END_TURN)
|
||||
{
|
||||
|
@ -108,6 +112,16 @@ void MenuButton::set_state(Mode mode, VertexType type, GameVertex* current)
|
|||
if (mode & MODE_BUILD && action & (BUTTON_BUILD_ATTACKER |
|
||||
BUTTON_BUILD_DEFENDER |
|
||||
BUTTON_BUILD_PRODUCER))
|
||||
{
|
||||
visible = true;
|
||||
|
||||
if (!can_build &&
|
||||
((action == BUTTON_BUILD_ATTACKER && type == VERTEX_ATTACKER) ||
|
||||
(action == BUTTON_BUILD_DEFENDER && type == VERTEX_DEFENDER) ||
|
||||
(action == BUTTON_BUILD_PRODUCER && type == VERTEX_PRODUCER)))
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
if (action == BUTTON_ATTACK && current->attacked) enabled = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ class MenuButton : public Entity
|
|||
// To get some complexity out of the Game class, let's teach MenuButton
|
||||
// how to handle her own state, based on the current Mode and VertexType
|
||||
// This isn't wonderful coupling, but it'll do
|
||||
void set_state(Mode mode, VertexType type, GameVertex* current);
|
||||
void set_state(Mode mode, VertexType type, GameVertex* current,
|
||||
bool can_build);
|
||||
|
||||
private:
|
||||
string text;
|
||||
|
@ -59,6 +60,7 @@ class MenuButton : public Entity
|
|||
bool hover;
|
||||
bool selected;
|
||||
bool visible;
|
||||
bool enabled;
|
||||
|
||||
TTF_Font* font;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user