-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathview_units.cpp
740 lines (663 loc) · 22 KB
/
view_units.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: Freeciv21 and Freeciv contributors
* SPDX-FileCopyrightText: James Robertson <[email protected]>
*/
/**
* \class units_view
*/
// client
#include "views/view_units.h"
#include "canvas.h"
#include "client_main.h"
#include "fc_client.h"
#include "goto.h"
#include "hudwidget.h"
#include "page_game.h"
#include "repodlgs_common.h"
#include "tileset/sprite.h"
#include "top_bar.h"
#include "turn_done_button.h"
#include "views/view_map.h"
#include "views/view_map_common.h"
// common
#include "movement.h"
#include "text.h"
#include "unittype.h"
/****************************
* units_view class functions
****************************/
/**
* Constructor for units view
*/
units_view::units_view() : QWidget()
{
ui.setupUi(this);
QFont font = ui.units_widget->horizontalHeader()->font();
font.setWeight(QFont::Bold);
ui.units_widget->horizontalHeader()->setFont(font);
ui.uwt_widget->horizontalHeader()->setFont(font);
// Configure the units table
QStringList slist;
slist << _("Type") << _("Name") << _("★ Upgradable")
<< _("⚒ In Progress") << _("⚔ Active") << _("Shield Upkeep")
<< _("Food Upkeep") << _("Gold Upkeep");
ui.units_label->setText(QString(_("Units:")));
ui.units_widget->setColumnCount(slist.count());
ui.units_widget->setHorizontalHeaderLabels(slist);
ui.units_widget->setSortingEnabled(false);
ui.units_widget->setAlternatingRowColors(true);
ui.upg_but->setText(_("Upgrade"));
ui.upg_but->setToolTip(_("Upgrade selected unit."));
ui.upg_but->setDisabled(true);
ui.find_but->setText(_("Find Nearest"));
ui.find_but->setToolTip(_("Center the map on the nearest unit in relation "
"to where the map is now."));
ui.find_but->setDisabled(true);
ui.disband_but->setText(_("Disband All"));
ui.disband_but->setToolTip(_("Disband all of the selected unit."));
ui.disband_but->setDisabled(true);
// Configure the unitwaittime table
slist.clear();
slist << _("Type") << _("Name") << _("Location") << _("Time Left");
ui.uwt_widget->setColumnCount(slist.count());
ui.uwt_widget->setHorizontalHeaderLabels(slist);
ui.uwt_widget->setSortingEnabled(true);
ui.uwt_widget->setAlternatingRowColors(true);
ui.uwt_label->setText("Units Waiting:");
// Add shield icon for shield upkeep column
const QPixmap *spr =
tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "upkeep.shield",
"citybar.shields", "", "", false);
ui.units_widget->horizontalHeaderItem(5)->setIcon(crop_sprite(spr));
// Add food icon for food upkeep column
spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "upkeep.food",
"citybar.food", "", "", false);
ui.units_widget->horizontalHeaderItem(6)->setIcon(crop_sprite(spr));
// Add gold icon for gold upkeep column
spr = tiles_lookup_sprite_tag_alt(tileset, LOG_VERBOSE, "upkeep.gold",
"citybar.trade", "", "", false);
ui.units_widget->horizontalHeaderItem(7)->setIcon(crop_sprite(spr));
connect(ui.upg_but, &QAbstractButton::pressed, this,
&units_view::upgrade_units);
connect(ui.find_but, &QAbstractButton::pressed, this,
&units_view::find_nearest);
connect(ui.disband_but, &QAbstractButton::pressed, this,
&units_view::disband_units);
connect(ui.units_widget->selectionModel(),
&QItemSelectionModel::selectionChanged, this,
&units_view::selection_changed);
setLayout(ui.units_layout);
queen()->gimmePlace(this, QStringLiteral("UNI"));
index = queen()->addGameTab(this);
}
/**
* Destructor for units view
*/
units_view::~units_view() { queen()->removeRepoDlg(QStringLiteral("UNI")); }
/**
* Initializes place in tab for units view
*/
void units_view::init() { queen()->game_tab_widget->setCurrentIndex(index); }
/**
* Refresh all widgets for units view
*/
void units_view::update_view()
{
// used to set the height of the unit sprite
QFont f = QApplication::font();
QFontMetrics fm(f);
int h = fm.height() + 24;
ui.units_widget->setRowCount(0);
ui.units_widget->clearContents();
int entries_used = 0; // Position in the units array
struct unit_view_entry unit_entries[U_LAST];
get_units_view_data(unit_entries, &entries_used);
// Variables for the nested loops
int total_count = 0; // Sum of unit type
int upg_count = 0; // Sum of upgradable
int in_progress = 0; // Sum of in progress by unit type
int total_gold = 0; // Sum of gold upkeep
int total_shield = 0; // Sum of shield upkeep
int total_food = 0; // Sum of food upkeep
int max_row = 0; // Max rows in the table widget
for (int i = 0; i < entries_used; i++) {
struct unit_view_entry *pentry = unit_entries + i;
const struct unit_type *putype = pentry->type;
cid id = cid_encode_unit(putype);
ui.units_widget->insertRow(max_row);
for (int j = 0; j < 8; j++) {
QTableWidgetItem *item = new QTableWidgetItem;
switch (j) {
case 0:
// Unit type image sprite
{
auto sprite =
get_unittype_sprite(tileset, putype, direction8_invalid())
->scaledToHeight(h);
QLabel *lbl = new QLabel;
lbl->setPixmap(QPixmap(sprite));
lbl->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
ui.units_widget->setCellWidget(i, j, lbl);
}
item->setData(Qt::UserRole, id);
break;
case 1:
// Unit type name
item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
item->setText(utype_name_translation(putype));
break;
case 2:
// Is Upgradable
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
if (pentry->upg) {
item->setData(Qt::DisplayRole, "★");
upg_count++;
} else {
item->setData(Qt::DisplayRole, "-");
}
break;
case 3:
// # In Progress
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
item->setData(Qt::DisplayRole, pentry->in_prod);
in_progress += pentry->in_prod;
break;
case 4:
// # Active
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
item->setData(Qt::DisplayRole, pentry->count);
total_count += pentry->count;
break;
case 5:
// Shield upkeep
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
if (pentry->shield_cost == 0) {
item->setText("-");
} else {
item->setData(Qt::DisplayRole, pentry->shield_cost);
}
total_shield += pentry->shield_cost;
break;
case 6:
// Food upkeep
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
if (pentry->food_cost == 0) {
item->setText("-");
} else {
item->setData(Qt::DisplayRole, pentry->food_cost);
}
total_food += pentry->food_cost;
break;
case 7:
// Gold upkeep
item->setTextAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
if (pentry->gold_cost == 0) {
item->setText("-");
} else {
item->setData(Qt::DisplayRole, pentry->gold_cost);
}
total_gold += pentry->gold_cost;
break;
}
ui.units_widget->setItem(max_row, j, item);
}
max_row++;
}
// Add a "footer" to the table showing the totals.
ui.units_widget->setRowCount(max_row);
ui.units_widget->insertRow(max_row);
for (int j = 0; j < 8; j++) {
QTableWidgetItem *item_totals = new QTableWidgetItem;
switch (j) {
case 1:
// Unit type name
item_totals->setTextAlignment(Qt::AlignRight);
item_totals->setText(_("--------------------\nTotals:"));
break;
case 2:
// Upgradable
item_totals->setTextAlignment(Qt::AlignCenter);
item_totals->setText(QString(_("------\n%1")).arg(upg_count));
break;
case 3:
// In Progress
item_totals->setTextAlignment(Qt::AlignCenter);
item_totals->setText(QString(_("------\n%1")).arg(in_progress));
break;
case 4:
item_totals->setTextAlignment(Qt::AlignCenter);
item_totals->setText(QString(_("------\n%1")).arg(total_count));
break;
case 5:
item_totals->setTextAlignment(Qt::AlignCenter);
item_totals->setText(QString(_("------\n%1")).arg(total_shield));
break;
case 6:
item_totals->setTextAlignment(Qt::AlignCenter);
item_totals->setText(QString(_("------\n%1")).arg(total_food));
break;
case 7:
item_totals->setTextAlignment(Qt::AlignCenter);
item_totals->setText(QString(_("------\n%1")).arg(total_gold));
break;
}
ui.units_widget->setItem(max_row, j, item_totals);
}
if (max_row == 0) {
ui.units_label->setHidden(true);
ui.units_widget->setHidden(true);
ui.find_but->setHidden(true);
ui.upg_but->setHidden(true);
ui.disband_but->setHidden(true);
} else {
ui.units_widget->resizeRowsToContents();
ui.units_widget->resizeColumnsToContents();
ui.units_widget->horizontalHeader()->resizeSections(
QHeaderView::ResizeToContents);
ui.units_widget->verticalHeader()->setSectionResizeMode(
QHeaderView::ResizeToContents);
}
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &units_view::update_waiting);
timer->start(1000);
update_waiting();
}
/**
* Function to load the units waiting table
*/
void units_view::update_waiting()
{
// used to set the height of the unit sprite
QFont f = QApplication::font();
QFontMetrics fm(f);
int h = fm.height() + 24;
ui.uwt_widget->setRowCount(0);
ui.uwt_widget->clearContents();
struct unit_waiting_entry unit_entries[U_LAST];
int entries_used = 0;
get_units_waiting_data(unit_entries, &entries_used);
max_row = 0;
for (int i = 0; i < entries_used; i++) {
struct unit_waiting_entry *pentry = unit_entries + i;
const struct unit_type *putype = pentry->type;
cid id = cid_encode_unit(putype);
ui.uwt_widget->insertRow(max_row);
for (int j = 0; j < 4; j++) {
auto item = new QTableWidgetItem;
switch (j) {
case 0:
// Unit type image sprite
{
auto sprite =
get_unittype_sprite(tileset, putype, direction8_invalid())
->scaledToHeight(h);
QLabel *lbl = new QLabel;
lbl->setPixmap(QPixmap(sprite));
lbl->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
ui.uwt_widget->setCellWidget(i, j, lbl);
}
item->setData(Qt::UserRole, id);
break;
case 1:
// Unit type name
item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
item->setText(utype_name_translation(putype));
break;
case 2:
// # Location
item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
item->setText(QString(_("%1")).arg(pentry->city_name));
break;
case 3:
// # Time Left
item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
item->setText(QString(_("%1")).arg(
format_simple_duration(abs(pentry->timer))));
break;
}
ui.uwt_widget->setItem(max_row, j, item);
}
max_row++;
}
if (max_row == 0) {
ui.uwt_label->setHidden(true);
ui.uwt_widget->setHidden(true);
} else {
ui.uwt_widget->setRowCount(max_row);
ui.uwt_widget->resizeRowsToContents();
ui.uwt_widget->resizeColumnsToContents();
ui.uwt_widget->horizontalHeader()->resizeSections(
QHeaderView::ResizeToContents);
ui.uwt_widget->verticalHeader()->setSectionResizeMode(
QHeaderView::ResizeToContents);
}
}
/**
* Action for selection changed in units view
*/
void units_view::selection_changed(const QItemSelection &sl,
const QItemSelection &ds)
{
QTableWidgetItem *itm;
QVariant qvar;
struct universal selected;
QString upg;
ui.upg_but->setDisabled(true);
ui.disband_but->setDisabled(true);
ui.find_but->setDisabled(true);
if (sl.isEmpty()) {
return;
}
curr_row = sl.indexes().at(0).row();
max_row = ui.units_widget->rowCount() - 1;
if (curr_row >= 0 && curr_row <= max_row) {
itm = ui.units_widget->item(curr_row, 0);
qvar = itm->data(Qt::UserRole);
uid = qvar.toInt();
selected = cid_decode(uid);
counter = ui.units_widget->item(curr_row, 4)->text().toInt();
if (counter > 0) {
ui.disband_but->setDisabled(false);
ui.find_but->setDisabled(false);
}
upg = ui.units_widget->item(curr_row, 2)->text();
if (upg != "-") {
ui.upg_but->setDisabled(false);
}
if (curr_row == max_row) {
ui.upg_but->setDisabled(true);
}
}
}
/**
* Disband selected units
*/
void units_view::disband_units()
{
struct universal selected;
QString buf;
hud_message_box *ask = new hud_message_box(king()->central_wdg);
Unit_type_id utype;
selected = cid_decode(uid);
utype = utype_number(selected.value.utype);
buf = QString(_("Do you really wish to disband every %1 (%2 total)?"))
.arg(utype_name_translation(utype_by_number(utype)),
QString::number(counter));
ask->set_text_title(buf, _("Disband Units?"));
ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
ask->setDefaultButton(QMessageBox::Cancel);
ask->button(QMessageBox::Yes)->setText(_("Yes Disband"));
ask->setAttribute(Qt::WA_DeleteOnClose);
connect(ask, &hud_message_box::accepted, [=]() {
struct unit_type *putype = utype_by_number(utype);
char buf[1024];
hud_message_box *result;
if (putype) {
disband_all_units(putype, false, buf, sizeof(buf));
result = new hud_message_box(king()->central_wdg);
result->set_text_title(buf, _("Disband Results"));
result->setStandardButtons(QMessageBox::Ok);
result->setAttribute(Qt::WA_DeleteOnClose);
result->show();
}
});
ask->show();
}
/**
* Find nearest selected unit, closest units view when button is clicked.
*/
void units_view::find_nearest()
{
struct universal selected;
struct tile *ptile;
struct unit *punit;
const struct unit_type *utype;
selected = cid_decode(uid);
utype = selected.value.utype;
ptile = get_center_tile_mapcanvas();
if ((punit = find_nearest_unit(utype, ptile))) {
queen()->mapview_wdg->center_on_tile(punit->tile);
if (ACTIVITY_IDLE == punit->activity
|| ACTIVITY_SENTRY == punit->activity) {
if (can_unit_do_activity(punit, ACTIVITY_IDLE)) {
unit_focus_set_and_select(punit);
}
}
}
popdown_units_view();
}
/**
* Upgrade selected units.
*/
void units_view::upgrade_units()
{
struct universal selected = cid_decode(uid);
const struct unit_type *utype = selected.value.utype;
Unit_type_id type = utype_number(utype);
const struct unit_type *upgrade =
can_upgrade_unittype(client_player(), utype);
int price = unit_upgrade_price(client_player(), utype, upgrade);
QString b = QString::asprintf(PL_("Treasury contains %d gold.",
"Treasury contains %d gold.",
client_player()->economic.gold),
client_player()->economic.gold);
QString c = QString::asprintf(PL_("Upgrade as many %s to %s as possible "
"for %d gold each?\n%s",
"Upgrade as many %s to %s as possible "
"for %d gold each?\n%s",
price),
utype_name_translation(utype),
utype_name_translation(upgrade), price,
b.toUtf8().data());
hud_message_box *ask = new hud_message_box(king()->central_wdg);
ask->set_text_title(c, _("Upgrade Obsolete Units?"));
ask->setStandardButtons(QMessageBox::Cancel | QMessageBox::Yes);
ask->setDefaultButton(QMessageBox::Cancel);
ask->button(QMessageBox::Yes)->setText(_("Yes Upgrade"));
ask->setAttribute(Qt::WA_DeleteOnClose);
connect(ask, &hud_message_box::accepted,
[=]() { dsend_packet_unit_type_upgrade(&client.conn, type); });
ask->show();
}
/****************************************
* Helper functions related to units view
****************************************/
/**
* Function to help us find the nearest unit
*/
struct unit *find_nearest_unit(const struct unit_type *utype,
struct tile *ptile)
{
struct unit *best_candidate = NULL;
int best_dist = FC_INFINITY, dist;
players_iterate(pplayer)
{
if (client_has_player() && pplayer != client_player()) {
continue;
}
unit_list_iterate(pplayer->units, punit)
{
if (utype == unit_type_get(punit)
&& FOCUS_AVAIL == punit->client.focus_status
&& 0 < punit->moves_left && !punit->done_moving
&& punit->ssa_controller == SSA_NONE) {
dist = sq_map_distance(unit_tile(punit), ptile);
if (dist < best_dist) {
best_candidate = punit;
best_dist = dist;
}
}
}
unit_list_iterate_end;
}
players_iterate_end;
return best_candidate;
}
/**
* Returns an array of units data.
*/
void get_units_view_data(struct unit_view_entry *entries,
int *num_entries_used)
{
*num_entries_used = 0;
players_iterate(pplayer)
{
if (client_has_player() && pplayer != client_player()) {
continue;
}
unit_type_iterate(unittype)
{
int count = 0; // Count of active unit type
int in_progress = 0; // Count of being produced
int gold_cost = 0; // Gold upkeep
int food_cost = 0; // Food upkeep
int shield_cost = 0; // Shield upkeep
bool upgradable = false; // Unit type is upgradable
unit_list_iterate(pplayer->units, punit)
{
if (unit_type_get(punit) == unittype) {
count++;
upgradable =
client_has_player()
&& nullptr != can_upgrade_unittype(client_player(), unittype);
// Only units with a home city have upkeep
if (punit->homecity != 0) {
gold_cost += punit->upkeep[O_GOLD];
food_cost += punit->upkeep[O_FOOD];
shield_cost += punit->upkeep[O_SHIELD];
}
}
}
unit_list_iterate_end;
city_list_iterate(pplayer->cities, pcity)
{
if (pcity->production.value.utype == unittype
&& pcity->production.kind == VUT_UTYPE) {
in_progress++;
}
}
city_list_iterate_end;
// Skip unused unit types
if (count == 0 && in_progress == 0) {
continue;
}
entries[*num_entries_used].type = unittype;
entries[*num_entries_used].count = count;
entries[*num_entries_used].in_prod = in_progress;
entries[*num_entries_used].upg = upgradable;
entries[*num_entries_used].gold_cost = gold_cost;
entries[*num_entries_used].food_cost = food_cost;
entries[*num_entries_used].shield_cost = shield_cost;
(*num_entries_used)++;
}
unit_type_iterate_end;
}
players_iterate_end;
std::sort(entries, entries + *num_entries_used,
[](const auto &lhs, const auto &rhs) {
return QString::localeAwareCompare(
utype_name_translation(lhs.type),
utype_name_translation(rhs.type))
< 0;
});
}
/**
* Returns an array of units subject to unitwaittime.
*/
void get_units_waiting_data(struct unit_waiting_entry *entries,
int *num_entries_used)
{
*num_entries_used = 0;
if (nullptr == client.conn.playing) {
return;
}
int pcity_near_dist = 0; // Init distance
unit_list_iterate(client.conn.playing->units, punit)
{
struct city *pcity_near = get_nearest_city(punit, &pcity_near_dist);
if (!can_unit_move_now(punit) && punit->ssa_controller == SSA_NONE) {
entries[*num_entries_used].type = punit->utype;
entries[*num_entries_used].city_name =
get_nearest_city_text(pcity_near, pcity_near_dist);
entries[*num_entries_used].timer =
time(nullptr) - punit->action_timestamp;
(*num_entries_used)++;
}
// Skip unused unit types
if (*num_entries_used == 0) {
continue;
}
}
unit_list_iterate_end;
std::sort(entries, entries + *num_entries_used,
[](const auto &lhs, const auto &rhs) {
return QString::localeAwareCompare(
utype_name_translation(lhs.type),
utype_name_translation(rhs.type))
< 0;
});
}
/************************************
* Functions for connecting to the UI
************************************/
/**
* Update the units view.
*/
void units_view_dialog_update(void *unused)
{
int i;
units_view *uv;
QWidget *w;
if (queen()->isRepoDlgOpen(QStringLiteral("UNI"))) {
i = queen()->gimmeIndexOf(QStringLiteral("UNI"));
if (queen()->game_tab_widget->currentIndex() == i) {
w = queen()->game_tab_widget->widget(i);
uv = reinterpret_cast<units_view *>(w);
uv->update_view();
}
}
queen()->updateSidebarTooltips();
}
/**
* Display the unis view. Typically triggered by F2.
*/
void units_view_dialog_popup()
{
int i;
units_view *uv;
QWidget *w;
if (!queen()->isRepoDlgOpen(QStringLiteral("UNI"))) {
uv = new units_view;
uv->init();
uv->update_view();
} else {
i = queen()->gimmeIndexOf(QStringLiteral("UNI"));
fc_assert(i != -1);
w = queen()->game_tab_widget->widget(i);
if (w->isVisible()) {
top_bar_show_map();
return;
}
uv = reinterpret_cast<units_view *>(w);
uv->init();
uv->update_view();
queen()->game_tab_widget->setCurrentWidget(uv);
}
}
/**
* Closes units view
*/
void popdown_units_view()
{
int i;
units_view *uv;
QWidget *w;
if (queen()->isRepoDlgOpen(QStringLiteral("UNI"))) {
i = queen()->gimmeIndexOf(QStringLiteral("UNI"));
fc_assert(i != -1);
w = queen()->game_tab_widget->widget(i);
uv = reinterpret_cast<units_view *>(w);
uv->deleteLater();
}
}