45#include <guichan/font.hpp>
52 mVersionStrings(servers->size(),
VersionString(0, std::string())),
108 graphics->fillRectangle(gcn::Rectangle(0, height * mSelected,
109 getWidth(), height));
113 for (
int i = 0, y = 0; i < model->getNumberOfElements();
123 if (!info.name.empty())
131 int top = y + height / 2;
135 if (info.version.first > 0)
141 getWidth() - info.version.first - 2, top);
148 return 2 * getFont()->getHeight();
154 Window(
_(
"Choose Your Server")),
156 mServerInfo(serverInfo)
166 usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
179 usedScroll->setVerticalScrollAmount(0);
195 int width = 0, height = 0;
210 addKeyListener(
this);
227 if (event.getId() ==
"ok")
232 else if (event.getId() ==
"connect")
238#ifndef MANASERV_SUPPORT
244 _(
"Please select a valid server."));
245 dlg->addActionListener(
this);
272 else if (event.getId() ==
"quit")
277 else if (event.getId() ==
"addEntry")
282 else if (event.getId() ==
"modify")
289 _(
"Please select a custom server."));
290 dlg->addActionListener(
this);
297 else if (event.getId() ==
"remove")
309 gcn::Key key = keyEvent.getKey();
357 switch (state.status) {
361 state.progress * 100));
393 if (listFile.empty())
397 if (listFile.empty())
398 listFile =
"https://www.manasource.org/serverlist.xml";
400 mDownload = std::make_unique<Net::Download>(listFile);
410 if (!rootNode || rootNode.
name() !=
"serverlist")
419 Log::error(
"Unsupported online server list version: %d", version);
423 for (
auto serverNode : rootNode.
children())
425 if (serverNode.name() ==
"server")
434 std::string type = serverNode.
getProperty(
"type",
"unknown");
440#ifndef MANASERV_SUPPORT
445 Log::info(
"Ignoring server entry with unknown type: %s",
452 std::string version = serverNode.
getProperty(
"minimumVersion",
455 bool meetsMinimumVersion = strcmp(version.c_str(), PACKAGE_VERSION) <= 0;
458 if (meetsMinimumVersion)
460 else if (version.empty())
461 version =
_(
"requires a newer version");
463 version =
strprintf(
_(
"requires v%s"), version.c_str());
465 for (
auto subNode : serverNode.
children())
467 if (subNode.name() ==
"connection")
469 server.
hostname = subNode.getProperty(
"hostname", std::string());
470 server.
port = subNode.getProperty(
"port", 0);
471 if (server.
port == 0)
477 else if (subNode.name() ==
"description")
481 else if (subNode.name() ==
"persistentIp")
483 const auto text = subNode.textContent();
489 server.
version.second = version;
499 s.name = server.
name;
516 if (server.isValid())
531 for (
auto it =
mServers.begin(), it_end =
mServers.end(); it != it_end; ++it)
533 if (*it == currentServer)
548 if (
static_cast<size_t>(index) <
mServers.size())
ChatLogger * chatLogger
Chat log object.
void setServerName(const std::string &serverName)
static void setState(State state)
std::string getStringValue(const std::string &key) const
void drawText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color &color, gcn::Font *font, bool outline=false, bool shadow=false, const std::optional< gcn::Color > &outlineColor={}, const std::optional< gcn::Color > &shadowColor={})
void setColor(const gcn::Color &color) override
gcn::Font * getFont() const
Return game font.
Theme * getTheme() const
The global GUI theme.
void setRowHeight(int n, int h)
LayoutCell & setPadding(int p)
Sets the padding around the cell content.
void reflow(int &nW, int &nH)
Sets the positions of all the widgets.
A list box, meant to be used inside a scroll area.
The server choice dialog.
void valueChanged(const gcn::SelectionEvent &event) override
Called when the selected value changed in the servers list box.
void saveCustomServers(const ServerInfo ¤tServer=ServerInfo(), int index=-1)
Saves the new server entry in the custom server list.
void downloadServerList()
Called to load a list of available server from an online xml file.
void keyPressed(gcn::KeyEvent &keyEvent) override
ServerDialog(ServerInfo *serverInfo, const std::string &dir)
void loadServer(XML::Node serverNode)
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
Button * mManualEntryButton
friend class CustomServerDialog
std::unique_ptr< ServersListModel > mServersListModel
void mouseClicked(gcn::MouseEvent &mouseEvent) override
std::unique_ptr< Net::Download > mDownload
static ServerType parseType(const std::string &type)
static uint16_t defaultPortForServerType(ServerType type)
unsigned int getRowHeight() const override
void draw(gcn::Graphics *graphics) override
ServersListBox(ServersListModel *model)
Server and Port List Model.
std::pair< int, std::string > VersionString
std::string getElementAt(int elementIndex) override
Used to get an element from the list.
int getNumberOfElements() override
Used to get number of line in the list.
std::vector< VersionString > mVersionStrings
ServersListModel(ServerInfos *servers, ServerDialog *parent)
void setVersionString(int index, const std::string &version)
int getGuiAlpha() const
Get the current GUI alpha value.
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
@ SERVER_VERSION_NOT_SUPPORTED
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
void setMinHeight(int height)
Sets the minimum height of the window.
void setContentSize(int width, int height)
Sets the size of this window.
Layout & getLayout()
Gets the layout handler for this window.
void setWindowName(const std::string &name)
Sets the name of the window.
void setResizable(bool resize)
Sets whether or not the window can be resized.
LayoutCell & place(int x, int y, gcn::Widget *, int w=1, int h=1)
Adds a widget to the window and sets it at given cell.
void setDefaultSize()
Set the default win pos and size to the current ones.
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
void setMinWidth(int width)
Sets the minimum width of the window.
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
std::string_view name() const
int getProperty(const char *name, int def) const
Children children() const
Config config
Global settings (config.xml)
bool isDoubleClick(int selected)
Returns whether this call and the last call were done for the same selected index and within a short ...
Configuration branding
XML branding information reader.
gcn::Font * boldFont
Bolded text font.
void info(const char *log_text,...) LOG_PRINTF_ATTR
void error(const char *log_text,...) LOG_PRINTF_ATTR
std::deque< ServerInfo > ServerInfos
std::string strprintf(char const *format,...)
A safe version of sprintf that returns a std::string of the result.
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.
std::string onlineServerList