-
-
Notifications
You must be signed in to change notification settings - Fork 994
/
gamestate_inspector.cpp
894 lines (757 loc) · 21.8 KB
/
gamestate_inspector.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
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
/*
Copyright (C) 2009 - 2016 by Yurii Chernyi <terraninfo@terraninfo.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/dialogs/lua_interpreter.hpp"
#include "gui/widgets/button.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
#else
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "desktop/clipboard.hpp"
#include "game_events/manager.hpp"
#include "serialization/parser.hpp" // for write()
#include "game_data.hpp"
#include "recall_list_manager.hpp"
#include "resources.hpp"
#include "team.hpp"
#include "units/unit.hpp"
#include "units/map.hpp"
#include "ai/manager.hpp"
#include "display_context.hpp"
#include "filter_context.hpp"
#include <vector>
#include "utils/functional.hpp"
namespace
{
inline std::string config_to_string(const config& cfg)
{
std::ostringstream s;
write(s, cfg);
return s.str();
}
inline std::string config_to_string(const config& cfg, std::string only_children)
{
config filtered;
for(const config& child : cfg.child_range(only_children)) {
filtered.add_child(only_children, child);
}
return config_to_string(filtered);
}
}
namespace gui2
{
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_gamestate_inspector
*
* == Gamestate inspector ==
*
* This shows the gamestate inspector
*
* @begin{table}{dialog_widgets}
*
* inspector_name & & control & m &
* Name of the inspector. $
*
* stuff_list & & control & m &
* List of various stuff that can be viewed. $
*
* inspect & & control & m &
* The state of the variable or event. $
*
* copy & & button & m &
* A button to copy the state to clipboard. $
*
* @end{table}
*/
/*
static void inspect_ai(twindow& window, int side)
{
const config &ai_cfg = ai::manager::to_config(side);
NEW_find_widget<tcontrol>(
&window,
"inspect",
false).set_label(config_to_string(ai_cfg.debug));
}
*/
/**
* Template for dialog callbacks for dialogs using model-view-controller
* architecture pattern.
*
* It allows delegating of the callback to a private view class, which should
* be accessible via dialog->get_view() (and return a pointer to the view
* class). Example usage: widget->set_callback(dialog_callback<my_dialog_class,
* my_dialog_class::inner_view_class
* &my_dialog_class::inner_view_class::member_function>);
*/
template <class D, class V, void (V::*fptr)()>
void dialog_view_callback(twidget& caller)
{
D* dialog = dynamic_cast<D*>(caller.dialog());
assert(dialog);
(*(dialog->get_view()).*fptr)();
}
// The model is an interface defining the data to be displayed or otherwise
// acted upon in the user interface.
class tgamestate_inspector::model
{
public:
model(const vconfig& c)
: cfg(c)
, name()
, stuff_list()
, stuff_types_list()
, inspect()
, inspector_name()
, copy_button()
, lua_button()
{
name = cfg["name"].str();
}
vconfig cfg;
std::string name;
tlistbox* stuff_list;
tlistbox* stuff_types_list;
tcontrol* inspect;
tcontrol* inspector_name;
tbutton* copy_button;
tbutton* lua_button;
static const unsigned int max_inspect_win_len = 20000;
void clear_stuff_list()
{
stuff_list->clear();
}
void clear_stuff_types_list()
{
stuff_types_list->clear();
}
void add_row_to_stuff_list(const std::string& id, const std::string& label, bool colorize = false)
{
std::map<std::string, string_map> data;
string_map item;
item["id"] = id;
item["label"] = label;
item["use_markup"] = colorize ? "true" : "false";
data.insert(std::make_pair("name", item));
stuff_list->add_row(data);
}
void add_row_to_stuff_types_list(const std::string& id, const std::string& label, bool colorize = false)
{
std::map<std::string, string_map> data;
string_map item;
item["id"] = id;
item["label"] = label;
item["use_markup"] = colorize ? "true" : "false";
data.insert(std::make_pair("typename", item));
stuff_types_list->add_row(data);
}
void set_inspect_window_text(const std::string& s, unsigned int page = 0)
{
unsigned int reminder = (s.length() - (max_inspect_win_len * page));
std::string s_ = s.substr(max_inspect_win_len * page, reminder > max_inspect_win_len ? max_inspect_win_len : reminder);
inspect->set_label(s_);
}
unsigned int get_num_page(const std::string& s)
{
// We always want to reserve a page for empty contents.
if(s.empty()) {
return 1;
}
return (s.length() / max_inspect_win_len) + (s.length() % max_inspect_win_len > 0 ? 1 : 0);
}
};
class single_mode_controller
{
public:
single_mode_controller(const std::string& name,
tgamestate_inspector::model& m)
: model_(m), name_(name)
{
}
virtual ~single_mode_controller()
{
}
std::string name() const
{
return name_;
}
virtual void show_stuff_list() = 0;
virtual void handle_stuff_list_selection() = 0;
virtual void update_view_from_model() = 0;
protected:
tgamestate_inspector::model& model_;
std::string name_;
};
class variable_mode_controller : public single_mode_controller
{
public:
variable_mode_controller(const std::string& name,
tgamestate_inspector::model& m)
: single_mode_controller(name, m)
{
}
void show_stuff_list()
{
model_.clear_stuff_list();
const config& vars = resources::gamedata
? resources::gamedata->get_variables()
: config();
for(const auto & a : vars.attribute_range())
{
model_.add_row_to_stuff_list(a.first, a.first);
}
std::map<std::string, size_t> wml_array_sizes;
for(const auto & c : vars.all_children_range())
{
if (wml_array_sizes.find(c.key) == wml_array_sizes.end()) {
wml_array_sizes[c.key] = 0;
} else {
++wml_array_sizes[c.key];
}
unsigned int num_pages = model_.get_num_page(config_to_string(c.cfg));
for (unsigned int i = 0; i < num_pages; i++) {
std::ostringstream cur_str;
cur_str << "[" << c.key << "][" << wml_array_sizes[c.key] << "]";
if (num_pages > 1) {
cur_str << " " << (i + 1) << "/" << num_pages;
}
model_.add_row_to_stuff_list(cur_str.str(), cur_str.str());
}
}
model_.set_inspect_window_text("");
}
void handle_stuff_list_selection()
{
int selected = model_.stuff_list->get_selected_row();
if(selected == -1) {
model_.set_inspect_window_text("");
return;
}
int i = 0; ///@todo replace with precached data
const config& vars = resources::gamedata
? resources::gamedata->get_variables()
: config();
for(const auto & a : vars.attribute_range())
{
if(selected == i) {
model_.set_inspect_window_text(a.second);
return;
}
i++;
}
for(const auto & c : vars.all_children_range())
{
for (unsigned int j = 0; j < model_.get_num_page(config_to_string(c.cfg)); ++j) {
if (selected == i) {
model_.set_inspect_window_text(config_to_string(c.cfg), j);
return;
}
i++;
}
}
}
virtual void update_view_from_model()
{
show_stuff_list();
handle_stuff_list_selection();
}
};
/**
* Controller for WML event and menu item handler views.
*/
class event_mode_controller : public single_mode_controller
{
public:
/** WML event handler tag identifier. */
enum HANDLER_TYPE
{
EVENT_HANDLER, /**< Standard WML event handler ([event]). */
WMI_HANDLER /**< WML menu item handler ([menu_item]). */
};
/**
* Constructor.
*
* @param name View name displayed on the UI.
* @param m Inspector model reference.
* @param wml_node WML node key. Should be either "event" or
* "menu_item".
*/
event_mode_controller(const std::string& name,
tgamestate_inspector::model& m,
HANDLER_TYPE handler_type)
: single_mode_controller(name, m)
, handler_type_(handler_type)
, pages_()
{
}
/**
* Populates the list of pages for this view.
*/
virtual void show_stuff_list()
{
assert(resources::game_events);
const std::string handler_key
= handler_type_ == WMI_HANDLER ? "menu_item" : "event";
model_.clear_stuff_list();
pages_.clear();
config events_config;
resources::game_events->write_events(events_config);
for(const auto & cfg : events_config.child_range(handler_key))
{
shared_string_ptr sstrp(new std::string(config_to_string(cfg)));
const std::string& wmltext = *sstrp;
const unsigned num_pages = model_.get_num_page(wmltext);
for(unsigned i = 0; i < num_pages; ++i) {
pages_.push_back(std::make_pair(sstrp, i));
std::ostringstream o;
if(handler_type_ == WMI_HANDLER) {
// [menu_item]
o << cfg["id"].str();
} else {
// [event]
o << cfg["name"].str();
if(!cfg["id"].empty()) {
o << " [id=\"" << cfg["id"].str() << "\"]";
}
}
if(num_pages > 1) {
o << " [page" << (i + 1) << '/' << num_pages << ']';
}
model_.add_row_to_stuff_list(o.str(), o.str());
}
}
model_.set_inspect_window_text("");
}
/**
* Updates the page display for the currently selected item in this view.
*/
virtual void handle_stuff_list_selection()
{
const int row = model_.stuff_list->get_selected_row();
if(row < 0 || size_t(row) >= pages_.size()) {
model_.set_inspect_window_text("");
return;
}
const page_descriptor& pd = pages_[size_t(row)];
model_.set_inspect_window_text(*pd.first, pd.second);
}
/**
* Updates the whole view (page list and page display).
*/
virtual void update_view_from_model()
{
show_stuff_list();
handle_stuff_list_selection();
}
private:
// Because of GUI2's limitations, we need to use set_inspect_window_text's
// option to split view pages into multiple subpages. Each of those
// subpages is built from a shared string object we cache beforehand for
// cycle efficiency. We use a vector of page content pointers/subpage
// number pairs matching the UI layout to keep things simple.
typedef std::shared_ptr<std::string> shared_string_ptr;
typedef std::pair<shared_string_ptr, unsigned> page_descriptor;
HANDLER_TYPE handler_type_;
std::vector<page_descriptor> pages_;
};
class unit_mode_controller : public single_mode_controller
{
public:
unit_mode_controller(const std::string& name,
tgamestate_inspector::model& m)
: single_mode_controller(name, m)
{
}
void show_stuff_list()
{
model_.clear_stuff_list();
if(resources::units && resources::filter_con) {
const display_context& viewer = resources::filter_con->get_disp_context();
for(unit_map::iterator i = resources::units->begin();
i != resources::units->end();
++i) {
Uint32 which_color = game_config::tc_info(viewer.teams()[i->side() - 1].color())[0];
std::stringstream s;
s << '(' << i->get_location();
s << ") <span color='#" << std::hex << which_color << std::dec;
s << "'>side=" << i->side() << "</span> ";
if(i->can_recruit()) {
s << "<span color='yellow'>LEADER</span> ";
}
s << "\nid=\"" << i->id() << "\" (" << i->type_id() << ")\n"
<< "L" << i->level() << "; " << i->experience() << '/'
<< i->max_experience() << " xp; " << i->hitpoints() << '/'
<< i->max_hitpoints() << " hp;";
for(const auto & str : i->get_traits_list())
{
s << " " << str;
}
std::string key = s.str();
model_.add_row_to_stuff_list(i->id(), key, true);
}
}
model_.set_inspect_window_text("");
}
void handle_stuff_list_selection()
{
int selected = model_.stuff_list->get_selected_row();
if(selected == -1) {
model_.set_inspect_window_text("");
return;
}
if(resources::units) {
int i = 0; ///@todo replace with precached data
for(unit_map::iterator u = resources::units->begin();
u != resources::units->end();
++u) {
if(selected == i) {
config c_unit;
u->write(c_unit);
std::ostringstream cfg_str;
write(cfg_str, c_unit);
model_.set_inspect_window_text(cfg_str.str());
return;
}
i++;
}
}
model_.set_inspect_window_text("");
}
virtual void update_view_from_model()
{
show_stuff_list();
handle_stuff_list_selection();
}
};
class team_mode_controller : public single_mode_controller
{
public:
team_mode_controller(const std::string& name,
tgamestate_inspector::model& m,
int side)
: single_mode_controller(name, m), side_(side)
{
}
void show_stuff_list()
{
model_.clear_stuff_list();
// note: needs sync with handle_stuff_list_selection()
model_.add_row_to_stuff_list("overview", "overview");
model_.add_row_to_stuff_list("ai overview", "ai overview");
model_.add_row_to_stuff_list("ai engines", "ai engines");
model_.add_row_to_stuff_list("ai stages", "ai stages");
model_.add_row_to_stuff_list("ai aspects", "ai aspects");
model_.add_row_to_stuff_list("ai goals", "ai goals");
model_.add_row_to_stuff_list("recall list overview",
"recall list overview");
model_.add_row_to_stuff_list("recall list full", "recall list full");
model_.add_row_to_stuff_list("ai component structure",
"ai component structure");
model_.add_row_to_stuff_list("unit list overview",
"unit list overview");
model_.set_inspect_window_text("");
}
void handle_stuff_list_selection()
{
int selected = model_.stuff_list->get_selected_row();
if(selected == -1) {
model_.set_inspect_window_text("");
return;
}
if(selected == 0) {
config c = resources::teams
? resources::teams->at(side_ - 1).to_config()
: config();
c.clear_children("ai", "village");
model_.set_inspect_window_text(config_to_string(c));
return;
}
if(selected == 1) {
model_.set_inspect_window_text(
ai::manager::get_active_ai_overview_for_side(side_));
return;
}
if(selected == 2) {
model_.set_inspect_window_text(
config_to_string(ai::manager::to_config(side_), "engine"));
}
if(selected == 3) {
model_.set_inspect_window_text(
config_to_string(ai::manager::to_config(side_), "stage"));
}
if(selected == 4) {
model_.set_inspect_window_text(
config_to_string(ai::manager::to_config(side_), "aspect"));
}
if(selected == 5) {
model_.set_inspect_window_text(
config_to_string(ai::manager::to_config(side_), "goal"));
}
if(selected == 6) {
std::stringstream s;
if (resources::teams) {
for(const auto & u : resources::teams->at(side_ - 1).recall_list())
{
s << "id=\"" << u->id() << "\" (" << u->type_id() << ")\nL"
<< u->level() << "; " << u->experience() << "/"
<< u->max_experience() << " xp; " << u->hitpoints() << "/"
<< u->max_hitpoints() << " hp\n";
for(const auto & str : u->get_traits_list())
{
s << "\t" << str << std::endl;
}
s << std::endl;
}
}
model_.set_inspect_window_text(s.str());
return;
}
if(selected == 7) {
config c;
if (resources::teams) {
for(const auto & u : resources::teams->at(side_ - 1).recall_list())
{
config c_unit;
u->write(c_unit);
c.add_child("unit", c_unit);
}
}
model_.set_inspect_window_text(config_to_string(c));
return;
}
if(selected == 8) {
model_.set_inspect_window_text(
ai::manager::get_active_ai_structure_for_side(side_));
return;
}
if(selected == 9) {
std::stringstream s;
if(resources::units) {
for(unit_map::iterator i = resources::units->begin();
i != resources::units->end();
++i) {
if(i->side() != side_) {
continue;
}
s << '(' << i->get_location() << ") ";
if(i->can_recruit()) {
s << "LEADER ";
}
s << "\nid=\"" << i->id() << "\" (" << i->type_id() << ")\n"
<< "L" << i->level() << "; " << i->experience() << '/'
<< i->max_experience() << " xp; " << i->hitpoints() << '/'
<< i->max_hitpoints() << " hp\n";
for(const auto & str : i->get_traits_list())
{
s << "\t" << str << std::endl;
}
s << std::endl;
}
}
model_.set_inspect_window_text(s.str());
return;
}
}
virtual void update_view_from_model()
{
show_stuff_list();
handle_stuff_list_selection();
}
private:
int side_;
};
// The controller acts upon the model. It retrieves data from repositories,
// persists it, manipulates it, and determines how it will be displayed in the
// view.
class tgamestate_inspector::controller
{
public:
typedef std::vector<std::shared_ptr<single_mode_controller> >
sm_controller_ptr_vector;
controller(model& m) : model_(m), sm_controllers_()
{
sm_controllers_.push_back(std::make_shared<variable_mode_controller>
("variables", model_));
sm_controllers_.push_back(std::make_shared<event_mode_controller>
("events", model_, event_mode_controller::EVENT_HANDLER));
sm_controllers_.push_back(std::make_shared<event_mode_controller>
("menu items", model_, event_mode_controller::WMI_HANDLER));
sm_controllers_.push_back(std::make_shared<unit_mode_controller>
("units", model_));
// BOOST_FOREACHteam
int sides = resources::teams
? static_cast<int>((*resources::teams).size())
: 0;
for(int side = 1; side <= sides; ++side) {
std::string side_str = std::to_string(side);
sm_controllers_.push_back(std::make_shared<team_mode_controller>
(std::string("team ") + side_str, model_, side));
}
}
std::shared_ptr<single_mode_controller> get_sm_controller()
{
int selected = model_.stuff_types_list->get_selected_row();
if(selected == -1) {
// TODO: select row (maybe remember last selected row?...)
selected = 0;
}
return sm_controllers_.at(selected);
}
void show_stuff_types_list()
{
model_.clear_stuff_types_list();
for(auto sm_controller : sm_controllers_)
{
model_.add_row_to_stuff_types_list(sm_controller->name(),
sm_controller->name());
}
}
void show_title()
{
model_.inspector_name->set_label(model_.name);
}
void update_view_from_model()
{
std::shared_ptr<single_mode_controller> c = get_sm_controller();
show_title();
c->update_view_from_model();
}
void handle_stuff_list_item_clicked()
{
model_.set_inspect_window_text("");
std::shared_ptr<single_mode_controller> c = get_sm_controller();
c->handle_stuff_list_selection();
}
void handle_stuff_types_list_item_clicked()
{
model_.clear_stuff_list();
model_.set_inspect_window_text("");
std::shared_ptr<single_mode_controller> c = get_sm_controller();
c->update_view_from_model(); // TODO: 'activate'
}
void handle_copy_button_clicked()
{
desktop::clipboard::copy_to_clipboard(model_.inspect->label(), false);
}
void handle_lua_button_clicked(CVideo & video)
{
tlua_interpreter::display(video, tlua_interpreter::GAME);
}
private:
model& model_;
sm_controller_ptr_vector sm_controllers_;
};
// The view is an interface that displays data (the model) and routes user
// commands to the controller to act upon that data.
class tgamestate_inspector::view
{
public:
view(const vconfig& cfg) : model_(cfg), controller_(model_)
{
}
void pre_show(twindow& /*window*/)
{
controller_.show_stuff_types_list();
controller_.update_view_from_model();
}
void handle_stuff_list_item_clicked()
{
controller_.handle_stuff_list_item_clicked();
}
void handle_stuff_types_list_item_clicked()
{
controller_.handle_stuff_types_list_item_clicked();
}
void handle_copy_button_clicked(twindow& /*window*/)
{
controller_.handle_copy_button_clicked();
}
void handle_lua_button_clicked(twindow& window)
{
controller_.handle_lua_button_clicked(window.video());
}
void bind(twindow& window)
{
model_.stuff_list
= &find_widget<tlistbox>(&window, "stuff_list", false);
model_.stuff_types_list
= &find_widget<tlistbox>(&window, "stuff_types_list", false);
model_.inspect = find_widget<tcontrol>(&window, "inspect", false, true);
model_.inspector_name
= &find_widget<tcontrol>(&window, "inspector_name", false);
model_.copy_button
= &find_widget<tbutton>(&window, "copy", false);
model_.lua_button
= &find_widget<tbutton>(&window, "lua", false);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
connect_signal_notify_modified(
*model_.stuff_list,
std::bind(&tgamestate_inspector::view::
handle_stuff_list_item_clicked,
this));
connect_signal_notify_modified(
*model_.stuff_types_list,
std::bind(&tgamestate_inspector::view::
handle_stuff_list_item_clicked,
this));
#else
model_.stuff_list->set_callback_value_change(
dialog_view_callback<tgamestate_inspector,
tgamestate_inspector::view,
&tgamestate_inspector::view::
handle_stuff_list_item_clicked>);
model_.stuff_types_list->set_callback_value_change(
dialog_view_callback<tgamestate_inspector,
tgamestate_inspector::view,
&tgamestate_inspector::view::
handle_stuff_types_list_item_clicked>);
#endif
connect_signal_mouse_left_click(
*model_.copy_button,
std::bind(&tgamestate_inspector::view::handle_copy_button_clicked,
this,
std::ref(window)));
connect_signal_mouse_left_click(
*model_.lua_button,
std::bind(&tgamestate_inspector::view::handle_lua_button_clicked,
this,
std::ref(window)));
if (!desktop::clipboard::available()) {
model_.copy_button->set_active(false);
model_.copy_button->set_tooltip(_("Clipboard support not found, contact your packager"));
}
}
private:
model model_;
controller controller_;
};
REGISTER_DIALOG(gamestate_inspector)
tgamestate_inspector::tgamestate_inspector(const vconfig& cfg)
: view_(new view(cfg))
{
}
std::shared_ptr<tgamestate_inspector::view> tgamestate_inspector::get_view()
{
return view_;
}
void tgamestate_inspector::pre_show(twindow& window)
{
view_->bind(window);
view_->pre_show(window);
}
} // end of namespace gui2