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 != buttons.end(); cursor++)
|
||||||
{
|
{
|
||||||
(*cursor)->set_state(data.get_mode(), data.get_build_type(),
|
(*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;
|
hover = false;
|
||||||
selected = false;
|
selected = false;
|
||||||
visible = true;
|
visible = true;
|
||||||
|
enabled = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +55,8 @@ void MenuButton::render(SDL_Surface* display)
|
||||||
if (!visible) return;
|
if (!visible) return;
|
||||||
|
|
||||||
int colour_to_use = colour;
|
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;
|
else if (hover) colour_to_use = hover_colour;
|
||||||
|
|
||||||
SDL_Rect pen = {x, y, 80, 20};
|
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;
|
selected = false;
|
||||||
visible = false;
|
visible = false;
|
||||||
|
enabled = true;
|
||||||
|
|
||||||
if (action & BUTTON_END_TURN)
|
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 |
|
if (mode & MODE_BUILD && action & (BUTTON_BUILD_ATTACKER |
|
||||||
BUTTON_BUILD_DEFENDER |
|
BUTTON_BUILD_DEFENDER |
|
||||||
BUTTON_BUILD_PRODUCER))
|
BUTTON_BUILD_PRODUCER))
|
||||||
|
{
|
||||||
visible = true;
|
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
|
// 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
|
// how to handle her own state, based on the current Mode and VertexType
|
||||||
// This isn't wonderful coupling, but it'll do
|
// 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:
|
private:
|
||||||
string text;
|
string text;
|
||||||
|
@ -59,6 +60,7 @@ class MenuButton : public Entity
|
||||||
bool hover;
|
bool hover;
|
||||||
bool selected;
|
bool selected;
|
||||||
bool visible;
|
bool visible;
|
||||||
|
bool enabled;
|
||||||
|
|
||||||
TTF_Font* font;
|
TTF_Font* font;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user