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