Skip to content

Commit 5228d5e

Browse files
committed
ui: add extended city info in debug
1 parent 82d0226 commit 5228d5e

File tree

10 files changed

+134
-10
lines changed

10 files changed

+134
-10
lines changed

src/empire/empire_city.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "empire_city.h"
22
#include "empire/empire.h"
33

4+
const token_holder<e_empire_city, EMPIRE_CITY_OURS, EMPIRE_CITY_COUNT> e_empire_city_tokens;
5+
46
void empire_city::remove_trader(int figure_id) {
57
for (int i = 0; i < 3; i++) {
68
if (trader_figure_ids[i] == figure_id)

src/empire/empire_city.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "empire/type.h"
44
#include "game/resource.h"
55
#include "empire/trade_route.h"
6+
#include "core/tokenum.h"
67

78
struct empire_city {
89
enum {
@@ -35,4 +36,6 @@ struct empire_city {
3536
void set_foreign() {
3637
type = EMPIRE_CITY_EGYPTIAN;
3738
}
38-
};
39+
};
40+
41+
extern const token_holder<e_empire_city, EMPIRE_CITY_OURS, EMPIRE_CITY_COUNT> e_empire_city_tokens;

src/empire/empire_city_properties.cpp

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include "empire_city.h"
2+
3+
#include "widget/debug_console.h"
4+
#include "imgui/imgui.h"
5+
#include "imgui/imgui_internal.h"
6+
#include "empire/empire_map.h"
7+
#include "empire/empire.h"
8+
9+
ANK_REGISTER_PROPS_ITERATOR(config_load_selected_empire_city_properties);
10+
ANK_REGISTER_PROPS_ITERATOR(config_load_all_empire_city_properties);
11+
12+
void game_debug_show_properties_object(pcstr prefix, empire_city *c) {
13+
ImGui::PushID(0x80000000 | c->name_id);
14+
15+
ImGui::TableNextRow();
16+
ImGui::TableSetColumnIndex(0);
17+
ImGui::AlignTextToFramePadding();
18+
pcstr city_name = ui::str(195, c->name_id);
19+
bool common_open = ImGui::TreeNodeEx(city_name, ImGuiTreeNodeFlags_DefaultOpen, city_name);
20+
ImGui::TableSetColumnIndex(1);
21+
22+
int i = 0;
23+
if (common_open) {
24+
game_debug_show_property(i, "in_use", c->in_use);
25+
bstring256 type_name; type_name.printf("%s [%d]", token::find_name(e_empire_city_tokens, c->type), c->type);
26+
game_debug_show_property(i, "type<name>", type_name);
27+
game_debug_show_property(i, "type", c->type);
28+
game_debug_show_property(i, "name_id", c->name_id);
29+
game_debug_show_property(i, "name", ui::str(195, c->name_id));
30+
game_debug_show_property(i, "route_id", c->route_id);
31+
game_debug_show_property(i, "is_open", c->is_open);
32+
game_debug_show_property(i, "cost_to_open", c->cost_to_open);
33+
game_debug_show_property(i, "ph_unk01", c->ph_unk01);
34+
game_debug_show_property(i, "ph_unk02", c->ph_unk02);
35+
game_debug_show_property(i, "trader_entry_delay", c->trader_entry_delay);
36+
game_debug_show_property(i, "empire_object_id", c->empire_object_id);
37+
game_debug_show_property(i, "is_sea_trade", c->is_sea_trade);
38+
game_debug_show_property(i, "trader_figure_ids[0]", c->trader_figure_ids[0], true);
39+
game_debug_show_property(i, "trader_figure_ids[1]", c->trader_figure_ids[1], true);
40+
game_debug_show_property(i, "trader_figure_ids[2]", c->trader_figure_ids[2], true);
41+
42+
{
43+
ImGui::PushID(0x81000000 | c->name_id);
44+
45+
ImGui::TableNextRow();
46+
ImGui::TableSetColumnIndex(0);
47+
ImGui::AlignTextToFramePadding();
48+
const bool buy_res_open = ImGui::TreeNodeEx("Buy Resources", ImGuiTreeNodeFlags_DefaultOpen, "Buy Resources");
49+
ImGui::TableSetColumnIndex(1);
50+
51+
if (buy_res_open) {
52+
for (const auto r : resource_list::all) {
53+
game_debug_show_property(i, ui::resource_name(r.type), c->buys_resource[r.type]);
54+
}
55+
56+
ImGui::TreePop();
57+
}
58+
ImGui::PopID();
59+
}
60+
61+
{
62+
ImGui::PushID(0x41000000 | c->name_id);
63+
64+
ImGui::TableNextRow();
65+
ImGui::TableSetColumnIndex(0);
66+
ImGui::AlignTextToFramePadding();
67+
const bool sell_res_open = ImGui::TreeNodeEx("Sells Resources", ImGuiTreeNodeFlags_DefaultOpen, "Sells Resource");
68+
ImGui::TableSetColumnIndex(1);
69+
70+
if (sell_res_open) {
71+
for (const auto r : resource_list::all) {
72+
game_debug_show_property(i, ui::resource_name(r.type), c->sells_resource[r.type]);
73+
}
74+
75+
ImGui::TreePop();
76+
}
77+
ImGui::PopID();
78+
}
79+
80+
ImGui::TreePop();
81+
}
82+
ImGui::PopID();
83+
}
84+
85+
void config_load_selected_empire_city_properties(bool header) {
86+
static bool _debug_city_open = true;
87+
88+
if (header) {
89+
ImGui::Checkbox("Selected Empire City", &_debug_city_open);
90+
return;
91+
}
92+
93+
int selected_object = g_empire_map.selected_object();
94+
int selected_city = selected_object ? g_empire.get_city_for_object(selected_object - 1) : 0;
95+
96+
if (_debug_city_open && selected_city > 0 && ImGui::BeginTable("split", 2, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable)) {
97+
empire_city *c = g_empire.city(selected_city);
98+
game_debug_show_properties_object("City", c);
99+
ImGui::EndTable();
100+
}
101+
}
102+
103+
void config_load_all_empire_city_properties(bool header) {
104+
static bool _debug_city_open = false;
105+
106+
if (header) {
107+
ImGui::Checkbox("Empire Cities", &_debug_city_open);
108+
return;
109+
}
110+
111+
if (_debug_city_open && ImGui::BeginTable("split", 2, ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable)) {
112+
for (auto &city : g_empire.get_cities()) {
113+
game_debug_show_properties_object("City", &city);
114+
}
115+
ImGui::EndTable();
116+
}
117+
}

src/empire/empire_map.h

-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ class empire_map_t {
3232
extern empire_map_t g_empire_map;
3333

3434
void empire_load_editor(int empire_id, int viewport_width, int viewport_height);
35-
bool empire_can_export_resource_to_city(int city_id, e_resource resource);

src/empire/type.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ enum e_empire_city {
1818
EMPIRE_CITY_EGYPTIAN_TRADING = 3, // EMPIRE_CITY_FUTURE_TRADE = 3
1919
EMPIRE_CITY_EGYPTIAN = 4, // EMPIRE_CITY_DISTANT_FOREIGN = 4
2020
EMPIRE_CITY_FOREIGN_TRADING = 5, // EMPIRE_CITY_VULNERABLE = 5
21-
EMPIRE_CITY_FOREIGN = 6 // EMPIRE_CITY_FUTURE_ROMAN = 6,
21+
EMPIRE_CITY_FOREIGN = 6, // EMPIRE_CITY_FUTURE_ROMAN = 6,
22+
23+
EMPIRE_CITY_COUNT
2224
};

src/graphics/elements/ui.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ pcstr ui::str(int group, int id) {
224224
return (pcstr)lang_get_string(group, id);
225225
}
226226

227+
pcstr ui::resource_name(e_resource r) {
228+
return (pcstr)lang_get_string(23, r);
229+
}
230+
227231
int ui::button_hover(const mouse *m) {
228232
for (auto &btn : g_state.buttons) {
229233
if (is_button_hover(btn, g_state.offset())) {

src/graphics/elements/ui.h

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ scrollbar_t &scrollbar(scrollbar_t &scrollbar, vec2i pos, int &value, vec2i size
8787
pcstr str(int group, int id);
8888
inline pcstr str(std::pair<int, int> r) { return str(r.first, r.second); }
8989
inline pcstr str(textid r) { return str(r.group, r.id); }
90+
pcstr resource_name(e_resource r);
9091

9192
struct emenu_header;
9293
struct eimage_button;

src/widget/debug_console.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void game_debug_show_property(int &i, pcstr field, const short &v, bool disabled
141141
void game_debug_show_property(int &i, pcstr field, const uint8_t &v, bool disabled) { game_debug_show_property_t(i, field, v, disabled); }
142142
void game_debug_show_property(int &i, pcstr field, const uint16_t &v, bool disabled) { game_debug_show_property_t(i, field, v, disabled); }
143143
void game_debug_show_property(int &i, pcstr field, const bool &v, bool disabled) { game_debug_show_property_t(i, field, v, disabled); }
144-
void game_debug_show_property(int &i, pcstr field, const pcstr v) { game_debug_show_property_t(i, field, v, true); }
144+
void game_debug_show_property(int &i, pcstr field, pcstr v) { game_debug_show_property_t(i, field, v, true); }
145145
void game_debug_show_property(int &i, pcstr field, const bstring64 &v, bool disabled) { game_debug_show_property_t(i, field, v, disabled); }
146146
void game_debug_show_property(int &i, pcstr field, const bstring256 &v, bool disabled) { game_debug_show_property_t(i, field, v, disabled); }
147147
void game_debug_show_property(int &i, pcstr field, const xstring &v, bool disabled) { game_debug_show_property_t(i, field, v, disabled); }

src/window/editor/empire.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ static void init() {
5959
auto &data = g_window_empire;
6060
data.selected_button = 0;
6161
int selected_object = g_empire_map.selected_object();
62-
if (selected_object)
63-
data.selected_city = g_empire.get_city_for_object(selected_object - 1);
64-
else {
65-
data.selected_city = 0;
66-
}
62+
data.selected_city = selected_object ? g_empire.get_city_for_object(selected_object - 1) : 0;
6763
data.focus_button_id = 0;
6864
}
6965

src/window/window_bazaar_orders.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void bazaar_orders_window::window_info_foreground(object_info &c) {
5454
int row_y = 0;
5555
for (const auto &r : resources) {
5656
ui.icon(items_area.pos + item_icon_column.pos + vec2i{ 0, row_y }, r.type);
57-
ui.label(ui::str(23, r.type), items_area.pos + item_name_column.pos + vec2i{ 0, row_y });
57+
ui.label(ui::resource_name(r.type), items_area.pos + item_name_column.pos + vec2i{ 0, row_y });
5858

5959
auto status = window_market_get_order_instruction(INSTR_MARKET, r.type, bazaar->is_good_accepted(r.type));
6060
ui.button(status.first, items_area.pos + vec2i{ item_orders_column.pos.x, row_y }, item_row.size, fonts_vec{ status.second }, UiFlags_NoBody | UiFlags_AlignYCentered)

0 commit comments

Comments
 (0)