~hjd/widelands/optimizations

« back to all changes in this revision

Viewing changes to src/wui/warehousewindow.cc

  • Committer: Joachim Breitner
  • Date: 2010-10-30 12:29:45 UTC
  • mto: (5613.1.3 rip-temp-economy)
  • mto: This revision was merged to the branch mainline in revision 5620.
  • Revision ID: mail@joachim-breitner.de-20101030122945-nz8h0biimoy9ord7
Warehouse UI changed to button-controlled
Entries in the wares list can be toggled. Buttons are added to the bottom to
set the policyies. Images are not yet polished.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
                        return false;
90
90
 
91
91
                if (m_igbase.can_act(m_warehouse.owner().player_number())) {
92
 
                        Warehouse::StockPolicy policy = m_warehouse.get_stock_policy(get_type() == WORKER, ware);
93
 
                        Warehouse::StockPolicy newpolicy;
94
 
 
95
 
                        switch(policy) {
96
 
                        case Warehouse::SP_Normal: newpolicy = Warehouse::SP_Prefer; break;
97
 
                        case Warehouse::SP_Prefer: newpolicy = Warehouse::SP_DontStock; break;
98
 
                        case Warehouse::SP_DontStock: newpolicy = Warehouse::SP_Remove; break;
99
 
                        default: newpolicy = Warehouse::SP_Normal; break;
100
 
                        }
101
 
 
102
 
                        m_igbase.game().send_player_command
103
 
                                (*new Widelands::Cmd_SetStockPolicy
104
 
                                        (m_igbase.game().get_gametime(), m_warehouse.owner().player_number(),
105
 
                                         m_warehouse, get_type() == WORKER, ware, newpolicy));
 
92
                        toggle_ware(ware);
106
93
                }
107
 
 
108
94
                return true;
109
95
        }
110
96
 
111
97
        return WaresDisplay::handle_mousepress(btn, x, y);
112
98
}
113
99
 
 
100
/**
 
101
 * Wraps the wares display together with some buttons
 
102
 */
 
103
struct WarehouseWaresPanel : UI::Box {
 
104
        WarehouseWaresPanel(UI::Panel * parent, uint32_t width, Interactive_GameBase &, Warehouse &, WaresDisplay::wdType type);
 
105
 
 
106
        void set_policy(Warehouse::StockPolicy);
 
107
private:
 
108
        WarehouseWaresDisplay m_display;
 
109
        Interactive_GameBase & m_gb;
 
110
        Warehouse & m_wh;
 
111
        WaresDisplay::wdType m_type;
 
112
 
 
113
};
 
114
 
 
115
WarehouseWaresPanel::WarehouseWaresPanel(UI::Panel * parent, uint32_t width, Interactive_GameBase & gb, Warehouse & wh, WaresDisplay::wdType type) :
 
116
        UI::Box(parent, 0, 0, UI::Box::Vertical),
 
117
        m_display(this, width, gb, wh, type),
 
118
        m_gb(gb),
 
119
        m_wh(wh),
 
120
        m_type(type)
 
121
{
 
122
        add(&m_display, UI::Box::AlignLeft, true);
 
123
 
 
124
        UI::Box *buttons = new UI::Box(this, 0, 0, UI::Box::Horizontal);
 
125
        add(buttons, UI::Box::AlignLeft);
 
126
                
 
127
        if (m_gb.can_act(m_wh.owner().player_number())) {
 
128
#define ADD_POLICY_BUTTON(policy, policyname)                             \
 
129
                buttons->add(new UI::Callback_Button(                     \
 
130
                        buttons, "workarea",                              \
 
131
                        0, 0, 34, 34,                                     \
 
132
                        g_gr->get_picture(PicMod_UI,"pics/but4.png"),     \
 
133
                        g_gr->get_picture(PicMod_Game,                    \
 
134
                              "pics/stock_policy_button_" #policy ".png"),\
 
135
                        boost::bind(&WarehouseWaresPanel::set_policy,     \
 
136
                                    this, Warehouse::SP_##policyname),    \
 
137
                        _("Normal policy"))                               \
 
138
                , UI::Box::AlignCenter);                                  \
 
139
        
 
140
                ADD_POLICY_BUTTON(normal, Normal)
 
141
                ADD_POLICY_BUTTON(prefer, Prefer)
 
142
                ADD_POLICY_BUTTON(dontstock, DontStock)
 
143
                ADD_POLICY_BUTTON(remove, Remove)
 
144
        }
 
145
}
 
146
 
 
147
/**
 
148
 * Add Buttons policy buttons
 
149
 */
 
150
void WarehouseWaresPanel::set_policy(Warehouse::StockPolicy newpolicy) {
 
151
        bool is_workers = m_type == WaresDisplay::WORKER;
 
152
        Widelands::Ware_Index nritems =
 
153
                           is_workers ? m_wh.owner().tribe().get_nrworkers() :
 
154
                                        m_wh.owner().tribe().get_nrwares();
 
155
        if (m_gb.can_act(m_wh.owner().player_number())) {
 
156
               for (Widelands::Ware_Index id = Widelands::Ware_Index::First();
 
157
                    id < nritems; ++id) {
 
158
                        if (m_display.ware_selected(id)) {
 
159
                                m_gb.game().send_player_command
 
160
                                        (*new Widelands::Cmd_SetStockPolicy
 
161
                                                (m_gb.game().get_gametime(),
 
162
                                                 m_wh.owner().player_number(),
 
163
                                                 m_wh, is_workers,
 
164
                                                 id, newpolicy));
 
165
                        }
 
166
                }
 
167
        }
 
168
}
 
169
 
114
170
 
115
171
/**
116
172
 * Status window for warehouses
149
205
void Warehouse_Window::make_wares_tab
150
206
        (WaresDisplay::wdType type, PictureID tabicon, const std::string & tooltip)
151
207
{
152
 
        WaresDisplay * display = new WarehouseWaresDisplay(get_tabs(), Width, igbase(), warehouse(), type);
153
 
        get_tabs()->add("wares", tabicon, display, tooltip);
 
208
        WarehouseWaresPanel * panel = new WarehouseWaresPanel(get_tabs(), Width, igbase(), warehouse(), type);
 
209
        get_tabs()->add("wares", tabicon, panel, tooltip);
154
210
}
155
211
 
156
212
/**