Merge lp:~widelands-dev/widelands/multiplayer_help into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7620
Proposed branch: lp:~widelands-dev/widelands/multiplayer_help
Merge into: lp:widelands
Diff against target: 761 lines (+254/-293)
13 files modified
scripting/widelands/multiplayer_help.lua (+32/-0)
src/ui_basic/CMakeLists.txt (+0/-2)
src/ui_basic/button.cc (+3/-2)
src/ui_fsmenu/CMakeLists.txt (+2/-0)
src/ui_fsmenu/helpwindow.cc (+123/-0)
src/ui_fsmenu/helpwindow.h (+61/-0)
src/ui_fsmenu/launch_mpg.cc (+7/-49)
src/ui_fsmenu/launch_mpg.h (+3/-2)
src/wui/CMakeLists.txt (+2/-0)
src/wui/buildingwindow.cc (+3/-3)
src/wui/helpwindow.cc (+8/-175)
src/wui/helpwindow.h (+9/-60)
utils/buildcat.py (+1/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/multiplayer_help
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+274271@code.launchpad.net

Description of the change

The Multiplayer help window now gets its contents from Lua, and its button will resize according to actual text height.

Split up the wui and ui_fsmenu components of helpwindow.cc/h into separate files and moved them away from ui_basic.

To post a comment you must log in.
Revision history for this message
TiborB (tiborb95) wrote :

How can I trigger this help? I have no idea...

Revision history for this message
GunChleoc (gunchleoc) wrote :

Ths affects 2 help windows:

1. Set up a new Multiplayer game, but don't start it. There is a ? button on the top right explaining how the game setup works.

2. Start a game, select a building, click on ? on the bottom right.

Revision history for this message
TiborB (tiborb95) wrote :

OK, I tested it, and the code LGTM

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'scripting/widelands'
2=== added file 'scripting/widelands/multiplayer_help.lua'
3--- scripting/widelands/multiplayer_help.lua 1970-01-01 00:00:00 +0000
4+++ scripting/widelands/multiplayer_help.lua 2015-11-06 19:00:56 +0000
5@@ -0,0 +1,32 @@
6+include "scripting/formatting.lua"
7+
8+function picture_li(imagepath, text)
9+ return "<rt image=" .. imagepath .. " image-align=left>" .. p(text) .. "</rt>"
10+end
11+
12+return {
13+ func = function()
14+ set_textdomain("widelands")
15+ local result = rt(h1(_"Multiplayer Game Setup"))
16+ result = result .. rt(p(_"You are in the multiplayer launch game menu."))
17+
18+
19+ result = result .. rt(h2(_"Client settings"))
20+ result = result .. rt(p(_"On the left side is a list of all clients including you. You can set your role with the button following your nickname. Available roles are:"))
21+ result = result .. picture_li("pics/genstats_enable_plr_08.png", _"The player with the color of the flag. If more than one client selected the same color, these share control over the player (‘shared kingdom mode’).")
22+ result = result .. picture_li("pics/menu_tab_watch.png", _"Spectator mode, meaning you can see everything, but cannot control any player")
23+
24+ result = result .. rt(h2(_"Player settings"))
25+ result = result .. rt(p(_"In the middle are the settings for the players. To start a game, each player must be one of the following:"))
26+ result = result .. picture_li("pics/genstats_nrworkers.png", _"Connected to one or more clients (see ‘Client settings’).")
27+ result = result .. picture_li("pics/ai_Normal.png", _"Connected to a computer player (the face in the picture as well as the mouse hover texts indicate the strength of the currently selected computer player).")
28+ result = result .. picture_li("pics/shared_in.png", _"Set as shared in starting position for another player.")
29+ result = result .. picture_li("pics/stop.png", _"Closed.")
30+ result = result .. rt(p(_"The latter three can only be set by the hosting client by left-clicking the ‘type’ button of a player. Hosting players can also set the initialization of each player (the set of buildings, wares and workers the player starts with) and the tribe and team for computer players"))
31+ result = result .. rt(p(_"Every client connected to a player (the set ‘role’ player) can set the tribe and the team for that player"))
32+
33+ result = result .. rt(h2(_"Map details"))
34+ result = result .. rt(p(_"You can see information about the selected map or savegame on the right-hand side. A button next to the map name allows the host to change to a different map. Furthermore, the host is able to set a specific win condition, and finally can start the game as soon as all players are set up."))
35+ return result
36+ end
37+}
38
39=== modified file 'src/ui_basic/CMakeLists.txt'
40--- src/ui_basic/CMakeLists.txt 2015-01-31 16:03:59 +0000
41+++ src/ui_basic/CMakeLists.txt 2015-11-06 19:00:56 +0000
42@@ -8,8 +8,6 @@
43 checkbox.h
44 editbox.cc
45 editbox.h
46- helpwindow.cc
47- helpwindow.h
48 icon.cc
49 icon.h
50 icongrid.cc
51
52=== modified file 'src/ui_basic/button.cc'
53--- src/ui_basic/button.cc 2015-10-11 09:47:05 +0000
54+++ src/ui_basic/button.cc 2015-11-06 19:00:56 +0000
55@@ -19,7 +19,6 @@
56
57 #include "ui_basic/button.h"
58
59-#include "base/log.h"
60 #include "graphic/font_handler1.h"
61 #include "graphic/image.h"
62 #include "graphic/rendertarget.h"
63@@ -58,7 +57,9 @@
64 {
65 // Automatically resize for font height and give it a margin.
66 if (h < 1) {
67- set_desired_size(w, UI::g_fh1->render(as_uifont("."))->height() + 4);
68+ int new_height = UI::g_fh1->render(as_uifont("."))->height() + 4;
69+ set_desired_size(w, new_height);
70+ set_size(w, new_height);
71 }
72 set_thinks(false);
73 }
74
75=== modified file 'src/ui_fsmenu/CMakeLists.txt'
76--- src/ui_fsmenu/CMakeLists.txt 2015-10-31 10:42:51 +0000
77+++ src/ui_fsmenu/CMakeLists.txt 2015-11-06 19:00:56 +0000
78@@ -6,6 +6,8 @@
79 campaign_select.h
80 fileview.cc
81 fileview.h
82+ helpwindow.cc
83+ helpwindow.h
84 internet_lobby.cc
85 internet_lobby.h
86 intro.cc
87
88=== added file 'src/ui_fsmenu/helpwindow.cc'
89--- src/ui_fsmenu/helpwindow.cc 1970-01-01 00:00:00 +0000
90+++ src/ui_fsmenu/helpwindow.cc 2015-11-06 19:00:56 +0000
91@@ -0,0 +1,123 @@
92+/*
93+ * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team
94+ *
95+ * This program is free software; you can redistribute it and/or
96+ * modify it under the terms of the GNU General Public License
97+ * as published by the Free Software Foundation; either version 2
98+ * of the License, or (at your option) any later version.
99+ *
100+ * This program is distributed in the hope that it will be useful,
101+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
102+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103+ * GNU General Public License for more details.
104+ *
105+ * You should have received a copy of the GNU General Public License
106+ * along with this program; if not, write to the Free Software
107+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
108+ *
109+ */
110+
111+#include "ui_fsmenu/helpwindow.h"
112+
113+#include <memory>
114+#include <string>
115+
116+#include <boost/format.hpp>
117+
118+#include "base/i18n.h"
119+#include "graphic/graphic.h"
120+#include "scripting/lua_coroutine.h"
121+#include "scripting/lua_table.h"
122+#include "ui_basic/button.h"
123+
124+namespace UI {
125+
126+FullscreenHelpWindow::FullscreenHelpWindow
127+ (Panel * const parent,
128+ LuaInterface* lua,
129+ const std::string& script_path,
130+ const std::string & caption,
131+ uint32_t width, uint32_t height)
132+ :
133+ Window(parent, "help_window", 0, 0, width, height, (boost::format(_("Help: %s")) % caption).str()),
134+ textarea_(new MultilineTextarea(this, 5, 5, width - 10, height - 30, std::string(), Align_Left))
135+{
136+ int margin = 5;
137+
138+ // Calculate sizes
139+ width = (width == 0) ? g_gr->get_xres() * 3 / 5 : width;
140+ height = (height == 0) ? g_gr->get_yres() * 4 / 5 : height;
141+
142+ Button* btn = new Button(this, "ok", width / 3, 0, width / 3, 0,
143+ g_gr->images().get("pics/but5.png"),
144+ _("OK"), "", true, false);
145+
146+ btn->sigclicked.connect(boost::bind(&FullscreenHelpWindow::clicked_ok, boost::ref(*this)));
147+ btn->set_pos(Point(btn->get_x(), height - margin - btn->get_h()));
148+
149+ std::string helptext;
150+ try {
151+ std::unique_ptr<LuaTable> t(lua->run_script(script_path));
152+ std::unique_ptr<LuaCoroutine> cr(t->get_coroutine("func"));
153+ cr->resume();
154+ helptext = cr->pop_string();
155+ } catch (LuaError& err) {
156+ helptext = err.what();
157+ }
158+
159+ textarea_->set_size(width - 2 * margin, height - btn->get_h() - 3 * margin);
160+ textarea_->set_text(helptext);
161+
162+ set_inner_size(width, height);
163+ center_to_parent();
164+ focus();
165+}
166+
167+
168+/**
169+ * Handle mouseclick.
170+ *
171+ * Clicking the right mouse button inside the window acts like pressing Ok.
172+ */
173+bool FullscreenHelpWindow::handle_mousepress(const uint8_t btn, int32_t, int32_t)
174+{
175+ if (btn == SDL_BUTTON_RIGHT) {
176+ play_click();
177+ clicked_ok();
178+ }
179+ return true;
180+}
181+
182+bool FullscreenHelpWindow::handle_mouserelease(const uint8_t, int32_t, int32_t)
183+{
184+ return true;
185+}
186+
187+bool FullscreenHelpWindow::handle_key(bool down, SDL_Keysym code)
188+{
189+ if (down) {
190+ switch (code.sym) {
191+ case SDLK_KP_ENTER:
192+ case SDLK_RETURN:
193+ clicked_ok();
194+ return true;
195+ default:
196+ return true; // handled
197+ }
198+ }
199+ return true;
200+}
201+
202+
203+void FullscreenHelpWindow::clicked_ok()
204+{
205+ if (is_modal())
206+ end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
207+ else {
208+ // Do not call die() here - could lead to broken pointers.
209+ // The window should get deleted with the parent anyways - best use a unique_ptr there.
210+ set_visible(false);
211+ }
212+}
213+
214+} // namespace UI
215
216=== added file 'src/ui_fsmenu/helpwindow.h'
217--- src/ui_fsmenu/helpwindow.h 1970-01-01 00:00:00 +0000
218+++ src/ui_fsmenu/helpwindow.h 2015-11-06 19:00:56 +0000
219@@ -0,0 +1,61 @@
220+/*
221+ * Copyright (C) 2002-2004, 2006, 2008-2010 by the Widelands Development Team
222+ *
223+ * This program is free software; you can redistribute it and/or
224+ * modify it under the terms of the GNU General Public License
225+ * as published by the Free Software Foundation; either version 2
226+ * of the License, or (at your option) any later version.
227+ *
228+ * This program is distributed in the hope that it will be useful,
229+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
230+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
231+ * GNU General Public License for more details.
232+ *
233+ * You should have received a copy of the GNU General Public License
234+ * along with this program; if not, write to the Free Software
235+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
236+ *
237+ */
238+
239+#ifndef WL_UI_FSMENU_HELPWINDOW_H
240+#define WL_UI_FSMENU_HELPWINDOW_H
241+
242+#include <memory>
243+
244+#include "scripting/lua_interface.h"
245+#include "ui_basic/multilinetextarea.h"
246+#include "ui_basic/window.h"
247+
248+
249+namespace UI {
250+
251+/**
252+ * Shows a help window with an OK button.
253+ * See scripting/widelands/multiplayer_help.lua for an example Lua file.
254+ */
255+class FullscreenHelpWindow : public Window {
256+public:
257+ FullscreenHelpWindow
258+ (Panel * parent,
259+ LuaInterface* lua,
260+ const std::string& script_path,
261+ const std::string & caption,
262+ uint32_t width = 0, uint32_t height = 0);
263+
264+ bool handle_mousepress (uint8_t btn, int32_t mx, int32_t my) override;
265+ bool handle_mouserelease(uint8_t btn, int32_t mx, int32_t my) override;
266+
267+ /// Handle keypresses
268+ bool handle_key(bool down, SDL_Keysym code) override;
269+
270+protected:
271+ void clicked_ok();
272+
273+private:
274+ std::unique_ptr<MultilineTextarea> textarea_;
275+};
276+
277+
278+} // namespace UI
279+
280+#endif // end of include guard: WL_UI_FSMENU_HELPWINDOW_H
281
282=== modified file 'src/ui_fsmenu/launch_mpg.cc'
283--- src/ui_fsmenu/launch_mpg.cc 2015-10-23 16:32:05 +0000
284+++ src/ui_fsmenu/launch_mpg.cc 2015-11-06 19:00:56 +0000
285@@ -240,8 +240,6 @@
286 FullscreenMenuLaunchMPG::~FullscreenMenuLaunchMPG() {
287 delete m_lua;
288 delete m_mpsg;
289- if (m_help)
290- delete m_help;
291 delete m_chat;
292 }
293
294@@ -667,51 +665,11 @@
295
296 /// Show help
297 void FullscreenMenuLaunchMPG::help_clicked() {
298- if (m_help)
299- delete m_help;
300- m_help = new UI::HelpWindow(this, _("Multiplayer Game Setup"), m_fs);
301- m_help->add_paragraph(_("You are in the multiplayer launch game menu."));
302- m_help->add_heading(_("Client settings"));
303- m_help->add_paragraph
304- (_
305- ("On the left side is a list of all clients including you. You can set your role "
306- "with the button following your nickname. Available roles are:"));
307- m_help->add_picture_li
308- (_
309- ("The player with the color of the flag. If more than one client selected the same color, these "
310- "share control over the player (‘shared kingdom mode’)."),
311- "pics/genstats_enable_plr_08.png");
312- m_help->add_picture_li
313- (_("Spectator mode, meaning you can see everything, but cannot control any player"),
314- "pics/menu_tab_watch.png");
315- m_help->add_heading(_("Player settings"));
316- m_help->add_paragraph
317- (_
318- ("In the middle are the settings for the players. To start a game, each player must be one of the "
319- "following:"));
320- m_help->add_picture_li
321- (_("Connected to one or more clients (see ‘Client settings’)."), "pics/genstats_nrworkers.png");
322- m_help->add_picture_li
323- (_
324- ("Connected to a computer player (the face in the picture as well as the mouse hover texts "
325- "indicate the strength of the currently selected computer player)."),
326- "pics/ai_Normal.png");
327- m_help->add_picture_li(_("Set as shared in starting position for another player."), "pics/shared_in.png");
328- m_help->add_picture_li(_("Closed."), "pics/stop.png");
329- m_help->add_block
330- (_
331- ("The latter three can only be set by the hosting client by left-clicking the ‘type’ button of a "
332- "player. Hosting players can also set the initialization of each player (the set of buildings, "
333- "wares and workers the player starts with) and the tribe and team for computer players"));
334- m_help->add_block
335- (_
336- ("Every client connected to a player (the set ‘role’ player) can set the tribe and the team "
337- "for that player"));
338- m_help->add_heading(_("Map details"));
339- m_help->add_paragraph
340- (_
341- ("You can see information about the selected map or savegame on the right-hand side. "
342- "A button next to the map name allows the host to change to a different map. "
343- "Furthermore, the host is able to set a specific win condition, and finally "
344- "can start the game as soon as all players are set up."));
345+ if (m_help) {
346+ m_help->set_visible(true);
347+ } else {
348+ m_help.reset(new UI::FullscreenHelpWindow(this, m_lua, "scripting/widelands/multiplayer_help.lua",
349+ /** TRANSLATORS: This is a heading for a help window */
350+ _("Multiplayer Game Setup")));
351+ }
352 }
353
354=== modified file 'src/ui_fsmenu/launch_mpg.h'
355--- src/ui_fsmenu/launch_mpg.h 2015-10-02 07:02:00 +0000
356+++ src/ui_fsmenu/launch_mpg.h 2015-11-06 19:00:56 +0000
357@@ -20,11 +20,12 @@
358 #ifndef WL_UI_FSMENU_LAUNCH_MPG_H
359 #define WL_UI_FSMENU_LAUNCH_MPG_H
360
361+#include <memory>
362 #include <string>
363
364 #include "ui_fsmenu/base.h"
365+#include "ui_fsmenu/helpwindow.h"
366 #include "ui_basic/button.h"
367-#include "ui_basic/helpwindow.h"
368 #include "ui_basic/listselect.h"
369 #include "ui_basic/multilinetextarea.h"
370 #include "ui_basic/textarea.h"
371@@ -85,7 +86,7 @@
372 UI::Button m_help_button;
373 UI::Textarea m_title, m_mapname, m_clients, m_players, m_map, m_wincondition_type;
374 UI::MultilineTextarea m_map_info, m_client_info;
375- UI::HelpWindow * m_help;
376+ std::unique_ptr<UI::FullscreenHelpWindow> m_help;
377 GameSettingsProvider * m_settings;
378 GameController * m_ctrl;
379 GameChatPanel * m_chat;
380
381=== modified file 'src/wui/CMakeLists.txt'
382--- src/wui/CMakeLists.txt 2015-10-31 10:42:51 +0000
383+++ src/wui/CMakeLists.txt 2015-11-06 19:00:56 +0000
384@@ -106,6 +106,8 @@
385 game_tips.h
386 general_statistics_menu.cc
387 general_statistics_menu.h
388+ helpwindow.cc
389+ helpwindow.h
390 interactive_base.cc
391 interactive_base.h
392 interactive_gamebase.cc
393
394=== modified file 'src/wui/buildingwindow.cc'
395--- src/wui/buildingwindow.cc 2015-10-21 16:43:30 +0000
396+++ src/wui/buildingwindow.cc 2015-11-06 19:00:56 +0000
397@@ -33,10 +33,10 @@
398 #include "logic/productionsite.h"
399 #include "logic/tribes/tribe_descr.h"
400 #include "logic/warehouse.h"
401-#include "ui_basic/helpwindow.h"
402 #include "ui_basic/tabpanel.h"
403 #include "wui/actionconfirm.h"
404 #include "wui/game_debug_ui.h"
405+#include "wui/helpwindow.h"
406 #include "wui/interactive_player.h"
407 #include "wui/unique_window_handler.h"
408 #include "wui/waresqueuedisplay.h"
409@@ -360,8 +360,8 @@
410 UI::UniqueWindow::Registry& registry =
411 igbase().unique_windows().get_registry(m_building.descr().name() + "_help");
412 registry.open_window = [this, &registry] {
413- new UI::LuaTextHelpWindow(
414- &igbase(), registry, m_building.descr(), building().owner().tribe(), &igbase().egbase().lua());
415+ new UI::BuildingHelpWindow(
416+ &igbase(), registry, m_building.descr(), m_building.owner().tribe(), &igbase().egbase().lua());
417 };
418
419 helpbtn->sigclicked.connect(boost::bind(&UI::UniqueWindow::Registry::toggle, boost::ref(registry)));
420
421=== renamed file 'src/ui_basic/helpwindow.cc' => 'src/wui/helpwindow.cc'
422--- src/ui_basic/helpwindow.cc 2015-11-02 19:29:03 +0000
423+++ src/wui/helpwindow.cc 2015-11-06 19:00:56 +0000
424@@ -1,4 +1,4 @@
425-/*
426+/*
427 * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team
428 *
429 * This program is free software; you can redistribute it and/or
430@@ -17,7 +17,7 @@
431 *
432 */
433
434-#include "ui_basic/helpwindow.h"
435+#include "wui/helpwindow.h"
436
437 #include <memory>
438 #include <string>
439@@ -25,178 +25,14 @@
440 #include <boost/format.hpp>
441
442 #include "base/i18n.h"
443-#include "base/log.h"
444-#include "graphic/font.h"
445-#include "graphic/font_handler1.h"
446-#include "graphic/graphic.h"
447-#include "graphic/text/font_set.h"
448-#include "graphic/text_constants.h"
449-#include "io/filesystem/layered_filesystem.h"
450 #include "logic/building.h"
451 #include "scripting/lua_interface.h"
452 #include "scripting/lua_table.h"
453-#include "ui_basic/button.h"
454-#include "ui_basic/window.h"
455+
456
457 namespace UI {
458
459-HelpWindow::HelpWindow
460- (Panel * const parent,
461- const std::string & caption,
462- uint32_t fontsize,
463- uint32_t width, uint32_t height)
464- :
465- Window(parent, "help_window", 0, 0, 20, 20, (boost::format(_("Help: %s")) % caption).str()),
466- textarea(new MultilineTextarea(this, 5, 5, 30, 30, std::string(), Align_Left)),
467- m_h1(std::to_string(fontsize < 12 ? 18 : fontsize * 3 / 2)),
468- m_h2(std::to_string(fontsize < 12 ? 12 : fontsize)),
469- m_p (std::to_string(fontsize < 12 ? 10 : fontsize * 5 / 6)),
470- m_fn(ui_fn().substr(0, ui_fn().size() - 4)) // Font file - .ttf
471-{
472- // Begin the text with the caption
473- m_text = "<rt text-align=center><p font-color=#AAFFAA font-face=";
474- m_text += m_fn;
475- m_text += " font-size=";
476- m_text += m_h1;
477- m_text += ">";
478- m_text += caption;
479- m_text += "</p></rt>";
480- textarea->set_text(m_text);
481- lastentry = HEADING;
482-
483- // Calculate sizes
484- int32_t const out_width = (width == 0) ? g_gr->get_xres() * 3 / 5 : width;
485- int32_t const out_height = (height == 0) ? g_gr->get_yres() * 4 / 5 : height;
486- int32_t const but_height = g_gr->get_yres() * 9 / 200;
487-
488- assert(out_width >= 80);
489- assert(out_height >= 60);
490- int32_t in_width = out_width - 80;
491- int32_t in_height = out_height - 60;
492-
493- set_inner_size(in_width, in_height);
494- set_pos(Point((g_gr->get_xres() - out_width) / 2, (g_gr->get_yres() - out_height) / 2));
495-
496- Button * btn = new Button
497- (this, "ok",
498- in_width / 3, in_height - but_height * 3 / 2,
499- in_width / 3, but_height,
500- g_gr->images().get("pics/but5.png"),
501- _("OK"), std::string(), true, false);
502- btn->sigclicked.connect(boost::bind(&HelpWindow::clicked_ok, boost::ref(*this)));
503- textarea->set_size(in_width - 10, in_height - 10 - (2 * but_height));
504- focus();
505-}
506-
507-
508-HelpWindow::~HelpWindow()
509-{
510-}
511-
512-/// Adds a new heading.
513-void HelpWindow::add_heading(std::string heading) {
514- m_text += "<rt text-align=left><p font-color=#AAAAFF font-face=";
515- m_text += m_fn;
516- m_text += " font-size=";
517- m_text += m_h2;
518- m_text += "><br><br>";
519- m_text += heading;
520- m_text += "</p></rt>";
521- textarea->set_text(m_text);
522- lastentry = HEADING;
523-}
524-
525-/// Adds a new paragraph.
526-void HelpWindow::add_paragraph(std::string block) {
527- m_text += "<rt><p font-face=";
528- m_text += m_fn;
529- m_text += " font-size=";
530- m_text += m_p;
531- if (lastentry == HEADING)
532- m_text += ">";
533- else
534- m_text += "><br>";
535- lastentry = BLOCK;
536- return add_block(block);
537-}
538-
539-/// Behaves the same as add_paragraph, just it adds only one < br> if last
540-/// written entry was already a block text.
541-void HelpWindow::add_block(std::string block) {
542- if (lastentry == HEADING)
543- return add_paragraph(block);
544- m_text += "<br>";
545- m_text += block;
546- m_text += "</p></rt>";
547- textarea->set_text(m_text);
548- lastentry = BLOCK;
549-}
550-
551-void HelpWindow::add_picture_li(std::string block, std::string picpath) {
552- m_text += "<rt image=";
553- m_text += picpath;
554- m_text += " image-align=left><p font-face=";
555- m_text += m_fn;
556- m_text += " font-size=";
557- m_text += m_p;
558- m_text += ">";
559- lastentry = BLOCK;
560- return add_block(block);
561-}
562-
563-
564-/**
565- * Handle mouseclick.
566- *
567- * Clicking the right mouse button inside the window acts like pressing Ok.
568- */
569-bool HelpWindow::handle_mousepress(const uint8_t btn, int32_t, int32_t)
570-{
571- if (btn == SDL_BUTTON_RIGHT) {
572- play_click();
573- clicked_ok();
574- }
575- return true;
576-}
577-
578-bool HelpWindow::handle_mouserelease(const uint8_t, int32_t, int32_t)
579-{
580- return true;
581-}
582-
583-bool HelpWindow::handle_key(bool down, SDL_Keysym code)
584-{
585- if (down) {
586- switch (code.sym) {
587- case SDLK_KP_ENTER:
588- case SDLK_RETURN:
589- clicked_ok();
590- return true;
591- default:
592- return true; // handled
593- }
594- }
595- return true;
596-}
597-
598-
599-void HelpWindow::clicked_ok()
600-{
601- if (is_modal())
602- end_modal<UI::Panel::Returncodes>(UI::Panel::Returncodes::kBack);
603- else {
604- // do not call die() here - could lead to broken pointers.
605- // the window should get deleted with the parent anyways.
606- set_visible(false);
607- }
608-}
609-
610-/*
611-===================
612-LuaTextHelpWindow
613-===================
614-*/
615-LuaTextHelpWindow::LuaTextHelpWindow
616+BuildingHelpWindow::BuildingHelpWindow
617 (Panel * const parent,
618 UI::UniqueWindow::Registry & reg,
619 const Widelands::BuildingDescr& building_description,
620@@ -206,7 +42,7 @@
621 :
622 UI::UniqueWindow(parent, "help_window", &reg, width, height,
623 (boost::format(_("Help: %s")) % building_description.descname()).str()),
624- textarea(new MultilineTextarea(this, 5, 5, width - 10, height -10, std::string(), Align_Left))
625+ textarea_(new MultilineTextarea(this, 5, 5, width - 10, height -10, std::string(), Align_Left))
626 {
627 assert(tribe.has_building(tribe.building_index(building_description.name())));
628 try {
629@@ -217,13 +53,10 @@
630 cr->push_arg(building_description.name());
631 cr->resume();
632 const std::string help_text = cr->pop_string();
633- textarea->set_text(help_text);
634+ textarea_->set_text(help_text);
635 } catch (LuaError& err) {
636- textarea->set_text(err.what());
637+ textarea_->set_text(err.what());
638 }
639 }
640-LuaTextHelpWindow::~LuaTextHelpWindow()
641-{
642-}
643
644-}
645+} // namespace UI
646
647=== renamed file 'src/ui_basic/helpwindow.h' => 'src/wui/helpwindow.h'
648--- src/ui_basic/helpwindow.h 2015-09-04 11:11:50 +0000
649+++ src/wui/helpwindow.h 2015-11-06 19:00:56 +0000
650@@ -17,8 +17,8 @@
651 *
652 */
653
654-#ifndef WL_UI_BASIC_HELPWINDOW_H
655-#define WL_UI_BASIC_HELPWINDOW_H
656+#ifndef WL_WUI_HELPWINDOW_H
657+#define WL_WUI_HELPWINDOW_H
658
659 #include <memory>
660
661@@ -26,7 +26,6 @@
662 #include "logic/tribes/tribe_descr.h"
663 #include "ui_basic/multilinetextarea.h"
664 #include "ui_basic/unique_window.h"
665-#include "ui_basic/window.h"
666
667 class LuaInterface;
668
669@@ -36,73 +35,23 @@
670
671 namespace UI {
672
673-/**
674- * Shows a help window.
675- *
676- * Using it is quite straightforward. To ensure, that all help windows have the
677- * same formations, all richtext formating will be done via add_* functions:
678- * HelpWindow help(parent, "Caption", fontsize);
679- * help.add_heading("A minor heading");
680- * help.add_block("Some lines of text!");
681- * help.add_block("More text, just one linebreak between");
682- * help.add_paragraph("Even more text, now drawn in a new paragraph");
683- * help.add_block("More text, same paragraph, but a linebreak between!");
684- * help.add_heading("Another minor heading");
685- * ...
686- * help.run();
687-*/
688-struct HelpWindow : public Window {
689- HelpWindow
690- (Panel * parent,
691- const std::string & caption,
692- uint32_t fontsize,
693- uint32_t width = 0, uint32_t height = 0);
694- ~HelpWindow();
695-
696- bool handle_mousepress (uint8_t btn, int32_t mx, int32_t my) override;
697- bool handle_mouserelease(uint8_t btn, int32_t mx, int32_t my) override;
698-
699- /// Handle keypresses
700- bool handle_key(bool down, SDL_Keysym code) override;
701-
702- void add_heading (std::string text);
703- void add_paragraph (std::string text);
704- void add_block (std::string text);
705- void add_picture_li(std::string text, std::string picpath);
706-
707-protected:
708- void clicked_ok();
709-
710-private:
711- enum State {
712- BLOCK = 0,
713- HEADING = 1
714- } lastentry;
715-
716- std::unique_ptr<MultilineTextarea> textarea;
717- std::string const m_h1, m_h2, m_p; // font sizes
718- std::string const m_fn; // font name
719- std::string m_text;
720-};
721-
722 /*
723- * This is a totally different beast than HelpWindow. It takes
724- * a Lua script, runs it and displays it's formatted content
725+ * This HelpWindow takes a Lua script, runs it and displays it's formatted content
726 * as a static text
727 */
728-struct LuaTextHelpWindow : public UI::UniqueWindow {
729- LuaTextHelpWindow
730+class BuildingHelpWindow : public UI::UniqueWindow {
731+public:
732+ BuildingHelpWindow
733 (Panel * parent, UI::UniqueWindow::Registry& reg,
734 const Widelands::BuildingDescr& building_description,
735 const Widelands::TribeDescr& tribe,
736 LuaInterface * const lua,
737 uint32_t width = 300, uint32_t height = 400);
738- ~LuaTextHelpWindow();
739
740 private:
741- std::unique_ptr<MultilineTextarea> textarea;
742+ std::unique_ptr<MultilineTextarea> textarea_;
743 };
744
745-}
746+} // namespace UI
747
748-#endif // end of include guard: WL_UI_BASIC_HELPWINDOW_H
749+#endif // end of include guard: WL_WUI_HELPWINDOW_H
750
751=== modified file 'utils/buildcat.py'
752--- utils/buildcat.py 2015-11-06 09:31:31 +0000
753+++ utils/buildcat.py 2015-11-06 19:00:56 +0000
754@@ -39,6 +39,7 @@
755 "../../src/wlapplication.h",
756 "../../src/*/*.h",
757 "../../src/*/*/*.h",
758+ "../../scripting/widelands/*.lua",
759 ] ),
760 ( "widelands_console/widelands_console", [
761 "../../src/wlapplication_messages.cc",

Subscribers

People subscribed via source and target branches

to status/vote changes: