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

Proposed by Jens Beyer
Status: Rejected
Rejected by: Jens Beyer
Proposed branch: lp:~widelands-dev/widelands/buildicon_playercolors
Merge into: lp:widelands
Diff against target: 143 lines (+34/-4)
3 files modified
src/logic/building.cc (+14/-0)
src/logic/building.h (+3/-0)
src/wui/fieldaction.cc (+17/-4)
To merge this branch: bzr merge lp:~widelands-dev/widelands/buildicon_playercolors
Reviewer Review Type Date Requested Status
SirVer Needs Fixing
Review via email: mp+211184@code.launchpad.net

Description of the change

This is not a merge-request per se, but more a request to review the code, and to find some way to create the necessary media files.

With this branch merged, the game displays the building icons in player color if available.
It uses playercolor mask files (menu_pc.png next to their menu.png files). Unfortunately, the mask files for the menu.png files are not available yet.
I added a rough playercolor image (a force-resize to the correct 30x30px) for the atlantean coal mine as proof of concept (you can check it ingame, best use a different player than player1 because of the blue player color of player1...)
The game can live without player color mask files, as you see (only the atlantean coal mine is there, the other files are missing). But now we need someone who is able to create the correct playercolor mask files where neccesary. Problem is that most animation frames are not of same width and height, but the menu icons are exactly 30x30, so simply force-resizing would probably lead to some undesired display effects.

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

I do not agree to this design. Especially since it needs new data files.

I suggest using code I added in https://code.launchpad.net/~widelands-dev/widelands/spritemaps/+merge/211225 which will be merged soonish (hopefully). I suggest using animation.representative_image together with image_transformations.h, resize to create the images shown in the menu. Maybe we can get rid of the menu.png altogether (which would be super awesome).

g_gr->animations().get_animation(world.get_bob_descr(j)->main_animation())
    .representative_image(RGBColor(0, 0, 0));

What do you think?

review: Needs Fixing
Revision history for this message
Jens Beyer (qcumber-some) wrote :

Thanks for the review and the suggestion.

Now that I have something working, it is easier for me to discuss it, so please be patient with me ;-)
I did not have a look into your branch yet, but from what I think I understand, you want to use a "representative image" of the animation, which is one, possibly selected, frame of the animation, and use it for the menus instead of menu.png/menu_pc.png.

I agree this would be awesome, and I think I could implement it (technologically).
And I will certainly go for this as a test (one can only learn from it).

But the animations are all at a very different size ranging from higher-than-wide to wider-than-high, while the menu items are at a fixed size. I can not really imagine having the build icons in the build menu at different sizes looking nicely, and I certainly don't want to force-resize them to equal-ratio 30x30px (as an example). What would be the correct approach to that?

Revision history for this message
SirVer (sirver) wrote :

I think resizing with keeping the aspect ratio is the way to go. The menu pictures we have right now have been created in the same way. Basically something like:

double ratio = 32. / std::max(image_w, image_h);
resize(image_w * ratio, image_h * ratio);

Revision history for this message
Jens Beyer (qcumber-some) wrote :

