1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
|
|
2 | |
2 | use strict; |
3 | use strict; |
|
|
4 | use utf8; |
3 | |
5 | |
4 | use Glib; |
6 | use Glib; |
5 | use Gtk2 -init; |
7 | use Gtk2 -init; |
6 | |
8 | |
7 | use SDL; |
9 | use SDL; |
… | |
… | |
10 | use SDL::Surface; |
12 | use SDL::Surface; |
11 | use SDL::OpenGL; |
13 | use SDL::OpenGL; |
12 | use SDL::OpenGL::Constants; |
14 | use SDL::OpenGL::Constants; |
13 | |
15 | |
14 | use Crossfire; |
16 | use Crossfire; |
15 | use Crossfire::Client; |
|
|
16 | use Crossfire::Protocol; |
17 | use Crossfire::Protocol; |
17 | |
18 | |
18 | use Crossfire::Client::Util; |
19 | use CFClient; |
19 | use Crossfire::Client::Widget; |
20 | use CFClient::UI; |
|
|
21 | |
|
|
22 | our $VERSION = '0.1'; |
|
|
23 | |
|
|
24 | my $MAX_FPS = 60; |
|
|
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
20 | |
26 | |
21 | our $FACECACHE; |
27 | our $FACECACHE; |
22 | |
|
|
23 | our $VERSION = '0.1'; |
|
|
24 | |
28 | |
25 | our $CFG; |
29 | our $CFG; |
26 | our $CONN; |
30 | our $CONN; |
27 | |
31 | |
|
|
32 | our @SDL_MODES; |
|
|
33 | our $WIDTH; |
|
|
34 | our $HEIGHT; |
|
|
35 | our $FULLSCREEN; |
|
|
36 | |
|
|
37 | our $NOW; |
|
|
38 | |
|
|
39 | our $MAPWIDGET; |
|
|
40 | our $FONTSIZE; |
|
|
41 | |
28 | our $SDL_TIMER; |
42 | our $SDL_TIMER; |
29 | our $SDL_APP; |
43 | our $SDL_APP; |
30 | our $SDL_EV = new SDL::Event; |
44 | our $SDL_EV; |
31 | our %SDL_CB; |
45 | our %SDL_CB; |
32 | |
46 | |
33 | our @GL_INIT; # hooks called on every gl init |
47 | our $ALT_ENTER_MESSAGE; |
|
|
48 | our $STATUS_LINE; |
|
|
49 | our $DEBUG_STATUS; |
|
|
50 | |
|
|
51 | my $last_refresh; |
|
|
52 | my %ANIMATE; |
|
|
53 | my $refresh_handler; |
|
|
54 | |
|
|
55 | our ($tw, $te); # Test widget #d# |
34 | |
56 | |
35 | sub init_screen { |
57 | sub init_screen { |
36 | $SDL_APP = new SDL::App |
58 | $SDL_APP = new SDL::App |
37 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
59 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
38 | -title => "Crossfire+ Client", |
60 | -title => "Crossfire+ Client", |
39 | -width => $CFG->{width}, |
61 | -width => $WIDTH, |
40 | -height => $CFG->{height}, |
62 | -height => $HEIGHT, |
41 | -opengl => 1, |
63 | -opengl => 1, |
42 | -red_size => 8, |
64 | -red_size => 5, |
43 | -green_size => 8, |
65 | -green_size => 5, |
44 | -blue_size => 8, |
66 | -blue_size => 5, |
|
|
67 | -alpha_size => 0, |
45 | -double_buffer => 1, |
68 | -double_buffer => 1, |
46 | -fullscreen => $CFG->{fullscreen}, |
69 | -fullscreen => $FULLSCREEN, |
47 | -resizeable => 0; |
70 | -resizeable => 0; |
48 | |
71 | |
|
|
72 | $SDL_EV = new SDL::Event; |
|
|
73 | $SDL_EV->set_unicode (1); |
|
|
74 | |
|
|
75 | $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { |
|
|
76 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
77 | while $SDL_EV->poll; |
|
|
78 | |
|
|
79 | 1 |
|
|
80 | }; |
|
|
81 | |
|
|
82 | $last_refresh = SDL::GetTicks; |
|
|
83 | |
|
|
84 | CFClient::gl_init; |
|
|
85 | |
|
|
86 | $FONTSIZE = int $HEIGHT / 40; |
|
|
87 | |
|
|
88 | ############################################################################# |
|
|
89 | |
49 | glClearColor 0, 0, 0, 0; |
90 | glClearColor 0.45, 0.45, 0.45, 1; |
50 | |
91 | |
51 | glEnable GL_TEXTURE_2D; |
92 | glEnable GL_TEXTURE_2D; |
52 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
93 | glEnable GL_COLOR_MATERIAL; |
53 | glShadeModel GL_FLAT; |
94 | glShadeModel GL_FLAT; |
54 | glDisable GL_DEPTH_TEST; |
95 | glDisable GL_DEPTH_TEST; |
55 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
96 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
56 | glEnable GL_BLEND; |
97 | |
|
|
98 | ############################################################################# |
|
|
99 | |
|
|
100 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
|
|
101 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
102 | |
|
|
103 | $STATUS_LINE = new CFClient::UI::Label |
|
|
104 | padding => 0, |
|
|
105 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
|
|
106 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
|
|
107 | |
|
|
108 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
109 | padding => 0, |
|
|
110 | y => $HEIGHT * 49 / 50, |
|
|
111 | height => $HEIGHT / 50, |
|
|
112 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
113 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
114 | |
|
|
115 | $MAPWIDGET = new CFClient::UI::MapWidget; |
|
|
116 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
|
|
117 | $MAPWIDGET->focus_in; |
|
|
118 | } |
|
|
119 | |
|
|
120 | sub destroy_screen { |
|
|
121 | remove Glib::Source $SDL_TIMER; |
|
|
122 | undef $SDL_APP; |
|
|
123 | undef $SDL_EV; |
|
|
124 | SDL::Quit; |
|
|
125 | } |
|
|
126 | |
|
|
127 | sub config_dialog { |
|
|
128 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
|
|
129 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
130 | $vbox->add (new CFClient::UI::Label align => 0, text => "Setup"); |
|
|
131 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
132 | |
|
|
133 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
|
|
134 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
|
|
135 | |
|
|
136 | $hbox->add (my $mode_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
137 | $hbox->add (my $mode_label = new CFClient::UI::Label); |
|
|
138 | |
|
|
139 | $mode_slider->connect (changed => sub { |
|
|
140 | my (undef, $value) = @_; |
|
|
141 | |
|
|
142 | $CFG->{sdl_mode} = $value = int $value + 0.5; |
|
|
143 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
144 | }); |
|
|
145 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
|
|
146 | |
|
|
147 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Host"); |
|
|
148 | $table->add (1, 1, my $host = new CFClient::UI::Entry text => $CFG->{host}); |
|
|
149 | |
|
|
150 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Port"); |
|
|
151 | $table->add (1, 2, my $port = new CFClient::UI::Entry text => $CFG->{port}); |
|
|
152 | |
|
|
153 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Username"); |
|
|
154 | $table->add (1, 3, my $user = new CFClient::UI::Entry text => $CFG->{user}); |
|
|
155 | |
|
|
156 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Password"); |
|
|
157 | $table->add (1, 4, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); |
|
|
158 | |
|
|
159 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Map Size"); |
|
|
160 | $table->add (1, 5, my $mapsize_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{mapsize}, 10, 100 + 1, 1]); |
|
|
161 | |
|
|
162 | $CFClient::UI::TOPLEVEL->add ($dialog); |
|
|
163 | } |
|
|
164 | |
|
|
165 | sub start_game { |
|
|
166 | $WIDTH = $CFG->{width}; |
|
|
167 | $HEIGHT = $CFG->{height}; |
|
|
168 | $FULLSCREEN = 0; |
|
|
169 | |
|
|
170 | init_screen; |
|
|
171 | |
|
|
172 | config_dialog; |
|
|
173 | |
|
|
174 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
175 | |
|
|
176 | $CONN = new conn |
|
|
177 | host => $CFG->{host}, |
|
|
178 | port => $CFG->{port}, |
|
|
179 | user => $CFG->{user}, |
|
|
180 | pass => $CFG->{password}, |
|
|
181 | mapw => $mapsize, |
|
|
182 | maph => $mapsize, |
|
|
183 | ; |
|
|
184 | |
|
|
185 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
186 | } |
|
|
187 | |
|
|
188 | sub stop_game { |
|
|
189 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
190 | undef $refresh_handler; |
|
|
191 | |
|
|
192 | undef $CONN; |
|
|
193 | destroy_screen; |
|
|
194 | } |
|
|
195 | |
|
|
196 | sub force_refresh { |
|
|
197 | glViewport 0, 0, $WIDTH, $HEIGHT; |
57 | |
198 | |
58 | glMatrixMode GL_PROJECTION; |
199 | glMatrixMode GL_PROJECTION; |
59 | glLoadIdentity; |
200 | glLoadIdentity; |
60 | glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -100 , 100; |
201 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
61 | |
|
|
62 | glMatrixMode GL_MODELVIEW; |
202 | glMatrixMode GL_MODELVIEW; |
|
|
203 | glLoadIdentity; |
63 | |
204 | |
64 | $_->() for @GL_INIT; |
205 | glClear GL_COLOR_BUFFER_BIT; |
65 | } |
|
|
66 | |
206 | |
67 | sub start_game { |
207 | $CFClient::UI::TOPLEVEL->draw; |
68 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
208 | |
69 | while ($SDL_EV->poll) { |
209 | SDL::GLSwapBuffers; |
70 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
210 | } |
|
|
211 | |
|
|
212 | sub debug { |
|
|
213 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
214 | my ($w, $h) = $DEBUG_STATUS->size_request; |
|
|
215 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
216 | } |
|
|
217 | |
|
|
218 | my $FPS; |
|
|
219 | |
|
|
220 | sub refresh { |
|
|
221 | $refresh_handler ||= add Glib::Idle sub { |
|
|
222 | if ($SDL_APP) { |
|
|
223 | $NOW = SDL::GetTicks; |
|
|
224 | |
|
|
225 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
|
|
226 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
|
|
227 | $NOW = SDL::GetTicks; |
|
|
228 | } |
|
|
229 | |
|
|
230 | my $interval = ($NOW - $last_refresh) * 0.001; |
|
|
231 | $last_refresh = $NOW; |
|
|
232 | |
|
|
233 | if ($interval) { |
|
|
234 | $FPS ||= 1 / $interval; |
|
|
235 | $FPS = $FPS * 0.9 + (1 / $interval) * 0.1; |
|
|
236 | debug sprintf "%5.02f", $FPS; |
|
|
237 | } |
|
|
238 | |
|
|
239 | force_refresh; |
|
|
240 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
241 | |
|
|
242 | if (%ANIMATE) { |
|
|
243 | 1 |
|
|
244 | } else { |
|
|
245 | undef $refresh_handler; |
|
|
246 | 0 |
|
|
247 | } |
|
|
248 | } else { |
|
|
249 | undef $refresh_handler; |
|
|
250 | 0 |
71 | } |
251 | } |
72 | |
|
|
73 | 1 |
|
|
74 | }; |
252 | }; |
75 | |
|
|
76 | init_screen; |
|
|
77 | |
|
|
78 | $CONN = new conn |
|
|
79 | host => $CFG->{host}, |
|
|
80 | port => $CFG->{port}; |
|
|
81 | } |
253 | } |
82 | |
254 | |
83 | sub stop_game { |
255 | sub animation_start { |
84 | remove Glib::Source $SDL_TIMER; |
256 | my ($widget) = @_; |
|
|
257 | $ANIMATE{$widget} = $widget; |
|
|
258 | Scalar::Util::weaken $ANIMATE{$widget}; |
85 | |
259 | |
86 | undef $SDL_APP; |
260 | refresh; |
87 | SDL::Quit; |
|
|
88 | } |
261 | } |
89 | |
262 | |
90 | sub refresh { |
263 | sub animation_stop { |
91 | glClear GL_COLOR_BUFFER_BIT; |
264 | my ($widget) = @_; |
92 | |
265 | delete $ANIMATE{$widget}; |
93 | $_->draw for values %Crossfire::Client::Widget::ACTIVE_WIDGETS; |
|
|
94 | |
|
|
95 | SDL::GLSwapBuffers; |
|
|
96 | } |
266 | } |
97 | |
267 | |
98 | %SDL_CB = ( |
268 | %SDL_CB = ( |
99 | SDL_QUIT() => sub { |
269 | SDL_QUIT() => sub { |
100 | main_quit Gtk2; |
270 | main_quit Gtk2; |
… | |
… | |
105 | refresh; |
275 | refresh; |
106 | }, |
276 | }, |
107 | SDL_KEYDOWN() => sub { |
277 | SDL_KEYDOWN() => sub { |
108 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
278 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
109 | # alt-enter |
279 | # alt-enter |
110 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
280 | $FULLSCREEN = !$FULLSCREEN; |
111 | init_screen; |
281 | init_screen; |
112 | } else { |
282 | } else { |
113 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
283 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
114 | } |
284 | } |
115 | }, |
285 | }, |
116 | SDL_KEYUP() => sub { |
286 | SDL_KEYUP() => sub { |
117 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
287 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
118 | }, |
288 | }, |
119 | SDL_MOUSEMOTION() => sub { |
289 | SDL_MOUSEMOTION() => sub { |
120 | warn "sdl motion\n";#d# |
290 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
121 | }, |
291 | }, |
122 | SDL_MOUSEBUTTONDOWN() => sub { |
292 | SDL_MOUSEBUTTONDOWN() => sub { |
123 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
293 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
124 | }, |
294 | }, |
125 | SDL_MOUSEBUTTONUP() => sub { |
295 | SDL_MOUSEBUTTONUP() => sub { |
126 | Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
296 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
127 | }, |
297 | }, |
128 | SDL_ACTIVEEVENT() => sub { |
298 | SDL_ACTIVEEVENT() => sub { |
129 | warn "active\n";#d# |
299 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
130 | }, |
300 | }, |
131 | ); |
301 | ); |
132 | |
302 | |
133 | @conn::ISA = Crossfire::Protocol::; |
303 | @conn::ISA = Crossfire::Protocol::; |
134 | |
304 | |
135 | sub conn::map_update { |
305 | sub conn::map_update { |
136 | my ($self, $dirty) = @_; |
306 | my ($self, $dirty) = @_; |
137 | |
307 | |
138 | refresh; |
308 | $MAPWIDGET->update; |
139 | } |
309 | } |
140 | |
310 | |
141 | sub conn::map_scroll { |
311 | sub conn::map_scroll { |
142 | my ($self, $dx, $dy) = @_; |
312 | my ($self, $dx, $dy) = @_; |
143 | |
313 | |
144 | refresh; |
314 | # refresh; |
145 | } |
315 | } |
146 | |
316 | |
147 | sub conn::map_clear { |
317 | sub conn::map_clear { |
148 | my ($self) = @_; |
318 | my ($self) = @_; |
149 | |
319 | |
150 | refresh; |
320 | # refresh; |
151 | } |
321 | } |
152 | |
322 | |
153 | sub conn::face_find { |
323 | sub conn::face_find { |
154 | my ($self, $face) = @_; |
324 | my ($self, $face) = @_; |
155 | |
325 | |
… | |
… | |
159 | sub conn::face_update { |
329 | sub conn::face_update { |
160 | my ($self, $face) = @_; |
330 | my ($self, $face) = @_; |
161 | |
331 | |
162 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
332 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
163 | |
333 | |
164 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
334 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
|
|
335 | } |
|
|
336 | |
|
|
337 | sub conn::query { |
|
|
338 | my ($self, $flags, $prompt) = @_; |
|
|
339 | |
|
|
340 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
165 | } |
341 | } |
166 | |
342 | |
167 | sub gtk_add_cfg_field { |
343 | sub gtk_add_cfg_field { |
168 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
344 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
169 | my $i = $cfg->{_i}++; |
345 | my $i = $cfg->{_i}++; |
… | |
… | |
175 | } |
351 | } |
176 | $ent->set_text ($value); |
352 | $ent->set_text ($value); |
177 | $ent->signal_connect (changed => sub { |
353 | $ent->signal_connect (changed => sub { |
178 | my ($ent) = @_; |
354 | my ($ent) = @_; |
179 | $cfg->{$key} = $ent->get_text; |
355 | $cfg->{$key} = $ent->get_text; |
|
|
356 | # TODO: Mapsize should be a slider in the game gui |
|
|
357 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
|
|
358 | $cfg->{$key} = 100; |
|
|
359 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
360 | $cfg->{$key} = 50; |
|
|
361 | } |
180 | }); |
362 | }); |
181 | } |
363 | } |
182 | |
364 | |
183 | sub run_config_dialog { |
365 | sub run_config_dialog { |
184 | my (%events) = @_; |
366 | my (%events) = @_; |
… | |
… | |
186 | my $w = Gtk2::Window->new; |
368 | my $w = Gtk2::Window->new; |
187 | |
369 | |
188 | my @cfg = ( |
370 | my @cfg = ( |
189 | [qw/Host host/], |
371 | [qw/Host host/], |
190 | [qw/Port port/], |
372 | [qw/Port port/], |
|
|
373 | [qw/Mapsize% mapsize/], |
191 | [qw/Username user/], |
374 | [qw/Username user/], |
192 | [qw/Password password/], |
375 | [qw/Password password/], |
193 | ); |
376 | ); |
194 | |
377 | |
195 | my $cfg = {}; |
378 | my $cfg = {}; |
196 | |
|
|
197 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
198 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
199 | |
379 | |
200 | $w->add (my $vb = Gtk2::VBox->new); |
380 | $w->add (my $vb = Gtk2::VBox->new); |
201 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
381 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
202 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
382 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
203 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
383 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
204 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
384 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
205 | my $i = 0; |
385 | my $i = 0; |
206 | my $act = 0; |
386 | my $act = 0; |
207 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
387 | for (map { "$_->[0]x$_->[1]" } @SDL_MODES) { |
208 | if ($_ eq $selmode) { $act = $i } |
388 | if ($_ eq $selmode) { $act = $i } |
209 | $cb->append_text ($_); |
389 | $cb->append_text ($_); |
210 | $i++; |
390 | $i++; |
211 | } |
391 | } |
212 | $cb->set_active ($act); |
392 | $cb->set_active ($act); |
… | |
… | |
229 | $cb->signal_connect (clicked => sub { |
409 | $cb->signal_connect (clicked => sub { |
230 | for (keys %$cfg) { |
410 | for (keys %$cfg) { |
231 | $::CFG->{$_} = $cfg->{$_} |
411 | $::CFG->{$_} = $cfg->{$_} |
232 | if $_ ne '_i'; |
412 | if $_ ne '_i'; |
233 | } |
413 | } |
234 | Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc"; |
414 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
235 | }); |
415 | }); |
236 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
416 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
237 | $cb->signal_connect (clicked => sub { |
417 | $cb->signal_connect (clicked => sub { |
238 | for (keys %$cfg) { |
418 | for (keys %$cfg) { |
239 | $::CFG->{$_} = $cfg->{$_} |
419 | $::CFG->{$_} = $cfg->{$_} |
… | |
… | |
242 | my $cb = $events{login} || sub {}; |
422 | my $cb = $events{login} || sub {}; |
243 | $cb->($::CFG->{user}, $::CFG->{password}); |
423 | $cb->($::CFG->{user}, $::CFG->{password}); |
244 | }); |
424 | }); |
245 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
425 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
246 | $cb->signal_connect (clicked => sub { |
426 | $cb->signal_connect (clicked => sub { |
247 | my $cb = $events{login} || sub {}; |
427 | my $cb = $events{logout} || sub {}; |
248 | $cb->(); |
428 | $cb->(); |
249 | }); |
429 | }); |
250 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
430 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
251 | $cb->signal_connect (clicked => sub { $w->destroy }); |
431 | $cb->signal_connect (clicked => sub { $w->destroy }); |
252 | |
432 | |
… | |
… | |
256 | } |
436 | } |
257 | |
437 | |
258 | |
438 | |
259 | ############################################################################# |
439 | ############################################################################# |
260 | |
440 | |
261 | SDL::Init(SDL_INIT_EVERYTHING()); |
441 | SDL::Init SDL_INIT_EVERYTHING; |
262 | |
442 | |
263 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
443 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
|
|
444 | @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; |
264 | |
445 | |
265 | find_rcfile "uifont.ttf"; |
|
|
266 | |
|
|
267 | $mapwidget->activate; |
|
|
268 | $mapwidget->focus_in; |
|
|
269 | |
|
|
270 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
446 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
271 | |
|
|
272 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
|
|
273 | |
447 | |
274 | $CFG ||= { |
448 | $CFG ||= { |
275 | width => 640, |
449 | width => 640, |
276 | height => 480, |
450 | height => 480, |
|
|
451 | mapsize => 100, |
277 | fullscreen => 0, |
452 | fullscreen => 0, |
278 | host => "crossfire.schmorp.de", |
453 | host => "crossfire.schmorp.de", |
279 | port => 13327, |
454 | port => 13327, |
280 | }; |
455 | }; |
281 | |
456 | |
|
|
457 | { |
|
|
458 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
|
|
459 | |
|
|
460 | CFClient::add_font $_ for @fonts; |
|
|
461 | CFClient::set_font $fonts[0]; |
|
|
462 | } |
|
|
463 | |
|
|
464 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
|
|
465 | |
282 | run_config_dialog |
466 | run_config_dialog |
283 | login => sub { start_game }, |
467 | login => sub { start_game }, |
284 | logout => sub { stop_game }; |
468 | logout => sub { stop_game }; |
285 | |
469 | |
286 | main Gtk2; |
470 | main Gtk2; |