Mana
Loading...
Searching...
No Matches
helpwindow.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "gui/helpwindow.h"
23
24#include "gui/gui.h"
25#include "gui/setup.h"
26
27#include "gui/widgets/button.h"
29#include "gui/widgets/layout.h"
31
32#include "configuration.h"
33
34#include "log.h"
35#include "utils/filesystem.h"
36#include "utils/gettext.h"
37
39 Window(_("Help"))
40{
41 setMinWidth(300);
42 setMinHeight(250);
43 setContentSize(455, 350);
44 setWindowName("Help");
45 setResizable(true);
47
49
52 auto *okButton = new Button(_("Close"), "close", this);
53
55 mBrowserBox->setFont(monoFont);
56
57 place(0, 0, mScrollArea, 5, 3).setPadding(3);
58 place(4, 3, okButton);
59
60 Layout &layout = getLayout();
62
64}
65
66void HelpWindow::action(const gcn::ActionEvent &event)
67{
68 if (event.getId() == "close")
69 setVisible(false);
70}
71
72void HelpWindow::handleLink(const std::string &link)
73{
74 std::string helpFile = link;
75 loadHelp(helpFile);
76}
77
78void HelpWindow::loadHelp(const std::string &helpFile)
79{
81
82 loadFile("header");
83 loadFile(helpFile);
84
85 mScrollArea->setVerticalScrollAmount(0);
86 setVisible(true);
87}
88
89void HelpWindow::loadFile(const std::string &file)
90{
91 std::string helpPath = branding.getStringValue("helpPath");
92 if (helpPath.empty())
93 helpPath = paths.getStringValue("help");
94
95 const std::string fileName = helpPath + file + ".txt";
96
97 size_t contentsLength;
98 char *fileContents = (char *) FS::loadFile(fileName, contentsLength);
99 if (!fileContents)
100 {
101 Log::info("Couldn't load text file: %s", fileName.c_str());
102 return;
103 }
104
105 mBrowserBox->addRows(std::string_view(fileContents, contentsLength));
106 SDL_free(fileContents);
107}
A simple browser box able to handle links and forward events to the parent conteiner.
Definition browserbox.h:74
void addRows(std::string_view rows)
Adds one or more text rows to the browser, separated by ' '.
void setLinkHandler(LinkHandler *handler)
Sets the handler for links.
Definition browserbox.h:88
void clearRows()
Remove all rows.
Button widget.
Definition button.h:38
std::string getStringValue(const std::string &key) const
gcn::ScrollArea * mScrollArea
Definition helpwindow.h:60
void loadFile(const std::string &file)
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
void handleLink(const std::string &link) override
Handles link action.
void loadHelp(const std::string &helpFile)
Loads help in the dialog.
BrowserBox * mBrowserBox
Definition helpwindow.h:59
void setRowHeight(int n, int h)
Definition layout.h:221
LayoutCell & setPadding(int p)
Sets the padding around the cell content.
Definition layout.h:179
This class is an helper for setting the position of widgets.
Definition layout.h:281
@ AUTO_SET
Uses the share as the new size.
Definition layout.h:304
A scroll area.
Definition scrollarea.h:38
void registerWindowForReset(Window *window)
Enables the Reset Windows button.
Definition setup.cpp:108
A window.
Definition window.h:59
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Definition window.cpp:282
void setMinHeight(int height)
Sets the minimum height of the window.
Definition window.cpp:197
void setContentSize(int width, int height)
Sets the size of this window.
Definition window.cpp:151
Layout & getLayout()
Gets the layout handler for this window.
Definition window.cpp:714
void setWindowName(const std::string &name)
Sets the name of the window.
Definition window.h:272
void setResizable(bool resize)
Sets whether or not the window can be resized.
Definition window.cpp:212
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.
Definition window.cpp:737
void setDefaultSize()
Set the default win pos and size to the current ones.
Definition window.cpp:545
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
Definition window.cpp:467
void setMinWidth(int width)
Sets the minimum width of the window.
Definition window.cpp:192
Configuration paths
XML default paths information reader.
Definition client.cpp:99
Configuration branding
XML branding information reader.
Definition client.cpp:98
#define _(s)
Definition gettext.h:38
gcn::Font * monoFont
Monospaced text font.
Definition gui.cpp:57
void * loadFile(const std::string &path, size_t &datasize)
Definition filesystem.h:288
void info(const char *log_text,...) LOG_PRINTF_ATTR
Setup * setupWindow
Definition setup.cpp:120