Setting rejected, I will push another merge request

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/logic/building.cc'
--- src/logic/building.cc 2014-03-04 13:24:58 +0000
+++ src/logic/building.cc 2014-03-15 19:51:27 +0000
@@ -21,6 +21,7 @@
2121
22#include <cstdio>22#include <cstdio>
23#include <sstream>23#include <sstream>
24#include <fstream>
2425
25#include <boost/foreach.hpp>26#include <boost/foreach.hpp>
2627
@@ -30,6 +31,7 @@
30#include "graphic/font_handler.h"31#include "graphic/font_handler.h"
31#include "graphic/font_handler1.h"32#include "graphic/font_handler1.h"
32#include "graphic/graphic.h"33#include "graphic/graphic.h"
34#include "graphic/image_transformations.h"
33#include "graphic/rendertarget.h"35#include "graphic/rendertarget.h"
34#include "io/filesystem/filesystem.h"36#include "io/filesystem/filesystem.h"
35#include "io/filesystem/layered_filesystem.h"37#include "io/filesystem/layered_filesystem.h"
@@ -62,6 +64,7 @@
62 m_tribe (_descr),64 m_tribe (_descr),
63 m_buildable (true),65 m_buildable (true),
64 m_buildicon (nullptr),66 m_buildicon (nullptr),
67 m_buildiconmask (nullptr),
65 m_size (BaseImmovable::SMALL),68 m_size (BaseImmovable::SMALL),
66 m_mine (false),69 m_mine (false),
67 m_port (false),70 m_port (false),
@@ -135,7 +138,9 @@
135 if (m_buildable || m_enhanced_building) {138 if (m_buildable || m_enhanced_building) {
136 // get build icon139 // get build icon
137 m_buildicon_fname = directory;140 m_buildicon_fname = directory;
141 m_buildiconmask_fname = directory;
138 m_buildicon_fname += "/menu.png";142 m_buildicon_fname += "/menu.png";
143 m_buildiconmask_fname += "/menu_pc.png";
139144
140 // build animation145 // build animation
141 if (Section * const build_s = prof.get_section("build")) {146 if (Section * const build_s = prof.get_section("build")) {
@@ -162,7 +167,9 @@
162 } else if (m_global) {167 } else if (m_global) {
163 // get build icon for global buildings (for statistics window)168 // get build icon for global buildings (for statistics window)
164 m_buildicon_fname = directory;169 m_buildicon_fname = directory;
170 m_buildiconmask_fname = directory;
165 m_buildicon_fname += "/menu.png";171 m_buildicon_fname += "/menu.png";
172 m_buildiconmask_fname += "/menu_pc.png";
166 }173 }
167174
168 { // parse basic animation data175 { // parse basic animation data
@@ -239,6 +246,13 @@
239{246{
240 if (m_buildicon_fname.size())247 if (m_buildicon_fname.size())
241 m_buildicon = g_gr->images().get(m_buildicon_fname);248 m_buildicon = g_gr->images().get(m_buildicon_fname);
249 if (m_buildiconmask_fname.size())
250 {
251 //TODO remove this when all menu_pc.png files are available
252 std::ifstream i(m_buildiconmask_fname);
253 if (i.good())
254 m_buildiconmask = g_gr->images().get(m_buildiconmask_fname);
255 }
242}256}
243257
244/*258/*
245259
=== modified file 'src/logic/building.h'
--- src/logic/building.h 2014-02-22 18:04:02 +0000
+++ src/logic/building.h 2014-03-15 19:51:27 +0000
@@ -92,6 +92,7 @@
92 */92 */
93 const Buildcost & returned_wares_enhanced() const {return m_return_enhanced;}93 const Buildcost & returned_wares_enhanced() const {return m_return_enhanced;}
94 const Image* get_buildicon() const {return m_buildicon;}94 const Image* get_buildicon() const {return m_buildicon;}
95 const Image* get_buildiconmask() const {return m_buildiconmask;}
95 int32_t get_size() const {return m_size;}96 int32_t get_size() const {return m_size;}
96 bool get_ismine() const {return m_mine;}97 bool get_ismine() const {return m_mine;}
97 bool get_isport() const {return m_port;}98 bool get_isport() const {return m_port;}
@@ -144,7 +145,9 @@
144 Buildcost m_enhance_cost; // cost for enhancing145 Buildcost m_enhance_cost; // cost for enhancing
145 Buildcost m_return_enhanced; // Returned ware for dismantling an enhanced building146 Buildcost m_return_enhanced; // Returned ware for dismantling an enhanced building
146 const Image* m_buildicon; // if buildable: picture in the build dialog147 const Image* m_buildicon; // if buildable: picture in the build dialog
148 const Image* m_buildiconmask; // if buildable: picture in the build dialog
147 std::string m_buildicon_fname; // filename for this icon149 std::string m_buildicon_fname; // filename for this icon
150 std::string m_buildiconmask_fname; // filename for this icon
148 int32_t m_size; // size of the building151 int32_t m_size; // size of the building
149 bool m_mine;152 bool m_mine;
150 bool m_port;153 bool m_port;
151154
=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc 2014-03-07 19:12:24 +0000
+++ src/wui/fieldaction.cc 2014-03-15 19:51:27 +0000
@@ -23,6 +23,7 @@
23#include "economy/flag.h"23#include "economy/flag.h"
24#include "economy/road.h"24#include "economy/road.h"
25#include "graphic/graphic.h"25#include "graphic/graphic.h"
26#include "graphic/image_transformations.h"
26#include "i18n.h"27#include "i18n.h"
27#include "logic/attackable.h"28#include "logic/attackable.h"
28#include "logic/cmd_queue.h"29#include "logic/cmd_queue.h"
@@ -69,7 +70,7 @@
69 boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmouseout;70 boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmouseout;
70 boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmousein;71 boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmousein;
7172
72 void add(Widelands::Building_Index::value_t);73 void add(Widelands::Building_Index::value_t, Widelands::Player *);
7374
74private:75private:
75 void clickslot(int32_t idx);76 void clickslot(int32_t idx);
@@ -102,12 +103,24 @@
102Add a new building to the list of buildable buildings103Add a new building to the list of buildable buildings
103===============104===============
104*/105*/
105void BuildGrid::add(Widelands::Building_Index::value_t id)106void BuildGrid::add(Widelands::Building_Index::value_t id, Widelands::Player * player)
106{107{
107 const Widelands::Building_Descr & descr =108 const Widelands::Building_Descr & descr =
108 *m_tribe.get_building_descr(Widelands::Building_Index(id));109 *m_tribe.get_building_descr(Widelands::Building_Index(id));
110 const Image * icon = descr.get_buildicon();
111 const Image * mask = descr.get_buildiconmask();
112 const Image * pcicon;
113 if (mask == nullptr)
114 {
115 pcicon = icon;
116
117 }
118 else
119 {
120 pcicon = ImageTransformations::player_colored(player->get_playercolor(), icon, mask);
121 }
109 UI::Icon_Grid::add122 UI::Icon_Grid::add
110 (descr.name(), descr.get_buildicon(),123 (descr.name(), pcicon,
111 reinterpret_cast<void *>(id),124 reinterpret_cast<void *>(id),
112 descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" +125 descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" +
113 waremap_to_richtext(m_tribe, descr.buildcost()));126 waremap_to_richtext(m_tribe, descr.buildcost()));
@@ -568,7 +581,7 @@
568 }581 }
569582
570 // Add it to the grid583 // Add it to the grid
571 (*ppgrid)->add(id.value());584 (*ppgrid)->add(id.value(), m_plr);
572 }585 }
573586
574 // Add all necessary tabs587 // Add all necessary tabs
575588
=== added file 'tribes/atlanteans/coalmine/menu_pc.png'
576Binary files tribes/atlanteans/coalmine/menu_pc.png 1970-01-01 00:00:00 +0000 and tribes/atlanteans/coalmine/menu_pc.png 2014-03-15 19:51:27 +0000 differ589Binary files tribes/atlanteans/coalmine/menu_pc.png 1970-01-01 00:00:00 +0000 and tribes/atlanteans/coalmine/menu_pc.png 2014-03-15 19:51:27 +0000 differ

Subscribers

People subscribed via source and target branches

to status/vote changes: