Author: fendrin
Date: Mon Nov 23 13:55:21 2009
New Revision: 39897

URL: http://svn.gna.org/viewcvs/wesnoth?rev=39897&view=rev
Log:
Grey out units the player can't afford to recruit.

Modified:
    branches/fendrin_gui_stuff/data/gui/default/window/icon_message.cfg
    branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.cpp
    branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.hpp
    branches/fendrin_gui_stuff/src/menu_events.cpp

Modified: branches/fendrin_gui_stuff/data/gui/default/window/icon_message.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/data/gui/default/window/icon_message.cfg?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/data/gui/default/window/icon_message.cfg 
(original)
+++ branches/fendrin_gui_stuff/data/gui/default/window/icon_message.cfg Mon Nov 
23 13:55:21 2009
@@ -404,6 +404,10 @@
                fixed_width = "true"
            [/linked_group]
 
+               [linked_group]
+               id = "usage"
+               fixed_width = "true"
+           [/linked_group]
 
            [grid]
 
@@ -929,6 +933,21 @@
 
                                        [/column]
 
+                    [column]
+                                           grow_factor = 1
+                                           horizontal_grow = "true"
+
+                                           border = "all"
+                                           border_size = 5
+
+                                           [label]
+                                               id = "usage"
+                                               definition = "default"
+                                               linked_group = "usage"
+                                           [/label]
+
+                                       [/column]
+
                                    [/row]
 
                                [/grid]

Modified: branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.cpp?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.cpp (original)
+++ branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.cpp Mon Nov 23 
13:55:21 2009
@@ -95,7 +95,7 @@
        if (!message.str().empty()) {
                const int res = gui2::show_message(video, "", message.str(),
                                tmessage::yes_no_buttons, false, false);
-               if (res == 0) {
+               if (res == gui2::twindow::CANCEL) {
                        return;
                }
        }
@@ -103,12 +103,14 @@
        game_menu_handler_->do_delete_recall(chosen_unit_);
 
        input_list.remove_row(input_list.get_selected_row());
+       window.invalidate_layout();
 
        unit_list_.erase(unit_list_.begin() + input_list.get_selected_row());
        if (unit_list_.empty()) {
                window.close();
        }
-       chosen_unit_ = &unit_list_[0];
+       *chosen_unit_ = unit_list_[0];
+       input_list.select_row(0,true);
        update_unit_list(window);
        input_list.set_dirty();
        window.set_dirty();
@@ -274,7 +276,11 @@
        std::map<std::string, string_map> data;
        for (size_t i = 0; i < unit_list_.size(); i++) {
                unit& unit = unit_list_[i];
-               std::string icon = (unit.absolute_image() + unit.image_mods());
+
+               bool affordable = unit.cost() <= gold_ ;
+
+               std::string unit_mod = affordable ? unit.image_mods() : "~GS()" 
;
+               std::string icon = (unit.absolute_image() + unit_mod);
                std::string type = unit.type_name();
                std::string name = unit.name();
                std::string traits = unit.traits_description();
@@ -298,11 +304,19 @@
                //                      }
                level << level_number;
 
+               std::string gold_color;
+
+               gold_color = affordable ? "green" : "red" ;
+
                std::ostringstream cost;
-               cost << unit.cost() << " " << _("Gold");
+               cost << "<span color=\"" << gold_color << "\">" << unit.cost() 
<< " " << _("Gold") << "</span>" ;
 
                // Add the data.
                data["cost"]["label"] = cost.str();
+               data["cost"]["use_markup"] = "true";
+
+               data["usage"]["label"] = unit.usage();
+
                data["icon"]["label"] = icon;
                data["icon"]["use_markup"] = "true";
                data["name"]["label"] = name;
@@ -519,12 +533,13 @@
 
 int show_recruit_message(const bool left_side, CVideo& video,
                const bool mirror, const std::vector<const unit_type*> 
type_list,
-               std::string& chosen_type_id) {
+               std::string& chosen_type_id,
+               int side_num, int gold) {
        std::auto_ptr<trecruit_message_> dlg;
        if (left_side) {
-               dlg.reset(new trecruit_message_left(mirror, type_list, 
chosen_type_id));
-       } else {
-               dlg.reset(new trecruit_message_right(mirror, type_list, 
chosen_type_id));
+               dlg.reset(new trecruit_message_left(mirror, type_list, 
chosen_type_id, side_num, gold));
+       } else {
+               dlg.reset(new trecruit_message_right(mirror, type_list, 
chosen_type_id, side_num, gold));
        }
        assert(dlg.get());
        dlg->show(video);

Modified: branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.hpp?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.hpp (original)
+++ branches/fendrin_gui_stuff/src/gui/dialogs/wml_message.hpp Mon Nov 23 
13:55:21 2009
@@ -241,7 +241,7 @@
                        const std::vector<unit>& unit_list,
                        unit* chosen_unit)
                        : ticon_message_(title, message, 
chosen_unit->transparent(), mirror)
-                         , unit_list_(unit_list) , chosen_unit_(chosen_unit)
+                         , unit_list_(unit_list) , chosen_unit_(chosen_unit), 
gold_(10000)
        {
        }
 
@@ -249,23 +249,19 @@
                        const std::string& message,
                        const bool mirror,
                        const std::vector<const unit_type*> type_list,
-                       unit* chosen_unit)
+                       unit* chosen_unit, int side_num, int gold)
                                : ticon_message_(title, message, "", mirror)
                                  , chosen_unit_(chosen_unit)
+                                 , gold_(gold)
                                  {
                std::vector<const unit_type*>::const_iterator it;
                it = type_list.begin();
-
-               int side_num = 1;
 
                for (it = type_list.begin(); it != type_list.end(); it++)
                {
                        unit new_unit(resources::units, *it, side_num, false);
                        unit_list_.push_back(new_unit);
                }
-
-
-
                                  }
 
        /** Handler for the profile button event. */
@@ -289,6 +285,9 @@
        /** Inherited from tdialog. */
        void post_show(twindow& window);
 
+private:
+       int gold_;
+
 };
 
 class trecruit_message_ : public tunit_message_
@@ -296,13 +295,14 @@
 public:
        trecruit_message_(const bool mirror,
                        const std::vector<const unit_type*> type_list,
-                       std::string& chosen_type)
+                       std::string& chosen_type,
+                       int side_num, int gold)
                        : tunit_message_(_("Recruit")
                                        , _("Select Unit")
                                        , mirror
-                                       , type_list, &unit_ )
+                                       , type_list, &unit_, side_num, gold )
                          , chosen_type_(chosen_type)
-                         , unit_(resources::units, type_list.front(), 1, false)
+                         , unit_(resources::units, type_list.front(), false, 
side_num)
        {
        }
 
@@ -326,8 +326,8 @@
 public:
        trecruit_message_left(const bool mirror,
                        const std::vector<const unit_type*> type_list,
-                       std::string& chosen_type)
-               : trecruit_message_(mirror, type_list, chosen_type)
+                       std::string& chosen_type, int side_num, int gold)
+               : trecruit_message_(mirror, type_list, chosen_type, side_num, 
gold)
        {
        }
 private:
@@ -340,8 +340,8 @@
 public:
        trecruit_message_right(const bool mirror,
                        const std::vector<const unit_type*> type_list,
-                       std::string& chosen_type)
-               : trecruit_message_(mirror, type_list, chosen_type)
+                       std::string& chosen_type, int side_num, int gold)
+               : trecruit_message_(mirror, type_list, chosen_type, side_num, 
gold)
        {
        }
 private:
@@ -514,7 +514,9 @@
                , CVideo& video
                , const bool mirror
            , const std::vector<const unit_type*> type_list
-           , std::string& chosen_type);
+           , std::string& chosen_type
+           , int side_num
+           , int gold);
 
 } // namespace gui2
 

Modified: branches/fendrin_gui_stuff/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/fendrin_gui_stuff/src/menu_events.cpp?rev=39897&r1=39896&r2=39897&view=diff
==============================================================================
--- branches/fendrin_gui_stuff/src/menu_events.cpp (original)
+++ branches/fendrin_gui_stuff/src/menu_events.cpp Mon Nov 23 13:55:21 2009
@@ -691,7 +691,7 @@
        int recruit_res = 0;
        std::string chosen_type_id;
 
-       recruit_res = gui2::show_recruit_message(left_side, gui_->video(), 
false, sample_units, chosen_type_id);
+       recruit_res = gui2::show_recruit_message(left_side, gui_->video(), 
false, sample_units, chosen_type_id, side_num, current_team.gold());
 
        if(recruit_res == gui2::twindow::OK) {
                do_recruit(chosen_type_id, side_num, last_hex);


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to