Skip to content

Commit 668c3fc

Browse files
committed
ui: loading entertainment windows from js moved to window_info.cpp
1 parent f30937f commit 668c3fc

6 files changed

+31
-21
lines changed

src/building/building_jugler_school.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
buildings::model_t<building_juggler_school> juggler_school_m;
1414

15-
ANK_REGISTER_CONFIG_ITERATOR(config_load_building_juggler_school);
16-
void config_load_building_juggler_school() {
17-
juggler_school_m.load();
18-
}
19-
2015
void building_juggler_school::update_month() {
2116
data.entertainment.spawned_entertainer_this_month = false;
2217
}

src/window/autoconfig_window.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ template<typename T>
2424
struct autoconfig_window_t : public autoconfig_window {
2525
inline pcstr section() const {
2626
static type_name_holder<T> _impl;
27-
static pcstr _section = strstr(_impl.value.data(), "::")
28-
? strstr(_impl.value.data(), "::") + 2
29-
: _impl.value.data();
27+
static pcstr _section = strstr(_impl.value.data(), "::") ? strstr(_impl.value.data(), "::") + 2
28+
: strstr(_impl.value.data(), "struct ") ? strstr(_impl.value.data(), "struct ") + 7
29+
: _impl.value.data();
3030
return _section;
3131
}
3232

src/window/window_building_info.h

+12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "window_info.h"
4+
#include "core/typename.h"
45

56
struct building;
67

@@ -23,4 +24,15 @@ struct building_info_window : public common_info_window {
2324

2425
void common_info_background(object_info& c);
2526
void draw_employment_details(object_info &c, int text_id = -1);
27+
};
28+
29+
template<typename T>
30+
struct building_info_window_t : public building_info_window {
31+
virtual pcstr section() const override {
32+
static type_name_holder<T> _impl;
33+
static pcstr _section = strstr(_impl.value.data(), "::") ? strstr(_impl.value.data(), "::") + 2
34+
: strstr(_impl.value.data(), "struct ") ? strstr(_impl.value.data(), "struct ") + 7
35+
: _impl.value.data();
36+
return _section;
37+
}
2638
};

src/window/window_entertainment_info.cpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,34 @@
55
#include "window/building/common.h"
66
#include "js/js_game.h"
77

8-
struct entertainment_info_window : public building_info_window {
8+
struct info_window_entertainment : public building_info_window_t<info_window_entertainment>{
99
virtual void window_info_background(object_info &c) override;
1010
virtual bool check(object_info &c) override {
1111
building *b = c.building_get();
12-
return building_type_any_of(b->type, BUILDING_PAVILLION);
12+
return building_type_any_of(b->type, BUILDING_PAVILLION, BUILDING_JUGGLER_SCHOOL);
1313
}
1414
};
1515

16-
struct info_window_bandstand : public building_info_window {
16+
struct info_window_bandstand : public building_info_window_t<info_window_bandstand>{
1717
virtual void window_info_background(object_info &c) override;
1818
virtual bool check(object_info &c) override {
1919
return c.building_get()->dcast_bandstand();
2020
}
2121
};
2222

23-
struct info_window_booth : public building_info_window {
23+
struct info_window_booth : public building_info_window_t<info_window_booth> {
2424
virtual void window_info_background(object_info &c) override;
2525
virtual bool check(object_info &c) override {
2626
building *b = c.building_get();
2727
return c.building_get()->dcast_booth();
2828
}
2929
};
3030

31-
entertainment_info_window entertainment_infow;
31+
info_window_entertainment entertainment_infow;
3232
info_window_bandstand bandstand_infow;
3333
info_window_booth booth_infow;
3434

35-
ANK_REGISTER_CONFIG_ITERATOR(config_load_entertainment_info_window);
36-
void config_load_entertainment_info_window() {
37-
entertainment_infow.load("info_window_entertainment");
38-
bandstand_infow.load("info_window_bandstand");
39-
booth_infow.load("info_window_bandstand");
40-
}
41-
42-
void entertainment_info_window::window_info_background(object_info &c) {
35+
void info_window_entertainment::window_info_background(object_info &c) {
4336
c.go_to_advisor.first = ADVISOR_ENTERTAINMENT;
4437

4538
building_info_window::window_info_background(c);

src/window/window_info.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ void config_load_info_window() {
7171
g_empty_info_window.load("empty_info_window");
7272
g_terrain_info_window.load("terrain_info_window");
7373
g_figure_info_window.load("figure_info_window");
74+
75+
for (auto &building_info_handler: *g_window_building_handlers) {
76+
pcstr section = building_info_handler->section();
77+
if (!section || !*section) {
78+
//custom loader
79+
continue;
80+
}
81+
building_info_handler->load(section);
82+
}
7483
}
7584

7685
static int center_in_city(int element_width_pixels) {

src/window/window_info.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct object_info;
77
struct tooltip_context;
88

99
struct common_info_window : public ui::widget {
10+
virtual pcstr section() const { return ""; }
1011
virtual bool check(object_info &c) { return false; }
1112
virtual int get_height_id(object_info &c) { return 0; }
1213
virtual void window_info_background(object_info &c);

0 commit comments

Comments
 (0)