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-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
24 
25 #include "client.h"
26 #include "settings.h"
27 
28 #include "gui/widgets/button.h"
30 #include "gui/widgets/layout.h"
31 #include "gui/widgets/listbox.h"
32 #include "gui/widgets/scrollarea.h"
33 
35 
36 #include "net/loginhandler.h"
37 
38 #include "utils/delete2.h"
39 #include "utils/gettext.h"
40 
41 #include "debug.h"
42 
43 extern WorldInfo **server_info;
44 
46  // TRANSLATORS: world select dialog name
47  Window(_("Select World"), Modal_false, nullptr, "world.xml"),
49  KeyListener(),
50  mWorldListModel(new WorldListModel(worlds)),
51  mWorldList(CREATEWIDGETR(ListBox, this, mWorldListModel, "")),
52  // TRANSLATORS: world dialog button
53  mChangeLoginButton(new Button(this, _("Change Login"), "login",
54  BUTTON_SKIN, this)),
55  // TRANSLATORS: world dialog button
56  mChooseWorld(new Button(this, _("Choose World"), "world",
57  BUTTON_SKIN, this))
58 {
59  ScrollArea *const worldsScroll = new ScrollArea(this, mWorldList,
60  fromBool(getOptionBool("showbackground", false), Opaque),
61  "world_background.xml");
62 
64 
65  place(0, 0, worldsScroll, 3, 5).setPadding(2);
66  place(1, 5, mChangeLoginButton, 1, 1);
67  place(2, 5, mChooseWorld, 1, 1);
68 
69  // Make sure the list has enough height
70  getLayout().setRowHeight(0, 60);
71 
72  reflowLayout(0, 0);
73 
74  if (worlds.empty())
75  {
76  // Disable Ok button
77  mChooseWorld->setEnabled(false);
78  }
79  else
80  {
81  // Select first server
83  }
84 
85  addKeyListener(this);
86 
87  center();
88 }
89 
91 {
95 }
96 
98 {
100 }
101 
103 {
104  const std::string &eventId = event.getId();
105  if (eventId == "world")
106  {
108  mChooseWorld->setEnabled(false);
111 
112  // Check in case netcode moves us forward
115  }
116  else if (eventId == "login")
117  {
119  }
120 }
121 
123 {
124  const InputActionT actionId = event.getActionId();
125 
126  if (actionId == InputAction::GUI_CANCEL)
127  {
128  action(ActionEvent(nullptr,
130  }
131  else if (actionId == InputAction::GUI_SELECT ||
132  actionId == InputAction::GUI_SELECT2)
133  {
135  }
136 }
std::vector< WorldInfo * > Worlds
Definition: worldinfo.h:58
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1383
#define _(s)
Definition: gettext.h:34
void setSelected(const int selected)
Definition: listbox.cpp:398
void action(const ActionEvent &event)
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1465
void setState(const StateT state)
Definition: client.h:65
const bool Visible_true
Definition: visible.h:29
bool persistentIp
Definition: settings.h:150
Definition: window.h:98
Definition: button.h:96
const std::string & getActionEventId() const
Definition: widget.h:604
Client * client
Definition: client.cpp:117
#define delete2(var)
Definition: delete2.h:24
void keyPressed(KeyEvent &event)
WorldInfo ** server_info
#define new
Definition: debug_new.h:147
Settings settings
Definition: settings.cpp:31
virtual void requestFocus()
Definition: widget.cpp:203
const std::string BUTTON_SKIN
Definition: button.h:88
Net::LoginHandler * loginHandler
Definition: net.cpp:87
#define fromBool(val, name)
Definition: booldefines.h:48
virtual void chooseServer(unsigned int server, const bool persistentIp) const =0
int getSelected() const
Definition: listbox.h:167
InputAction ::T InputActionT
Definition: inputaction.h:715
#define nullptr
Definition: localconsts.h:44
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
void setEnabled(const bool enabled)
Definition: widget.h:351
LayoutCell & setPadding(int p)
Definition: layoutcell.h:59
Layout & getLayout()
Definition: window.cpp:1364
virtual void setVisible(Visible visible)
Definition: window.cpp:777
void center()
Definition: window.cpp:1416
WorldListModel * mWorldListModel
StateT getState() const
Definition: client.h:68
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
WorldSelectDialog(const Worlds &worlds)
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
void reflowLayout(int w, int h)
Definition: window.cpp:1395
void postInit()
Definition: window.cpp:248
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)