penguins  1.0.0
new_game_dialog.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/game_state.hh"
4 #include <wx/button.h>
5 #include <wx/choice.h>
6 #include <wx/defs.h>
7 #include <wx/dialog.h>
8 #include <wx/event.h>
9 #include <wx/persist.h>
10 #include <wx/persist/window.h>
11 #include <wx/sizer.h>
12 #include <wx/spinbutt.h>
13 #include <wx/spinctrl.h>
14 #include <wx/string.h>
15 #include <wx/textctrl.h>
16 #include <wx/vector.h>
17 #include <wx/window.h>
18 
19 class NewGameDialog : public wxDialog {
20 public:
21  NewGameDialog(wxWindow* parent, wxWindowID id);
22  virtual ~NewGameDialog();
23 
24  static const int DEFAULT_BOARD_WIDTH = 16;
25  static const int DEFAULT_BOARD_HEIGHT = 16;
26  static const int DEFAULT_PENGUINS_PER_PLAYER = 2;
27  static const int DEFAULT_NUMBER_OF_PLAYERS = 2;
28 
29  int get_board_width() const;
30  int get_board_height() const;
32  int get_penguins_per_player() const;
33  size_t get_number_of_players() const;
34  wxString get_player_name(size_t index) const;
35  PlayerType get_player_type(size_t index) const;
36 
37 protected:
40  bool width_was_changed = false;
43  bool height_was_changed = false;
51  };
52  wxVector<PlayerRowWidgets> player_rows;
55 
56  wxWindow* add_option(const wxString& label, wxWindow* input);
57  wxSpinCtrl*
58  create_number_option(const wxString& label, wxWindowID id, int min, int max, int initial);
59  wxChoice*
60  create_choice_option(const wxString& label, wxWindowID id, int n, const wxString choices[]);
61 
62  void update_layout();
63 
64  void set_player_rows_count(size_t count);
65  void update_new_player_row();
66  void add_new_player_row(bool initial = false);
67  void realize_player_row(size_t index);
68  void delete_player_row(size_t index);
69 
70  void on_ok(wxCommandEvent& event);
71  void on_close(wxCommandEvent& event);
74  void on_board_width_input(wxSpinEvent& event);
78 
79 public:
80  class Persistence : public wxPersistentWindow<NewGameDialog> {
81  public:
83  virtual wxString GetKind() const override {
84  return "NewGameDialog";
85  }
86  virtual bool Restore() override;
87  virtual void Save() const override;
88  };
89 };
90 
92  return new NewGameDialog::Persistence(dialog);
93 }
virtual void Save() const override
virtual wxString GetKind() const override
Persistence(NewGameDialog *dialog)
virtual bool Restore() override
wxFlexGridSizer * options_grid
static const int DEFAULT_NUMBER_OF_PLAYERS
void delete_player_row(size_t index)
wxChoice * create_choice_option(const wxString &label, wxWindowID id, int n, const wxString choices[])
NewGameDialog(wxWindow *parent, wxWindowID id)
wxSpinCtrl * players_number_input
wxWindow * add_option(const wxString &label, wxWindow *input)
wxSpinCtrl * width_input
static const int DEFAULT_BOARD_WIDTH
void on_player_delete_clicked(wxCommandEvent &event)
virtual ~NewGameDialog()
wxString get_player_name(size_t index) const
void realize_player_row(size_t index)
static const int DEFAULT_PENGUINS_PER_PLAYER
int get_board_width() const
int get_penguins_per_player() const
BoardGenType get_board_gen_type() const
int get_board_height() const
void on_player_name_input(wxCommandEvent &event)
PlayerType get_player_type(size_t index) const
void on_close(wxCommandEvent &event)
void on_board_width_input(wxSpinEvent &event)
wxSpinCtrl * create_number_option(const wxString &label, wxWindowID id, int min, int max, int initial)
void on_board_height_input(wxSpinEvent &event)
void on_player_name_enter_pressed(wxCommandEvent &event)
wxVector< PlayerRowWidgets > player_rows
void on_players_number_input(wxSpinEvent &event)
wxFlexGridSizer * players_grid
void on_ok(wxCommandEvent &event)
wxSpinCtrl * penguins_input
void set_player_rows_count(size_t count)
PlayerRowWidgets new_player_row
void update_new_player_row()
wxStdDialogButtonSizer * buttons_sizer
static const int DEFAULT_BOARD_HEIGHT
wxSpinCtrl * height_input
wxChoice * board_gen_input
size_t get_number_of_players() const
void add_new_player_row(bool initial=false)
BoardGenType
Definition: game_state.hh:5
PlayerType
Definition: game_state.hh:11
wxPersistentObject * wxCreatePersistentObject(NewGameDialog *dialog)
int wxWindowID