Merge lp:~widelands-dev/widelands/pc_on_buttons into lp:widelands
- pc_on_buttons
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
TiborB | Approve | ||
Review via email:
|
Commit message
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
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
TiborB (tiborb95) wrote : | # |
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
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
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
TiborB (tiborb95) wrote : | # |
Ok, now I saw it. Code looks good
review:
Approve
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
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 | 39 | #include "graphic/image.h" | 39 | #include "graphic/image.h" |
6 | 40 | #include "graphic/image_cache.h" | 40 | #include "graphic/image_cache.h" |
7 | 41 | #include "graphic/surface.h" | 41 | #include "graphic/surface.h" |
8 | 42 | #include "graphic/texture.h" | ||
9 | 42 | #include "io/filesystem/layered_filesystem.h" | 43 | #include "io/filesystem/layered_filesystem.h" |
10 | 43 | #include "logic/bob.h" | 44 | #include "logic/bob.h" |
11 | 44 | #include "logic/instances.h" | 45 | #include "logic/instances.h" |
12 | @@ -123,7 +124,8 @@ | |||
13 | 123 | uint16_t nr_frames() const override; | 124 | uint16_t nr_frames() const override; |
14 | 124 | uint32_t frametime() const override; | 125 | uint32_t frametime() const override; |
15 | 125 | const Point& hotspot() const override; | 126 | const Point& hotspot() const override; |
17 | 126 | const std::string& representative_image_from_disk_filename() const override; | 127 | Image* representative_image(const RGBColor* clr) const override; |
18 | 128 | const std::string& representative_image_filename() const override; | ||
19 | 127 | virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) | 129 | virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) |
20 | 128 | const override; | 130 | const override; |
21 | 129 | void trigger_soundfx(uint32_t framenumber, uint32_t stereo_position) const override; | 131 | void trigger_soundfx(uint32_t framenumber, uint32_t stereo_position) const override; |
22 | @@ -297,7 +299,33 @@ | |||
23 | 297 | return hotspot_; | 299 | return hotspot_; |
24 | 298 | } | 300 | } |
25 | 299 | 301 | ||
27 | 300 | const std::string& NonPackedAnimation::representative_image_from_disk_filename() const { | 302 | Image* NonPackedAnimation::representative_image(const RGBColor* clr) const { |
28 | 303 | assert(!image_files_.empty()); | ||
29 | 304 | |||
30 | 305 | const Image* image = g_gr->images().get(image_files_[0]); | ||
31 | 306 | int w = image->width(); | ||
32 | 307 | int h = image->height(); | ||
33 | 308 | |||
34 | 309 | Texture* rv = new Texture(w, h); | ||
35 | 310 | if (!hasplrclrs_ || clr == nullptr) { | ||
36 | 311 | ::blit(Rect(Point(0, 0), w, h), | ||
37 | 312 | *image, | ||
38 | 313 | Rect(Point(0, 0), w, h), | ||
39 | 314 | 1., | ||
40 | 315 | BlendMode::UseAlpha, | ||
41 | 316 | rv); | ||
42 | 317 | } else { | ||
43 | 318 | blit_blended(Rect(Point(0, 0), w, h), | ||
44 | 319 | *image, | ||
45 | 320 | *g_gr->images().get(pc_mask_image_files_[0]), | ||
46 | 321 | Rect(Point(0, 0), w, h), | ||
47 | 322 | *clr, | ||
48 | 323 | rv); | ||
49 | 324 | } | ||
50 | 325 | return rv; | ||
51 | 326 | } | ||
52 | 327 | |||
53 | 328 | const std::string& NonPackedAnimation::representative_image_filename() const { | ||
54 | 301 | return image_files_[0]; | 329 | return image_files_[0]; |
55 | 302 | } | 330 | } |
56 | 303 | 331 | ||
57 | @@ -383,20 +411,24 @@ | |||
58 | 383 | */ | 411 | */ |
59 | 384 | 412 | ||
60 | 385 | uint32_t AnimationManager::load(const LuaTable& table) { | 413 | uint32_t AnimationManager::load(const LuaTable& table) { |
63 | 386 | m_animations.push_back(new NonPackedAnimation(table)); | 414 | animations_.push_back(std::unique_ptr<Animation>(new NonPackedAnimation(table))); |
64 | 387 | return m_animations.size(); | 415 | return animations_.size(); |
65 | 388 | } | 416 | } |
66 | 389 | 417 | ||
67 | 390 | const Animation& AnimationManager::get_animation(uint32_t id) const | 418 | const Animation& AnimationManager::get_animation(uint32_t id) const |
68 | 391 | { | 419 | { |
70 | 392 | if (!id || id > m_animations.size()) | 420 | if (!id || id > animations_.size()) |
71 | 393 | throw wexception("Requested unknown animation with id: %i", id); | 421 | throw wexception("Requested unknown animation with id: %i", id); |
72 | 394 | 422 | ||
74 | 395 | return *m_animations[id - 1]; | 423 | return *animations_[id - 1].get(); |
75 | 396 | } | 424 | } |
76 | 397 | 425 | ||
81 | 398 | AnimationManager::~AnimationManager() | 426 | const Image* AnimationManager::get_representative_image(uint32_t id, const RGBColor* clr) { |
82 | 399 | { | 427 | if (representative_images_.count(id) != 1) { |
83 | 400 | for (vector<Animation*>::iterator it = m_animations.begin(); it != m_animations.end(); ++it) | 428 | representative_images_.insert( |
84 | 401 | delete *it; | 429 | std::make_pair( |
85 | 430 | id, | ||
86 | 431 | std::unique_ptr<Image>(g_gr->animations().get_animation(id).representative_image(clr)))); | ||
87 | 432 | } | ||
88 | 433 | return representative_images_.at(id).get(); | ||
89 | 402 | } | 434 | } |
90 | 403 | 435 | ||
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 | 22 | 22 | ||
96 | 23 | #include <cstring> | 23 | #include <cstring> |
97 | 24 | #include <map> | 24 | #include <map> |
98 | 25 | #include <memory> | ||
99 | 25 | #include <string> | 26 | #include <string> |
100 | 26 | #include <vector> | 27 | #include <vector> |
101 | 27 | 28 | ||
102 | @@ -67,13 +68,17 @@ | |||
103 | 67 | /// so the caller has to adjust for the hotspot himself. | 68 | /// so the caller has to adjust for the hotspot himself. |
104 | 68 | virtual const Point& hotspot() const = 0; | 69 | virtual const Point& hotspot() const = 0; |
105 | 69 | 70 | ||
108 | 70 | /// Returns the disk filename for the first image in the animation | 71 | /// An image of the first frame, blended with the given player color. |
109 | 71 | virtual const std::string& representative_image_from_disk_filename() const = 0; | 72 | /// The 'clr' is the player color used for blending - the parameter can be |
110 | 73 | /// 'nullptr', in which case the neutral image will be returned. | ||
111 | 74 | virtual Image* representative_image(const RGBColor* clr) const = 0; | ||
112 | 75 | /// The filename of the image used for the first frame, without player color. | ||
113 | 76 | virtual const std::string& representative_image_filename() const = 0; | ||
114 | 72 | 77 | ||
115 | 73 | /// Blit the animation frame that should be displayed at the given time index | 78 | /// Blit the animation frame that should be displayed at the given time index |
116 | 74 | /// so that the given point is at the top left of the frame. Srcrc defines | 79 | /// so that the given point is at the top left of the frame. Srcrc defines |
117 | 75 | /// the part of the animation that should be blitted. The 'clr' is the player | 80 | /// the part of the animation that should be blitted. The 'clr' is the player |
119 | 76 | /// color used for blitting - the parameter can be nullptr in which case the | 81 | /// color used for blitting - the parameter can be 'nullptr', in which case the |
120 | 77 | /// neutral image will be blitted. The Surface is the target for the blit | 82 | /// neutral image will be blitted. The Surface is the target for the blit |
121 | 78 | /// operation and must be non-null. | 83 | /// operation and must be non-null. |
122 | 79 | virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) const = 0; | 84 | virtual void blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) const = 0; |
123 | @@ -90,7 +95,6 @@ | |||
124 | 90 | */ | 95 | */ |
125 | 91 | class AnimationManager { | 96 | class AnimationManager { |
126 | 92 | public: | 97 | public: |
127 | 93 | ~AnimationManager(); | ||
128 | 94 | /** | 98 | /** |
129 | 95 | * Loads an animation, graphics sound and everything from a Lua table. | 99 | * Loads an animation, graphics sound and everything from a Lua table. |
130 | 96 | * | 100 | * |
131 | @@ -104,10 +108,14 @@ | |||
132 | 104 | /// unknown. | 108 | /// unknown. |
133 | 105 | const Animation& get_animation(uint32_t id) const; | 109 | const Animation& get_animation(uint32_t id) const; |
134 | 106 | 110 | ||
135 | 111 | /// Returns the representative image, using the given player color. | ||
136 | 112 | /// If this image has been generated before, it is pulled from the cache using | ||
137 | 113 | /// the clr argument that was used previously. | ||
138 | 114 | const Image* get_representative_image(uint32_t id, const RGBColor* clr = nullptr); | ||
139 | 115 | |||
140 | 107 | private: | 116 | private: |
144 | 108 | // TODO(SirVer): this vector should be changed to unique__ptr (spelled wrong to avoid message by CodeCheck) | 117 | std::vector<std::unique_ptr<Animation>> animations_; |
145 | 109 | // instead of raw pointers to get rid of the destructor | 118 | std::map<uint32_t, std::unique_ptr<Image>> representative_images_; |
143 | 110 | std::vector<Animation*> m_animations; | ||
146 | 111 | }; | 119 | }; |
147 | 112 | 120 | ||
148 | 113 | #endif // end of include guard: WL_GRAPHIC_ANIMATION_H | 121 | #endif // end of include guard: WL_GRAPHIC_ANIMATION_H |
149 | 114 | 122 | ||
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 | 249 | throw GameDataError("Map object %s has animations but no idle animation", init_name.c_str()); | 249 | throw GameDataError("Map object %s has animations but no idle animation", init_name.c_str()); |
155 | 250 | } | 250 | } |
156 | 251 | representative_image_filename_ = g_gr->animations().get_animation(get_animation("idle")) | 251 | representative_image_filename_ = g_gr->animations().get_animation(get_animation("idle")) |
158 | 252 | .representative_image_from_disk_filename(); | 252 | .representative_image_filename(); |
159 | 253 | } | 253 | } |
160 | 254 | if (table.has_key("icon")) { | 254 | if (table.has_key("icon")) { |
161 | 255 | icon_filename_ = table.get_string("icon"); | 255 | icon_filename_ = table.get_string("icon"); |
162 | @@ -310,9 +310,9 @@ | |||
163 | 310 | return ""; | 310 | return ""; |
164 | 311 | } | 311 | } |
165 | 312 | 312 | ||
169 | 313 | const Image* MapObjectDescr::representative_image() const { | 313 | const Image* MapObjectDescr::representative_image(const RGBColor* player_color) const { |
170 | 314 | if (!representative_image_filename_.empty()) { | 314 | if (is_animation_known("idle")) { |
171 | 315 | return g_gr->images().get(representative_image_filename_); | 315 | return g_gr->animations().get_representative_image(get_animation("idle"), player_color); |
172 | 316 | } | 316 | } |
173 | 317 | return nullptr; | 317 | return nullptr; |
174 | 318 | } | 318 | } |
175 | 319 | 319 | ||
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 | 32 | 32 | ||
181 | 33 | #include "base/log.h" | 33 | #include "base/log.h" |
182 | 34 | #include "base/macros.h" | 34 | #include "base/macros.h" |
183 | 35 | #include "graphic/color.h" | ||
184 | 35 | #include "graphic/image.h" | 36 | #include "graphic/image.h" |
185 | 36 | #include "logic/cmd_queue.h" | 37 | #include "logic/cmd_queue.h" |
186 | 37 | #include "logic/widelands.h" | 38 | #include "logic/widelands.h" |
187 | @@ -139,7 +140,7 @@ | |||
188 | 139 | 140 | ||
189 | 140 | /// Returns the image for the first frame of the idle animation if the MapObject has animations, | 141 | /// Returns the image for the first frame of the idle animation if the MapObject has animations, |
190 | 141 | /// nullptr otherwise | 142 | /// nullptr otherwise |
192 | 142 | const Image* representative_image() const; | 143 | const Image* representative_image(const RGBColor* player_color = nullptr) const; |
193 | 143 | /// Returns the image fileneme for first frame of the idle animation if the MapObject has animations, | 144 | /// Returns the image fileneme for first frame of the idle animation if the MapObject has animations, |
194 | 144 | /// is empty otherwise | 145 | /// is empty otherwise |
195 | 145 | const std::string& representative_image_filename() const; | 146 | const std::string& representative_image_filename() const; |
196 | 146 | 147 | ||
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 | 149 | */ | 149 | */ |
202 | 150 | const Image* PartiallyFinishedBuilding::representative_image() const | 150 | const Image* PartiallyFinishedBuilding::representative_image() const |
203 | 151 | { | 151 | { |
205 | 152 | return m_building->representative_image(); | 152 | return m_building->representative_image(&owner().get_playercolor()); |
206 | 153 | } | 153 | } |
207 | 154 | 154 | ||
208 | 155 | 155 | ||
209 | 156 | 156 | ||
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 | 394 | kBuildGridCellWidth, | 394 | kBuildGridCellWidth, |
215 | 395 | kBuildGridCellHeight, | 395 | kBuildGridCellHeight, |
216 | 396 | g_gr->images().get("pics/but1.png"), | 396 | g_gr->images().get("pics/but1.png"), |
218 | 397 | descr.representative_image(), | 397 | descr.representative_image(&iplayer().get_player() |
219 | 398 | ->get_playercolor()), | ||
220 | 398 | "", | 399 | "", |
221 | 399 | false, | 400 | false, |
222 | 400 | true); | 401 | true); |
223 | 401 | 402 | ||
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 | 56 | // The BuildGrid presents a selection of buildable buildings | 56 | // The BuildGrid presents a selection of buildable buildings |
229 | 57 | struct BuildGrid : public UI::IconGrid { | 57 | struct BuildGrid : public UI::IconGrid { |
230 | 58 | BuildGrid(UI::Panel* parent, | 58 | BuildGrid(UI::Panel* parent, |
232 | 59 | const Widelands::TribeDescr& tribe, | 59 | Widelands::Player* plr, |
233 | 60 | int32_t x, | 60 | int32_t x, |
234 | 61 | int32_t y, | 61 | int32_t y, |
235 | 62 | int32_t cols); | 62 | int32_t cols); |
236 | @@ -73,14 +73,14 @@ | |||
237 | 73 | void mousein_slot(int32_t idx); | 73 | void mousein_slot(int32_t idx); |
238 | 74 | 74 | ||
239 | 75 | private: | 75 | private: |
241 | 76 | const Widelands::TribeDescr& tribe_; | 76 | Widelands::Player* plr_; |
242 | 77 | }; | 77 | }; |
243 | 78 | 78 | ||
244 | 79 | BuildGrid::BuildGrid( | 79 | BuildGrid::BuildGrid( |
246 | 80 | UI::Panel* parent, const Widelands::TribeDescr& tribe, | 80 | UI::Panel* parent, Widelands::Player* plr, |
247 | 81 | int32_t x, int32_t y, int32_t cols) : | 81 | int32_t x, int32_t y, int32_t cols) : |
248 | 82 | UI::IconGrid(parent, x, y, kBuildGridCellSize, kBuildGridCellSize, cols), | 82 | UI::IconGrid(parent, x, y, kBuildGridCellSize, kBuildGridCellSize, cols), |
250 | 83 | tribe_(tribe) | 83 | plr_(plr) |
251 | 84 | { | 84 | { |
252 | 85 | clicked.connect(boost::bind(&BuildGrid::click_slot, this, _1)); | 85 | clicked.connect(boost::bind(&BuildGrid::click_slot, this, _1)); |
253 | 86 | mouseout.connect(boost::bind(&BuildGrid::mouseout_slot, this, _1)); | 86 | mouseout.connect(boost::bind(&BuildGrid::mouseout_slot, this, _1)); |
254 | @@ -95,15 +95,16 @@ | |||
255 | 95 | void BuildGrid::add(Widelands::DescriptionIndex id) | 95 | void BuildGrid::add(Widelands::DescriptionIndex id) |
256 | 96 | { | 96 | { |
257 | 97 | const Widelands::BuildingDescr & descr = | 97 | const Widelands::BuildingDescr & descr = |
259 | 98 | *tribe_.get_building_descr(Widelands::DescriptionIndex(id)); | 98 | *plr_->tribe().get_building_descr(Widelands::DescriptionIndex(id)); |
260 | 99 | |||
261 | 99 | // TODO(sirver): change this to take a Button subclass instead of | 100 | // TODO(sirver): change this to take a Button subclass instead of |
262 | 100 | // parameters. This will allow overriding the way it is rendered | 101 | // parameters. This will allow overriding the way it is rendered |
263 | 101 | // to bring back player colors. | 102 | // to bring back player colors. |
264 | 102 | UI::IconGrid::add(descr.name(), | 103 | UI::IconGrid::add(descr.name(), |
266 | 103 | descr.representative_image(), | 104 | descr.representative_image(&plr_->get_playercolor()), |
267 | 104 | reinterpret_cast<void*>(id), | 105 | reinterpret_cast<void*>(id), |
268 | 105 | descr.descname() + "<br><font size=11>" + _("Construction costs:") + | 106 | descr.descname() + "<br><font size=11>" + _("Construction costs:") + |
270 | 106 | "</font><br>" + waremap_to_richtext(tribe_, descr.buildcost())); | 107 | "</font><br>" + waremap_to_richtext(plr_->tribe(), descr.buildcost())); |
271 | 107 | } | 108 | } |
272 | 108 | 109 | ||
273 | 109 | 110 | ||
274 | @@ -531,7 +532,7 @@ | |||
275 | 531 | 532 | ||
276 | 532 | // Allocate the tab's grid if necessary | 533 | // Allocate the tab's grid if necessary |
277 | 533 | if (!*ppgrid) { | 534 | if (!*ppgrid) { |
279 | 534 | *ppgrid = new BuildGrid(&m_tabpanel, tribe, 0, 0, 5); | 535 | *ppgrid = new BuildGrid(&m_tabpanel, m_plr, 0, 0, 5); |
280 | 535 | (*ppgrid)->buildclicked.connect(boost::bind(&FieldActionWindow::act_build, this, _1)); | 536 | (*ppgrid)->buildclicked.connect(boost::bind(&FieldActionWindow::act_build, this, _1)); |
281 | 536 | (*ppgrid)->buildmouseout.connect | 537 | (*ppgrid)->buildmouseout.connect |
282 | 537 | (boost::bind(&FieldActionWindow::building_icon_mouse_out, this, _1)); | 538 | (boost::bind(&FieldActionWindow::building_icon_mouse_out, this, _1)); |
Well I cannot see a difference... or rather I dont understand where exactly should I look at...