Skip to content

Commit

Permalink
Further improvements to the themes menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sago007 committed Oct 18, 2023
1 parent 3e88117 commit ddceb7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
16 changes: 13 additions & 3 deletions source/code/MenuSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,17 @@ void Menu::addButton(Button* b) {
placeButtons();
}

Menu::Menu(SDL_Renderer* screen) : buttons{std::vector<Button*>(10)}, isSubmenu{true}, screen{screen} {
Menu::Menu(SDL_Renderer* screen) {
buttons = std::vector<Button*>(10);
isSubmenu = true;
this->screen = screen;
exit.setLabel( _("Back") );
}

Menu::Menu(SDL_Renderer* screen,bool submenu) : buttons{std::vector<Button*>(0)}, isSubmenu{submenu}, screen{screen} {
Menu::Menu(SDL_Renderer* screen,bool submenu) {
buttons = std::vector<Button*>(0);
isSubmenu = submenu;
this->screen = screen;
if (isSubmenu) {
exit.setLabel( _("Back") );
}
Expand All @@ -169,7 +175,11 @@ Menu::Menu(SDL_Renderer* screen,bool submenu) : buttons{std::vector<Button*>(0)}
}
}

Menu::Menu(SDL_Renderer* screen, const std::string& title, bool submenu) : buttons{std::vector<Button*>(0)}, isSubmenu{submenu}, screen{screen}, title{title} {
Menu::Menu(SDL_Renderer* screen, const std::string& title, bool submenu) {
buttons = std::vector<Button*>(0);
isSubmenu = submenu;
this->screen = screen;
this->title = title;
if (isSubmenu) {
exit.setLabel(_("Back") );
}
Expand Down
9 changes: 5 additions & 4 deletions source/code/MenuSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ class Button
class Menu : public sago::GameStateInterface
{
private:
std::vector<Button*> buttons; //Vector holder the buttons
Button exit; //The exit button is special since it does not have a callback function
bool isSubmenu = false; //True if the menu is a submenu
int marked = 0; //The index of the marked button (for keyboard up/down)
bool running = true; //The menu is running. The menu will terminate then this is false
SDL_Renderer *screen = nullptr; //Pointer to the screen to draw to
std::string title;
void drawSelf(SDL_Renderer* target); //Private function to draw the screen
void placeButtons(); //Rearanges the buttons to the correct place.
bool bMouseUp = false;
public:
//numberOfItems is the expected numberOfItems for vector initialization
Expand All @@ -117,6 +113,11 @@ class Menu : public sago::GameStateInterface
void Draw(SDL_Renderer* target) override;
void ProcessInput(const SDL_Event& event, bool &processed) override;
void Update() override;
void drawSelf(SDL_Renderer* target); //Private function to draw the screen
virtual void placeButtons(); //Rearanges the buttons to the correct place.

std::vector<Button*> buttons; //Vector holder the buttons
Button exit; //The exit button is special since it does not have a callback function
};

class FileMenu
Expand Down
12 changes: 12 additions & 0 deletions source/code/menudef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,18 @@ class ThemesMenu : public Menu {
game = std::make_shared<BlockGameSdl>(1024-500,100,&globalData.spriteHolder->GetDataHolder());
}

void placeButtons() {
int nextY = 100;
int X = 50;
for (Button* it : buttons) {
it->x = X;
it->y = nextY;
nextY += standardButton.ysize+10;
}
exit.x = X;
exit.y = nextY;
}

void Draw(SDL_Renderer* target) override {
Menu::Draw(target);
game->DoPaintJob();
Expand Down

0 comments on commit ddceb7e

Please sign in to comment.