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
1=== modified file 'src/logic/building.cc'
2--- src/logic/building.cc 2014-03-04 13:24:58 +0000
3+++ src/logic/building.cc 2014-03-15 19:51:27 +0000
4@@ -21,6 +21,7 @@
5
6 #include <cstdio>
7 #include <sstream>
8+#include <fstream>
9
10 #include <boost/foreach.hpp>
11
12@@ -30,6 +31,7 @@
13 #include "graphic/font_handler.h"
14 #include "graphic/font_handler1.h"
15 #include "graphic/graphic.h"
16+#include "graphic/image_transformations.h"
17 #include "graphic/rendertarget.h"
18 #include "io/filesystem/filesystem.h"
19 #include "io/filesystem/layered_filesystem.h"
20@@ -62,6 +64,7 @@
21 m_tribe (_descr),
22 m_buildable (true),
23 m_buildicon (nullptr),
24+ m_buildiconmask (nullptr),
25 m_size (BaseImmovable::SMALL),
26 m_mine (false),
27 m_port (false),
28@@ -135,7 +138,9 @@
29 if (m_buildable || m_enhanced_building) {
30 // get build icon
31 m_buildicon_fname = directory;
32+ m_buildiconmask_fname = directory;
33 m_buildicon_fname += "/menu.png";
34+ m_buildiconmask_fname += "/menu_pc.png";
35
36 // build animation
37 if (Section * const build_s = prof.get_section("build")) {
38@@ -162,7 +167,9 @@
39 } else if (m_global) {
40 // get build icon for global buildings (for statistics window)
41 m_buildicon_fname = directory;
42+ m_buildiconmask_fname = directory;
43 m_buildicon_fname += "/menu.png";
44+ m_buildiconmask_fname += "/menu_pc.png";
45 }
46
47 { // parse basic animation data
48@@ -239,6 +246,13 @@
49 {
50 if (m_buildicon_fname.size())
51 m_buildicon = g_gr->images().get(m_buildicon_fname);
52+ if (m_buildiconmask_fname.size())
53+ {
54+ //TODO remove this when all menu_pc.png files are available
55+ std::ifstream i(m_buildiconmask_fname);
56+ if (i.good())
57+ m_buildiconmask = g_gr->images().get(m_buildiconmask_fname);
58+ }
59 }
60
61 /*
62
63=== modified file 'src/logic/building.h'
64--- src/logic/building.h 2014-02-22 18:04:02 +0000
65+++ src/logic/building.h 2014-03-15 19:51:27 +0000
66@@ -92,6 +92,7 @@
67 */
68 const Buildcost & returned_wares_enhanced() const {return m_return_enhanced;}
69 const Image* get_buildicon() const {return m_buildicon;}
70+ const Image* get_buildiconmask() const {return m_buildiconmask;}
71 int32_t get_size() const {return m_size;}
72 bool get_ismine() const {return m_mine;}
73 bool get_isport() const {return m_port;}
74@@ -144,7 +145,9 @@
75 Buildcost m_enhance_cost; // cost for enhancing
76 Buildcost m_return_enhanced; // Returned ware for dismantling an enhanced building
77 const Image* m_buildicon; // if buildable: picture in the build dialog
78+ const Image* m_buildiconmask; // if buildable: picture in the build dialog
79 std::string m_buildicon_fname; // filename for this icon
80+ std::string m_buildiconmask_fname; // filename for this icon
81 int32_t m_size; // size of the building
82 bool m_mine;
83 bool m_port;
84
85=== modified file 'src/wui/fieldaction.cc'
86--- src/wui/fieldaction.cc 2014-03-07 19:12:24 +0000
87+++ src/wui/fieldaction.cc 2014-03-15 19:51:27 +0000
88@@ -23,6 +23,7 @@
89 #include "economy/flag.h"
90 #include "economy/road.h"
91 #include "graphic/graphic.h"
92+#include "graphic/image_transformations.h"
93 #include "i18n.h"
94 #include "logic/attackable.h"
95 #include "logic/cmd_queue.h"
96@@ -69,7 +70,7 @@
97 boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmouseout;
98 boost::signals2::signal<void (Widelands::Building_Index::value_t)> buildmousein;
99
100- void add(Widelands::Building_Index::value_t);
101+ void add(Widelands::Building_Index::value_t, Widelands::Player *);
102
103 private:
104 void clickslot(int32_t idx);
105@@ -102,12 +103,24 @@
106 Add a new building to the list of buildable buildings
107 ===============
108 */
109-void BuildGrid::add(Widelands::Building_Index::value_t id)
110+void BuildGrid::add(Widelands::Building_Index::value_t id, Widelands::Player * player)
111 {
112 const Widelands::Building_Descr & descr =
113 *m_tribe.get_building_descr(Widelands::Building_Index(id));
114+ const Image * icon = descr.get_buildicon();
115+ const Image * mask = descr.get_buildiconmask();
116+ const Image * pcicon;
117+ if (mask == nullptr)
118+ {
119+ pcicon = icon;
120+
121+ }
122+ else
123+ {
124+ pcicon = ImageTransformations::player_colored(player->get_playercolor(), icon, mask);
125+ }
126 UI::Icon_Grid::add
127- (descr.name(), descr.get_buildicon(),
128+ (descr.name(), pcicon,
129 reinterpret_cast<void *>(id),
130 descr.descname() + "<br><font size=11>" + _("Construction costs:") + "</font><br>" +
131 waremap_to_richtext(m_tribe, descr.buildcost()));
132@@ -568,7 +581,7 @@
133 }
134
135 // Add it to the grid
136- (*ppgrid)->add(id.value());
137+ (*ppgrid)->add(id.value(), m_plr);
138 }
139
140 // Add all necessary tabs
141
142=== added file 'tribes/atlanteans/coalmine/menu_pc.png'
143Binary 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: