hegyi@112
|
1 |
#include "mapselector.h"
|
hegyi@112
|
2 |
|
hegyi@114
|
3 |
MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false)
|
hegyi@112
|
4 |
{
|
hegyi@112
|
5 |
update_list(ml);
|
hegyi@112
|
6 |
|
hegyi@112
|
7 |
if(act=="")
|
hegyi@112
|
8 |
{
|
hegyi@112
|
9 |
cbt.set_active(0);
|
hegyi@112
|
10 |
default_state=true;
|
hegyi@112
|
11 |
}
|
hegyi@112
|
12 |
else
|
hegyi@112
|
13 |
{
|
hegyi@112
|
14 |
cbt.set_active_text((Glib::ustring)act);
|
hegyi@112
|
15 |
default_state=false;
|
hegyi@112
|
16 |
}
|
hegyi@112
|
17 |
|
hegyi@112
|
18 |
//binding signal to the actual entry
|
hegyi@112
|
19 |
cbt.signal_changed().connect
|
hegyi@112
|
20 |
(
|
hegyi@112
|
21 |
sigc::mem_fun((*this), &MapSelector::comboChanged),
|
hegyi@112
|
22 |
false
|
hegyi@112
|
23 |
);
|
hegyi@112
|
24 |
|
hegyi@114
|
25 |
label=new Gtk::Label(labeltext);
|
hegyi@112
|
26 |
|
hegyi@112
|
27 |
label->set_width_chars(longest_property_string_length);
|
hegyi@112
|
28 |
|
hegyi@122
|
29 |
defbut=NULL;
|
hegyi@122
|
30 |
if(def)
|
hegyi@122
|
31 |
{
|
hegyi@122
|
32 |
defbut=new Gtk::Button();
|
hegyi@122
|
33 |
defbut->set_label("Reset");
|
hegyi@122
|
34 |
|
hegyi@122
|
35 |
defbut->signal_pressed().connect
|
hegyi@122
|
36 |
(
|
hegyi@122
|
37 |
sigc::mem_fun(*this, &MapSelector::reset)
|
hegyi@122
|
38 |
);
|
hegyi@122
|
39 |
}
|
hegyi@112
|
40 |
|
hegyi@112
|
41 |
newbut=new Gtk::Button(Gtk::Stock::NEW);
|
hegyi@112
|
42 |
|
hegyi@112
|
43 |
newbut->signal_pressed().connect
|
hegyi@112
|
44 |
(
|
hegyi@112
|
45 |
sigc::mem_fun(*this, &MapSelector::new_but_pressed)
|
hegyi@112
|
46 |
);
|
hegyi@112
|
47 |
|
hegyi@112
|
48 |
add(*label);
|
hegyi@112
|
49 |
|
hegyi@112
|
50 |
add(cbt);
|
hegyi@112
|
51 |
|
hegyi@122
|
52 |
if(def)
|
hegyi@122
|
53 |
{
|
hegyi@122
|
54 |
add(*defbut);
|
hegyi@122
|
55 |
}
|
hegyi@122
|
56 |
|
hegyi@112
|
57 |
add(*newbut);
|
hegyi@112
|
58 |
}
|
hegyi@112
|
59 |
|
hegyi@112
|
60 |
void MapSelector::new_but_pressed()
|
hegyi@112
|
61 |
{
|
hegyi@112
|
62 |
set_new_map=true;
|
hegyi@112
|
63 |
signal_newmapwin.emit(itisedge);
|
hegyi@112
|
64 |
}
|
hegyi@112
|
65 |
|
hegyi@112
|
66 |
void MapSelector::update_list( std::vector< std::string > ml )
|
hegyi@112
|
67 |
{
|
hegyi@112
|
68 |
int prev_act=cbt.get_active_row_number();
|
hegyi@112
|
69 |
cbt.clear();
|
hegyi@112
|
70 |
std::vector< std::string >::iterator emsi=ml.begin();
|
hegyi@112
|
71 |
for(;emsi!=ml.end();emsi++)
|
hegyi@112
|
72 |
{
|
hegyi@112
|
73 |
cbt.append_text(*emsi);
|
hegyi@112
|
74 |
}
|
hegyi@114
|
75 |
if(def)
|
hegyi@114
|
76 |
{
|
hegyi@114
|
77 |
cbt.prepend_text("Default values");
|
hegyi@114
|
78 |
}
|
hegyi@112
|
79 |
if(prev_act!=-1)
|
hegyi@112
|
80 |
{
|
hegyi@112
|
81 |
cbt.set_active(prev_act);
|
hegyi@112
|
82 |
}
|
hegyi@112
|
83 |
}
|
hegyi@112
|
84 |
|
hegyi@112
|
85 |
void MapSelector::comboChanged()
|
hegyi@112
|
86 |
{
|
hegyi@122
|
87 |
if(cbt.get_active_row_number()!=0 || !def)
|
hegyi@112
|
88 |
{
|
hegyi@112
|
89 |
default_state=false;
|
hegyi@112
|
90 |
Glib::ustring mapname = cbt.get_active_text();
|
hegyi@112
|
91 |
if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
|
hegyi@112
|
92 |
{
|
hegyi@112
|
93 |
signal_cbt.emit(mapname);
|
hegyi@112
|
94 |
}
|
hegyi@112
|
95 |
}
|
hegyi@112
|
96 |
else if((!default_state)&&(cbt.get_active_row_number()==0))
|
hegyi@112
|
97 |
{
|
hegyi@112
|
98 |
reset();
|
hegyi@112
|
99 |
}
|
hegyi@112
|
100 |
}
|
hegyi@112
|
101 |
|
hegyi@112
|
102 |
void MapSelector::reset()
|
hegyi@112
|
103 |
{
|
hegyi@112
|
104 |
default_state=true;
|
hegyi@112
|
105 |
|
hegyi@112
|
106 |
cbt.set_active(0);
|
hegyi@112
|
107 |
|
hegyi@112
|
108 |
signal_cbt.emit("");
|
hegyi@112
|
109 |
}
|
hegyi@112
|
110 |
|
hegyi@112
|
111 |
|
hegyi@112
|
112 |
Glib::ustring MapSelector::get_active_text()
|
hegyi@112
|
113 |
{
|
hegyi@112
|
114 |
return cbt.get_active_text();
|
hegyi@112
|
115 |
}
|
hegyi@112
|
116 |
|
hegyi@112
|
117 |
void MapSelector::set_active_text(Glib::ustring text)
|
hegyi@112
|
118 |
{
|
hegyi@112
|
119 |
cbt.set_active_text(text);
|
hegyi@112
|
120 |
}
|
hegyi@112
|
121 |
|
hegyi@112
|
122 |
void MapSelector::append_text(Glib::ustring text)
|
hegyi@112
|
123 |
{
|
hegyi@112
|
124 |
cbt.append_text(text);
|
hegyi@112
|
125 |
if(set_new_map)
|
hegyi@112
|
126 |
{
|
hegyi@112
|
127 |
set_active_text(text);
|
hegyi@112
|
128 |
set_new_map=false;
|
hegyi@112
|
129 |
}
|
hegyi@112
|
130 |
}
|
hegyi@112
|
131 |
|
hegyi@112
|
132 |
sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
|
hegyi@112
|
133 |
{
|
hegyi@112
|
134 |
return signal_cbt;
|
hegyi@112
|
135 |
}
|
hegyi@112
|
136 |
|
hegyi@112
|
137 |
sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
|
hegyi@112
|
138 |
{
|
hegyi@112
|
139 |
return signal_newmapwin;
|
hegyi@112
|
140 |
}
|