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.135 by root, Tue Apr 18 06:26:55 2006 UTC vs.
Revision 1.177 by root, Mon Apr 24 11:45:17 2006 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3use strict; 3use strict;
4use utf8; 4use utf8;
5 5
6BEGIN {
7 if (%PAR::LibCache) {
8 @INC = grep ref, @INC; # weed out all paths except pars loader refs
9
10 while (my ($filename, $zip) = each %PAR::LibCache) {
11 for ($zip->memberNames) {
12 next unless /^\/root\/(.*)/;
13 $zip->extractMember ($_, "$ENV{PAR_TEMP}/$1")
14 unless -e "$ENV{PAR_TEMP}/$1";
15 }
16 }
17
18 unshift @INC, $ENV{PAR_TEMP};
19
20 if ($^O eq "MSWin32") {
21 $ENV{GTK_RC_FILES} = "$ENV{PAR_TEMP}/share/themes/MS-Windows/gtk-2.0/gtkrc";
22 }
23 }
24}
25
26# need to do it again because that pile of garbage called PAR nukes it before main
27unshift @INC, $ENV{PAR_TEMP};
28
6use Time::HiRes 'time'; 29use Time::HiRes 'time';
7use Event; 30use Event;
8 31
9use SDL;
10use SDL::App;
11use SDL::Event;
12use SDL::Surface;
13
14use SDL::Mixer;
15use SDL::Sound;
16use SDL::Music;
17
18use SDL::OpenGL;
19
20use Crossfire; 32use Crossfire;
21use Crossfire::Protocol; 33use Crossfire::Protocol;
22 34
23use Compress::LZF; 35use Compress::LZF;
24 36
25use CFClient; 37use CFClient;
26use CFClient::UI; 38use CFClient::UI;
39use CFClient::MapWidget;
40
41$Event::DIED = sub {
42 CFClient::error $_[1];
43};
27 44
28our $VERSION = '0.1'; 45our $VERSION = '0.1';
29 46
30my $MAX_FPS = 60; 47my $MAX_FPS = 60;
31my $MIN_FPS = 5; # unused as of yet 48my $MIN_FPS = 5; # unused as of yet
46our @SDL_MODES; 63our @SDL_MODES;
47our $WIDTH; 64our $WIDTH;
48our $HEIGHT; 65our $HEIGHT;
49our $FULLSCREEN; 66our $FULLSCREEN;
50our $FONTSIZE; 67our $FONTSIZE;
68
69our $FONT_PROP;
70our $FONT_FIXED;
51 71
52our $MAP; 72our $MAP;
53our $MAPWIDGET; 73our $MAPWIDGET;
54our $BUTTONBAR; 74our $BUTTONBAR;
55our $LOGVIEW; 75our $LOGVIEW;
56our $CONSOLE; 76our $CONSOLE;
57our $METASERVER; 77our $METASERVER;
58 78
79our $FLOORBOX;
59our $GAUGES; 80our $GAUGES;
81our $STATWIDS;
60 82
61our $SDL_ACTIVE; 83our $SDL_ACTIVE;
62our $SDL_EV;
63our %SDL_CB; 84our %SDL_CB;
64 85
65our $SDL_MIXER; 86our $SDL_MIXER;
66our @SOUNDS; # event => file mapping 87our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files 88our %AUDIO_CHUNKS; # audio files
109 undef $CONN; 130 undef $CONN;
110} 131}
111 132
112sub client_setup { 133sub client_setup {
113 my $dialog = new CFClient::UI::FancyFrame 134 my $dialog = new CFClient::UI::FancyFrame
135 title => "Client Setup",
114 child => (my $vbox = new CFClient::UI::VBox); 136 child => (my $vbox = new CFClient::UI::VBox);
115 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
116 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 137 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
117 138
118 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 139 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
119 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 140 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
120 141
121 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 142 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
122 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 143 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
123 144
124 $mode_slider->connect (changed => sub { 145 $mode_slider->connect (changed => sub {
125 my ($self, $value) = @_; 146 my ($self, $value) = @_;
126 147
127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 148 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
128 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 149 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
129 }); 150 });
130 $mode_slider->emit (changed => $mode_slider->{range}[0]); 151 $mode_slider->emit (changed => $mode_slider->{range}[0]);
131 152
153 my $row = 1;
154
132 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 155 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
133 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 156 $table->add (1, $row++, new CFClient::UI::CheckBox
157 state => $CFG->{fullscreen},
158 tooltip => "Bring the client into fullscreen mode",
159 connect_changed => sub {
134 my ($self, $value) = @_; 160 my ($self, $value) = @_;
135 $CFG->{fullscreen} = $value; 161 $CFG->{fullscreen} = $value;
162 }
136 }); 163 );
137 164
138 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 165 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
139 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 166 $table->add (1, $row++, new CFClient::UI::CheckBox
167 state => $CFG->{fast},
168 tooltip => "Lower the visual quality considerably to speed up rendering.",
169 connect_changed => sub {
140 my ($self, $value) = @_; 170 my ($self, $value) = @_;
141 $CFG->{fast} = $value; 171 $CFG->{fast} = $value;
172 }
142 }); 173 );
143 174
144 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 175 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale");
145 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 176 $table->add (1, $row++, new CFClient::UI::Slider
177 range => [$CFG->{map_scale}, 0.25, 2, 0.05],
178 tooltip => "Enlarge or shrink the displayed map",
179 connect_changed => sub {
146 my ($self, $value) = @_; 180 my ($self, $value) = @_;
181 $CFG->{map_scale} = 0.05 * int $value / 0.05;
182 }
183 );
184
185 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
186 $table->add (1, $row++, new CFClient::UI::CheckBox
187 state => $CFG->{fow_enable},
188 tooltip => "Fog-of-War marks areas that cannot be seen by the player",
189 connect_changed => sub {
190 my ($self, $value) = @_;
147 $CFG->{fow_enable} = $value; 191 $CFG->{fow_enable} = $value;
192 }
148 }); 193 );
149 194
150 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 195 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
151 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 196 $table->add (1, $row++, new CFClient::UI::Slider
197 range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001],
198 tooltip => "The higher the intensity, the lighter the Fog-of-War color",
199 connect_changed => sub {
152 my ($self, $value) = @_; 200 my ($self, $value) = @_;
153 $CFG->{fow_intensity} = $value; 201 $CFG->{fow_intensity} = $value;
202 }
154 }); 203 );
155 204
156 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 205 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
157 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 206 $table->add (1, $row++, new CFClient::UI::CheckBox
207 state => $CFG->{fow_smooth},
208 tooltip => "Smooth the Fog-of-War a bit to make it more realistic",
209 connect_changed => sub {
158 my ($self, $value) = @_; 210 my ($self, $value) = @_;
159 $CFG->{fow_smooth} = $value; 211 $CFG->{fow_smooth} = $value;
160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 212 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
213 }
161 }); 214 );
162 215
163 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 216 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 217 $table->add (1, $row++, new CFClient::UI::Slider
165 my ($self, $value) = @_; 218 range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1],
166 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 219 tooltip => "The font size used by most GUI elements",
220 connect_changed => sub {
221 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
222# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
223 }
167 }); 224 );
168 225
169 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 226 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
227 $table->add (1, $row++, new CFClient::UI::Slider
228 range => [$CFG->{log_fontsize}, 0.5, 2, 0.1],
229 tooltip => "The font size used by the server log window only",
230 connect_changed => sub {
231 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
232 }
233 );
234
235 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize");
236
237 $table->add (1, $row++, new CFClient::UI::Slider
238 range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1],
239 tooltip => "The font size used by the statistics window only",
240 connect_changed => sub {
241 $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10;
242 &set_stats_window_fontsize;
243 }
244 );
245
246 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size");
247 $table->add (1, $row++, new CFClient::UI::Slider
248 range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02],
249 tooltip => "Adjust the size of the stats gauges at the bottom right",
250 connect_changed => sub {
251 $CFG->{gauge_size} = $_[1];
252 my $h = int $HEIGHT * $CFG->{gauge_size};
253 $GAUGES->{win}->set_size ($WIDTH, $h);
254 $GAUGES->{win}->move (0, $HEIGHT - $h);
255 }
256 );
257
258 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
259 $table->add (1, $row++, new CFClient::UI::Slider
260 range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1],
261 tooltip => "Adjusts the fontsize of the gauges at the bottom right",
262 connect_changed => sub {
263 $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10;
264 &set_gauge_window_fontsize;
265 }
266 );
267
268 $table->add (1, $row++, new CFClient::UI::Button
269 expand => 1, align => 0, text => "Apply",
270 tooltip => "Apply the video settings",
271 connect_activate => sub {
170 video_shutdown (); 272 video_shutdown ();
171 video_init (); 273 video_init ();
274 }
275 );
276
277 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
278 $table->add (1, $row++, new CFClient::UI::CheckBox
279 state => $CFG->{audio_enable},
280 tooltip => "If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.",
281 connect_changed => sub {
282 $CFG->{audio_enable} = $_[1];
283 }
284 );
285# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
286# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
287# $CFG->{effects_volume} = $_[1];
172 }); 288# });
289 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
290 $table->add (1, $row++, my $hbox = new CFClient::UI::HBox);
291 $hbox->add (new CFClient::UI::CheckBox
292 expand => 1, state => $CFG->{bgm_enable},
293 tooltip => "Enable background music playing",
294 connect_changed => sub {
295 $CFG->{bgm_enable} = $_[1];
296 }
297 );
298 $hbox->add (new CFClient::UI::Slider
299 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1],
300 tooltip => "The volume of the background music",
301 connect_changed => sub {
302 $CFG->{bgm_volume} = $_[1];
303 CFClient::MixMusic::volume $_[1] * 128;
304 }
305 );
306
307 $table->add (1, $row++, new CFClient::UI::Button
308 expand => 1, align => 0, text => "Apply",
309 tooltip => "Apply the audio settings",
310 connect_activate => sub {
311 audio_shutdown ();
312 audio_init ();
313 }
314 );
173 315
174 $dialog 316 $dialog
317}
318
319sub set_stats_window_fontsize {
320 for (values %{$STATWIDS}) {
321 $_->set_fontsize ($::CFG->{stat_fontsize});
322 }
323}
324
325sub set_gauge_window_fontsize {
326 for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) {
327 $_->set_fontsize ($::CFG->{gauge_fontsize});
328 }
329
330# local $GAUGES->{win}{parent};#d#
331# use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D;
332}
333
334sub make_gauge_window {
335 my $gh = int ($HEIGHT * $CFG->{gauge_size});
336# my $gw = int ($WIDTH * $CFG->{gauge_w_size});
337
338 my $win = new CFClient::UI::Frame (
339 y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh
340 );
341 $win->add (my $hbox = new CFClient::UI::HBox
342 children => [
343 (new CFClient::UI::HBox expand => 1),
344 ($FLOORBOX = new CFClient::UI::VBox),
345 (my $vbox = new CFClient::UI::VBox),
346 ],
347 );
348
349 $vbox->add (new CFClient::UI::HBox
350 expand => 1,
351 children => [
352 (new CFClient::UI::Empty expand => 1),
353 (my $hb = new CFClient::UI::HBox),
354 ],
355 );
356
357 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp',
358 tooltip => "Health points - depletes when you get wounded, refills when you heal or idle");
359 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana',
360 tooltip => "Spell points - deplete when you cast wizard spells, refills when you idle");
361 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace',
362 tooltip => "Grace points - deplete when you cast priest spells, refills when you pray");
363 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food',
364 tooltip => "Food - depletes with time, faster when you heal or build mana, refills when you eat healthy food");
365
366 $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1,
367 tooltip => "Experience points and level - increases when you kill monsters or successfully use skills");
368 $vbox->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1,
369 tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)");
370
371 $GAUGES = {
372 exp => $exp, win => $win, range => $rng,
373 food => $fg, mana => $mg, hp => $hg, grace => $gg
374 };
375
376 &set_gauge_window_fontsize;
377
378 $win
379}
380
381sub make_stats_window {
382 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats");
383
384 $tgw->add (my $vb = new CFClient::UI::VBox);
385 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1);
386 $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
387
388 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
389
390 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
391
392 my $black = [0, 0, 0];
393
394 $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
395 $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
396 $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
397 $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
398 $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
399 $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
400 $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
401
402 $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Str");
403 $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Dex");
404 $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Con");
405 $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Int");
406 $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Wis");
407 $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Pow");
408 $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Cha");
409
410 $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120");
411 $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120");
412 $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120");
413 $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120");
414 $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54");
415 $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9");
416
417 $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Wc");
418 $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Ac");
419 $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Dam");
420 $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Arm");
421 $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Sp");
422 $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "WSp");
423
424 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1);
425
426 my $row = 0;
427 my $col = 0;
428
429 my %resist_names = (
430 slow => "Slow",
431 holyw => "Holy Word",
432 conf => "Confusion",
433 fire => "Fire",
434 depl => "Depletion",
435 magic => "Magic",
436 drain => "Draining",
437 acid => "Acid",
438 pois => "Poison",
439 para => "Paralysation",
440 deat => "Death",
441 phys => "Physical",
442 blind => "Blind",
443 fear => "Fear",
444 tund => "Turn undead",
445 elec => "Electricity",
446 cold => "Cold",
447 ghit => "Ghost hit",
448 );
449 for (qw/slow holyw conf fire depl magic
450 drain acid pois para deat phys
451 blind fear tund elec cold ghit/)
452 {
453 $tbl2->add ($col, $row,
454 $STATWIDS->{"res_$_"} =
455 new CFClient::UI::Label
456 template => "-100%",
457 align => +1,
458 valign => 0,
459 tooltip => $resist_names{$_}
460 );
461 $tbl2->add ($col + 1, $row, new CFClient::UI::Image
462 can_hover => 1,
463 can_events => 1,
464 image => "ui/resist/resist_$_.png",
465 tooltip => $resist_names{$_}
466 );
467
468 $row++;
469 if ($row % 6 == 0) {
470 $col += 2;
471 $row = 0;
472 }
473 }
474
475 &set_stats_window_fontsize;
476 update_stats_window ({});
477
478 $tgw
479}
480
481sub formsep {
482 reverse join ",", grep length, split /(...)/, reverse $_[0] * 1
483}
484
485sub update_stats_window {
486 my ($stats) = @_;
487
488 # i love text protocols!!!
489 my $hp = $stats->{Crossfire::Protocol::CS_STAT_HP} * 1;
490 my $hp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXHP} * 1;
491 my $sp = $stats->{Crossfire::Protocol::CS_STAT_SP} * 1;
492 my $sp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXSP} * 1;
493 my $fo = $stats->{Crossfire::Protocol::CS_STAT_FOOD} * 1;
494 my $fo_m = 999;
495 my $gr = $stats->{Crossfire::Protocol::CS_STAT_GRACE} * 1;
496 my $gr_m = $stats->{Crossfire::Protocol::CS_STAT_MAXGRACE} * 1;
497
498 $GAUGES->{hp} ->set_value ($hp, $hp_m);
499 $GAUGES->{mana} ->set_value ($sp, $sp_m);
500 $GAUGES->{food} ->set_value ($fo, $fo_m);
501 $GAUGES->{grace} ->set_value ($gr, $gr_m);
502 $GAUGES->{exp} ->set_text ("Exp: " . (formsep $stats->{Crossfire::Protocol::CS_STAT_EXP64})
503 . " (lvl " . ($stats->{Crossfire::Protocol::CS_STAT_LEVEL} * 1) . ")");
504 my $rng = $stats->{Crossfire::Protocol::CS_STAT_RANGE};
505 $rng =~ s/^Range: //; # thank you so much dear server
506 $GAUGES->{range} ->set_text ("Rng: " . $rng);
507 my $title = $stats->{Crossfire::Protocol::CS_STAT_TITLE};
508 $title =~ s/^Player: //;
509 $STATWIDS->{title} ->set_text ("Title: " . $title);
510
511 $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5});
512 $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8});
513 $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9});
514 $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6});
515 $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7});
516 $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22});
517 $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10});
518 $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13});
519 $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14});
520 $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15});
521 $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16});
522 $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_SPEED});
523 $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_WEAP_SP});
524
525 my %tbl = (
526 phys => 100,
527 magic => 101,
528 fire => 102,
529 elec => 103,
530 cold => 104,
531 conf => 105,
532 acid => 106,
533 drain => 107,
534 ghit => 108,
535 pois => 109,
536 slow => 110,
537 para => 111,
538 tund => 112,
539 fear => 113,
540 depl => 113,
541 deat => 115,
542 holyw => 116,
543 blind => 117
544 );
545
546 for (keys %tbl) {
547 $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}});
548 }
549
175} 550}
176 551
177sub metaserver_dialog { 552sub metaserver_dialog {
178 my $dialog = new CFClient::UI::FancyFrame 553 my $dialog = new CFClient::UI::FancyFrame
554 title => "Metaserver",
179 child => (my $vbox = new CFClient::UI::VBox); 555 child => (my $vbox = new CFClient::UI::VBox);
180 556
181 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 557 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
182 558
183 $dialog 559 $dialog
240 $HOST->set_text ($CFG->{host} = $host); 616 $HOST->set_text ($CFG->{host} = $host);
241 }), 617 }),
242 (new CFClient::UI::Empty expand => 1), 618 (new CFClient::UI::Empty expand => 1),
243 ]); 619 ]);
244 620
245 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 621 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
246 for 0 .. $#$m; 622 for 0 .. $#$m;
247 } 623 }
248 } 624 }
249 }); 625 });
250} 626}
251 627
252sub server_setup { 628sub server_setup {
253 my $dialog = new CFClient::UI::FancyFrame 629 my $dialog = new CFClient::UI::FancyFrame
630 title => "Server Setup",
254 child => (my $vbox = new CFClient::UI::VBox); 631 child => (my $vbox = new CFClient::UI::VBox);
255 632
256 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
257 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 633 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
258 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 634 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
259 635
260 { 636 {
261 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 637 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
262 638
263 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 639 $vbox->add (
640 my $HOST = new CFClient::UI::Entry
641 expand => 1,
642 text => $CFG->{host},
643 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
644 connect_changed => sub {
645 my ($self, $value) = @_;
646 $CFG->{host} = $value;
647 }
648 );
649
650 $METASERVER = metaserver_dialog;
651
652 $vbox->add (new CFClient::UI::Flopper
653 expand => 1,
654 text => "Metaserver",
655 other => $METASERVER,
656 tooltip => "Show a list of avaible crossfire servers",
657 connect_open => sub {
658 update_metaserver $HOST;
659 }
660 );
661 }
662
663 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
664 $table->add (1, 4, new CFClient::UI::Entry
665 text => $CFG->{user},
666 tooltip => "The name of your character on the server",
667 connect_changed => sub {
264 my ($self, $value) = @_; 668 my ($self, $value) = @_;
265 $CFG->{host} = $value; 669 $CFG->{user} = $value;
266 }); 670 }
671 );
267 672
268 $METASERVER = metaserver_dialog;
269
270 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub {
271 update_metaserver $HOST;
272 });
273 }
274
275 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 673 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
276 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 674 $table->add (1, 5, new CFClient::UI::Entry
675 text => $CFG->{password},
676 hidden => 1,
677 tooltip => "The password for your character",
678 connect_changed => sub {
277 my ($self, $value) = @_; 679 my ($self, $value) = @_;
278 $CFG->{user} = $value;
279 });
280
281 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
282 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
283 my ($self, $value) = @_;
284 $CFG->{password} = $value; 680 $CFG->{password} = $value;
681 }
285 }); 682 );
286 683
287 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 684 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
288 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 685 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry
686 text => $CFG->{say_command},
687 tooltip => "This is the command that will be used if you write a line in the message window entry. "
688 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
689 ."But you could also set it to 'tell &lt;playername&gt;' to only chat with that user.",
690 connect_changed => sub {
289 my ($self, $value) = @_; 691 my ($self, $value) = @_;
290 $CFG->{say_command} = $value; 692 $CFG->{say_command} = $value;
693 }
291 }); 694 );
292 695
293 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 696 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
294 $table->add (1, 7, new CFClient::UI::Slider 697 $table->add (1, 7, new CFClient::UI::Slider
295 req_w => 100, 698 req_w => 100,
296 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 699 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
700 tooltip => "This is the size of the portion of the map update the server sends you. "
701 ."If you set this to a high value you will be able to see further for example.",
297 connect_changed => sub { 702 connect_changed => sub {
298 my ($self, $value) = @_; 703 my ($self, $value) = @_;
299 704
300 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 705 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
301 }, 706 },
308 $dialog 713 $dialog
309} 714}
310 715
311sub message_window { 716sub message_window {
312 my $window = new CFClient::UI::FancyFrame 717 my $window = new CFClient::UI::FancyFrame
718 title => "Messages",
313 border_bg => [1, 1, 1, 0.5], 719 border_bg => [1, 1, 1, 0.5],
314 bg => [0.3, 0.3, 0.3, 0.8], 720 bg => [0.3, 0.3, 0.3, 0.8],
315 user_w => int $::WIDTH / 3, 721 user_w => int $::WIDTH / 3,
316 user_h => int $::HEIGHT / 5, 722 user_h => int $::HEIGHT / 5,
317 child => (my $vbox = new CFClient::UI::VBox); 723 child => (my $vbox = new CFClient::UI::VBox);
318 724
319 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 725 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
320 expand => 1, 726 expand => 1,
727 font => $FONT_FIXED,
321 fontsize => $::CFG->{log_fontsize}, 728 fontsize => $::CFG->{log_fontsize},
322 ); 729 );
323 730
324 $vbox->add (my $input = new CFClient::UI::Entry 731 $vbox->add (my $input = new CFClient::UI::Entry
325 connect_focus_in => sub { 732 connect_focus_in => sub {
359 766
360 $window 767 $window
361} 768}
362 769
363sub sdl_init { 770sub sdl_init {
364 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 771 CFClient::SDL_Init
365 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
366 and die "SDL::Init failed!\n"; 772 and die "SDL::Init failed!\n";
367} 773}
368 774
369sub video_init { 775sub video_init {
370 sdl_init; 776 sdl_init;
371 777
372 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 778 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
373 $FULLSCREEN = $CFG->{fullscreen}; 779 $FULLSCREEN = $CFG->{fullscreen};
374 $FAST = $CFG->{fast}; 780 $FAST = $CFG->{fast};
375 781
376 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 782 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
377 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
378 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
379 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
380
381 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
382 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
383 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
384 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
385
386 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
387 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
388 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
389
390 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
391 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
392 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
393 or die "SDL::SetVideoMode failed!\n"; 783 or die "SDL_SetVideoMode failed!\n";
394
395 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
396
397 $SDL_EV = new SDL::Event;
398 $SDL_EV->set_unicode (1);
399 784
400 $SDL_ACTIVE = 1; 785 $SDL_ACTIVE = 1;
401 786
402 $LAST_REFRESH = time - 0.01; 787 $LAST_REFRESH = time - 0.01;
403 788
404 CFClient::gl_init; 789 CFClient::gl_init;
405 790
406 $FONTSIZE = int $HEIGHT / 40; 791 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
407 792
408 ############################################################################# 793 #############################################################################
409 794
410 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 795 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
411 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 796 $DEBUG_STATUS->show;
412 797
413 $STATUS_LINE = new CFClient::UI::Label 798 $STATUS_LINE = new CFClient::UI::Label
414 padding => 0, 799 padding => 0,
415 y => $HEIGHT * 44 / 45 - $FONTSIZE; 800 y => $HEIGHT - $FONTSIZE * 1.8;
416 $CFClient::UI::ROOT->add ($STATUS_LINE); 801 $STATUS_LINE->show;
417 802
418 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 803 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
419 padding => 0, 804 padding => 0,
420 y => $HEIGHT * 44 / 45,
421 fontsize => $HEIGHT / 45, 805 fontsize => 0.8,
422 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 806 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
423 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 807 $ALT_ENTER_MESSAGE->show;
808 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
424 809
425 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 810 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
426 $MAPWIDGET->focus_in; 811 $MAPWIDGET->focus_in;
427 $MAPWIDGET->connect (activate_console => sub { 812 $MAPWIDGET->connect (activate_console => sub {
428 my ($mapwidget, $preset) = @_; 813 my ($mapwidget, $preset) = @_;
429 814
430 if ($CONSOLE) { 815 if ($CONSOLE) {
440 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); 825 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
441 826
442 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 827 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
443 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 828 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
444 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 829 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
830
831 $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
832 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
445 833
446 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 834 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
447 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 835 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
448 status "Configuration Saved"; 836 status "Configuration Saved";
449 }); 837 });
450 838
451 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 839 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
452
453 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
454 $tgw->add (my $hbox = new CFClient::UI::HBox ());
455
456 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
457 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
458 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
459 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
460
461 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
462 $CFClient::UI::ROOT->add ($tgw);
463} 840}
464 841
465sub video_shutdown { 842sub video_shutdown {
466 $CFClient::UI::ROOT->{children} = []; 843 $CFClient::UI::ROOT->{children} = [];
844 undef $CFClient::UI::GRAB;
845 undef $CFClient::UI::HOVER;
467 undef $SDL_ACTIVE; 846 undef $SDL_ACTIVE;
468 undef $SDL_EV;
469} 847}
470 848
849my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
471my $bgmusic;#TODO#hack#d# 850my $bgmusic;#TODO#hack#d#
472 851
852sub audio_music_finished {
853 return unless $CFG->{bgm_enable};
854
855 # TODO: hack, do play loop and mood music
856 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
857 $bgmusic->play (0);
858
859 push @bgmusic, shift @bgmusic;
860}
861
473sub audio_init { 862sub audio_init {
474 if ($CFG->{sound} || 1) { 863 if ($CFG->{audio_enable}) {
475 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 864 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
476 $SDL_MIXER = new SDL::Mixer; 865 $SDL_MIXER = !CFClient::Mix_OpenAudio;
477 $SDL_MIXER->allocate_channels (8); 866 CFClient::Mix_AllocateChannels 8;
867 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
478 868
479 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 869 audio_music_finished;
480 $SDL_MIXER->play_music ($bgmusic, 0);
481 870
482 while (<$fh>) { 871 while (<$fh>) {
483 next if /^\s*#/; 872 next if /^\s*#/;
484 next if /^\s*$/; 873 next if /^\s*$/;
485 874
486 my ($file, $volume, $event) = split /\s+/, $_, 3; 875 my ($file, $volume, $event) = split /\s+/, $_, 3;
487 876
488 push @SOUNDS, "$volume,$file"; 877 push @SOUNDS, "$volume,$file";
489 878
490 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 879 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
491 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 880 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
492 $chunk->volume ($volume * 128 / 100); 881 $chunk->volume ($volume * 128 / 100);
493 $chunk 882 $chunk
494 }; 883 };
495 } 884 }
496 } else { 885 } else {
498 } 887 }
499 } 888 }
500} 889}
501 890
502sub audio_shutdown { 891sub audio_shutdown {
892 CFClient::Mix_CloseAudio if $SDL_MIXER;
503 undef $SDL_MIXER; 893 undef $SDL_MIXER;
504 @SOUNDS = (); 894 @SOUNDS = ();
505 %AUDIO_CHUNKS = (); 895 %AUDIO_CHUNKS = ();
506} 896}
507 897
520 $want_refresh = 0; 910 $want_refresh = 0;
521 $can_refresh = 0; 911 $can_refresh = 0;
522 912
523 $CFClient::UI::ROOT->draw; 913 $CFClient::UI::ROOT->draw;
524 914
525 SDL::GLSwapBuffers; 915 CFClient::SDL_GL_SwapBuffers;
526 916
527 $LAST_REFRESH = $NOW; 917 $LAST_REFRESH = $NOW;
528} 918}
529 919
530my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 920my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
531 $NOW = time; 921 $NOW = time;
532 922
533 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 923 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
534 while $SDL_EV->poll; 924 for CFClient::SDL_PollEvent;
535 925
536 if (%animate_object) { 926 if (%animate_object) {
537 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 927 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
538 $want_refresh++; 928 $want_refresh++;
539 } 929 }
562@conn::ISA = Crossfire::Protocol::; 952@conn::ISA = Crossfire::Protocol::;
563 953
564sub conn::stats_update { 954sub conn::stats_update {
565 my ($self, $stats) = @_; 955 my ($self, $stats) = @_;
566 956
567 # i love text protocols!!! 957 update_stats_window ($stats);
568 # FIXME: the stats are somehow weird
569 my $hp = $stats->{1};
570 my $hp_m = $stats->{2};
571 my $sp = $stats->{3};
572 my $sp_m = $stats->{4};
573 my $fo = $stats->{18};
574 my $fo_m = 1000;
575 my $gr = $stats->{23};
576 my $gr_m = $stats->{24};
577
578 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
579 $GAUGES->{hp}->set_value ($hp, $hp_m);
580 $GAUGES->{mana}->set_value ($sp, $sp_m);
581 $GAUGES->{food}->set_value ($fo, $fo_m);
582 $GAUGES->{grace}->set_value ($gr, $gr_m);
583} 958}
584 959
585sub conn::user_send { 960sub conn::user_send {
586 my ($self, $command) = @_; 961 my ($self, $command) = @_;
587 962
612 987
613 my ($hash, $x, $y, $w, $h) = @$map_info; 988 my ($hash, $x, $y, $w, $h) = @$map_info;
614 989
615 my $data = $MAP->get_rect ($x, $y, $w, $h); 990 my $data = $MAP->get_rect ($x, $y, $w, $h);
616 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 991 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
617
618 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 992 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
619
620} 993}
621 994
622sub conn::map_clear { 995sub conn::map_clear {
623 my ($self) = @_; 996 my ($self) = @_;
624 997
625 $self->flush_map; 998 $self->flush_map;
626 delete $self->{neigh}; 999 delete $self->{neigh_map};
627 1000
628 $MAP->clear; 1001 $MAP->clear;
629} 1002}
630 1003
631 1004
632sub conn::load_map($$$) { 1005sub conn::load_map($$$) {
633 my ($self, $hash, $x, $y) = @_; 1006 my ($self, $hash, $x, $y) = @_;
634 1007
635 if (defined (my $data = $MAPCACHE->get ($hash))) { 1008 if (defined (my $data = $MAPCACHE->get ($hash))) {
636 $data = Compress::LZF::decompress $data; 1009 $data = Compress::LZF::decompress $data;
637 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 1010 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
638 for my $id ($MAP->set_rect ($x, $y, $data)) { 1011 for my $id ($MAP->set_rect ($x, $y, $data)) {
639 my $data = $TILECACHE->get ($id) 1012 my $data = $TILECACHE->get ($id)
640 or next; 1013 or next;
641 1014
642 $self->set_texture ($id => $data); 1015 $self->set_texture ($id => $data);
643 } 1016 }
644 } 1017 }
645} 1018}
646 1019
1020# this method does a "flood fill" into every tile direction
1021# it assumes that tiles are arranged in a rectangular grid,
1022# i.e. a map is the same as the left of the right map etc.
1023# failure to comply are harmless and result in display errors
1024# at worst.
647sub conn::flood_fill { 1025sub conn::flood_fill {
648 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 1026 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
649 1027
650 # the server does not allow map paths > 6 1028 # the server does not allow map paths > 6
651 return if 6 <= length $path; 1029 return if 6 <= length $path;
652 1030
653 for my $tile (1..4) { 1031 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
654 next if $self->{neigh}{$hash}[$tile]; 1032
1033 for (
1034 [1, 0, -1],
1035 [2, 1, 0],
1036 [3, 0, 1],
1037 [4, -1, 0],
1038 ) {
1039 my ($tile, $dx, $dy) = @$_;
1040
1041 my $gx = $gx + $dx;
1042 my $gy = $gy + $dy;
1043
655 next unless $flags & (1 << ($tile - 1)); 1044 next unless $flags & (1 << ($tile - 1));
1045 next if $self->{neigh_grid}{$gx, $gy}++;
656 1046
657 my $neigh = $self->{neigh}{$hash} ||= []; 1047 my $neigh = $self->{neigh_map}{$hash} ||= [];
658 1048 if (my $info = $neigh->[$tile]) {
659 $self->send_mapinfo ("spatial $path$tile", sub {
660 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 1049 my ($flags, $x, $y, $w, $h, $hash) = @$info;
661 1050
662 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
663 return if $mode ne "spatial";
664
665 $x += $MAP->ox;
666 $y += $MAP->oy;
667
668 $self->load_map ($hash, $x, $y)
669 unless $self->{neigh}{$hash}[5]++;#d#
670
671 $neigh->[$tile] = [$x, $y, $w, $h];
672
673 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 1051 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
674 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 1052 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
1053
1054 } else {
1055 $self->send_mapinfo ("spatial $path$tile", sub {
1056 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
1057
1058 return if $mode ne "spatial";
1059
1060 $x += $MAP->ox;
1061 $y += $MAP->oy;
1062
1063 $self->load_map ($hash, $x, $y)
1064 unless $self->{neigh_map}{$hash}[5]++;#d#
1065
1066 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
1067
1068 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
1069 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
1070 });
675 }); 1071 }
676 } 1072 }
677} 1073}
678 1074
679sub conn::map_change { 1075sub conn::map_change {
680 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 1076 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
683 1079
684 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 1080 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
685 1081
686 my $mapmapw = 250; 1082 my $mapmapw = 250;
687 my $mapmaph = 250; 1083 my $mapmaph = 250;
1084
1085 $self->{neigh_rect} = [
1086 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
1087 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
1088 ];
688 1089
1090 delete $self->{neigh_grid};
689 $self->flood_fill ("", $hash, $flags, 1091 $self->flood_fill (0, 0, "", $hash, $flags);
690 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
691 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
692 1092
693 $x += $ox; 1093 $x += $ox;
694 $y += $oy; 1094 $y += $oy;
695 1095
696 $self->{map_info} = [$hash, $x, $y, $w, $h]; 1096 $self->{map_info} = [$hash, $x, $y, $w, $h];
1097
1098 my $map = $self->{map_info}[0];
1099 $map =~ s/^.*?\/([^\/]+)$/\1/;
1100 $STATWIDS->{map}->set_text ("Map: " . $map);
697 1101
698 $self->load_map ($hash, $x, $y); 1102 $self->load_map ($hash, $x, $y);
699} 1103}
700 1104
701sub conn::face_find { 1105sub conn::face_find {
727 } 1131 }
728 1132
729gotid: 1133gotid:
730 $face->{id} = $id; 1134 $face->{id} = $id;
731 $MAP->set_face ($facenum => $id); 1135 $MAP->set_face ($facenum => $id);
1136 $self->{faceid}[$facenum] = $id;#d#
732 $TILECACHE->get ($id) 1137 $TILECACHE->get ($id)
733} 1138}
734 1139
735sub conn::face_update { 1140sub conn::face_update {
736 my ($self, $facenum, $face) = @_; 1141 my ($self, $facenum, $face) = @_;
744 my ($self, $id, $data) = @_; 1149 my ($self, $id, $data) = @_;
745 1150
746 $self->{texture}[$id] ||= do { 1151 $self->{texture}[$id] ||= do {
747 my $tex = 1152 my $tex =
748 new_from_image CFClient::Texture 1153 new_from_image CFClient::Texture
749 $data, minify => 1; 1154 $data, minify => 1, mipmap => 1;
750 1155
751 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 1156 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
752 $MAPWIDGET->update; 1157 $MAPWIDGET->update;
753 1158
754 $tex 1159 $tex
756} 1161}
757 1162
758sub conn::sound_play { 1163sub conn::sound_play {
759 my ($self, $x, $y, $soundnum, $type) = @_; 1164 my ($self, $x, $y, $soundnum, $type) = @_;
760 1165
1166 $SDL_MIXER
1167 or return;
1168
761 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 1169 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
762 or return; 1170 or return;
763 1171
764 $SDL_MIXER->play_channel (-1, $chunk); 1172 $chunk->play;
765 warn "sound $x,$y,$soundnum,$type\n";#d# 1173# warn "sound $x,$y,$soundnum,$type\n";#d#
766} 1174}
1175
1176my $LAST_QUERY; # server is stupid, stupid, stupid
767 1177
768sub conn::query { 1178sub conn::query {
769 my ($self, $flags, $prompt) = @_; 1179 my ($self, $flags, $prompt) = @_;
770 1180
771 #TODO 1181 $prompt = $LAST_QUERY unless length $prompt;
772 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 1182 $LAST_QUERY = $prompt;
1183
1184 my $dialog = new CFClient::UI::FancyFrame
1185 title => "Query",
1186 child => my $vbox = new CFClient::UI::VBox;
1187
1188 $vbox->add (new CFClient::UI::Label
1189 max_w => $::WIDTH * 0.4,
1190 text => $prompt);
1191
1192 if ($flags & Crossfire::Protocol::CS_QUERY_YESNO) {
1193 $vbox->add (my $hbox = new CFClient::HBox);
1194 $hbox->add (new CFClient::Button
1195 text => "No",
1196 connect_activate => sub {
1197 $self->send ("reply n");
1198 $dialog->destroy;
1199 $MAPWIDGET->focus_in;
1200 }
1201 );
1202 $hbox->add (new CFClient::Button
1203 text => "Yes",
1204 connect_activate => sub {
1205 $self->send ("reply y");
1206 $dialog->destroy;
1207 $MAPWIDGET->focus_in;
1208 },
1209 );
1210
1211 $dialog->focus_in;
1212
1213 } elsif ($flags & Crossfire::Protocol::CS_QUERY_SINGLECHAR) {
1214 $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)";
1215 $vbox->add (my $entry = new CFClient::UI::Entry
1216 connect_changed => sub {
1217 $self->send ("reply $_[1]");
1218 $dialog->destroy;
1219 $MAPWIDGET->focus_in;
1220 },
1221 );
1222
1223 $entry->focus_in;
1224
1225 } else {
1226 $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)";
1227
1228 $vbox->add (my $entry = new CFClient::UI::Entry
1229 $flags & Crossfire::Protocol::CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (),
1230 connect_activate => sub {
1231 $self->send ("reply $_[1]");
1232 $dialog->destroy;
1233 $MAPWIDGET->focus_in;
1234 },
1235 );
1236
1237 $entry->focus_in;
1238 }
1239
1240 $dialog->show;
773} 1241}
774 1242
775sub conn::drawinfo { 1243sub conn::drawinfo {
776 my ($self, $color, $text) = @_; 1244 my ($self, $color, $text) = @_;
777 1245
792 ); 1260 );
793 1261
794 $LOGVIEW->add_paragraph ($color[$color], $text); 1262 $LOGVIEW->add_paragraph ($color[$color], $text);
795} 1263}
796 1264
1265sub conn::spell_add {
1266 my ($self, $spell) = @_;
1267
1268 # TODO
1269 # create a widget dynamically, using spell face (CF::Protocol downloads them)
1270 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message});
1271 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message});
1272}
1273
1274sub conn::spell_delete {
1275 my ($self, $spell) = @_;
1276}
1277
1278sub conn::addme_success {
1279 my ($self) = @_;
1280
1281 for my $skill (values %{$self->{skill_info}}) {
1282 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1283 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1284 }
1285}
1286
1287sub update_floorbox {
1288 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1289 $FLOORBOX->clear;
1290 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1291
1292 my @items = values %{ $CONN->{container}{0} };
1293
1294 # we basically have to use the same sorting as everybody else
1295 @items = sort { $a->{type} <=> $b->{type} } @items;
1296
1297 for my $item (reverse @items) {
1298 my $desc = $item->{nrof} < 2
1299 ? $item->{name}
1300 : "$item->{nrof} $item->{name_pl}";
1301 # todo: animation widget, face widget, weight(?) etc.
1302 $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
1303 tooltip => (CFClient::UI::Label->escape ($desc)
1304 . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"),
1305 can_hover => 1,
1306 can_events => 1,
1307 connect_button_down => sub {
1308 my ($self, $ev, $x, $y) = @_;
1309
1310 # todo: maybe put examine on 1? but should just be a tooltip :(
1311 if ($ev->{button} == 1) {
1312 $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
1313 } elsif ($ev->{button} == 2) {
1314 $CONN->send ("apply $item->{tag}");
1315 } elsif ($ev->{button} == 3) {
1316 # examine, lock, mark, maybe other things
1317 warn "MENU not implemented yet\n";
1318 }
1319
1320 1
1321 },
1322 );
1323
1324 $hbox->add (new CFClient::UI::Face
1325 can_events => 0,
1326 face => $item->{face},
1327 anim => $item->{anim},
1328 animspeed => $item->{animspeed},
1329 );
1330
1331 $hbox->add (new CFClient::UI::Label
1332 can_events => 0,
1333 text => $desc,
1334 );
1335 }
1336 });
1337 refresh;
1338}
1339
1340sub conn::container_add {
1341 my ($self, $id, $items) = @_;
1342
1343 update_floorbox if $id == 0;
1344 # $self-<{player}{tag} => player inv
1345 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1346}
1347
1348sub conn::container_clear {
1349 my ($self, $id) = @_;
1350
1351 update_floorbox if $id == 0;
1352# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1353}
1354
1355sub conn::item_delete {
1356 my ($self, @items) = @_;
1357
1358 for (@items) {
1359 update_floorbox if $_->{container} == 0;
1360 }
1361}
1362
1363sub conn::item_update {
1364 my ($self, $item) = @_;
1365
1366 update_floorbox if $item->{container} == 0;
1367}
1368
797%SDL_CB = ( 1369%SDL_CB = (
798 SDL_QUIT() => sub { 1370 CFClient::SDL_QUIT => sub {
799 Event::unloop -1; 1371 Event::unloop -1;
800 }, 1372 },
801 SDL_VIDEORESIZE() => sub { 1373 CFClient::SDL_VIDEORESIZE => sub {
802 }, 1374 },
803 SDL_VIDEOEXPOSE() => sub { 1375 CFClient::SDL_VIDEOEXPOSE => \&refresh,
804 refresh; 1376 CFClient::SDL_ACTIVEEVENT => sub {
1377# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
805 }, 1378 },
806 SDL_KEYDOWN() => sub { 1379 CFClient::SDL_KEYDOWN => sub {
807 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 1380 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
808 # alt-enter 1381 # alt-enter
809 video_shutdown; 1382 video_shutdown;
810 $CFG->{fullscreen} = !$CFG->{fullscreen}; 1383 $CFG->{fullscreen} = !$CFG->{fullscreen};
811 video_init; 1384 video_init;
812 } else { 1385 } else {
813 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 1386 CFClient::UI::feed_sdl_key_down_event ($_[0]);
814 } 1387 }
815 }, 1388 },
816 SDL_KEYUP() => sub { 1389 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
817 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 1390 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
818 }, 1391 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
819 SDL_MOUSEMOTION() => sub { 1392 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
820 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 1393 CFClient::SDL_USEREVENT => \&audio_music_finished,
821 },
822 SDL_MOUSEBUTTONDOWN() => sub {
823 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
824 },
825 SDL_MOUSEBUTTONUP() => sub {
826 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
827 },
828 SDL_ACTIVEEVENT() => sub {
829# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
830 },
831); 1394);
832 1395
833############################################################################# 1396#############################################################################
834 1397
835$SIG{INT} = $SIG{TERM} = sub { exit }; 1398$SIG{INT} = $SIG{TERM} = sub { exit };
843 sdl_mode => 0, 1406 sdl_mode => 0,
844 width => 640, 1407 width => 640,
845 height => 480, 1408 height => 480,
846 fullscreen => 0, 1409 fullscreen => 0,
847 fast => 0, 1410 fast => 0,
1411 map_scale => 0.5,
848 fow_enable => 1, 1412 fow_enable => 1,
849 fow_intensity => 0.45, 1413 fow_intensity => 0.45,
850 fow_smooth => 0, 1414 fow_smooth => 0,
1415 gui_fontsize => 1,
851 log_fontsize => 14, 1416 log_fontsize => 1,
1417 gauge_fontsize => 1,
1418 gauge_size => 0.35,
1419 stat_fontsize => 1,
852 mapsize => 100, 1420 mapsize => 100,
853 host => "crossfire.schmorp.de", 1421 host => "crossfire.schmorp.de",
854 say_command => 'say', 1422 say_command => 'say',
1423 audio_enable => 1,
1424 bgm_enable => 1,
1425 bgm_volume => 0.25,
855); 1426);
856 1427
857while (my ($k, $v) = each %DEF_CFG) { 1428while (my ($k, $v) = each %DEF_CFG) {
858 $CFG->{$k} = $v unless exists $CFG->{$k}; 1429 $CFG->{$k} = $v unless exists $CFG->{$k};
859} 1430}
860 1431
861sdl_init; 1432sdl_init;
862 1433
863@SDL_MODES = reverse 1434@SDL_MODES = reverse
864 grep $_->[0] >= 640 && $_->[1] >= 480, 1435 grep $_->[0] >= 640 && $_->[1] >= 480,
865 map [SDL::RectW ($_), SDL::RectH ($_)], 1436 CFClient::SDL_ListModes;
866 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
867 1437
868@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 1438@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
869 1439
870$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 1440$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
871 1441
872{ 1442{
873 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 1443 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1444 DejaVuSans.ttf
1445 DejaVuSansMono.ttf
1446 DejaVuSans-Bold.ttf
1447 DejaVuSansMono-Bold.ttf
1448 DejaVuSans-Oblique.ttf
1449 DejaVuSansMono-Oblique.ttf
1450 DejaVuSans-BoldOblique.ttf
1451 DejaVuSansMono-BoldOblique.ttf
1452 );
874 1453
875 CFClient::add_font $_ for @fonts; 1454 CFClient::add_font $_ for @fonts;
876 CFClient::set_font $fonts[0]; 1455
1456 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1457 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1458
1459 $FONT_PROP->make_default;
877} 1460}
878 1461
879video_init; 1462video_init;
880audio_init; 1463audio_init;
881 1464
882Event::loop; 1465Event::loop;
883 1466
884END { SDL::Quit } 1467END { CFClient::SDL_Quit }
885 1468
886 1469

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines