widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #08627
[Merge] lp:~widelands-dev/widelands/fsmenu_fullscreen_1_main_menus into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/fsmenu_fullscreen_1_main_menus into lp:widelands.
Commit message:
The main, multiplayer and single player menus now relayout themselves when fullscreen mode is toggled.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1398733 in widelands: "Fullscreen Menus cannot relayout themselves"
https://bugs.launchpad.net/widelands/+bug/1398733
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fsmenu_fullscreen_1_main_menus/+merge/309655
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/fsmenu_fullscreen_1_main_menus into lp:widelands.
=== modified file 'src/ui_basic/box.cc'
--- src/ui_basic/box.cc 2016-10-16 09:31:42 +0000
+++ src/ui_basic/box.cc 2016-10-31 07:01:05 +0000
@@ -81,6 +81,14 @@
}
/**
+ * Sets the value for the inner spacing.
+ * \note This does not relayout the box.
+ */
+void Box::set_inner_spacing(uint32_t size) {
+ inner_spacing_ = size;
+}
+
+/**
* Compute the desired size based on our children. This assumes that the
* infinite space is zero, and is later on also re-used to calculate the
* space assigned to an infinite space.
@@ -198,7 +206,7 @@
infspace_count--;
}
- // Forth pass: Update positions of all other items
+ // Fourth pass: Update positions of all other items
update_positions();
}
=== modified file 'src/ui_basic/box.h'
--- src/ui_basic/box.h 2016-08-04 15:49:05 +0000
+++ src/ui_basic/box.h 2016-10-31 07:01:05 +0000
@@ -62,6 +62,7 @@
}
void set_min_desired_breadth(uint32_t min);
+ void set_inner_spacing(uint32_t size);
protected:
void layout() override;
=== modified file 'src/ui_fsmenu/base.cc'
--- src/ui_fsmenu/base.cc 2016-10-16 20:35:47 +0000
+++ src/ui_fsmenu/base.cc 2016-10-31 07:01:05 +0000
@@ -48,6 +48,11 @@
*/
FullscreenMenuBase::FullscreenMenuBase(const std::string& bgpic)
: UI::Panel(nullptr, 0, 0, g_gr->get_xres(), g_gr->get_yres()), background_image_(bgpic) {
+ graphic_resolution_changed_subscriber_ = Notifications::subscribe<GraphicResolutionChanged>(
+ [this](const GraphicResolutionChanged& message) {
+ set_size(message.width, message.height);
+ layout();
+ });
}
FullscreenMenuBase::~FullscreenMenuBase() {
=== modified file 'src/ui_fsmenu/base.h'
--- src/ui_fsmenu/base.h 2016-08-04 15:49:05 +0000
+++ src/ui_fsmenu/base.h 2016-10-31 07:01:05 +0000
@@ -20,8 +20,11 @@
#ifndef WL_UI_FSMENU_BASE_H
#define WL_UI_FSMENU_BASE_H
+#include <memory>
#include <string>
+#include "graphic/graphic.h"
+#include "notifications/notifications.h"
#include "ui_basic/panel.h"
/**
@@ -86,6 +89,8 @@
private:
std::string background_image_;
+ std::unique_ptr<Notifications::Subscriber<GraphicResolutionChanged>>
+ graphic_resolution_changed_subscriber_;
};
#endif // end of include guard: WL_UI_FSMENU_BASE_H
=== modified file 'src/ui_fsmenu/main.cc'
--- src/ui_fsmenu/main.cc 2016-09-25 10:42:26 +0000
+++ src/ui_fsmenu/main.cc 2016-10-31 07:01:05 +0000
@@ -29,14 +29,6 @@
: FullscreenMenuMainMenu("images/ui_fsmenu/mainmenu.jpg"),
// Buttons
- // This box needs to be a bit higher than in the other menus, because we have a lot of buttons
- vbox(this,
- box_x_,
- box_y_ - buth_,
- UI::Box::Vertical,
- butw_,
- get_h() - (box_y_ - buth_),
- padding_),
playtutorial(&vbox,
"play_tutorial",
0,
@@ -93,14 +85,14 @@
// Textlabels
version(
this,
- get_w(),
- get_h(),
+ 0,
+ 0,
/** TRANSLATORS: %1$s = version string, %2%s = "Debug" or "Release" */
(boost::format(_("Version %1$s (%2$s)")) % build_id().c_str() % build_type().c_str()).str(),
UI::Align::kBottomRight),
copyright(this,
0,
- get_h() - 0.5 * buth_,
+ 0,
/** TRANSLATORS: Placeholders are the copyright years */
(boost::format(_("(C) %1%-%2% by the Widelands Development Team")) %
kWidelandsCopyrightStart % kWidelandsCopyrightEnd)
@@ -108,7 +100,7 @@
UI::Align::kBottomLeft),
gpl(this,
0,
- get_h(),
+ 0,
_("Licensed under the GNU General Public License V2.0"),
UI::Align::kBottomLeft) {
playtutorial.sigclicked.connect(
@@ -136,33 +128,46 @@
boost::bind(&FullscreenMenuMain::end_modal<FullscreenMenuBase::MenuTarget>, boost::ref(*this),
FullscreenMenuBase::MenuTarget::kExit));
- vbox.add(&playtutorial, UI::Align::kHCenter);
- vbox.add(&singleplayer, UI::Align::kHCenter);
- vbox.add(&multiplayer, UI::Align::kHCenter);
-
- vbox.add_space(2 * padding_);
-
- vbox.add(&replay, UI::Align::kHCenter);
-
- vbox.add_space(2 * padding_);
-
- vbox.add(&editor, UI::Align::kHCenter);
-
- vbox.add_space(2 * padding_);
-
- vbox.add(&options, UI::Align::kHCenter);
-
- vbox.add_space(2 * padding_);
-
- vbox.add(&about, UI::Align::kHCenter);
-
- vbox.add_space(5 * padding_);
-
- vbox.add(&exit, UI::Align::kHCenter);
-
- vbox.set_size(butw_, get_h() - vbox.get_y());
+ vbox.add(&playtutorial, UI::Align::kHCenter, true);
+ vbox.add(&singleplayer, UI::Align::kHCenter, true);
+ vbox.add(&multiplayer, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add(&replay, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add(&editor, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add(&options, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add(&about, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add(&exit, UI::Align::kHCenter, true);
+
+ layout();
}
void FullscreenMenuMain::clicked_ok() {
; // do nothing
}
+
+void FullscreenMenuMain::layout() {
+ FullscreenMenuMainMenu::layout();
+ const int text_height = 0.5 * version.get_h() + padding_;
+ version.set_pos(Vector2i(get_w() - version.get_w(), get_h() - text_height));
+ copyright.set_pos(Vector2i(0, get_h() - 2 * text_height));
+ gpl.set_pos(Vector2i(0, get_h() - text_height));
+
+ playtutorial.set_desired_size(butw_, buth_);
+ singleplayer.set_desired_size(butw_, buth_);
+ multiplayer.set_desired_size(butw_, buth_);
+ replay.set_desired_size(butw_, buth_);
+ editor.set_desired_size(butw_, buth_);
+ options.set_desired_size(butw_, buth_);
+ about.set_desired_size(butw_, buth_);
+ exit.set_desired_size(butw_, buth_);
+
+ // This box needs to be positioned a bit higher than in the other menus, because we have a lot of
+ // buttons
+ vbox.set_pos(Vector2i(box_x_, box_y_ - buth_));
+ vbox.set_inner_spacing(padding_);
+ vbox.set_size(butw_, get_h() - vbox.get_y() - 5 * padding_);
+}
=== modified file 'src/ui_fsmenu/main.h'
--- src/ui_fsmenu/main.h 2016-08-04 15:49:05 +0000
+++ src/ui_fsmenu/main.h 2016-10-31 07:01:05 +0000
@@ -20,7 +20,6 @@
#ifndef WL_UI_FSMENU_MAIN_H
#define WL_UI_FSMENU_MAIN_H
-#include "ui_basic/box.h"
#include "ui_basic/button.h"
#include "ui_basic/textarea.h"
#include "ui_fsmenu/main_menu.h"
@@ -37,7 +36,8 @@
void clicked_ok() override;
private:
- UI::Box vbox;
+ void layout() override;
+
UI::Button playtutorial;
UI::Button singleplayer;
UI::Button multiplayer;
=== modified file 'src/ui_fsmenu/main_menu.cc'
--- src/ui_fsmenu/main_menu.cc 2016-08-04 15:49:05 +0000
+++ src/ui_fsmenu/main_menu.cc 2016-10-31 07:01:05 +0000
@@ -33,5 +33,15 @@
buth_(get_h() * 9 / 200),
title_y_(get_h() * 3 / 40),
padding_(buth_ / 3),
- button_background_("images/ui_basic//but3.png") {
+ button_background_("images/ui_basic//but3.png"),
+ vbox(this, 0, 0, UI::Box::Vertical, 0, 0, padding_) {
+}
+
+void FullscreenMenuMainMenu::layout() {
+ box_x_ = get_w() * 13 / 40;
+ box_y_ = get_h() * 6 / 25;
+ butw_ = get_w() * 7 / 20;
+ buth_ = get_h() * 9 / 200;
+ title_y_ = get_h() * 3 / 40;
+ padding_ = buth_ / 3;
}
=== modified file 'src/ui_fsmenu/main_menu.h'
--- src/ui_fsmenu/main_menu.h 2016-08-04 15:49:05 +0000
+++ src/ui_fsmenu/main_menu.h 2016-10-31 07:01:05 +0000
@@ -20,6 +20,7 @@
#ifndef WL_UI_FSMENU_MAIN_MENU_H
#define WL_UI_FSMENU_MAIN_MENU_H
+#include "ui_basic/box.h"
#include "ui_fsmenu/base.h"
/**
@@ -37,12 +38,15 @@
FullscreenMenuMainMenu(const std::string& background_image);
protected:
- const uint32_t box_x_, box_y_;
- const uint32_t butw_, buth_;
- const uint32_t title_y_;
- const uint32_t padding_;
+ void layout() override;
+
+ uint32_t box_x_, box_y_;
+ uint32_t butw_, buth_;
+ uint32_t title_y_;
+ uint32_t padding_;
const std::string button_background_;
+ UI::Box vbox;
};
#endif // end of include guard: WL_UI_FSMENU_MAIN_MENU_H
=== modified file 'src/ui_fsmenu/multiplayer.cc'
--- src/ui_fsmenu/multiplayer.cc 2016-09-25 10:13:23 +0000
+++ src/ui_fsmenu/multiplayer.cc 2016-10-31 07:01:05 +0000
@@ -30,10 +30,9 @@
: FullscreenMenuMainMenu(),
// Title
- title(this, get_w() / 2, title_y_, _("Choose game type"), UI::Align::kHCenter),
+ title(this, 0, 0, _("Choose game type"), UI::Align::kHCenter),
// Buttons
- vbox(this, box_x_, box_y_, UI::Box::Vertical, butw_, get_h() - box_y_, padding_),
metaserver(&vbox,
"metaserver",
0,
@@ -42,6 +41,7 @@
buth_,
g_gr->images().get(button_background_),
_("Internet game")),
+ showloginbox(nullptr),
lan(&vbox,
"lan",
0,
@@ -64,29 +64,21 @@
title.set_fontsize(fs_big());
- vbox.add(&metaserver, UI::Align::kHCenter);
- vbox.add(&lan, UI::Align::kHCenter);
-
- // Multiple add_space calls to get the same height for the back button as in the single player
- // menu
- vbox.add_space(buth_);
- vbox.add_space(buth_);
- vbox.add_space(6 * buth_);
-
- vbox.add(&back, UI::Align::kHCenter);
-
- vbox.set_size(butw_, get_h() - vbox.get_y());
+ vbox.add(&metaserver, UI::Align::kHCenter, true);
+ vbox.add(&lan, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add(&back, UI::Align::kHCenter, true);
Section& s = g_options.pull_section("global");
auto_log_ = s.get_bool("auto_log", false);
if (auto_log_) {
- showloginbox =
- new UI::Button(this, "login_dialog", box_x_ + butw_ + buth_ / 4, get_h() * 6 / 25, buth_,
- buth_, g_gr->images().get("images/ui_basic/but1.png"),
- g_gr->images().get("images/ui_basic/continue.png"), _("Show login dialog"));
+ showloginbox = new UI::Button(
+ this, "login_dialog", 0, 0, 0, 0, g_gr->images().get("images/ui_basic/but1.png"),
+ g_gr->images().get("images/ui_basic/continue.png"), _("Show login dialog"));
showloginbox->sigclicked.connect(
boost::bind(&FullscreenMenuMultiPlayer::show_internet_login, boost::ref(*this)));
}
+ layout();
}
/// called if the showloginbox button was pressed
@@ -151,3 +143,23 @@
void FullscreenMenuMultiPlayer::clicked_ok() {
internet_login();
}
+
+void FullscreenMenuMultiPlayer::layout() {
+ title.set_size(get_w(), title.get_h());
+ FullscreenMenuMainMenu::layout();
+
+ title.set_pos(Vector2i(0, title_y_));
+
+ metaserver.set_size(butw_, buth_);
+ if (showloginbox) {
+ showloginbox->set_pos(Vector2i(box_x_ + butw_ + padding_ / 2, box_y_));
+ showloginbox->set_size(buth_, buth_);
+ }
+ metaserver.set_desired_size(butw_, buth_);
+ lan.set_desired_size(butw_, buth_);
+ back.set_desired_size(butw_, buth_);
+
+ vbox.set_pos(Vector2i(box_x_, box_y_));
+ vbox.set_inner_spacing(padding_);
+ vbox.set_size(butw_, get_h() - vbox.get_y() - 3 * title_y_);
+}
=== modified file 'src/ui_fsmenu/multiplayer.h'
--- src/ui_fsmenu/multiplayer.h 2016-08-04 15:49:05 +0000
+++ src/ui_fsmenu/multiplayer.h 2016-10-31 07:01:05 +0000
@@ -21,7 +21,6 @@
#define WL_UI_FSMENU_MULTIPLAYER_H
#include "network/internet_gaming.h"
-#include "ui_basic/box.h"
#include "ui_basic/button.h"
#include "ui_basic/textarea.h"
#include "ui_fsmenu/main_menu.h"
@@ -50,8 +49,9 @@
void clicked_ok() override;
private:
+ void layout() override;
+
UI::Textarea title;
- UI::Box vbox;
UI::Button metaserver;
UI::Button* showloginbox;
UI::Button lan;
=== modified file 'src/ui_fsmenu/singleplayer.cc'
--- src/ui_fsmenu/singleplayer.cc 2016-09-25 10:42:26 +0000
+++ src/ui_fsmenu/singleplayer.cc 2016-10-31 07:01:05 +0000
@@ -27,10 +27,9 @@
: FullscreenMenuMainMenu(),
// Title
- title(this, get_w() / 2, title_y_, _("Single Player"), UI::Align::kHCenter),
+ title(this, 0, 0, _("Single Player"), UI::Align::kHCenter),
// Buttons
- vbox(this, box_x_, box_y_, UI::Box::Vertical, butw_, get_h() - box_y_, padding_),
new_game(&vbox,
"new_game",
0,
@@ -71,20 +70,34 @@
title.set_fontsize(fs_big());
- vbox.add(&new_game, UI::Align::kHCenter);
- vbox.add(&campaign, UI::Align::kHCenter);
-
- vbox.add_space(buth_);
-
- vbox.add(&load_game, UI::Align::kHCenter);
-
- vbox.add_space(6 * buth_);
-
- vbox.add(&back, UI::Align::kHCenter);
-
- vbox.set_size(butw_, get_h() - vbox.get_y());
+ vbox.add(&new_game, UI::Align::kHCenter, true);
+ vbox.add(&campaign, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add(&load_game, UI::Align::kHCenter, true);
+ vbox.add_inf_space();
+ vbox.add_inf_space();
+ vbox.add_inf_space();
+ vbox.add(&back, UI::Align::kHCenter, true);
+
+ layout();
}
void FullscreenMenuSinglePlayer::clicked_ok() {
end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kNewGame);
}
+
+void FullscreenMenuSinglePlayer::layout() {
+ title.set_size(get_w(), title.get_h());
+ FullscreenMenuMainMenu::layout();
+
+ title.set_pos(Vector2i(0, title_y_));
+
+ new_game.set_desired_size(butw_, buth_);
+ campaign.set_desired_size(butw_, buth_);
+ load_game.set_desired_size(butw_, buth_);
+ back.set_desired_size(butw_, buth_);
+
+ vbox.set_pos(Vector2i(box_x_, box_y_));
+ vbox.set_inner_spacing(padding_);
+ vbox.set_size(butw_, get_h() - vbox.get_y() - 3 * title_y_);
+}
=== modified file 'src/ui_fsmenu/singleplayer.h'
--- src/ui_fsmenu/singleplayer.h 2016-08-04 15:49:05 +0000
+++ src/ui_fsmenu/singleplayer.h 2016-10-31 07:01:05 +0000
@@ -20,7 +20,6 @@
#ifndef WL_UI_FSMENU_SINGLEPLAYER_H
#define WL_UI_FSMENU_SINGLEPLAYER_H
-#include "ui_basic/box.h"
#include "ui_basic/button.h"
#include "ui_basic/textarea.h"
#include "ui_fsmenu/main_menu.h"
@@ -37,8 +36,9 @@
void clicked_ok() override;
private:
+ void layout() override;
+
UI::Textarea title;
- UI::Box vbox;
UI::Button new_game;
UI::Button campaign;
UI::Button load_game;
Follow ups