ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.85 by root, Wed Apr 12 17:11:02 2006 UTC vs.
Revision 1.154 by elmex, Thu Apr 20 16:29:40 2006 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3use strict; 3use strict;
4use utf8; 4use utf8;
5 5
6use Glib; 6use Time::HiRes 'time';
7use Gtk2 -init;
8
9use SDL;
10use SDL::App;
11use SDL::Event; 7use Event;
12use SDL::Surface;
13use SDL::OpenGL;
14use SDL::OpenGL::Constants;
15 8
16use Crossfire; 9use Crossfire;
17use Crossfire::Protocol; 10use Crossfire::Protocol;
18 11
12use Compress::LZF;
13
19use CFClient; 14use CFClient;
20use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
21 17
22our $VERSION = '0.1'; 18our $VERSION = '0.1';
23 19
24my $MAX_FPS = 60; 20my $MAX_FPS = 60;
25my $MIN_FPS = 5; # unused 21my $MIN_FPS = 5; # unused as of yet
26my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame
27 22
23our $META_SERVER = "crossfire.real-time.com:13326";
24
25our $FACEMAP;
26our $TILECACHE;
28our $FACECACHE; 27our $MAPCACHE;
28
29our $LAST_REFRESH;
30our $NOW;
29 31
30our $CFG; 32our $CFG;
31our $CONN; 33our $CONN;
32our $FAST; # fast, low-quality mode, possibly useful for software-rendering 34our $FAST; # fast, low-quality mode, possibly useful for software-rendering
33 35
34our @SDL_MODES; 36our @SDL_MODES;
35our $WIDTH; 37our $WIDTH;
36our $HEIGHT; 38our $HEIGHT;
37our $FULLSCREEN; 39our $FULLSCREEN;
40our $FONTSIZE;
38 41
39our $NOW; 42our $MAP;
40
41our $MAPWIDGET; 43our $MAPWIDGET;
42our $FONTSIZE; 44our $BUTTONBAR;
45our $LOGVIEW;
46our $CONSOLE;
47our $METASERVER;
43 48
49our $GAUGES;
50our $STATWIDS;
51
44our $SDL_TIMER; 52our $SDL_ACTIVE;
45our $SDL_APP;
46our $SDL_EV;
47our %SDL_CB; 53our %SDL_CB;
54
55our $SDL_MIXER;
56our @SOUNDS; # event => file mapping
57our %AUDIO_CHUNKS; # audio files
48 58
49our $ALT_ENTER_MESSAGE; 59our $ALT_ENTER_MESSAGE;
50our $STATUS_LINE; 60our $STATUS_LINE;
51our $DEBUG_STATUS; 61our $DEBUG_STATUS;
52 62
53my $last_refresh;
54my %ANIMATE;
55my $refresh_handler;
56
57sub status { 63sub status {
58 $STATUS_LINE->set_text ($_[0]); 64 $STATUS_LINE->set_text ($_[0]);
59 my ($w, $h) = $STATUS_LINE->size_request;
60 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 65 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
61} 66}
62 67
63sub debug { 68sub debug {
64 $DEBUG_STATUS->set_text ($_[0]); 69 $DEBUG_STATUS->set_text ($_[0]);
65 my ($w, $h) = $DEBUG_STATUS->size_request; 70 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
66 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
67} 71}
68 72
69sub start_game { 73sub start_game {
70 status "logging in..."; 74 status "logging in...";
71 75
72 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 76 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
73 77
78 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
79
80 $MAP = new CFClient::Map $mapsize, $mapsize;
81
82 my ($host, $port) = split /:/, $CFG->{host};
83
74 $CONN = new conn 84 $CONN = new conn
75 host => $CFG->{host}, 85 host => $host,
76 port => $CFG->{port}, 86 port => $port || 13327,
77 user => $CFG->{user}, 87 user => $CFG->{user},
78 pass => $CFG->{password}, 88 pass => $CFG->{password},
79 mapw => $mapsize, 89 mapw => $mapsize,
80 maph => $mapsize, 90 maph => $mapsize,
81 ; 91 ;
87 97
88sub stop_game { 98sub stop_game {
89 undef $CONN; 99 undef $CONN;
90} 100}
91 101
92sub config_dialog { 102sub client_setup {
93 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, 103 my $dialog = new CFClient::UI::FancyFrame
104 title => "Client Setup",
94 child => (my $vbox = new CFClient::UI::VBox); 105 child => (my $vbox = new CFClient::UI::VBox);
95 $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]); 106 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
97 107
98 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 108 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
99 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 109 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
100 110
101 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 111 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
102 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 112 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
103 113
104 $mode_slider->connect (changed => sub { 114 $mode_slider->connect (changed => sub {
105 my ($self, $value) = @_; 115 my ($self, $value) = @_;
106 116
107 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 117 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
108 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 118 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
109 }); 119 });
110 $mode_slider->emit (changed => $mode_slider->{range}[0]); 120 $mode_slider->emit (changed => $mode_slider->{range}[0]);
111 121
112 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 122 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
113 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 123 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
114 my ($self, $value) = @_; 124 my ($self, $value) = @_;
115 $CFG->{fullscreen} = $value; 125 $CFG->{fullscreen} = $value;
116 }); 126 });
117 127
128 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
129 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
130 my ($self, $value) = @_;
131 $CFG->{fast} = $value;
132 });
133
134 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
135 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
136 my ($self, $value) = @_;
137 $CFG->{fow_enable} = $value;
138 });
139
140 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
141 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
142 my ($self, $value) = @_;
143 $CFG->{fow_intensity} = $value;
144 });
145
146 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
147 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
148 my ($self, $value) = @_;
149 $CFG->{fow_smooth} = $value;
150 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 });
152
153 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
154 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
155 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
156# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
157 });
158
159 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
160 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
161 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
162 });
163
118 $table->add (1, 2, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 164 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
119 destroy_screen (); 165 video_shutdown ();
120 init_screen (); 166 video_init ();
167 });
168
169 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
170 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
171 $CFG->{audio_enable} = $_[1];
172 });
173# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
174# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
175# $CFG->{effects_volume} = $_[1];
121 }); 176# });
177 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
178 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
179 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
180 $CFG->{bgm_enable} = $_[1];
181 });
182 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
183 $CFG->{bgm_volume} = $_[1];
184 CFClient::MixMusic::volume $_[1] * 128;
185 });
186
187 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
188 audio_shutdown ();
189 audio_init ();
190 });
191
192 $dialog
193}
194
195sub make_stats_window {
196 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/3, y => 0, title => "Stats");
197 $tgw->add (my $vb = new CFClient::UI::VBox ());
198 $vb->add ($STATWIDS->{stat} = new CFClient::UI::Label valign => 0, align => -1);
199 $vb->add (my $hb2 = new CFClient::UI::HBox);
200 $hb2->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
201 $hb2->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
202 $hb2->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
203 $hb2->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
204 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
205 $tgw
206}
207
208sub update_stats_window {
209 my ($stats) = @_;
210
211 $STATWIDS->{stat}->set_text (
212 "Title: $stats->{21}\nExp.: " . ($stats->{11} || $stats->{28})
213 . " Level: $stats->{12}\n"
214 . (sprintf "S%d D%d Co%d I%d W%d P%d Ch%2d, Wc%d Ac%d\n",
215 @$stats{5,8,9,6,7,22,10, 13, 14})
216 . (sprintf "Dam %d Arm %d Speed %.2f/%.2f",
217 @$stats{15,16,17,19})
218 );
219}
220
221sub metaserver_dialog {
222 my $dialog = new CFClient::UI::FancyFrame
223 title => "Metaserver",
224 child => (my $vbox = new CFClient::UI::VBox);
225
226 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
227
228 $dialog
229}
230
231sub update_metaserver {
232 my ($HOST) = @_;
233
234 status "fetching metaserver list...";
235
236 my $buf;
237
238 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
239
240 Event->io (fd => $fh, poll => 'r', cb => sub {
241 my $res = sysread $fh, $buf, 8192, length $buf;
242
243 if (!defined $res) {
244 $_[0]->w->cancel;
245 status "metaserver: $!";
246 } elsif ($res == 0) {
247 $_[0]->w->cancel;
248 status "server list retrieved";
249
250 my $table = $METASERVER->{table};
251
252 $table->clear;
253
254 my @col = qw(Use #Users Host Uptime Version Description);
255 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_])
256 for 0 .. $#col;
257
258 my @align = qw(1 0 1 1 -1);
259
260 my $y = 0;
261 for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) {
262 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m;
263
264 for ($desc) {
265 s/<br>/\n/gi;
266 s/<li>/\n· /gi;
267 s/<.*?>//sgi;
268 s/&/&amp;/g;
269 s/</&lt;/g;
270 s/>/&gt;/g;
271 }
272
273 $uptime = sprintf "%dd %02d:%02d:%02d",
274 (int $m->[8] / 86400),
275 (int $m->[8] / 3600) % 24,
276 (int $m->[8] / 60) % 60,
277 $m->[8] % 60;
278
279 $m = [$users, $host, $uptime, $version, $desc];
280
281 $y++;
282
283 $table->add (0, $y, new CFClient::UI::VBox children => [
284 (new CFClient::UI::Button text => " ", connect_activate => sub {
285 $HOST->set_text ($CFG->{host} = $host);
286 }),
287 (new CFClient::UI::Empty expand => 1),
288 ]);
289
290 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
291 for 0 .. $#$m;
292 }
293 }
294 });
295}
296
297sub server_setup {
298 my $dialog = new CFClient::UI::FancyFrame
299 title => "Server Setup",
300 child => (my $vbox = new CFClient::UI::VBox);
122 301
123 $vbox->add (new CFClient::UI::Label align => 0, text => "Server");
124 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 302 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
125 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); 303 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
126 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}); 304
127 305 {
128 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); 306 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
129 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port});
130 307
308 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
309 my ($self, $value) = @_;
310 $CFG->{host} = $value;
311 });
312
313 $METASERVER = metaserver_dialog;
314
315 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
316 update_metaserver $HOST;
317 });
318 }
319
131 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 320 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
132 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}); 321 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
322 my ($self, $value) = @_;
323 $CFG->{user} = $value;
324 });
133 325
134 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 326 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
135 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); 327 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
328 my ($self, $value) = @_;
329 $CFG->{password} = $value;
330 });
136 331
332 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
333 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
334 my ($self, $value) = @_;
335 $CFG->{say_command} = $value;
336 });
337
137 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size"); 338 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
138 $table->add (1, 6, new CFClient::UI::Slider 339 $table->add (1, 7, new CFClient::UI::Slider
139 req_w => 100, 340 req_w => 100,
140 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 341 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
141 connect_changed => sub { 342 connect_changed => sub {
142 my ($self, $value) = @_; 343 my ($self, $value) = @_;
143 344
144 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 345 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
145 }, 346 },
146 ); 347 );
147 348
148 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 349 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
149 start_game; 350 start_game;
150 }); 351 });
151 352
152 $vbox->add (my $hbox = new CFClient::UI::HBox); 353 $dialog
354}
153 355
154 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { 356sub message_window {
155 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 357 my $window = new CFClient::UI::FancyFrame
156 status "Configuration Saved"; 358 title => "Messages",
359 border_bg => [1, 1, 1, 0.5],
360 bg => [0.3, 0.3, 0.3, 0.8],
361 user_w => int $::WIDTH / 3,
362 user_h => int $::HEIGHT / 5,
363 child => (my $vbox = new CFClient::UI::VBox);
364
365 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
366 expand => 1,
367 fontsize => $::CFG->{log_fontsize},
157 }); 368 );
158 $CFClient::UI::TOPLEVEL->add ($dialog);
159}
160 369
161sub init_screen { 370 $vbox->add (my $input = new CFClient::UI::Entry
371 connect_focus_in => sub {
372 my ($input, $prev_focus) = @_;
373
374 delete $input->{refocus_map};
375
376 if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
377 $input->{refocus_map} = 1;
378 }
379 delete $input->{auto_activated};
380 },
381 connect_activate => sub {
382 my ($input, $text) = @_;
383 $input->set_text ('');
384
385 if ($text =~ /^\/(.*)/) {
386 $::CONN->user_send ($1);
387 } else {
388 my $say_cmd = $::CFG->{say_command} || 'say';
389 $::CONN->user_send ("$say_cmd $text");
390 }
391 if ($input->{refocus_map}) {
392 delete $input->{refocus_map};
393 $MAPWIDGET->focus_in
394 }
395 },
396 connect_escape => sub {
397 $MAPWIDGET->focus_in
398 },
399 );
400
401 $CONSOLE = {
402 window => $window,
403 input => $input
404 };
405
406 $window
407}
408
409sub sdl_init {
410 CFClient::SDL_Init
411 and die "SDL::Init failed!\n";
412}
413
414sub video_init {
415 sdl_init;
416
162 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 417 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
163 $FULLSCREEN = $CFG->{fullscreen}; 418 $FULLSCREEN = $CFG->{fullscreen};
419 $FAST = $CFG->{fast};
164 420
165 $SDL_APP = new SDL::App 421 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
166 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 422 or die "SDL_SetVideoMode failed!\n";
167 -title => "Crossfire+ Client",
168 -width => $WIDTH,
169 -height => $HEIGHT,
170 -opengl => 1,
171 -red_size => 5,
172 -green_size => 5,
173 -blue_size => 5,
174 -alpha_size => 0,
175 -double_buffer => 1,
176 -fullscreen => $FULLSCREEN,
177 -resizeable => 0;
178 423
179 $SDL_EV = new SDL::Event; 424 $SDL_ACTIVE = 1;
180 $SDL_EV->set_unicode (1);
181 425
182 $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { 426 $LAST_REFRESH = time - 0.01;
183 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
184 while $SDL_EV->poll;
185
186 1
187 };
188
189 $last_refresh = SDL::GetTicks;
190 427
191 CFClient::gl_init; 428 CFClient::gl_init;
192 429
193 $FONTSIZE = int $HEIGHT / 40; 430 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
194 431
195 ############################################################################# 432 #############################################################################
196 433
197 $DEBUG_STATUS = new CFClient::UI::Label padding => 0; 434 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
198 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 435 $DEBUG_STATUS->show;
199 436
200 $STATUS_LINE = new CFClient::UI::Label 437 $STATUS_LINE = new CFClient::UI::Label
201 padding => 0, 438 padding => 0,
202 y => $HEIGHT * 49 / 50 - $FONTSIZE; 439 y => $HEIGHT - $FONTSIZE * 1.8;
203 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); 440 $STATUS_LINE->show;
204 441
205 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 442 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
206 padding => 0, 443 padding => 0,
207 y => $HEIGHT * 49 / 50, 444 fontsize => 0.8,
208 height => $HEIGHT / 50,
209 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 445 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
210 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 446 $ALT_ENTER_MESSAGE->show;
447 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
211 448
212 $MAPWIDGET = new CFClient::UI::MapWidget; 449 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
213 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
214 $MAPWIDGET->focus_in; 450 $MAPWIDGET->focus_in;
451 $MAPWIDGET->connect (activate_console => sub {
452 my ($mapwidget, $preset) = @_;
215 453
216 config_dialog;
217}
218
219sub destroy_screen {
220 $CFClient::UI::TOPLEVEL->{children} = [];
221 remove Glib::Source $SDL_TIMER;
222 remove Glib::Source $refresh_handler if $refresh_handler;
223 undef $refresh_handler;
224 undef $SDL_APP;
225 undef $SDL_EV;
226 SDL::Quit;
227}
228
229sub force_refresh {
230 glViewport 0, 0, $WIDTH, $HEIGHT;
231
232 glMatrixMode GL_PROJECTION;
233 glLoadIdentity;
234 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
235 glMatrixMode GL_MODELVIEW;
236 glLoadIdentity;
237
238 glClear GL_COLOR_BUFFER_BIT;
239
240 $CFClient::UI::TOPLEVEL->draw;
241
242 SDL::GLSwapBuffers;
243}
244
245my $FPS;
246
247sub refresh {
248 $refresh_handler ||= add Glib::Idle sub {
249 if ($SDL_APP) { 454 if ($CONSOLE) {
250 $NOW = SDL::GetTicks; 455 $CONSOLE->{input}->{auto_activated} = 1;
456 $CONSOLE->{input}->focus_in;
251 457
252 if ($NOW - $last_refresh < $TICKS_PER_FRAME) { 458 if ($preset && $CONSOLE->{input}->get_text eq '') {
253 SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); 459 $CONSOLE->{input}->set_text ($preset);
254 $NOW = SDL::GetTicks;
255 } 460 }
256
257 my $interval = ($NOW - $last_refresh) * 0.001;
258 $last_refresh = $NOW;
259
260 if ($interval) {
261 $FPS ||= 1 / $interval;
262 $FPS = $FPS * 0.9 + (1 / $interval) * 0.1;
263 debug sprintf "%5.02f", $FPS;
264 } 461 }
462 });
265 463
266 force_refresh; 464 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
267 $_->animate ($interval) for grep $_, values %ANIMATE;
268 465
269 if (%ANIMATE) { 466 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
467 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
468 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
469
470 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
471 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
472 status "Configuration Saved";
473 });
474
475 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
476
477
478 $CFClient::UI::ROOT->add (make_stats_window);
479}
480
481sub video_shutdown {
482 $CFClient::UI::ROOT->{children} = [];
483 undef $SDL_ACTIVE;
484}
485
486my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
487my $bgmusic;#TODO#hack#d#
488
489sub audio_music_finished {
490 return unless $CFG->{bgm_enable};
491
492 # TODO: hack, do play loop and mood music
493 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
494 $bgmusic->play (0);
495
496 push @bgmusic, shift @bgmusic;
497}
498
499sub audio_init {
500 if ($CFG->{audio_enable}) {
501 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
502 $SDL_MIXER = !CFClient::Mix_OpenAudio;
503 CFClient::Mix_AllocateChannels 8;
504 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
505
506 audio_music_finished;
507
508 while (<$fh>) {
509 next if /^\s*#/;
510 next if /^\s*$/;
511
512 my ($file, $volume, $event) = split /\s+/, $_, 3;
513
514 push @SOUNDS, "$volume,$file";
515
516 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
517 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
518 $chunk->volume ($volume * 128 / 100);
519 $chunk
270 1 520 };
271 } else {
272 undef $refresh_handler;
273 0
274 } 521 }
275 } else { 522 } else {
276 undef $refresh_handler; 523 status "unable to open sound config: $!";
277 0
278 } 524 }
279 }; 525 }
526}
527
528sub audio_shutdown {
529 CFClient::Mix_CloseAudio if $SDL_MIXER;
530 undef $SDL_MIXER;
531 @SOUNDS = ();
532 %AUDIO_CHUNKS = ();
533}
534
535my %animate_object;
536my $animate_timer;
537
538my $want_refresh;
539my $can_refresh;
540
541my $fps = 9;
542
543sub force_refresh {
544 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
545 debug sprintf "%3.2f", $fps;
546
547 $want_refresh = 0;
548 $can_refresh = 0;
549
550 $CFClient::UI::ROOT->draw;
551
552 CFClient::SDL_GL_SwapBuffers;
553
554 $LAST_REFRESH = $NOW;
555}
556
557my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
558 $NOW = time;
559
560 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
561 for CFClient::SDL_PollEvent;
562
563 if (%animate_object) {
564 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
565 $want_refresh++;
566 }
567
568 if ($want_refresh) {
569 force_refresh;
570 } else {
571 $can_refresh = 1;
572 }
573});
574
575sub refresh {
576 $want_refresh++;
280} 577}
281 578
282sub animation_start { 579sub animation_start {
283 my ($widget) = @_; 580 my ($widget) = @_;
284 $ANIMATE{$widget} = $widget; 581 $animate_object{$widget} = $widget;
285 Scalar::Util::weaken $ANIMATE{$widget};
286
287 refresh;
288} 582}
289 583
290sub animation_stop { 584sub animation_stop {
291 my ($widget) = @_; 585 my ($widget) = @_;
292 delete $ANIMATE{$widget}; 586 delete $animate_object{$widget};
587}
588
589@conn::ISA = Crossfire::Protocol::;
590
591sub conn::stats_update {
592 my ($self, $stats) = @_;
593
594 # i love text protocols!!!
595 # FIXME: the stats are somehow weird
596 my $hp = $stats->{1};
597 my $hp_m = $stats->{2};
598 my $sp = $stats->{3};
599 my $sp_m = $stats->{4};
600 my $fo = $stats->{18};
601 my $fo_m = 999;
602 my $gr = $stats->{23};
603 my $gr_m = $stats->{24};
604
605 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
606 $GAUGES->{hp} ->set_value ($hp, $hp_m);
607 $GAUGES->{mana} ->set_value ($sp, $sp_m);
608 $GAUGES->{food} ->set_value ($fo, $fo_m);
609 $GAUGES->{grace}->set_value ($gr, $gr_m);
610
611 update_stats_window ($stats);
612}
613
614sub conn::user_send {
615 my ($self, $command) = @_;
616
617 $self->send_command ($command);
618 status $command;
619}
620
621sub conn::map_scroll {
622 my ($self, $dx, $dy) = @_;
623
624 $MAP->scroll ($dx, $dy);
625}
626
627sub conn::feed_map1a {
628 my ($self, $data) = @_;
629
630# $self->Crossfire::Protocol::feed_map1a ($data);
631
632 $MAP->map1a_update ($data);
633 $MAPWIDGET->update;
634}
635
636sub conn::flush_map {
637 my ($self) = @_;
638
639 my $map_info = delete $self->{map_info}
640 or return;
641
642 my ($hash, $x, $y, $w, $h) = @$map_info;
643
644 my $data = $MAP->get_rect ($x, $y, $w, $h);
645 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
646 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
647}
648
649sub conn::map_clear {
650 my ($self) = @_;
651
652 $self->flush_map;
653 delete $self->{neigh_map};
654
655 $MAP->clear;
656}
657
658
659sub conn::load_map($$$) {
660 my ($self, $hash, $x, $y) = @_;
661
662 if (defined (my $data = $MAPCACHE->get ($hash))) {
663 $data = Compress::LZF::decompress $data;
664 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
665 for my $id ($MAP->set_rect ($x, $y, $data)) {
666 my $data = $TILECACHE->get ($id)
667 or next;
668
669 $self->set_texture ($id => $data);
670 }
671 }
672}
673
674# this method does a "flood fill" into every tile direction
675# it assumes that tiles are arranged in a rectangular grid,
676# i.e. a map is the same as the left of the right map etc.
677# failure to comply are harmless and result in display errors
678# at worst.
679sub conn::flood_fill {
680 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
681
682 # the server does not allow map paths > 6
683 return if 6 <= length $path;
684
685 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
686
687 for (
688 [1, 0, -1],
689 [2, 1, 0],
690 [3, 0, 1],
691 [4, -1, 0],
692 ) {
693 my ($tile, $dx, $dy) = @$_;
694
695 my $gx = $gx + $dx;
696 my $gy = $gy + $dy;
697
698 next unless $flags & (1 << ($tile - 1));
699 next if $self->{neigh_grid}{$gx, $gy}++;
700
701 my $neigh = $self->{neigh_map}{$hash} ||= [];
702 if (my $info = $neigh->[$tile]) {
703 my ($flags, $x, $y, $w, $h, $hash) = @$info;
704
705 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
706 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
707
708 } else {
709 $self->send_mapinfo ("spatial $path$tile", sub {
710 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
711
712 return if $mode ne "spatial";
713
714 $x += $MAP->ox;
715 $y += $MAP->oy;
716
717 $self->load_map ($hash, $x, $y)
718 unless $self->{neigh_map}{$hash}[5]++;#d#
719
720 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
721
722 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
723 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
724 });
725 }
726 }
727}
728
729sub conn::map_change {
730 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
731
732 $self->flush_map;
733
734 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
735
736 my $mapmapw = 250;
737 my $mapmaph = 250;
738
739 $self->{neigh_rect} = [
740 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
741 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
742 ];
743
744 delete $self->{neigh_grid};
745 $self->flood_fill (0, 0, "", $hash, $flags);
746
747 $x += $ox;
748 $y += $oy;
749
750 $self->{map_info} = [$hash, $x, $y, $w, $h];
751
752 $self->load_map ($hash, $x, $y);
753}
754
755sub conn::face_find {
756 my ($self, $facenum, $face) = @_;
757
758 my $hash = "$face->{chksum},$face->{name}";
759
760 my $id = $FACEMAP->get ($hash);
761
762 unless ($id) {
763 # create new id for face
764 # i love transactions
765 for (1..100) {
766 my $txn = $CFClient::DB_ENV->txn_begin;
767 my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW);
768 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
769 $id++;
770 if ($FACEMAP->put (id => $id) == 0
771 && $FACEMAP->put ($hash => $id) == 0) {
772 $txn->txn_commit;
773
774 goto gotid;
775 }
776 }
777 $txn->abort;
778 }
779
780 CFClient::fatal "maximum number of transaction retries reached - database problems?";
781 }
782
783gotid:
784 $face->{id} = $id;
785 $MAP->set_face ($facenum => $id);
786 $TILECACHE->get ($id)
787}
788
789sub conn::face_update {
790 my ($self, $facenum, $face) = @_;
791
792 $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes
793
794 $self->set_texture ($face->{id} => delete $face->{image});
795}
796
797sub conn::set_texture {
798 my ($self, $id, $data) = @_;
799
800 $self->{texture}[$id] ||= do {
801 my $tex =
802 new_from_image CFClient::Texture
803 $data, minify => 1;
804
805 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
806 $MAPWIDGET->update;
807
808 $tex
809 };
810}
811
812sub conn::sound_play {
813 my ($self, $x, $y, $soundnum, $type) = @_;
814
815 $SDL_MIXER
816 or return;
817
818 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
819 or return;
820
821 $chunk->play;
822# warn "sound $x,$y,$soundnum,$type\n";#d#
823}
824
825sub conn::query {
826 my ($self, $flags, $prompt) = @_;
827
828 #TODO, display dialog with relevant information
829 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
830}
831
832sub conn::drawinfo {
833 my ($self, $color, $text) = @_;
834
835 my @color = (
836 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
837 [1.00, 1.00, 1.00],
838 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
839 [1.00, 0.00, 0.00],
840 [1.00, 0.54, 0.00],
841 [0.11, 0.56, 1.00],
842 [0.93, 0.46, 0.00],
843 [0.18, 0.54, 0.34],
844 [0.56, 0.73, 0.56],
845 [0.80, 0.80, 0.80],
846 [0.55, 0.41, 0.13],
847 [0.99, 0.77, 0.26],
848 [0.74, 0.65, 0.41],
849 );
850
851 $LOGVIEW->add_paragraph ($color[$color], $text);
852}
853
854sub conn::spell_add {
855 my ($self, $spell) = @_;
856
857 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
858 });
859 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
860 });
861}
862
863sub conn::spell_delete {
864 my ($self, $spell) = @_;
865}
866
867sub conn::addme_success {
868 my ($self) = @_;
869
870 for my $skill (values %{$self->{skill_info}}) {
871 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
872 });
873 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
874 });
875 }
293} 876}
294 877
295%SDL_CB = ( 878%SDL_CB = (
296 SDL_QUIT() => sub { 879 CFClient::SDL_QUIT => sub {
297 main_quit Gtk2; 880 Event::unloop -1;
298 }, 881 },
299 SDL_VIDEORESIZE() => sub { 882 CFClient::SDL_VIDEORESIZE => sub {
300 }, 883 },
301 SDL_VIDEOEXPOSE() => sub { 884 CFClient::SDL_VIDEOEXPOSE => \&refresh,
302 refresh; 885 CFClient::SDL_ACTIVEEVENT => sub {
886# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
303 }, 887 },
304 SDL_KEYDOWN() => sub { 888 CFClient::SDL_KEYDOWN => sub {
305 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 889 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
306 # alt-enter 890 # alt-enter
307 $FULLSCREEN = !$FULLSCREEN; 891 video_shutdown;
308 destroy_screen; 892 $CFG->{fullscreen} = !$CFG->{fullscreen};
309 init_screen; 893 video_init;
310 } else { 894 } else {
311 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 895 CFClient::UI::feed_sdl_key_down_event ($_[0]);
312 } 896 }
313 }, 897 },
314 SDL_KEYUP() => sub { 898 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
315 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 899 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
316 }, 900 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
317 SDL_MOUSEMOTION() => sub { 901 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
318 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 902 CFClient::SDL_USEREVENT => \&audio_music_finished,
319 },
320 SDL_MOUSEBUTTONDOWN() => sub {
321 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
322 },
323 SDL_MOUSEBUTTONUP() => sub {
324 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
325 },
326 SDL_ACTIVEEVENT() => sub {
327# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
328 },
329); 903);
330 904
331@conn::ISA = Crossfire::Protocol::;
332
333sub conn::map_update {
334 my ($self, $dirty) = @_;
335
336 $MAPWIDGET->update;
337}
338
339sub conn::map_scroll {
340 my ($self, $dx, $dy) = @_;
341
342# refresh;
343}
344
345sub conn::map_clear {
346 my ($self) = @_;
347
348# refresh;
349}
350
351sub conn::face_find {
352 my ($self, $face) = @_;
353
354 $FACECACHE->{"$face->{chksum},$face->{name}"}
355}
356
357sub conn::face_update {
358 my ($self, $face) = @_;
359
360 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
361
362 $face->{texture} = new_from_image CFClient::Texture delete $face->{image};
363}
364
365sub conn::query {
366 my ($self, $flags, $prompt) = @_;
367
368 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
369}
370
371sub gtk_add_cfg_field {
372 my ($tbl, $cfg, $klbl, $key, $value) = @_;
373 my $i = $cfg->{_i}++;
374 $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1);
375 $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1);
376 if ($key eq 'password') {
377 $ent->set_invisible_char ("*");
378 $ent->set (visibility => 0)
379 }
380 $ent->set_text ($value);
381 $ent->signal_connect (changed => sub {
382 my ($ent) = @_;
383 $cfg->{$key} = $ent->get_text;
384 # TODO: Mapsize should be a slider in the game gui
385 if ($key eq 'mapsize' and $cfg->{$key} > 100) {
386 $cfg->{$key} = 100;
387 } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
388 $cfg->{$key} = 50;
389 }
390 });
391}
392
393sub run_config_dialog {
394 my (%events) = @_;
395
396 my $w = Gtk2::Window->new;
397
398 my @cfg = (
399 [qw/Host host/],
400 [qw/Port port/],
401 [qw/Mapsize% mapsize/],
402 [qw/Username user/],
403 [qw/Password password/],
404 );
405
406 my $cfg = {};
407
408 $w->add (my $vb = Gtk2::VBox->new);
409 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0);
410 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height};
411 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1);
412 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1);
413 my $i = 0;
414 my $act = 0;
415 for (map { "$_->[0]x$_->[1]" } @SDL_MODES) {
416 if ($_ eq $selmode) { $act = $i }
417 $cb->append_text ($_);
418 $i++;
419 }
420 $cb->set_active ($act);
421 $cb->signal_connect (changed => sub {
422 my ($cb) = @_;
423 my $txt = $cb->get_active_text;
424 if ($txt =~ m/(\d+)x(\d+)/) {
425 $::CFG->{width} = $1;
426 $::CFG->{height} = $2;
427 }
428 });
429
430 $cfg->{_i} = 1;
431 for (@cfg) {
432 gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]});
433 }
434
435 $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
436 $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5);
437 $cb->signal_connect (clicked => sub {
438 for (keys %$cfg) {
439 $::CFG->{$_} = $cfg->{$_}
440 if $_ ne '_i';
441 }
442 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc";
443 });
444 $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5);
445 $cb->signal_connect (clicked => sub {
446 for (keys %$cfg) {
447 $::CFG->{$_} = $cfg->{$_}
448 if $_ ne '_i';
449 }
450 my $cb = $events{login} || sub {};
451 $cb->($::CFG->{user}, $::CFG->{password});
452 });
453 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
454 $cb->signal_connect (clicked => sub {
455 my $cb = $events{logout} || sub {};
456 $cb->();
457 });
458 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
459 $cb->signal_connect (clicked => sub { $w->destroy });
460
461 $w->show_all;
462
463 $w->signal_connect (destroy => sub { Gtk2->main_quit });
464}
465
466
467############################################################################# 905#############################################################################
468 906
469SDL::Init SDL_INIT_EVERYTHING; 907$SIG{INT} = $SIG{TERM} = sub { exit };
470 908
471@SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], 909$TILECACHE = CFClient::db_table "tilecache";
472 @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; 910$FACEMAP = CFClient::db_table "facemap";
473 911
474CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 912CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
475 913
476$CFG ||= { 914my %DEF_CFG = (
915 sdl_mode => 0,
477 width => 640, 916 width => 640,
478 height => 480, 917 height => 480,
479 fullscreen => 0, 918 fullscreen => 0,
480 sdl_mode => 0, 919 fast => 0,
920 fow_enable => 1,
921 fow_intensity => 0.45,
922 fow_smooth => 0,
923 gui_fontsize => 1,
924 log_fontsize => 14,
481 mapsize => 100, 925 mapsize => 100,
482 host => "crossfire.schmorp.de", 926 host => "crossfire.schmorp.de",
483 port => 13327, 927 say_command => 'say',
484}; 928 audio_enable => 1,
929 bgm_enable => 1,
930 bgm_volume => 0.25,
931);
932
933while (my ($k, $v) = each %DEF_CFG) {
934 $CFG->{$k} = $v unless exists $CFG->{$k};
935}
936
937sdl_init;
938
939@SDL_MODES = reverse
940 grep $_->[0] >= 640 && $_->[1] >= 480,
941 CFClient::SDL_ListModes;
942
943@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
944
945$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
485 946
486{ 947{
487 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 948 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
488 949
489 CFClient::add_font $_ for @fonts; 950 CFClient::add_font $_ for @fonts;
490 CFClient::set_font $fonts[0]; 951 CFClient::set_font $fonts[0];
491} 952}
492 953
493$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 954video_init;
955audio_init;
494 956
495init_screen; 957Event::loop;
496 958
497main Gtk2; 959END { CFClient::SDL_Quit }
498 960
499Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";
500 961

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines