~qcumber-some/widelands/spice-up-cmake

« back to all changes in this revision

Viewing changes to src/wui/fieldaction.cc

  • Committer: Jens Beyer (Qcumber-some)
  • Date: 2010-05-28 14:51:37 UTC
  • mfrom: (5149.1.226 trunk)
  • Revision ID: qcumber-some@buerotiger.de-20100528145137-0pyil9qw7szyztsw
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
         int32_t                        cols)
89
89
:
90
90
        UI::Icon_Grid
91
 
                (parent, x, y, BG_CELL_WIDTH, BG_CELL_HEIGHT, Grid_Horizontal, cols),
 
91
                (parent, x, y, BG_CELL_WIDTH, BG_CELL_HEIGHT, cols),
92
92
        m_tribe(tribe)
93
93
{
94
94
        clicked.set(this, &BuildGrid::clickslot);
107
107
        Widelands::Building_Descr const & descr =
108
108
                *m_tribe.get_building_descr(Widelands::Building_Index(id));
109
109
        UI::Icon_Grid::add
110
 
                (descr.get_buildicon(), reinterpret_cast<void *>(id), descr.descname());
 
110
                (descr.name(), descr.get_buildicon(),
 
111
                 reinterpret_cast<void *>(id), descr.descname());
111
112
}
112
113
 
113
114
 
204
205
 
205
206
private:
206
207
        uint32_t add_tab
207
 
                (const char * picname,
 
208
                (const std::string & name,
 
209
                 const char * picname,
208
210
                 UI::Panel * panel,
209
211
                 const std::string & tooltip_text = std::string());
210
212
        void add_button
211
213
                (UI::Box *,
 
214
                 char const * name,
212
215
                 char const * picname,
213
216
                 void (FieldActionWindow::*fn)(),
214
217
                 std::string const & tooltip_text,
244
247
        _("Build medium buildings"),
245
248
        _("Build large buildings")
246
249
};
 
250
static const std::string name_tab_build[] = { "small", "medium", "big" };
 
251
 
247
252
 
248
253
static char const * const pic_tab_buildmine  = "pics/menu_tab_buildmine.png";
249
254
 
272
277
         Widelands::Player          * const plr,
273
278
         UI::UniqueWindow::Registry * const registry)
274
279
:
275
 
        UI::UniqueWindow(ib, registry, 68, 34, _("Action")),
 
280
        UI::UniqueWindow(ib, "field_action", registry, 68, 34, _("Action")),
276
281
        m_plr(plr),
277
282
        m_map(&ib->egbase().map()),
278
283
        m_overlay_manager(*m_map->get_overlay_manager()),
