Huge refactor with the basic goal of reducing complexity in the Game class. Broke a couple of small things in the process - still working on fixing them back up
This commit is contained in:
31
menubutton.h
31
menubutton.h
@ -8,6 +8,9 @@
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
#include <string>
|
||||
#include "entity.h"
|
||||
#include "gamedata.h"
|
||||
#include "gamevertex.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -17,27 +20,45 @@ enum ButtonAction {BUTTON_BUILD=0x1, BUTTON_ATTACK=0x2, BUTTON_MOVE=0x4,
|
||||
BUTTON_BUILD_ATTACKER=0x8, BUTTON_BUILD_DEFENDER=0x10,
|
||||
BUTTON_BUILD_PRODUCER=0x20, BUTTON_END_TURN=0x40};
|
||||
|
||||
class MenuButton
|
||||
class MenuButton : public Entity
|
||||
{
|
||||
public:
|
||||
MenuButton(string text = "", TTF_Font* font = NULL, int x = 0, int y = 0,
|
||||
ButtonAction action = BUTTON_BUILD);
|
||||
ButtonAction action = BUTTON_BUILD, int colour=0x000000,
|
||||
int hover_colour=0xff0000, int selected_colour=0x0000ff,
|
||||
int background_colour=0x888888);
|
||||
|
||||
// Selectable buttons change colour for the duration they are selected,
|
||||
// and should ignore clicks while selected
|
||||
void set_hover(bool is_hovering);
|
||||
void draw(SDL_Surface* display, int colour = 0x000000,
|
||||
int background_colour = 0x888888);
|
||||
void set_selected(bool is_selected);
|
||||
void set_visible(bool is_visible);
|
||||
|
||||
bool init();
|
||||
void render(SDL_Surface* display);
|
||||
void iterate();
|
||||
|
||||
bool is_at(int test_x, int test_y);
|
||||
ButtonAction get_action() const { return action; }
|
||||
|
||||
|
||||
// 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);
|
||||
|
||||
private:
|
||||
string text;
|
||||
int x;
|
||||
int y;
|
||||
|
||||
int colour;
|
||||
int hover_colour;
|
||||
int selected_colour;
|
||||
int background_colour;
|
||||
|
||||
bool hover;
|
||||
bool selected;
|
||||
bool visible;
|
||||
|
||||
TTF_Font* font;
|
||||
|
||||
|
Reference in New Issue
Block a user