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

Proposed by GunChleoc
Status: Merged
Merged at revision: 7636
Proposed branch: lp:~widelands-dev/widelands/pc_on_buttons
Merge into: lp:widelands
Diff against target: 282 lines (+75/-32)
7 files modified
src/graphic/animation.cc (+42/-10)
src/graphic/animation.h (+15/-7)
src/logic/instances.cc (+4/-4)
src/logic/instances.h (+2/-1)
src/logic/partially_finished_building.cc (+1/-1)
src/wui/building_statistics_menu.cc (+2/-1)
src/wui/fieldaction.cc (+9/-8)
To merge this branch: bzr merge lp:~widelands-dev/widelands/pc_on_buttons
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+278191@code.launchpad.net

Description of the change

This adds player color to building buttons. You can see it in action when building a new building or in the building statistics window.

The images with player color are cached in the AnimationManager.

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

Well I cannot see a difference... or rather I dont understand where exactly should I look at...

Revision history for this message
GunChleoc (gunchleoc) wrote :

E.g. if you are Player 1, all white bits in the buildings are replaced by blue bits. If you are player 2, they are red. Have a look at the Atlantean Sawmill, it has quite a big player color area, so it should be more noticeabe there.

Revision history for this message
TiborB (tiborb95) wrote :

Ok, now I saw it. Code looks good

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=== modified file 'src/graphic/animation.cc'
2--- src/graphic/animation.cc 2015-11-06 12:19:22 +0000
3+++ src/graphic/animation.cc 2015-11-21 10:37:21 +0000
4@@ -39,6 +39,7 @@
5 #include "graphic/image.h"
6 #include "graphic/image_cache.h"
7 #include "graphic/surface.h"
8+#include "graphic/texture.h"
9 #include "io/filesystem/layered_filesystem.h"
10 #include "logic/bob.h"
11 #include "logic/instances.h"
12@@ -123,7 +124,8 @@
13 uint16_t nr_frames() const override;
14 uint32_t frametime() const override;
15 const Point& hotspot() const override;
16- const std::string& representative_image_from_disk_filename() const override;
17+ Image* representative_image(const RGBColor* clr) const override;
18+ const std::string& representative_image_filename() const override;
19 virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*)
20 const override;
21 void trigger_soundfx(uint32_t framenumber, uint32_t stereo_position) const override;
22@@ -297,7 +299,33 @@
23 return hotspot_;
24 }
25
26-const std::string& NonPackedAnimation::representative_image_from_disk_filename() const {
27+Image* NonPackedAnimation::representative_image(const RGBColor* clr) const {
28+ assert(!image_files_.empty());
29+
30+ const Image* image = g_gr->images().get(image_files_[0]);
31+ int w = image->width();
32+ int h = image->height();
33+
34+ Texture* rv = new Texture(w, h);
35+ if (!hasplrclrs_ || clr == nullptr) {
36+ ::blit(Rect(Point(0, 0), w, h),
37+ *image,
38+ Rect(Point(0, 0), w, h),
39+ 1.,
40+ BlendMode::UseAlpha,
41+ rv);
42+ } else {
43+ blit_blended(Rect(Point(0, 0), w, h),
44+ *image,
45+ *g_gr->images().get(pc_mask_image_files_[0]),
46+ Rect(Point(0, 0), w, h),
47+ *clr,
48+ rv);
49+ }
50+ return rv;
51+}
52+
53+const std::string& NonPackedAnimation::representative_image_filename() const {
54 return image_files_[0];
55 }
56
57@@ -383,20 +411,24 @@
58 */
59
60 uint32_t AnimationManager::load(const LuaTable& table) {
61- m_animations.push_back(new NonPackedAnimation(table));
62- return m_animations.size();
63+ animations_.push_back(std::unique_ptr<Animation>(new NonPackedAnimation(table)));
64+ return animations_.size();
65 }
66
67 const Animation& AnimationManager::get_animation(uint32_t id) const
68 {
69- if (!id || id > m_animations.size())
70+ if (!id || id > animations_.size())
71 throw wexception("Requested unknown animation with id: %i", id);
72
73- return *m_animations[id - 1];
74+ return *animations_[id - 1].get();
75 }
76
77-AnimationManager::~AnimationManager()
78-{
79- for (vector<Animation*>::iterator it = m_animations.begin(); it != m_animations.end(); ++it)
80- delete *it;
81+const Image* AnimationManager::get_representative_image(uint32_t id, const RGBColor* clr) {
82+ if (representative_images_.count(id) != 1) {
83+ representative_images_.insert(
84+ std::make_pair(
85+ id,
86+ std::unique_ptr<Image>(g_gr->animations().get_animation(id).representative_image(clr))));
87+ }
88+ return representative_images_.at(id).get();
89 }
90
91=== modified file 'src/graphic/animation.h'
92--- src/graphic/animation.h 2015-11-06 12:19:22 +0000
93+++ src/graphic/animation.h 2015-11-21 10:37:21 +0000
94@@ -22,6 +22,7 @@
95
96 #include <cstring>
97 #include <map>
98+#include <memory>
99 #include <string>
100 #include <vector>
101
102@@ -67,13 +68,17 @@
103 /// so the caller has to adjust for the hotspot himself.
104 virtual const Point& hotspot() const = 0;
105
106- /// Returns the disk filename for the first image in the animation
107- virtual const std::string& representative_image_from_disk_filename() const = 0;
108+ /// An image of the first frame, blended with the given player color.
109+ /// The 'clr' is the player color used for blending - the parameter can be
110+ /// 'nullptr', in which case the neutral image will be returned.
111+ virtual Image* representative_image(const RGBColor* clr) const = 0;
112+ /// The filename of the image used for the first frame, without player color.
113+ virtual const std::string& representative_image_filename() const = 0;
114
115 /// Blit the animation frame that should be displayed at the given time index
116 /// so that the given point is at the top left of the frame. Srcrc defines
117 /// the part of the animation that should be blitted. The 'clr' is the player
118- /// color used for blitting - the parameter can be nullptr in which case the
119+ /// color used for blitting - the parameter can be 'nullptr', in which case the
120 /// neutral image will be blitted. The Surface is the target for the blit
121 /// operation and must be non-null.
122 virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) const = 0;
123@@ -90,7 +95,6 @@
124 */
125 class AnimationManager {
126 public:
127- ~AnimationManager();
128 /**
129 * Loads an animation, graphics sound and everything from a Lua table.
130 *
131@@ -104,10 +108,14 @@
132 /// unknown.
133 const Animation& get_animation(uint32_t id) const;
134
135+ /// Returns the representative image, using the given player color.
136+ /// If this image has been generated before, it is pulled from the cache using
137+ /// the clr argument that was used previously.
138+ const Image* get_representative_image(uint32_t id, const RGBColor* clr = nullptr);
139+
140 private:
141- // TODO(SirVer): this vector should be changed to unique__ptr (spelled wrong to avoid message by CodeCheck)
142- // instead of raw pointers to get rid of the destructor
143- std::vector<Animation*> m_animations;
144+ std::vector<std::unique_ptr<Animation>> animations_;
145+ std::map<uint32_t, std::unique_ptr<Image>> representative_images_;
146 };
147
148 #endif // end of include guard: WL_GRAPHIC_ANIMATION_H
149
150=== modified file 'src/logic/instances.cc'
151--- src/logic/instances.cc 2015-11-02 19:29:03 +0000
152+++ src/logic/instances.cc 2015-11-21 10:37:21 +0000
153@@ -249,7 +249,7 @@
154 throw GameDataError("Map object %s has animations but no idle animation", init_name.c_str());
155 }
156 representative_image_filename_ = g_gr->animations().get_animation(get_animation("idle"))
157- .representative_image_from_disk_filename();
158+ .representative_image_filename();
159 }
160 if (table.has_key("icon")) {
161 icon_filename_ = table.get_string("icon");
162@@ -310,9 +310,9 @@
163 return "";
164 }
165
166-const Image* MapObjectDescr::representative_image() const {
167- if (!representative_image_filename_.empty()) {
168- return g_gr->images().get(representative_image_filename_);
169+const Image* MapObjectDescr::representative_image(const RGBColor* player_color) const {
170+ if (is_animation_known("idle")) {
171+ return g_gr->animations().get_representative_image(get_animation("idle"), player_color);
172 }
173 return nullptr;
174 }
175
176=== modified file 'src/logic/instances.h'
177--- src/logic/instances.h 2015-10-21 16:43:30 +0000
178+++ src/logic/instances.h 2015-11-21 10:37:21 +0000
179@@ -32,6 +32,7 @@
180
181 #include "base/log.h"
182 #include "base/macros.h"
183+#include "graphic/color.h"
184 #include "graphic/image.h"
185 #include "logic/cmd_queue.h"
186 #include "logic/widelands.h"
187@@ -139,7 +140,7 @@
188
189 /// Returns the image for the first frame of the idle animation if the MapObject has animations,
190 /// nullptr otherwise
191- const Image* representative_image() const;
192+ const Image* representative_image(const RGBColor* player_color = nullptr) const;
193 /// Returns the image fileneme for first frame of the idle animation if the MapObject has animations,
194 /// is empty otherwise
195 const std::string& representative_image_filename() const;
196
197=== modified file 'src/logic/partially_finished_building.cc'
198--- src/logic/partially_finished_building.cc 2015-11-11 09:52:55 +0000
199+++ src/logic/partially_finished_building.cc 2015-11-21 10:37:21 +0000
200@@ -149,7 +149,7 @@
201 */
202 const Image* PartiallyFinishedBuilding::representative_image() const
203 {
204- return m_building->representative_image();
205+ return m_building->representative_image(&owner().get_playercolor());
206 }
207
208
209
210=== modified file 'src/wui/building_statistics_menu.cc'
211--- src/wui/building_statistics_menu.cc 2015-11-17 14:36:25 +0000
212+++ src/wui/building_statistics_menu.cc 2015-11-21 10:37:21 +0000
213@@ -394,7 +394,8 @@
214 kBuildGridCellWidth,
215 kBuildGridCellHeight,
216 g_gr->images().get("pics/but1.png"),
217- descr.representative_image(),
218+ descr.representative_image(&iplayer().get_player()
219+ ->get_playercolor()),
220 "",
221 false,
222 true);
223
224=== modified file 'src/wui/fieldaction.cc'
225--- src/wui/fieldaction.cc 2015-11-11 09:53:54 +0000
226+++ src/wui/fieldaction.cc 2015-11-21 10:37:21 +0000
227@@ -56,7 +56,7 @@
228 // The BuildGrid presents a selection of buildable buildings
229 struct BuildGrid : public UI::IconGrid {
230 BuildGrid(UI::Panel* parent,
231- const Widelands::TribeDescr& tribe,
232+ Widelands::Player* plr,
233 int32_t x,
234 int32_t y,
235 int32_t cols);
236@@ -73,14 +73,14 @@
237 void mousein_slot(int32_t idx);
238
239 private:
240- const Widelands::TribeDescr& tribe_;
241+ Widelands::Player* plr_;
242 };
243
244 BuildGrid::BuildGrid(
245- UI::Panel* parent, const Widelands::TribeDescr& tribe,
246+ UI::Panel* parent, Widelands::Player* plr,
247 int32_t x, int32_t y, int32_t cols) :
248 UI::IconGrid(parent, x, y, kBuildGridCellSize, kBuildGridCellSize, cols),
249- tribe_(tribe)
250+ plr_(plr)
251 {
252 clicked.connect(boost::bind(&BuildGrid::click_slot, this, _1));
253 mouseout.connect(boost::bind(&BuildGrid::mouseout_slot, this, _1));
254@@ -95,15 +95,16 @@
255 void BuildGrid::add(Widelands::DescriptionIndex id)
256 {
257 const Widelands::BuildingDescr & descr =
258- *tribe_.get_building_descr(Widelands::DescriptionIndex(id));
259+ *plr_->tribe().get_building_descr(Widelands::DescriptionIndex(id));
260+
261 // TODO(sirver): change this to take a Button subclass instead of
262 // parameters. This will allow overriding the way it is rendered
263 // to bring back player colors.
264 UI::IconGrid::add(descr.name(),
265- descr.representative_image(),
266+ descr.representative_image(&plr_->get_playercolor()),
267 reinterpret_cast<void*>(id),
268 descr.descname() + "<br><font size=11>" + _("Construction costs:") +
269- "</font><br>" + waremap_to_richtext(tribe_, descr.buildcost()));
270+ "</font><br>" + waremap_to_richtext(plr_->tribe(), descr.buildcost()));
271 }
272
273
274@@ -531,7 +532,7 @@
275
276 // Allocate the tab's grid if necessary
277 if (!*ppgrid) {
278- *ppgrid = new BuildGrid(&m_tabpanel, tribe, 0, 0, 5);
279+ *ppgrid = new BuildGrid(&m_tabpanel, m_plr, 0, 0, 5);
280 (*ppgrid)->buildclicked.connect(boost::bind(&FieldActionWindow::act_build, this, _1));
281 (*ppgrid)->buildmouseout.connect
282 (boost::bind(&FieldActionWindow::building_icon_mouse_out, this, _1));

Subscribers

People subscribed via source and target branches

to status/vote changes: