… | |
… | |
21 | our $VERSION = '0.1'; |
21 | our $VERSION = '0.1'; |
22 | |
22 | |
23 | my $MAX_FPS = 60; |
23 | my $MAX_FPS = 60; |
24 | my $MIN_FPS = 5; # unused as of yet |
24 | my $MIN_FPS = 5; # unused as of yet |
25 | |
25 | |
|
|
26 | our $META_SERVER = "crossfire.real-time.com:13326"; |
|
|
27 | |
26 | our $FACECACHE; |
28 | our $FACECACHE; |
27 | |
29 | |
28 | our $LAST_REFRESH; |
30 | our $LAST_REFRESH; |
29 | our $NOW; |
31 | our $NOW; |
30 | |
32 | |
… | |
… | |
38 | our $FULLSCREEN; |
40 | our $FULLSCREEN; |
39 | our $FONTSIZE; |
41 | our $FONTSIZE; |
40 | |
42 | |
41 | our $MAP; |
43 | our $MAP; |
42 | our $MAPWIDGET; |
44 | our $MAPWIDGET; |
|
|
45 | our $BUTTONBAR; |
|
|
46 | our $LOGVIEW; |
|
|
47 | our $CONSOLE; |
|
|
48 | our $METASERVER; |
43 | |
49 | |
44 | our $SDL_ACTIVE; |
50 | our $SDL_ACTIVE; |
45 | our $SDL_EV; |
51 | our $SDL_EV; |
46 | our %SDL_CB; |
52 | our %SDL_CB; |
47 | |
53 | |
48 | our $ALT_ENTER_MESSAGE; |
54 | our $ALT_ENTER_MESSAGE; |
49 | our $STATUS_LINE; |
55 | our $STATUS_LINE; |
50 | our $DEBUG_STATUS; |
56 | our $DEBUG_STATUS; |
51 | our $BUTTONBAR; |
|
|
52 | our $LOGVIEW; |
|
|
53 | our $CONSOLE; |
|
|
54 | |
57 | |
55 | sub status { |
58 | sub status { |
56 | $STATUS_LINE->set_text ($_[0]); |
59 | $STATUS_LINE->set_text ($_[0]); |
57 | my ($w, $h) = $STATUS_LINE->size_request; |
60 | my ($w, $h) = $STATUS_LINE->size_request; |
58 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
61 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
… | |
… | |
68 | status "logging in..."; |
71 | status "logging in..."; |
69 | |
72 | |
70 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
73 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
71 | |
74 | |
72 | $MAP = new CFClient::Map $mapsize, $mapsize; |
75 | $MAP = new CFClient::Map $mapsize, $mapsize; |
|
|
76 | |
|
|
77 | my ($host, $port) = split /:/, $CFG->{host}; |
73 | |
78 | |
74 | $CONN = new conn |
79 | $CONN = new conn |
75 | host => $CFG->{host}, |
80 | host => $host, |
76 | port => $CFG->{port}, |
81 | port => $port || 13327, |
77 | user => $CFG->{user}, |
82 | user => $CFG->{user}, |
78 | pass => $CFG->{password}, |
83 | pass => $CFG->{password}, |
79 | mapw => $mapsize, |
84 | mapw => $mapsize, |
80 | maph => $mapsize, |
85 | maph => $mapsize, |
81 | ; |
86 | ; |
… | |
… | |
87 | |
92 | |
88 | sub stop_game { |
93 | sub stop_game { |
89 | undef $CONN; |
94 | undef $CONN; |
90 | } |
95 | } |
91 | |
96 | |
92 | sub config_dialog { |
97 | sub client_setup { |
93 | my $dialog = new CFClient::UI::FancyFrame |
98 | my $dialog = new CFClient::UI::FancyFrame |
94 | child => (my $vbox = new CFClient::UI::VBox); |
99 | child => (my $vbox = new CFClient::UI::VBox); |
95 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
100 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
96 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
101 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
97 | |
102 | |
… | |
… | |
137 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
142 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
138 | my ($self, $value) = @_; |
143 | my ($self, $value) = @_; |
139 | $CFG->{fow_smooth} = $value; |
144 | $CFG->{fow_smooth} = $value; |
140 | }); |
145 | }); |
141 | |
146 | |
142 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
147 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
143 | $table->add (1, 5, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
148 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
144 | my ($self, $value) = @_; |
149 | my ($self, $value) = @_; |
145 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
150 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
146 | }); |
151 | }); |
147 | |
152 | |
148 | $table->add (1, 6, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
153 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
149 | destroy_screen (); |
154 | destroy_screen (); |
150 | init_screen (); |
155 | init_screen (); |
151 | }); |
156 | }); |
|
|
157 | |
|
|
158 | $dialog |
|
|
159 | } |
|
|
160 | |
|
|
161 | sub metaserver_dialog { |
|
|
162 | my $dialog = new CFClient::UI::FancyFrame |
|
|
163 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
164 | |
|
|
165 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
|
|
166 | |
|
|
167 | $dialog |
|
|
168 | } |
|
|
169 | |
|
|
170 | sub update_metaserver { |
|
|
171 | status "fetching metaserver list..."; |
|
|
172 | |
|
|
173 | my $buf; |
|
|
174 | |
|
|
175 | my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; |
|
|
176 | |
|
|
177 | Event->io (fd => $fh, poll => 'r', cb => sub { |
|
|
178 | my $res = sysread $fh, $buf, 8192, length $buf; |
|
|
179 | |
|
|
180 | if (!defined $res) { |
|
|
181 | $_[0]->w->cancel; |
|
|
182 | status "metaserver: $!"; |
|
|
183 | } elsif ($res == 0) { |
|
|
184 | $_[0]->w->cancel; |
|
|
185 | status "server list retrieved"; |
|
|
186 | |
|
|
187 | my $table = $METASERVER->{table}; |
|
|
188 | |
|
|
189 | $table->clear; |
|
|
190 | |
|
|
191 | my @col = qw(#Users Host Uptime Version Description); |
|
|
192 | $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) |
|
|
193 | for 0 .. $#col; |
|
|
194 | |
|
|
195 | my @align = qw(1 0 1 1 -1); |
|
|
196 | |
|
|
197 | my $y = 0; |
|
|
198 | for my $m (map [split /\|/], split /\015?\012/, $buf) { |
|
|
199 | my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; |
|
|
200 | |
|
|
201 | for ($desc) { |
|
|
202 | s/<br>/\n/gi; |
|
|
203 | s/<li>/\n· /gi; |
|
|
204 | s/<.*?>//sgi; |
|
|
205 | s/&/&/g; |
|
|
206 | s/</</g; |
|
|
207 | s/>/>/g; |
|
|
208 | } |
|
|
209 | |
|
|
210 | $uptime = sprintf "%dd %02d:%02d:%02d", |
|
|
211 | (int $m->[8] / 86400), |
|
|
212 | (int $m->[8] / 3600) % 24, |
|
|
213 | (int $m->[8] / 60) % 60, |
|
|
214 | $m->[8] % 60; |
|
|
215 | |
|
|
216 | $m = [$users, $host, $uptime, $version, $desc]; |
|
|
217 | |
|
|
218 | $y++; |
|
|
219 | $table->add ($_, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) |
|
|
220 | for 0 .. $#$m; |
|
|
221 | } |
|
|
222 | } |
|
|
223 | }); |
|
|
224 | } |
|
|
225 | |
|
|
226 | sub server_setup { |
|
|
227 | my $dialog = new CFClient::UI::FancyFrame |
|
|
228 | child => (my $vbox = new CFClient::UI::VBox); |
152 | |
229 | |
153 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
230 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
154 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
231 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
155 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); |
232 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); |
|
|
233 | |
|
|
234 | { |
|
|
235 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
|
|
236 | |
156 | $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { |
237 | $vbox->add (new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { |
157 | my ($self, $value) = @_; |
238 | my ($self, $value) = @_; |
158 | $CFG->{host} = $value; |
239 | $CFG->{host} = $value; |
159 | }); |
240 | }); |
160 | |
241 | |
161 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); |
242 | $METASERVER = metaserver_dialog; |
162 | $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}, connect_changed => sub { |
243 | |
163 | my ($self, $value) = @_; |
244 | $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { |
164 | $CFG->{port} = $value; |
245 | update_metaserver; |
165 | }); |
246 | }); |
|
|
247 | } |
166 | |
248 | |
167 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
249 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
168 | $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
250 | $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
169 | my ($self, $value) = @_; |
251 | my ($self, $value) = @_; |
170 | $CFG->{user} = $value; |
252 | $CFG->{user} = $value; |
… | |
… | |
195 | |
277 | |
196 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
278 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
197 | start_game; |
279 | start_game; |
198 | }); |
280 | }); |
199 | |
281 | |
200 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
201 | |
|
|
202 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
|
|
203 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
204 | status "Configuration Saved"; |
|
|
205 | }); |
|
|
206 | |
|
|
207 | $dialog |
282 | $dialog |
208 | } |
283 | } |
209 | |
284 | |
210 | sub console_window { |
285 | sub message_window { |
211 | my $window = new CFClient::UI::FancyFrame |
286 | my $window = new CFClient::UI::FancyFrame |
212 | border_bg => [1, 1, 1, 0.5], |
287 | border_bg => [1, 1, 1, 0.5], |
213 | bg => [0.3, 0.3, 0.3, 0.8], |
288 | bg => [0.3, 0.3, 0.3, 0.8], |
214 | user_w => $::WIDTH/4, |
289 | user_w => $::WIDTH/4, |
215 | user_h => $::HEIGHT, |
290 | user_h => $::HEIGHT, |
… | |
… | |
292 | $FONTSIZE = int $HEIGHT / 40; |
367 | $FONTSIZE = int $HEIGHT / 40; |
293 | |
368 | |
294 | ############################################################################# |
369 | ############################################################################# |
295 | |
370 | |
296 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
371 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
297 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
372 | $CFClient::UI::ROOT->add ($DEBUG_STATUS); |
298 | |
373 | |
299 | $STATUS_LINE = new CFClient::UI::Label |
374 | $STATUS_LINE = new CFClient::UI::Label |
300 | padding => 0, |
375 | padding => 0, |
301 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
376 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
302 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
377 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
303 | |
378 | |
304 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
379 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
305 | padding => 0, |
380 | padding => 0, |
306 | y => $HEIGHT * 44 / 45, |
381 | y => $HEIGHT * 44 / 45, |
307 | height => $HEIGHT / 45, |
382 | height => $HEIGHT / 45, |
308 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
383 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
309 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
384 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
310 | |
385 | |
311 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
386 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
312 | $MAPWIDGET->focus_in; |
387 | $MAPWIDGET->focus_in; |
313 | $MAPWIDGET->connect (activate_console => sub { |
388 | $MAPWIDGET->connect (activate_console => sub { |
314 | my ($mapwidget, $preset) = @_; |
389 | my ($mapwidget, $preset) = @_; |
315 | |
390 | |
316 | if ($CONSOLE) { |
391 | if ($CONSOLE) { |
… | |
… | |
320 | $CONSOLE->{input}->set_text ($preset); |
395 | $CONSOLE->{input}->set_text ($preset); |
321 | } |
396 | } |
322 | } |
397 | } |
323 | }); |
398 | }); |
324 | |
399 | |
325 | $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox); |
400 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
326 | |
401 | |
327 | $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1); |
402 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
328 | $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Console", other => console_window); |
403 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
|
|
404 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
|
|
405 | |
|
|
406 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
|
|
407 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
408 | status "Configuration Saved"; |
|
|
409 | }); |
|
|
410 | |
|
|
411 | $BUTTONBAR->{children}[0]->emit ("activate"); |
329 | } |
412 | } |
330 | |
413 | |
331 | sub destroy_screen { |
414 | sub destroy_screen { |
332 | $CFClient::UI::TOPLEVEL->{children} = []; |
415 | $CFClient::UI::ROOT->{children} = []; |
333 | undef $SDL_ACTIVE; |
416 | undef $SDL_ACTIVE; |
334 | undef $SDL_EV; |
417 | undef $SDL_EV; |
335 | SDL::Quit; |
418 | SDL::Quit; |
336 | } |
419 | } |
337 | |
420 | |
… | |
… | |
348 | debug sprintf "%3.2f", $fps; |
431 | debug sprintf "%3.2f", $fps; |
349 | |
432 | |
350 | $want_refresh = 0; |
433 | $want_refresh = 0; |
351 | $can_refresh = 0; |
434 | $can_refresh = 0; |
352 | |
435 | |
353 | $CFClient::UI::TOPLEVEL->draw; |
436 | $CFClient::UI::ROOT->draw; |
354 | |
437 | |
355 | SDL::GLSwapBuffers; |
438 | SDL::GLSwapBuffers; |
356 | |
439 | |
357 | $LAST_REFRESH = $NOW; |
440 | $LAST_REFRESH = $NOW; |
358 | } |
441 | } |
… | |
… | |
520 | fow_intensity => 0.45, |
603 | fow_intensity => 0.45, |
521 | fow_smooth => 0, |
604 | fow_smooth => 0, |
522 | log_fontsize => 14, |
605 | log_fontsize => 14, |
523 | mapsize => 100, |
606 | mapsize => 100, |
524 | host => "crossfire.schmorp.de", |
607 | host => "crossfire.schmorp.de", |
525 | port => 13327, |
|
|
526 | say_command => 'say', |
608 | say_command => 'say', |
527 | ); |
609 | ); |
528 | |
610 | |
529 | while (my ($k, $v) = each %DEF_CFG) { |
611 | while (my ($k, $v) = each %DEF_CFG) { |
530 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
612 | $CFG->{$k} = $v unless exists $CFG->{$k}; |