285
290
{
286
291
        ib->set_sel_freeze(true);
287
292
 
288
 
        m_tabpanel.set_snapparent(true);
 
293
        set_center_panel(&m_tabpanel);
289
294
 
290
295
        char filename[] = "pics/workarea0cumulative.png";
291
296
        compile_assert(NUMBER_OF_WORKAREA_PICS <= 9);
321
326
*/
322
327
void FieldActionWindow::init()
323
328
{
324
 
        m_tabpanel.layout();
325
 
 
326
329
        center_to_parent(); // override UI::UniqueWindow position
327
330
 
328
331
        // Move the window away from the current mouse position, i.e.
376
379
                        bool const can_act = igbase.can_act(owner);
377
380
                        if (can_act) {
378
381
                                add_button
379
 
                                        (buildbox,
 
382
                                        (buildbox, "build_road",
380
383
                                         pic_buildroad,
381
384
                                         &FieldActionWindow::act_buildroad,
382
385
                                         _("Build road"));
388
391
                                         ||
389
392
                                         building->get_playercaps() & (1 << Building::PCap_Bulldoze))
390
393
                                        add_button
391
 
                                                (buildbox,
 
394
                                                (buildbox, "rip_flag",
392
395
                                                 pic_ripflag,
393
396
                                                 &FieldActionWindow::act_ripflag,
394
397
                                                 _("Destroy this flag"));
396
399
 
397
400
                        if (dynamic_cast<Game const *>(&ibase().egbase())) {
398
401
                                add_button
399
 
                                        (buildbox,
 
402
                                        (buildbox, "configure_economy",
400
403
                                         "pics/genstats_nrwares.png",
401
404
                                         &FieldActionWindow::act_configure_economy,
402
405
                                         _("Configure economy"));
403
406
                                if (can_act)
404
407
                                        add_button
405
 
                                                (buildbox,
 
408
                                                (buildbox, "geologist",
406
409
                                                 pic_geologist,
407
410
                                                 &FieldActionWindow::act_geologist,
408
411
                                                 _("Send geologist to explore site"));
420
423
                        // Add build actions
421
424
                        if ((m_fastclick = buildcaps & Widelands::BUILDCAPS_FLAG))
422
425
                                add_button
423
 
                                        (buildbox,
 
426
                                        (buildbox, "build_flag",
424
427
                                         pic_buildflag,
425
428
                                         &FieldActionWindow::act_buildflag,
426
429
                                         _("Put a flag"));
427
430
 
428
431
                        if (dynamic_cast<Widelands::Road const *>(imm))
429
432
                                add_button
430
 
                                        (buildbox,
 
433
                                        (buildbox, "destroy_road",
431
434
                                         pic_remroad,
432
435
                                         &FieldActionWindow::act_removeroad,
433
436
                                         _("Destroy a road"));
445
448
        //  census is ok
446
449
        if (dynamic_cast<Game const *>(&ibase().egbase())) {
447
450
                add_button
448
 
                        (&watchbox,
 
451
                        (&watchbox, "watch",
449
452
                         pic_watchfield,
450
453
                         &FieldActionWindow::act_watch,
451
454
                         _("Watch field in a separate window"));
452
455
                add_button
453
 
                        (&watchbox,
 
456
                        (&watchbox, "statistics",
454
457
                         pic_showstatistics,
455
458
                         &FieldActionWindow::act_show_statistics,
456
459
                         _("Toggle building statistics display"));
457
460
        }
458
461
        add_button
459
 
                (&watchbox,
 
462
                (&watchbox, "census",
460
463
                 pic_showcensus,
461
464
                 &FieldActionWindow::act_show_census,
462
465
                 _("Toggle building label display"));
463
466
 
464
467
        if (ibase().get_display_flag(Interactive_Base::dfDebug))
465
468
                add_button
466
 
                        (&watchbox,
 
469
                        (&watchbox, "debug",
467
470
                         pic_debug,
468
471
                         &FieldActionWindow::act_debug,
469
472
                         _("Debug window"));
472
475
                m_plr ? new MilitaryBox(&m_tabpanel, m_plr, 0, 0) : 0;
473
476
 
474
477
        // Add tabs
475
 
        if (buildbox && buildbox->get_nritems()) {
476
 
                buildbox->layout();
477
 
                add_tab(pic_tab_buildroad, buildbox, _("Build roads"));
478
 
        }
 
478
        if (buildbox && buildbox->get_nritems())
 
479
                add_tab("roads", pic_tab_buildroad, buildbox, _("Build roads"));
479
480
 
480
 
        watchbox.layout();
481
 
        add_tab(pic_tab_watch, &watchbox, _("Watch"));
 
481
        add_tab("watch", pic_tab_watch, &watchbox, _("Watch"));
482
482
 
483
483
        if (militarybox) {
484
484
                if (militarybox->allowed_change()) {
485
 
                        militarybox->layout();
486
 
                        add_tab(pic_tab_military, militarybox, _("Military settings"));
 
485
                        add_tab("military", pic_tab_military,
 
486
                                        militarybox, _("Military settings")
 
487
                        );
487
488
                } else
488
489
                        delete militarybox;
489
490
        }
505
506
                                a_box.add(m_attack_box, UI::Box::AlignTop);
506
507
 
507
508
                                add_button
508
 
                                        (&a_box,
 
509
                                        (&a_box, "attack",
509
510
                                         pic_attack,
510
511
                                         &FieldActionWindow::act_attack,
511
512
                                         _("Start attack"));
513
514
        }
514
515
 
515
516
        if (a_box.get_nritems()) { //  add tab
516
 
                m_attack_box->layout();
517
 
                a_box.layout();
518
 
                add_tab(pic_tab_attack, &a_box, _("Attack"));
 
517
                add_tab("attack", pic_tab_attack, &a_box, _("Attack"));
519
518
        }
520
519
}
521
520
 
587
586
                if (bbg_house[i])
588
587
                        m_tabpanel.activate
589
588
                                (m_best_tab = add_tab
590
 
                                        (pic_tab_buildhouse[i],
 
589
                                        (name_tab_build[i], pic_tab_buildhouse[i],
591
590
                                         bbg_house[i],
592
591
                                         i18n::translate(tooltip_tab_build[i])));
593
592
 
594
593
        if (bbg_mine)
595
594
                m_tabpanel.activate
596
 
                        (m_best_tab = add_tab(pic_tab_buildmine, bbg_mine, _("Build mines")));
 
595
                        (m_best_tab = add_tab
 
596
                                ("mines", pic_tab_buildmine, bbg_mine, _("Build mines")));
597
597
}
598
598
 
599
599
 
608
608
 
609
609
        if (flag)
610
610
                add_button
611
 
                        (&buildbox,
 
611
                        (&buildbox, "build_flag",
612
612
                         pic_buildflag, &FieldActionWindow::act_buildflag, _("Build flag"));
613
613
 
614
614
        add_button
615
 
                (&buildbox,
 
615
                (&buildbox, "cancel_road",
616
616
                 pic_abort, &FieldActionWindow::act_abort_buildroad, _("Cancel road"));
617
617
 
618
618
        // Add the box as tab
619
 
        buildbox.layout();
620
 
        add_tab(pic_tab_buildroad, &buildbox, _("Build roads"));
 
619
        add_tab("roads", pic_tab_buildroad, &buildbox, _("Build roads"));
621
620
}
622
621
 
623
622
 
627
626
===============
628
627
*/
629
628
uint32_t FieldActionWindow::add_tab
630
 
        (char const * picname, UI::Panel * panel, std::string const & tooltip_text)
 
629
        (std::string const & name, char const * picname,
 
630
         UI::Panel * panel, std::string const & tooltip_text)
631
631
{
632
632
        return
633
633
                m_tabpanel.add
634
 
                        (g_gr->get_picture(PicMod_Game, picname), panel, tooltip_text);
 
634
                        (name, g_gr->get_picture(PicMod_Game, picname), panel, tooltip_text);
635
635
}
636
636
 
637
637
 
638
638
void FieldActionWindow::add_button
639
639
        (UI::Box           * const box,
 
640
         char        const * const name,
640
641
         char        const * const picname,
641
642
         void (FieldActionWindow::*fn)(),
642
643
         std::string const & tooltip_text,
644
645
{
645
646
        UI::Callback_Button<FieldActionWindow> & button =
646
647
                *new UI::Callback_Button<FieldActionWindow>
647
 
                        (box,
 
648
                        (box, name,
648
649
                         0, 0, 34, 34,
649
650
                         g_gr->get_picture(PicMod_UI, "pics/but2.png"),
650
651
                         g_gr->get_picture(PicMod_Game, picname),
839
840
void FieldActionWindow::building_icon_mouse_in
840
841
        (Widelands::Building_Index::value_t const idx)
841
842
{
842
 
        if (ibase().m_show_workarea_preview) {
843
 
                assert(not m_workarea_preview_job_id);
 
843
        if (ibase().m_show_workarea_preview and not m_workarea_preview_job_id) {
844
844
                m_workarea_preview_job_id = m_overlay_manager.get_a_job_id();
845
845
                Widelands::HollowArea<> hollow_area(Widelands::Area<>(m_node, 0), 0);
846
846
                const Workarea_Info & workarea_info =
936
936
        // Force closing of old fieldaction windows. This is necessary because
937
937
        // show_field_action() does not always open a FieldActionWindow (e.g.
938
938
        // connecting the road we are building to an existing flag)
939
 
                delete registry->window;
 
939
        delete registry->window;
940
940
        *registry = UI::UniqueWindow::Registry();
941
941
 
942
942
        if (!ibase->is_building_road()) {