widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01492
[Merge] lp:~widelands-dev/widelands/wareslist_sizes into lp:widelands
cghislai has proposed merging lp:~widelands-dev/widelands/wareslist_sizes into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1205609 in widelands: "Wincondition scripts reloaded too often"
https://bugs.launchpad.net/widelands/+bug/1205609
Bug #1205806 in widelands: "Ware statistics window too small for empire warelist"
https://bugs.launchpad.net/widelands/+bug/1205806
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/wareslist_sizes/+merge/178257
This adds a new max_height parameter to waresdisplay, so wrapping of too long columns at low res is done differently for each window.
- TribeDescr::resize_ware_orders has been changed to get_resized_ware_orders, which return a pair with the new ware orders and their coordinates. Previously wareorder were changed in place.
- The waresdisplay calls this method in the constructor and store the returned list locally. So each waresdisplay may have different wrapping
- Several constructor of classes extending abstractwaresdisplay have been modified to allow passing of the max_height parameter
- In a few places the max_height parameter is computed and passed in when creating the waresdisplay. This is the ware statistics window and the warehouse window. For the other warelists I could find, the default value of y_res - 100 seems to be sufficient.
I also added a small fix to not create a game object each time a replay as preloaded. Instead, the one created in wlapplication is passed in, similar to what is done in the load game menu.
--
https://code.launchpad.net/~widelands-dev/widelands/wareslist_sizes/+merge/178257
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/wareslist_sizes into lp:widelands.
=== modified file 'src/logic/soldier.cc'
--- src/logic/soldier.cc 2013-08-01 08:33:15 +0000
+++ src/logic/soldier.cc 2013-08-02 10:56:32 +0000
@@ -764,7 +764,7 @@
struct FindNodeOwned {
FindNodeOwned(Player_Number owner) : m_owner(owner)
{};
- bool accept(const Map & map, const FCoords & coords) const {
+ bool accept(const Map &, const FCoords & coords) const {
return (coords.field->get_owned_by() == m_owner);
}
private:
=== modified file 'src/logic/tribe.cc'
--- src/logic/tribe.cc 2013-07-26 20:19:36 +0000
+++ src/logic/tribe.cc 2013-08-02 10:56:32 +0000
@@ -20,6 +20,7 @@
#include "logic/tribe.h"
#include <iostream>
+#include <utility>
#include <boost/algorithm/string.hpp>
@@ -636,37 +637,38 @@
return empty;
}
-void Tribe_Descr::resize_ware_orders(size_t maxLength) {
+std::pair<Tribe_Descr::WaresOrder, Tribe_Descr::WaresOrderCoords>
+Tribe_Descr::get_resized_ware_orders(size_t maxLength) {
bool need_resize = false;
//check if we actually need to resize
for (WaresOrder::iterator it = m_wares_order.begin(); it != m_wares_order.end(); ++it) {
if (it->size() > maxLength) {
need_resize = true;
- }
- }
+ }
+ }
+ if (!need_resize) {
+ return std::make_pair(m_wares_order, m_wares_order_coords);
+ }
//resize
- if (need_resize) {
- //build new smaller wares_order
- WaresOrder new_wares_order;
- for (WaresOrder::iterator it = m_wares_order.begin(); it != m_wares_order.end(); ++it) {
- new_wares_order.push_back(std::vector<Widelands::Ware_Index>());
- for (std::vector<Widelands::Ware_Index>::iterator it2 = it->begin(); it2 != it->end(); ++it2) {
- if (new_wares_order.rbegin()->size() >= maxLength) {
- new_wares_order.push_back(std::vector<Widelands::Ware_Index>());
- }
- new_wares_order.rbegin()->push_back(*it2);
- m_wares_order_coords[*it2].first = new_wares_order.size() - 1;
- m_wares_order_coords[*it2].second = new_wares_order.rbegin()->size() - 1;
+ //build new smaller wares_order
+ WaresOrder new_wares_order;
+ WaresOrderCoords new_wares_order_coords(m_wares_order_coords);
+ for (WaresOrder::iterator it = m_wares_order.begin(); it != m_wares_order.end(); ++it) {
+ new_wares_order.push_back(std::vector<Widelands::Ware_Index>());
+ for (std::vector<Widelands::Ware_Index>::iterator it2 = it->begin(); it2 != it->end(); ++it2) {
+ if (new_wares_order.rbegin()->size() >= maxLength) {
+ new_wares_order.push_back(std::vector<Widelands::Ware_Index>());
}
+ new_wares_order.rbegin()->push_back(*it2);
+ new_wares_order_coords[*it2].first = new_wares_order.size() - 1;
+ new_wares_order_coords[*it2].second = new_wares_order.rbegin()->size() - 1;
}
-
- //remove old array
- m_wares_order.clear();
- m_wares_order = new_wares_order;
}
+
+ return std::make_pair(new_wares_order, new_wares_order_coords);
}
}
=== modified file 'src/logic/tribe.h'
--- src/logic/tribe.h 2013-07-26 20:19:36 +0000
+++ src/logic/tribe.h 2013-08-02 10:56:32 +0000
@@ -233,7 +233,7 @@
return m_workers_order_coords;
}
- void resize_ware_orders(size_t maxLength);
+ std::pair<WaresOrder, WaresOrderCoords> get_resized_ware_orders(size_t maxLength);
const std::vector<std::string> & compatibility_immovable(const std::string & name) const;
=== modified file 'src/ui_fsmenu/loadreplay.cc'
--- src/ui_fsmenu/loadreplay.cc 2013-07-31 17:09:15 +0000
+++ src/ui_fsmenu/loadreplay.cc 2013-08-02 10:56:32 +0000
@@ -30,7 +30,7 @@
#include "timestring.h"
#include "ui_basic/messagebox.h"
-Fullscreen_Menu_LoadReplay::Fullscreen_Menu_LoadReplay() :
+Fullscreen_Menu_LoadReplay::Fullscreen_Menu_LoadReplay(Widelands::Game & g) :
Fullscreen_Menu_Base("choosemapmenu.jpg"),
// Values for alignment and size
@@ -82,7 +82,8 @@
m_ta_players
(this, get_w() * 71 / 100, get_h() * 41 / 100),
m_ta_win_condition
- (this, get_w() * 71 / 100, get_h() * 9 / 20)
+ (this, get_w() * 71 / 100, get_h() * 9 / 20),
+ m_game(g)
{
m_back.sigclicked.connect(boost::bind(&Fullscreen_Menu_LoadReplay::end_modal, boost::ref(*this), 0));
m_ok.sigclicked.connect(boost::bind(&Fullscreen_Menu_LoadReplay::clicked_ok, boost::ref(*this)));
@@ -171,11 +172,10 @@
if (m_list.has_selection()) {
std::string name = m_list.get_selected() + WLGF_SUFFIX;
- Widelands::Game game;
Widelands::Game_Preload_Data_Packet gpdp;
try {
- Widelands::Game_Loader gl(name, game);
+ Widelands::Game_Loader gl(name, m_game);
gl.preload_game(gpdp);
} catch (const _wexception & e) {
log("Replay '%s' must have changed from under us\nException: %s\n", name.c_str(), e.what());
@@ -215,6 +215,7 @@
g_fs->FindFiles(REPLAY_DIR, "*" REPLAY_SUFFIX, &files, 1);
+ Widelands::Game_Preload_Data_Packet gpdp;
for
(filenameset_t::iterator pname = files.begin();
pname != files.end();
@@ -226,9 +227,7 @@
continue;
try {
- Widelands::Game_Preload_Data_Packet gpdp;
- Widelands::Game game;
- Widelands::Game_Loader gl(savename, game);
+ Widelands::Game_Loader gl(savename, m_game);
gl.preload_game(gpdp);
m_list.add
=== modified file 'src/ui_fsmenu/loadreplay.h'
--- src/ui_fsmenu/loadreplay.h 2013-07-26 20:19:36 +0000
+++ src/ui_fsmenu/loadreplay.h 2013-08-02 10:56:32 +0000
@@ -25,12 +25,13 @@
#include "ui_basic/listselect.h"
#include "ui_basic/textarea.h"
-
+namespace Widelands
+{struct Game;}
/**
* Select a replay from a list of replays.
*/
struct Fullscreen_Menu_LoadReplay : public Fullscreen_Menu_Base {
- Fullscreen_Menu_LoadReplay();
+ Fullscreen_Menu_LoadReplay(Widelands::Game &);
const std::string & filename() {return m_filename;}
@@ -51,16 +52,17 @@
UI::Button m_back;
UI::Button m_ok;
UI::Button m_delete;
- UI::Listselect<std::string> m_list;
- UI::Textarea m_title;
- UI::Textarea m_label_mapname;
- UI::Textarea m_tamapname;
- UI::Textarea m_label_gametime;
- UI::Textarea m_tagametime;
- UI::Textarea m_label_players;
- UI::Textarea m_ta_players;
- UI::Textarea m_ta_win_condition;
- std::string m_filename;
+ UI::Listselect<std::string> m_list;
+ UI::Textarea m_title;
+ UI::Textarea m_label_mapname;
+ UI::Textarea m_tamapname;
+ UI::Textarea m_label_gametime;
+ UI::Textarea m_tagametime;
+ UI::Textarea m_label_players;
+ UI::Textarea m_ta_players;
+ UI::Textarea m_ta_win_condition;
+ std::string m_filename;
+ Widelands::Game & m_game;
};
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2013-07-30 08:58:02 +0000
+++ src/wlapplication.cc 2013-08-02 10:56:32 +0000
@@ -84,12 +84,12 @@
#include "wui/interactive_player.h"
#include "wui/interactive_spectator.h"
-#ifndef NDEBUG
+#ifndef NDEBUG
#ifndef _WIN32
int32_t WLApplication::pid_me = 0;
int32_t WLApplication::pid_peer = 0;
volatile int32_t WLApplication::may_run = 0;
-#endif
+#endif
#endif
#define MINIMUM_DISK_SPACE 250000000lu
@@ -2204,15 +2204,15 @@
*/
void WLApplication::replay()
{
+ Widelands::Game game;
if (m_filename.empty()) {
- Fullscreen_Menu_LoadReplay rm;
+ Fullscreen_Menu_LoadReplay rm(game);
if (rm.run() <= 0)
return;
m_filename = rm.filename();
}
- Widelands::Game game;
try {
UI::ProgressWindow loaderUI;
std::vector<std::string> tipstext;
=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc 2013-07-27 10:35:55 +0000
+++ src/wui/buildingwindow.cc 2013-08-02 10:56:32 +0000
@@ -52,7 +52,7 @@
:
UI::Window
(&parent, "building_window",
- 0, 0, Width, 0,
+ 0, 0, BUILDING_WINDOW_DEFAULT_WIDTH, 0,
b.descname()),
m_registry(registry),
m_building (b),
=== modified file 'src/wui/buildingwindow.h'
--- src/wui/buildingwindow.h 2013-07-26 20:19:36 +0000
+++ src/wui/buildingwindow.h 2013-08-02 10:56:32 +0000
@@ -27,6 +27,7 @@
#include "ui_basic/window.h"
#include "wui/waresdisplay.h"
+#define BUILDING_WINDOW_DEFAULT_WIDTH (4 * 34) // 4 normally sized buttons
/**
* Base class for all building windows.
*
@@ -35,9 +36,6 @@
struct Building_Window : public UI::Window {
friend struct TrainingSite_Window;
friend struct MilitarySite_Window;
- enum {
- Width = 4 * 34 // 4 normally sized buttons
- };
Building_Window
(Interactive_GameBase & parent, Widelands::Building &, UI::Window * & registry);
=== modified file 'src/wui/portdockwaresdisplay.cc'
--- src/wui/portdockwaresdisplay.cc 2013-07-26 20:19:36 +0000
+++ src/wui/portdockwaresdisplay.cc 2013-08-02 10:56:32 +0000
@@ -35,7 +35,9 @@
* Display wares or workers that are waiting to be shipped from a port.
*/
struct PortDockWaresDisplay : AbstractWaresDisplay {
- PortDockWaresDisplay(Panel * parent, uint32_t width, PortDock & pd, Widelands::WareWorker type);
+ PortDockWaresDisplay
+ (Panel * parent, uint32_t width, uint16_t max_height,
+ PortDock & pd, Widelands::WareWorker type);
virtual std::string info_for_ware(Widelands::Ware_Index ware);
@@ -44,8 +46,8 @@
};
PortDockWaresDisplay::PortDockWaresDisplay
- (Panel * parent, uint32_t width, PortDock & pd, Widelands::WareWorker type) :
- AbstractWaresDisplay(parent, 0, 0, pd.owner().tribe(), type, false),
+ (Panel * parent, uint32_t width, uint16_t max_height, PortDock & pd, Widelands::WareWorker type) :
+ AbstractWaresDisplay(parent, 0, 0, pd.owner().tribe(), type, false, max_height),
m_portdock(pd)
{
set_inner_size(width, 0);
@@ -63,9 +65,9 @@
* Create a panel that displays the wares or workers that are waiting to be shipped from a port.
*/
AbstractWaresDisplay * create_portdock_wares_display
- (UI::Panel * parent, uint32_t width, PortDock & pd, Widelands::WareWorker type)
+ (UI::Panel * parent, uint32_t width, uint16_t max_height, PortDock & pd, Widelands::WareWorker type)
{
- return new PortDockWaresDisplay(parent, width, pd, type);
+ return new PortDockWaresDisplay(parent, width, max_height, pd, type);
}
/// Create a panel that displays the wares and the builder waiting for the expedition to start.
=== modified file 'src/wui/portdockwaresdisplay.h'
--- src/wui/portdockwaresdisplay.h 2013-07-26 20:19:36 +0000
+++ src/wui/portdockwaresdisplay.h 2013-08-02 10:56:32 +0000
@@ -29,7 +29,7 @@
}
AbstractWaresDisplay * create_portdock_wares_display
- (UI::Panel * parent, uint32_t width, Widelands::PortDock & pd,
+ (UI::Panel * parent, uint32_t width, uint16_t max_height, Widelands::PortDock & pd,
Widelands::WareWorker type);
UI::Box * create_portdock_expedition_display
=== modified file 'src/wui/transport_ui.cc'
--- src/wui/transport_ui.cc 2013-07-26 20:19:36 +0000
+++ src/wui/transport_ui.cc 2013-08-02 10:56:32 +0000
@@ -81,9 +81,10 @@
const Widelands::Tribe_Descr & tribe,
Widelands::WareWorker type,
bool selectable,
- Economy & economy)
+ Economy & economy,
+ uint16_t max_height = 0)
:
- AbstractWaresDisplay(parent, x, y, tribe, type, selectable),
+ AbstractWaresDisplay(parent, x, y, tribe, type, selectable, max_height),
m_economy(economy)
{
if (type == Widelands::wwWORKER) {
=== modified file 'src/wui/ware_statistics_menu.cc'
--- src/wui/ware_statistics_menu.cc 2013-07-26 20:19:36 +0000
+++ src/wui/ware_statistics_menu.cc 2013-08-02 10:56:32 +0000
@@ -108,10 +108,11 @@
(UI::Panel * const parent,
int32_t const x, int32_t const y,
const Widelands::Tribe_Descr & tribe,
+ uint16_t max_height,
boost::function<void(Widelands::Ware_Index, bool)> callback_function,
std::vector<uint8_t> & color_map)
:
- AbstractWaresDisplay(parent, x, y, tribe, Widelands::wwWARE, true, callback_function),
+ AbstractWaresDisplay(parent, x, y, tribe, Widelands::wwWARE, true, max_height, callback_function),
m_color_map(color_map)
{
uint32_t w, h;
@@ -245,9 +246,11 @@
colors[cur_ware]);
}
+ // tot height - tab height - plot height - slider height - box spacings
+ uint16_t max_height = g_gr->get_yres() - 34 - plot_height - 45 - 2 * spacing;
box->add
(new StatisticWaresDisplay
- (box, 0, 0, parent.get_player()->tribe(),
+ (box, 0, 0, parent.get_player()->tribe(), max_height,
boost::bind(&Ware_Statistics_Menu::cb_changed_to, boost::ref(*this), _1, _2),
m_color_map),
UI::Box::AlignLeft, true);
=== modified file 'src/wui/warehousewindow.cc'
--- src/wui/warehousewindow.cc 2013-07-28 08:40:06 +0000
+++ src/wui/warehousewindow.cc 2013-08-02 10:56:32 +0000
@@ -45,7 +45,7 @@
class WarehouseWaresDisplay : public WaresDisplay {
public:
WarehouseWaresDisplay
- (UI::Panel * parent, uint32_t width,
+ (UI::Panel * parent, uint32_t width, uint16_t max_width,
Warehouse & wh, Widelands::WareWorker type, bool selectable);
protected:
@@ -56,10 +56,10 @@
};
WarehouseWaresDisplay::WarehouseWaresDisplay
- (UI::Panel * parent, uint32_t width,
+ (UI::Panel * parent, uint32_t width, uint16_t max_width,
Warehouse & wh, Widelands::WareWorker type, bool selectable)
:
-WaresDisplay(parent, 0, 0, wh.owner().tribe(), type, selectable),
+WaresDisplay(parent, 0, 0, wh.owner().tribe(), type, selectable, max_width),
m_warehouse(wh)
{
set_inner_size(width, 0);
@@ -90,7 +90,7 @@
*/
struct WarehouseWaresPanel : UI::Box {
WarehouseWaresPanel
- (UI::Panel * parent, uint32_t width,
+ (UI::Panel * parent, uint32_t width, uint16_t max_height,
Interactive_GameBase &, Warehouse &, Widelands::WareWorker type);
void set_policy(Warehouse::StockPolicy);
@@ -103,7 +103,7 @@
};
WarehouseWaresPanel::WarehouseWaresPanel
- (UI::Panel * parent, uint32_t width,
+ (UI::Panel * parent, uint32_t width, uint16_t max_height,
Interactive_GameBase & gb, Warehouse & wh, Widelands::WareWorker type)
:
UI::Box(parent, 0, 0, UI::Box::Vertical),
@@ -111,7 +111,7 @@
m_wh(wh),
m_can_act(m_gb.can_act(m_wh.owner().player_number())),
m_type(type),
- m_display(this, width, m_wh, m_type, m_can_act)
+ m_display(this, width, max_height, m_wh, m_type, m_can_act)
{
add(&m_display, UI::Box::AlignLeft, true);
@@ -184,12 +184,15 @@
UI::Window * & registry)
: Building_Window(parent, wh, registry)
{
+ uint16_t wares_max_height = g_gr->get_yres() - 10 // safe margein
+ - 3 * 34; // tabs + 2 rows of buttons and a label
get_tabs()->add
("wares",
g_gr->images().get(pic_tab_wares),
new WarehouseWaresPanel
(get_tabs(),
- Width,
+ BUILDING_WINDOW_DEFAULT_WIDTH,
+ wares_max_height,
igbase(),
warehouse(),
Widelands::wwWARE),
@@ -199,7 +202,8 @@
g_gr->images().get(pic_tab_workers),
new WarehouseWaresPanel
(get_tabs(),
- Width,
+ BUILDING_WINDOW_DEFAULT_WIDTH,
+ wares_max_height,
igbase(),
warehouse(),
Widelands::wwWORKER),
@@ -209,12 +213,16 @@
get_tabs()->add
("dock_wares",
g_gr->images().get(pic_tab_dock_wares),
- create_portdock_wares_display(get_tabs(), Width, *pd, Widelands::wwWARE),
+ create_portdock_wares_display
+ (get_tabs(), BUILDING_WINDOW_DEFAULT_WIDTH, wares_max_height,
+ *pd, Widelands::wwWARE),
_("Wares in dock"));
get_tabs()->add
("dock_workers",
g_gr->images().get(pic_tab_dock_workers),
- create_portdock_wares_display(get_tabs(), Width, *pd, Widelands::wwWORKER),
+ create_portdock_wares_display
+ (get_tabs(), BUILDING_WINDOW_DEFAULT_WIDTH, wares_max_height,
+ *pd, Widelands::wwWORKER),
_("Workers in dock"));
if (pd->expedition_started()) {
get_tabs()->add
=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc 2013-07-26 20:19:36 +0000
+++ src/wui/waresdisplay.cc 2013-08-02 10:56:32 +0000
@@ -20,6 +20,7 @@
#include "wui/waresdisplay.h"
#include <cstdio>
+#include <utility>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
@@ -45,6 +46,7 @@
const Widelands::Tribe_Descr & tribe,
Widelands::WareWorker type,
bool selectable,
+ uint16_t max_height,
boost::function<void(Widelands::Ware_Index, bool)> callback_function,
bool horizontal)
:
@@ -73,8 +75,17 @@
m_callback_function(callback_function)
{
//resize the configuration of our wares if they won't fit in the current window
- int number = (g_gr->get_yres() - 160) / (WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + WARE_MENU_PIC_PAD_Y);
- const_cast<Widelands::Tribe_Descr &>(m_tribe).resize_ware_orders(number);
+ if (max_height == 0) {
+ max_height = g_gr->get_yres() - 100; //Keep a safe margin
+ } else {
+ max_height -= 20; // Keep place for the cur selection label
+ }
+ int number = max_height / (WARE_MENU_PIC_HEIGHT + WARE_MENU_INFO_SIZE + WARE_MENU_PIC_PAD_Y);
+ log("Cropping ware height to max %d\n", max_height);
+ std::pair<Widelands::Tribe_Descr::WaresOrder, Widelands::Tribe_Descr::WaresOrderCoords> ware_order =
+ const_cast<Widelands::Tribe_Descr &>(m_tribe).get_resized_ware_orders(number);
+ m_wares_order = ware_order.first;
+ m_wares_order_coords = ware_order.second;
// Find out geometry from icons_order
unsigned int columns = icons_order().size();
@@ -305,7 +316,7 @@
{
switch (m_type) {
case Widelands::wwWARE:
- return m_tribe.wares_order();
+ return m_wares_order;
break;
case Widelands::wwWORKER:
return m_tribe.workers_order();
@@ -319,7 +330,7 @@
{
switch (m_type) {
case Widelands::wwWARE:
- return m_tribe.wares_order_coords();
+ return m_wares_order_coords;
break;
case Widelands::wwWORKER:
return m_tribe.workers_order_coords();
@@ -450,8 +461,8 @@
int32_t x, int32_t y,
const Widelands::Tribe_Descr & tribe,
Widelands::WareWorker type,
- bool selectable)
-: AbstractWaresDisplay(parent, x, y, tribe, type, selectable)
+ bool selectable, uint16_t max_height)
+: AbstractWaresDisplay(parent, x, y, tribe, type, selectable, max_height)
{}
RGBColor AbstractWaresDisplay::info_color_for_ware(Widelands::Ware_Index /* ware */) {
=== modified file 'src/wui/waresdisplay.h'
--- src/wui/waresdisplay.h 2013-07-26 19:16:51 +0000
+++ src/wui/waresdisplay.h 2013-08-02 10:56:32 +0000
@@ -50,6 +50,7 @@
const Widelands::Tribe_Descr &,
Widelands::WareWorker type,
bool selectable,
+ uint16_t max_height = 0,
boost::function<void(Widelands::Ware_Index, bool)> callback_function = 0,
bool horizontal = false);
@@ -89,6 +90,8 @@
private:
typedef std::vector<const Widelands::WareList *> vector_type;
typedef std::vector<bool> selection_type;
+ Widelands::Tribe_Descr::WaresOrder m_wares_order;
+ Widelands::Tribe_Descr::WaresOrderCoords m_wares_order_coords;
/**
* Update the anchored selection. When first mouse button is
@@ -131,7 +134,7 @@
int32_t x, int32_t y,
const Widelands::Tribe_Descr &,
Widelands::WareWorker type,
- bool selectable);
+ bool selectable, uint16_t max_height = 0);
virtual ~WaresDisplay();
Follow ups