ManaPlus
worldselectdialog.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "client.h"
27 #include "settings.h"
28 
29 #include "gui/widgets/button.h"
31 #include "gui/widgets/layout.h"
32 #include "gui/widgets/listbox.h"
33 #include "gui/widgets/scrollarea.h"
34 
36 
37 #include "net/loginhandler.h"
38 
39 #include "utils/delete2.h"
40 #include "utils/gettext.h"
41 
42 #include "debug.h"
43 
44 extern WorldInfo **server_info;
45 
47  // TRANSLATORS: world select dialog name
48  Window(_("Select World"), Modal_false, nullptr, "world.xml"),
50  KeyListener(),
51  mWorldListModel(new WorldListModel(worlds)),
52  mWorldList(CREATEWIDGETR(ListBox, this, mWorldListModel, "")),
53  // TRANSLATORS: world dialog button
54  mChangeLoginButton(new Button(this, _("Change Login"), "login",
55  BUTTON_SKIN, this)),
56  // TRANSLATORS: world dialog button
57  mChooseWorld(new Button(this, _("Choose World"), "world",
58  BUTTON_SKIN, this))
59 {
60  ScrollArea *const worldsScroll = new ScrollArea(this, mWorldList,
61  fromBool(getOptionBool("showbackground", false), Opaque),
62  "world_background.xml");
63 
65 
66  place(0, 0, worldsScroll, 3, 5).setPadding(2);
67  place(1, 5, mChangeLoginButton, 1, 1);
68  place(2, 5, mChooseWorld, 1, 1);
69 
70  // Make sure the list has enough height
71  getLayout().setRowHeight(0, 60);
72 
73  reflowLayout(0, 0);
74 
75  if (worlds.empty())
76  {
77  // Disable Ok button
78  mChooseWorld->setEnabled(false);
79  }
80  else
81  {
82  // Select first server
84  }
85 
86  addKeyListener(this);
87 
88  center();
89 }
90 
92 {
96 }
97 
99 {
101 }
102 
104 {
105  const std::string &eventId = event.getId();
106  if (eventId == "world")
107  {
109  mChooseWorld->setEnabled(false);
112 
113  // Check in case netcode moves us forward
116  }
117  else if (eventId == "login")
118  {
120  }
121 }
122 
124 {
125  const InputActionT actionId = event.getActionId();
126 
127  if (actionId == InputAction::GUI_CANCEL)
128  {
129  action(ActionEvent(nullptr,
131  }
132  else if (actionId == InputAction::GUI_SELECT ||
133  actionId == InputAction::GUI_SELECT2)
134  {
136  }
137 }
#define fromBool(val, name)
Definition: booldefines.h:49
const std::string BUTTON_SKIN
Definition: button.h:89
Definition: button.h:102
void setState(const StateT state)
Definition: client.h:66
StateT getState() const
Definition: client.h:69
LayoutCell & setPadding(int p)
Definition: layoutcell.h:60
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:128
int getSelected() const
Definition: listbox.h:168
void setSelected(const int selected)
Definition: listbox.cpp:399
virtual void chooseServer(unsigned int server, const bool persistentIp) const =0
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
bool persistentIp
Definition: settings.h:153
void setEnabled(const bool enabled)
Definition: widget.h:352
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
virtual void requestFocus()
Definition: widget.cpp:204
const std::string & getActionEventId() const
Definition: widget.h:605
Definition: window.h:102
void center()
Definition: window.cpp:1417
virtual void setVisible(Visible visible)
Definition: window.cpp:778
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1466
void reflowLayout(int w, int h)
Definition: window.cpp:1396
Layout & getLayout()
Definition: window.cpp:1365
void postInit()
Definition: window.cpp:249
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1384
void action(const ActionEvent &event)
void keyPressed(KeyEvent &event)
WorldListModel * mWorldListModel
WorldSelectDialog(const Worlds &worlds)
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
#define new
Definition: debug_new.h:147
#define delete2(var)
Definition: delete2.h:25
Client * client
Definition: client.cpp:118
#define _(s)
Definition: gettext.h:35
InputAction ::T InputActionT
Definition: inputaction.h:717
#define nullptr
Definition: localconsts.h:45
Net::LoginHandler * loginHandler
Definition: net.cpp:90
const bool Modal_false
Definition: modal.h:30
@ WORLD_SELECT_ATTEMPT
Definition: state.h:43
@ WORLD_SELECT
Definition: state.h:42
@ SWITCH_LOGIN
Definition: state.h:63
bool Opaque
Definition: opaque.h:30
Settings settings
Definition: settings.cpp:32
const bool Visible_true
Definition: visible.h:30
std::vector< WorldInfo * > Worlds
Definition: worldinfo.h:59
WorldInfo ** server_info