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
=== modified file 'src/graphic/animation.cc'
--- src/graphic/animation.cc 2015-11-06 12:19:22 +0000
+++ src/graphic/animation.cc 2015-11-21 10:37:21 +0000
@@ -39,6 +39,7 @@
39#include "graphic/image.h"39#include "graphic/image.h"
40#include "graphic/image_cache.h"40#include "graphic/image_cache.h"
41#include "graphic/surface.h"41#include "graphic/surface.h"
42#include "graphic/texture.h"
42#include "io/filesystem/layered_filesystem.h"43#include "io/filesystem/layered_filesystem.h"
43#include "logic/bob.h"44#include "logic/bob.h"
44#include "logic/instances.h"45#include "logic/instances.h"
@@ -123,7 +124,8 @@
123 uint16_t nr_frames() const override;124 uint16_t nr_frames() const override;
124 uint32_t frametime() const override;125 uint32_t frametime() const override;
125 const Point& hotspot() const override;126 const Point& hotspot() const override;
126 const std::string& representative_image_from_disk_filename() const override;127 Image* representative_image(const RGBColor* clr) const override;
128 const std::string& representative_image_filename() const override;
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*)
128 const override;130 const override;
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;
@@ -297,7 +299,33 @@
297 return hotspot_;299 return hotspot_;
298}300}
299301
300const std::string& NonPackedAnimation::representative_image_from_disk_filename() const {302Image* NonPackedAnimation::representative_image(const RGBColor* clr) const {
303 assert(!image_files_.empty());
304
305 const Image* image = g_gr->images().get(image_files_[0]);
306 int w = image->width();
307 int h = image->height();
308
309 Texture* rv = new Texture(w, h);
310 if (!hasplrclrs_ || clr == nullptr) {
311 ::blit(Rect(Point(0, 0), w, h),
312 *image,
313 Rect(Point(0, 0), w, h),
314 1.,
315 BlendMode::UseAlpha,
316 rv);
317 } else {
318 blit_blended(Rect(Point(0, 0), w, h),
319 *image,
320 *g_gr->images().get(pc_mask_image_files_[0]),
321 Rect(Point(0, 0), w, h),
322 *clr,
323 rv);
324 }
325 return rv;
326}
327
328const std::string& NonPackedAnimation::representative_image_filename() const {
301 return image_files_[0];329 return image_files_[0];
302}330}
303331
@@ -383,20 +411,24 @@
383*/411*/
384412
385uint32_t AnimationManager::load(const LuaTable& table) {413uint32_t AnimationManager::load(const LuaTable& table) {
386 m_animations.push_back(new NonPackedAnimation(table));414 animations_.push_back(std::unique_ptr<Animation>(new NonPackedAnimation(table)));
387 return m_animations.size();415 return animations_.size();
388}416}
389417
390const Animation& AnimationManager::get_animation(uint32_t id) const418const Animation& AnimationManager::get_animation(uint32_t id) const
391{419{
392 if (!id || id > m_animations.size())420 if (!id || id > animations_.size())
393 throw wexception("Requested unknown animation with id: %i", id);421 throw wexception("Requested unknown animation with id: %i", id);
394422
395 return *m_animations[id - 1];423 return *animations_[id - 1].get();
396}424}
397425
398AnimationManager::~AnimationManager()426const Image* AnimationManager::get_representative_image(uint32_t id, const RGBColor* clr) {
399{427 if (representative_images_.count(id) != 1) {
400 for (vector<Animation*>::iterator it = m_animations.begin(); it != m_animations.end(); ++it)428 representative_images_.insert(
401 delete *it;429 std::make_pair(
430 id,
431 std::unique_ptr<Image>(g_gr->animations().get_animation(id).representative_image(clr))));
432 }
433 return representative_images_.at(id).get();
402}434}
403435
=== modified file 'src/graphic/animation.h'
--- src/graphic/animation.h 2015-11-06 12:19:22 +0000
+++ src/graphic/animation.h 2015-11-21 10:37:21 +0000
@@ -22,6 +22,7 @@
2222
23#include <cstring>23#include <cstring>
24#include <map>24#include <map>
25#include <memory>
25#include <string>26#include <string>
26#include <vector>27#include <vector>
2728
@@ -67,13 +68,17 @@
67 /// so the caller has to adjust for the hotspot himself.68 /// so the caller has to adjust for the hotspot himself.
68 virtual const Point& hotspot() const = 0;69 virtual const Point& hotspot() const = 0;
6970
70 /// Returns the disk filename for the first image in the animation71 /// An image of the first frame, blended with the given player color.
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
73 /// 'nullptr', in which case the neutral image will be returned.
74 virtual Image* representative_image(const RGBColor* clr) const = 0;
75 /// The filename of the image used for the first frame, without player color.
76 virtual const std::string& representative_image_filename() const = 0;
7277
73 /// Blit the animation frame that should be displayed at the given time index78 /// Blit the animation frame that should be displayed at the given time index
74 /// so that the given point is at the top left of the frame. Srcrc defines79 /// so that the given point is at the top left of the frame. Srcrc defines
75 /// the part of the animation that should be blitted. The 'clr' is the player80 /// the part of the animation that should be blitted. The 'clr' is the player
76 /// color used for blitting - the parameter can be nullptr in which case the81 /// color used for blitting - the parameter can be 'nullptr', in which case the
77 /// neutral image will be blitted. The Surface is the target for the blit82 /// neutral image will be blitted. The Surface is the target for the blit
78 /// operation and must be non-null.83 /// operation and must be non-null.
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;
@@ -90,7 +95,6 @@
90*/95*/
91class AnimationManager {96class AnimationManager {
92public:97public:
93 ~AnimationManager();
94 /**98 /**
95 * Loads an animation, graphics sound and everything from a Lua table.99 * Loads an animation, graphics sound and everything from a Lua table.
96 *100 *
@@ -104,10 +108,14 @@
104 /// unknown.108 /// unknown.
105 const Animation& get_animation(uint32_t id) const;109 const Animation& get_animation(uint32_t id) const;
106110
111 /// Returns the representative image, using the given player color.
112 /// If this image has been generated before, it is pulled from the cache using
113 /// the clr argument that was used previously.
114 const Image* get_representative_image(uint32_t id, const RGBColor* clr = nullptr);
115
107private:116private:
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_;
109 // instead of raw pointers to get rid of the destructor118 std::map<uint32_t, std::unique_ptr<Image>> representative_images_;
110 std::vector<Animation*> m_animations;
111};119};
112120
113#endif // end of include guard: WL_GRAPHIC_ANIMATION_H121#endif // end of include guard: WL_GRAPHIC_ANIMATION_H
114122
=== modified file 'src/logic/instances.cc'
--- src/logic/instances.cc 2015-11-02 19:29:03 +0000
+++ src/logic/instances.cc 2015-11-21 10:37:21 +0000
@@ -249,7 +249,7 @@
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());
250 }250 }
251 representative_image_filename_ = g_gr->animations().get_animation(get_animation("idle"))251 representative_image_filename_ = g_gr->animations().get_animation(get_animation("idle"))
252 .representative_image_from_disk_filename();252 .representative_image_filename();
253 }253 }
254 if (table.has_key("icon")) {254 if (table.has_key("icon")) {
255 icon_filename_ = table.get_string("icon");255 icon_filename_ = table.get_string("icon");
@@ -310,9 +310,9 @@
310 return "";310 return "";
311}311}
312312
313const Image* MapObjectDescr::representative_image() const {313const Image* MapObjectDescr::representative_image(const RGBColor* player_color) const {
314 if (!representative_image_filename_.empty()) {314 if (is_animation_known("idle")) {
315 return g_gr->images().get(representative_image_filename_);315 return g_gr->animations().get_representative_image(get_animation("idle"), player_color);
316 }316 }
317 return nullptr;317 return nullptr;
318}318}
319319
=== modified file 'src/logic/instances.h'
--- src/logic/instances.h 2015-10-21 16:43:30 +0000
+++ src/logic/instances.h 2015-11-21 10:37:21 +0000
@@ -32,6 +32,7 @@
3232
33#include "base/log.h"33#include "base/log.h"
34#include "base/macros.h"34#include "base/macros.h"
35#include "graphic/color.h"
35#include "graphic/image.h"36#include "graphic/image.h"
36#include "logic/cmd_queue.h"37#include "logic/cmd_queue.h"
37#include "logic/widelands.h"38#include "logic/widelands.h"
@@ -139,7 +140,7 @@
139140
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,
141 /// nullptr otherwise142 /// nullptr otherwise
142 const Image* representative_image() const;143 const Image* representative_image(const RGBColor* player_color = nullptr) const;
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,
144 /// is empty otherwise145 /// is empty otherwise
145 const std::string& representative_image_filename() const;146 const std::string& representative_image_filename() const;
146147
=== modified file 'src/logic/partially_finished_building.cc'
--- src/logic/partially_finished_building.cc 2015-11-11 09:52:55 +0000
+++ src/logic/partially_finished_building.cc 2015-11-21 10:37:21 +0000
@@ -149,7 +149,7 @@
149*/149*/
150const Image* PartiallyFinishedBuilding::representative_image() const150const Image* PartiallyFinishedBuilding::representative_image() const
151{151{
152 return m_building->representative_image();152 return m_building->representative_image(&owner().get_playercolor());
153}153}
154154
155155
156156
=== modified file 'src/wui/building_statistics_menu.cc'
--- src/wui/building_statistics_menu.cc 2015-11-17 14:36:25 +0000
+++ src/wui/building_statistics_menu.cc 2015-11-21 10:37:21 +0000
@@ -394,7 +394,8 @@
394 kBuildGridCellWidth,394 kBuildGridCellWidth,
395 kBuildGridCellHeight,395 kBuildGridCellHeight,
396 g_gr->images().get("pics/but1.png"),396 g_gr->images().get("pics/but1.png"),
397 descr.representative_image(),397 descr.representative_image(&iplayer().get_player()
398 ->get_playercolor()),
398 "",399 "",
399 false,400 false,
400 true);401 true);
401402
=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc 2015-11-11 09:53:54 +0000
+++ src/wui/fieldaction.cc 2015-11-21 10:37:21 +0000
@@ -56,7 +56,7 @@
56// The BuildGrid presents a selection of buildable buildings56// The BuildGrid presents a selection of buildable buildings
57struct BuildGrid : public UI::IconGrid {57struct BuildGrid : public UI::IconGrid {
58 BuildGrid(UI::Panel* parent,58 BuildGrid(UI::Panel* parent,
59 const Widelands::TribeDescr& tribe,59 Widelands::Player* plr,
60 int32_t x,60 int32_t x,
61 int32_t y,61 int32_t y,
62 int32_t cols);62 int32_t cols);
@@ -73,14 +73,14 @@
73 void mousein_slot(int32_t idx);73 void mousein_slot(int32_t idx);
7474
75private:75private:
76 const Widelands::TribeDescr& tribe_;76 Widelands::Player* plr_;
77};77};
7878
79BuildGrid::BuildGrid(79BuildGrid::BuildGrid(
80 UI::Panel* parent, const Widelands::TribeDescr& tribe,80 UI::Panel* parent, Widelands::Player* plr,
81 int32_t x, int32_t y, int32_t cols) :81 int32_t x, int32_t y, int32_t cols) :
82 UI::IconGrid(parent, x, y, kBuildGridCellSize, kBuildGridCellSize, cols),82 UI::IconGrid(parent, x, y, kBuildGridCellSize, kBuildGridCellSize, cols),
83 tribe_(tribe)83 plr_(plr)
84{84{
85 clicked.connect(boost::bind(&BuildGrid::click_slot, this, _1));85 clicked.connect(boost::bind(&BuildGrid::click_slot, this, _1));
86 mouseout.connect(boost::bind(&BuildGrid::mouseout_slot, this, _1));86 mouseout.connect(boost::bind(&BuildGrid::mouseout_slot, this, _1));
@@ -95,15 +95,16 @@
95void BuildGrid::add(Widelands::DescriptionIndex id)95void BuildGrid::add(Widelands::DescriptionIndex id)
96{96{
97 const Widelands::BuildingDescr & descr =97 const Widelands::BuildingDescr & descr =
98 *tribe_.get_building_descr(Widelands::DescriptionIndex(id));98 *plr_->tribe().get_building_descr(Widelands::DescriptionIndex(id));
99
99 // TODO(sirver): change this to take a Button subclass instead of100 // TODO(sirver): change this to take a Button subclass instead of
100 // parameters. This will allow overriding the way it is rendered101 // parameters. This will allow overriding the way it is rendered
101 // to bring back player colors.102 // to bring back player colors.
102 UI::IconGrid::add(descr.name(),103 UI::IconGrid::add(descr.name(),
103 descr.representative_image(),104 descr.representative_image(&plr_->get_playercolor()),
104 reinterpret_cast<void*>(id),105 reinterpret_cast<void*>(id),
105 descr.descname() + "<br><font size=11>" + _("Construction costs:") +106 descr.descname() + "<br><font size=11>" + _("Construction costs:") +
106 "</font><br>" + waremap_to_richtext(tribe_, descr.buildcost()));107 "</font><br>" + waremap_to_richtext(plr_->tribe(), descr.buildcost()));
107}108}
108109
109110
@@ -531,7 +532,7 @@
531532
532 // Allocate the tab's grid if necessary533 // Allocate the tab's grid if necessary
533 if (!*ppgrid) {534 if (!*ppgrid) {
534 *ppgrid = new BuildGrid(&m_tabpanel, tribe, 0, 0, 5);535 *ppgrid = new BuildGrid(&m_tabpanel, m_plr, 0, 0, 5);
535 (*ppgrid)->buildclicked.connect(boost::bind(&FieldActionWindow::act_build, this, _1));536 (*ppgrid)->buildclicked.connect(boost::bind(&FieldActionWindow::act_build, this, _1));
536 (*ppgrid)->buildmouseout.connect537 (*ppgrid)->buildmouseout.connect
537 (boost::bind(&FieldActionWindow::building_icon_mouse_out, this, _1));538 (boost::bind(&FieldActionWindow::building_icon_mouse_out, this, _1));

Subscribers

People subscribed via source and target branches

to status/vote changes: