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.134 by root, Tue Apr 18 05:13:15 2006 UTC vs.
Revision 1.168 by root, Sun Apr 23 21:47:32 2006 UTC

4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL;
10use SDL::App;
11use SDL::Event;
12use SDL::Surface;
13
14use SDL::Sound;
15use SDL::Mixer;
16
17use SDL::OpenGL;
18
19use Crossfire; 9use Crossfire;
20use Crossfire::Protocol; 10use Crossfire::Protocol;
21 11
22use Compress::LZF; 12use Compress::LZF;
23 13
24use CFClient; 14use CFClient;
25use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
26 17
27our $VERSION = '0.1'; 18our $VERSION = '0.1';
28 19
29my $MAX_FPS = 60; 20my $MAX_FPS = 60;
30my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
45our @SDL_MODES; 36our @SDL_MODES;
46our $WIDTH; 37our $WIDTH;
47our $HEIGHT; 38our $HEIGHT;
48our $FULLSCREEN; 39our $FULLSCREEN;
49our $FONTSIZE; 40our $FONTSIZE;
41
42our $FONT_PROP;
43our $FONT_FIXED;
50 44
51our $MAP; 45our $MAP;
52our $MAPWIDGET; 46our $MAPWIDGET;
53our $BUTTONBAR; 47our $BUTTONBAR;
54our $LOGVIEW; 48our $LOGVIEW;
55our $CONSOLE; 49our $CONSOLE;
56our $METASERVER; 50our $METASERVER;
57 51
58our $GAUGES; 52our $GAUGES;
53our $STATWIDS;
59 54
60our $SDL_ACTIVE; 55our $SDL_ACTIVE;
61our $SDL_EV;
62our %SDL_CB; 56our %SDL_CB;
63 57
64our $SDL_MIXER; 58our $SDL_MIXER;
65our @SOUNDS; # event => file mapping 59our @SOUNDS; # event => file mapping
66our %AUDIO_CHUNKS; # audio files 60our %AUDIO_CHUNKS; # audio files
108 undef $CONN; 102 undef $CONN;
109} 103}
110 104
111sub client_setup { 105sub client_setup {
112 my $dialog = new CFClient::UI::FancyFrame 106 my $dialog = new CFClient::UI::FancyFrame
107 title => "Client Setup",
113 child => (my $vbox = new CFClient::UI::VBox); 108 child => (my $vbox = new CFClient::UI::VBox);
114 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
115 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 109 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
116 110
117 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 111 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
118 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 112 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
119 113
120 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 114 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
121 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 115 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
122 116
123 $mode_slider->connect (changed => sub { 117 $mode_slider->connect (changed => sub {
124 my ($self, $value) = @_; 118 my ($self, $value) = @_;
125 119
126 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 120 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
127 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 121 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
128 }); 122 });
129 $mode_slider->emit (changed => $mode_slider->{range}[0]); 123 $mode_slider->emit (changed => $mode_slider->{range}[0]);
130 124
125 my $row = 1;
126
131 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 127 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
132 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 128 $table->add (1, $row++, new CFClient::UI::CheckBox
129 state => $CFG->{fullscreen},
130 tooltip => "Bring the client into fullscreen mode",
131 connect_changed => sub {
133 my ($self, $value) = @_; 132 my ($self, $value) = @_;
134 $CFG->{fullscreen} = $value; 133 $CFG->{fullscreen} = $value;
134 }
135 }); 135 );
136 136
137 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 137 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
138 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 138 $table->add (1, $row++, new CFClient::UI::CheckBox
139 state => $CFG->{fast},
140 tooltip => "Lower the visual quality considerably to speed up rendering.",
141 connect_changed => sub {
139 my ($self, $value) = @_; 142 my ($self, $value) = @_;
140 $CFG->{fast} = $value; 143 $CFG->{fast} = $value;
144 }
141 }); 145 );
142 146
143 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 147 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
144 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 148 $table->add (1, $row++, new CFClient::UI::CheckBox
149 state => $CFG->{fow_enable},
150 tooltip => "Fog-of-War marks areas that cannot be seen by the player",
151 connect_changed => sub {
145 my ($self, $value) = @_; 152 my ($self, $value) = @_;
146 $CFG->{fow_enable} = $value; 153 $CFG->{fow_enable} = $value;
154 }
147 }); 155 );
148 156
149 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 157 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
150 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 158 $table->add (1, $row++, new CFClient::UI::Slider
159 range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001],
160 tooltip => "The higher the intensity, the lighter the Fog-of-War color",
161 connect_changed => sub {
151 my ($self, $value) = @_; 162 my ($self, $value) = @_;
152 $CFG->{fow_intensity} = $value; 163 $CFG->{fow_intensity} = $value;
164 }
153 }); 165 );
154 166
155 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 167 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
156 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 168 $table->add (1, $row++, new CFClient::UI::CheckBox
169 state => $CFG->{fow_smooth},
170 tooltip => "Smooth the Fog-of-War a bit to make it more realistic",
171 connect_changed => sub {
157 my ($self, $value) = @_; 172 my ($self, $value) = @_;
158 $CFG->{fow_smooth} = $value; 173 $CFG->{fow_smooth} = $value;
159 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 174 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
175 }
160 }); 176 );
161 177
162 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 178 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
163 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 179 $table->add (1, $row++, new CFClient::UI::Slider
164 my ($self, $value) = @_; 180 range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1],
165 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 181 tooltip => "The font size used by most GUI elements",
182 connect_changed => sub {
183 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
184# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
185 }
166 }); 186 );
167 187
168 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 188 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
189 $table->add (1, $row++, new CFClient::UI::Slider
190 range => [$CFG->{log_fontsize}, 0.5, 2, 0.1],
191 tooltip => "The font size used by the server log window only",
192 connect_changed => sub {
193 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
194 }
195 );
196
197 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize");
198
199 $table->add (1, $row++, new CFClient::UI::Slider
200 range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1],
201 tooltip => "The font size used by the statistics window only",
202 connect_changed => sub {
203 $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10;
204 &set_stats_window_fontsize;
205 }
206 );
207
208 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size");
209 $table->add (1, $row++, new CFClient::UI::Slider
210 range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02],
211 tooltip => "Adjust the size of the stats gauges at the bottom right",
212 connect_changed => sub {
213 $CFG->{gauge_size} = $_[1];
214 my $h = int $HEIGHT * $CFG->{gauge_size};
215 $GAUGES->{win}->set_size ($WIDTH, $h);
216 $GAUGES->{win}->move (0, $HEIGHT - $h);
217 }
218 );
219
220 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
221 $table->add (1, $row++, new CFClient::UI::Slider
222 range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1],
223 tooltip => "Adjusts the fontsize of the gauges at the bottom right",
224 connect_changed => sub {
225 $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10;
226 &set_gauge_window_fontsize;
227 #$GAUGES->{win}->check_size;
228 #$GAUGES->{win}->update;
229 }
230 );
231
232 $table->add (1, $row++, new CFClient::UI::Button
233 expand => 1, align => 0, text => "Apply",
234 tooltip => "Apply the video settings",
235 connect_activate => sub {
169 video_shutdown (); 236 video_shutdown ();
170 video_init (); 237 video_init ();
238 }
239 );
240
241 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
242 $table->add (1, $row++, new CFClient::UI::CheckBox
243 state => $CFG->{audio_enable},
244 tooltip => "If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.",
245 connect_changed => sub {
246 $CFG->{audio_enable} = $_[1];
247 }
248 );
249# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
250# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
251# $CFG->{effects_volume} = $_[1];
171 }); 252# });
253 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
254 $table->add (1, $row++, my $hbox = new CFClient::UI::HBox);
255 $hbox->add (new CFClient::UI::CheckBox
256 expand => 1, state => $CFG->{bgm_enable},
257 tooltip => "Enable background music playing",
258 connect_changed => sub {
259 $CFG->{bgm_enable} = $_[1];
260 }
261 );
262 $hbox->add (new CFClient::UI::Slider
263 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1],
264 tooltip => "The volume of the background music",
265 connect_changed => sub {
266 $CFG->{bgm_volume} = $_[1];
267 CFClient::MixMusic::volume $_[1] * 128;
268 }
269 );
270
271 $table->add (1, $row++, new CFClient::UI::Button
272 expand => 1, align => 0, text => "Apply",
273 tooltip => "Apply the audio settings",
274 connect_activate => sub {
275 audio_shutdown ();
276 audio_init ();
277 }
278 );
172 279
173 $dialog 280 $dialog
281}
282
283sub set_stats_window_fontsize {
284 for (values %{$STATWIDS}) {
285 $_->set_fontsize ($::CFG->{stat_fontsize});
286 }
287}
288
289sub set_gauge_window_fontsize {
290 for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) {
291 $_->set_fontsize ($::CFG->{gauge_fontsize});
292 }
293}
294
295sub make_gauge_window {
296 my $gh = int ($HEIGHT * $CFG->{gauge_size});
297# my $gw = int ($WIDTH * $CFG->{gauge_w_size});
298
299 my $win = new CFClient::UI::Frame (
300 y => $HEIGHT - $gh, x => 0, req_w => $WIDTH, req_h => $gh
301 );
302 $win->add (my $vb = new CFClient::UI::VBox);
303
304 $vb->add (my $hbg = new CFClient::UI::HBox expand => 1);
305
306
307 $hbg->add (new CFClient::UI::Empty expand => 1);
308 $hbg->add (my $hb = new CFClient::UI::HBox);
309 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', tooltip => "Health points");
310 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', tooltip => "Spellpoints");
311 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', tooltip => "Grace");
312 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', tooltip => "Food");
313
314 $vb->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, text => "XP: 0 LVL: 0");
315 $vb->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, text => "Rng:");
316
317 $GAUGES = {
318 exp => $exp, win => $win, range => $rng,
319 food => $fg, mana => $mg, hp => $hg, grace => $gg
320 };
321 $win
322}
323
324sub make_stats_window {
325 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats");
326
327 $tgw->add (my $vb = new CFClient::UI::VBox);
328 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1);
329 $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
330
331 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
332
333 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
334
335 $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
336 $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
337 $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
338 $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
339 $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
340 $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
341 $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
342
343 $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Str");
344 $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dex");
345 $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Con");
346 $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Int");
347 $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wis");
348 $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Pow");
349 $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Cha");
350
351 $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120");
352 $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120");
353 $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120");
354 $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120");
355 $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54");
356 $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9");
357
358 $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc");
359 $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac");
360 $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam");
361 $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm");
362 $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp");
363 $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp");
364
365 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1);
366
367 my $row = 0;
368 my $col = 0;
369
370 my %resist_names = (
371 slow => "Slow",
372 holyw => "Holy Word",
373 conf => "Confusion",
374 fire => "Fire",
375 depl => "Depletion",
376 magic => "Magic",
377 drain => "Draining",
378 acid => "Acid",
379 pois => "Poison",
380 para => "Paralysation",
381 deat => "Death",
382 phys => "Physical",
383 blind => "Blind",
384 fear => "Fear",
385 tund => "Turn undead",
386 elec => "Electricity",
387 cold => "Cold",
388 ghit => "Ghost hit",
389 );
390 for (qw/slow holyw conf fire depl magic
391 drain acid pois para deat phys
392 blind fear tund elec cold ghit/)
393 {
394 $tbl2->add ($col, $row,
395 $STATWIDS->{"res_$_"} =
396 new CFClient::UI::Label
397 template => "-100%",
398 align => +1,
399 valign => 0,
400 tooltip => $resist_names{$_}
401 );
402 $tbl2->add ($col + 1, $row, new CFClient::UI::Image
403 can_hover => 1,
404 can_events => 1,
405 image => "ui/resist/resist_$_.png",
406 tooltip => $resist_names{$_}
407 );
408
409 $row++;
410 if ($row % 6 == 0) {
411 $col += 2;
412 $row = 0;
413 }
414 }
415
416 &set_stats_window_fontsize;
417 update_stats_window ({});
418
419 $tgw
420}
421
422sub update_stats_window {
423 my ($stats) = @_;
424
425 # i love text protocols!!!
426 my $hp = $stats->{1} * 1;
427 my $hp_m = $stats->{2} * 1;
428 my $sp = $stats->{3} * 1;
429 my $sp_m = $stats->{4} * 1;
430 my $fo = $stats->{18} * 1;
431 my $fo_m = 999;
432 my $gr = $stats->{23} * 1;
433 my $gr_m = $stats->{24} * 1;
434
435 $GAUGES->{hp} ->set_value ($hp, $hp_m);
436 $GAUGES->{mana} ->set_value ($sp, $sp_m);
437 $GAUGES->{food} ->set_value ($fo, $fo_m);
438 $GAUGES->{grace} ->set_value ($gr, $gr_m);
439 $GAUGES->{exp} ->set_text ("XP: " . ($stats->{11} || $stats->{28}) * 1
440 ." LVL: " . $stats->{12} * 1);
441 my $rng = $stats->{20};
442 $rng =~ s/^Range: //; # thank you so much dear server
443 $GAUGES->{range} ->set_text ("Rng: " . $rng);
444 my $title = $stats->{21};
445 $title =~ s/^Player: //;
446 $STATWIDS->{title} ->set_text ("Title: " . $title);
447
448 $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5});
449 $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8});
450 $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9});
451 $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6});
452 $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7});
453 $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22});
454 $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10});
455 $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13});
456 $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14});
457 $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15});
458 $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16});
459 $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17});
460 $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19});
461
462 my %tbl = (
463 phys => 100,
464 magic => 101,
465 fire => 102,
466 elec => 103,
467 cold => 104,
468 conf => 105,
469 acid => 106,
470 drain => 107,
471 ghit => 108,
472 pois => 109,
473 slow => 110,
474 para => 111,
475 tund => 112,
476 fear => 113,
477 depl => 113,
478 deat => 115,
479 holyw => 116,
480 blind => 117
481 );
482
483 for (keys %tbl) {
484 $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}});
485 }
486
174} 487}
175 488
176sub metaserver_dialog { 489sub metaserver_dialog {
177 my $dialog = new CFClient::UI::FancyFrame 490 my $dialog = new CFClient::UI::FancyFrame
491 title => "Metaserver",
178 child => (my $vbox = new CFClient::UI::VBox); 492 child => (my $vbox = new CFClient::UI::VBox);
179 493
180 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 494 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
181 495
182 $dialog 496 $dialog
239 $HOST->set_text ($CFG->{host} = $host); 553 $HOST->set_text ($CFG->{host} = $host);
240 }), 554 }),
241 (new CFClient::UI::Empty expand => 1), 555 (new CFClient::UI::Empty expand => 1),
242 ]); 556 ]);
243 557
244 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 558 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
245 for 0 .. $#$m; 559 for 0 .. $#$m;
246 } 560 }
247 } 561 }
248 }); 562 });
249} 563}
250 564
251sub server_setup { 565sub server_setup {
252 my $dialog = new CFClient::UI::FancyFrame 566 my $dialog = new CFClient::UI::FancyFrame
567 title => "Server Setup",
253 child => (my $vbox = new CFClient::UI::VBox); 568 child => (my $vbox = new CFClient::UI::VBox);
254 569
255 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
256 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 570 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
257 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 571 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
258 572
259 { 573 {
260 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 574 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
261 575
262 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 576 $vbox->add (
577 my $HOST = new CFClient::UI::Entry
578 expand => 1,
579 text => $CFG->{host},
580 tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
581 connect_changed => sub {
582 my ($self, $value) = @_;
583 $CFG->{host} = $value;
584 }
585 );
586
587 $METASERVER = metaserver_dialog;
588
589 $vbox->add (new CFClient::UI::Flopper
590 expand => 1,
591 text => "Metaserver",
592 other => $METASERVER,
593 tooltip => "Show a list of avaible crossfire servers",
594 connect_open => sub {
595 update_metaserver $HOST;
596 }
597 );
598 }
599
600 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
601 $table->add (1, 4, new CFClient::UI::Entry
602 text => $CFG->{user},
603 tooltip => "The name of your character on the server",
604 connect_changed => sub {
263 my ($self, $value) = @_; 605 my ($self, $value) = @_;
264 $CFG->{host} = $value; 606 $CFG->{user} = $value;
265 }); 607 }
608 );
266 609
267 $METASERVER = metaserver_dialog;
268
269 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub {
270 update_metaserver $HOST;
271 });
272 }
273
274 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 610 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
275 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 611 $table->add (1, 5, new CFClient::UI::Entry
612 text => $CFG->{password},
613 hidden => 1,
614 tooltip => "The password for your character",
615 connect_changed => sub {
276 my ($self, $value) = @_; 616 my ($self, $value) = @_;
277 $CFG->{user} = $value;
278 });
279
280 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
281 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
282 my ($self, $value) = @_;
283 $CFG->{password} = $value; 617 $CFG->{password} = $value;
618 }
284 }); 619 );
285 620
286 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 621 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
287 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 622 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry
623 text => $CFG->{say_command},
624 tooltip => "This is the command that will be used if you write a line in the message window entry. "
625 ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
626 ."But you could also set it to 'tell <playername>' to only chat with that user.",
627 connect_changed => sub {
288 my ($self, $value) = @_; 628 my ($self, $value) = @_;
289 $CFG->{say_command} = $value; 629 $CFG->{say_command} = $value;
630 }
290 }); 631 );
291 632
292 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 633 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
293 $table->add (1, 7, new CFClient::UI::Slider 634 $table->add (1, 7, new CFClient::UI::Slider
294 req_w => 100, 635 req_w => 100,
295 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 636 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
637 tooltip => "This is the size of the portion of the map update the server sends you. "
638 ."If you set this to a high value you will be able to see further for example.",
296 connect_changed => sub { 639 connect_changed => sub {
297 my ($self, $value) = @_; 640 my ($self, $value) = @_;
298 641
299 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 642 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
300 }, 643 },
307 $dialog 650 $dialog
308} 651}
309 652
310sub message_window { 653sub message_window {
311 my $window = new CFClient::UI::FancyFrame 654 my $window = new CFClient::UI::FancyFrame
655 title => "Messages",
312 border_bg => [1, 1, 1, 0.5], 656 border_bg => [1, 1, 1, 0.5],
313 bg => [0.3, 0.3, 0.3, 0.8], 657 bg => [0.3, 0.3, 0.3, 0.8],
314 user_w => int $::WIDTH / 3, 658 user_w => int $::WIDTH / 3,
315 user_h => int $::HEIGHT / 5, 659 user_h => int $::HEIGHT / 5,
316 child => (my $vbox = new CFClient::UI::VBox); 660 child => (my $vbox = new CFClient::UI::VBox);
317 661
318 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 662 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
319 expand => 1, 663 expand => 1,
664 font => $FONT_FIXED,
320 fontsize => $::CFG->{log_fontsize}, 665 fontsize => $::CFG->{log_fontsize},
321 ); 666 );
322 667
323 $vbox->add (my $input = new CFClient::UI::Entry 668 $vbox->add (my $input = new CFClient::UI::Entry
324 connect_focus_in => sub { 669 connect_focus_in => sub {
358 703
359 $window 704 $window
360} 705}
361 706
362sub sdl_init { 707sub sdl_init {
363 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 708 CFClient::SDL_Init
364 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
365 and die "SDL::Init failed!\n"; 709 and die "SDL::Init failed!\n";
366} 710}
367 711
368sub video_init { 712sub video_init {
369 sdl_init; 713 sdl_init;
370 714
371 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 715 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
372 $FULLSCREEN = $CFG->{fullscreen}; 716 $FULLSCREEN = $CFG->{fullscreen};
373 $FAST = $CFG->{fast}; 717 $FAST = $CFG->{fast};
374 718
375 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 719 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
376 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
377 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
378 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
379
380 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
381 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
382 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
383 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
384
385 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
386 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
387 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
388
389 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
390 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
391 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
392 or die "SDL::SetVideoMode failed!\n"; 720 or die "SDL_SetVideoMode failed!\n";
393
394 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
395
396 $SDL_EV = new SDL::Event;
397 $SDL_EV->set_unicode (1);
398 721
399 $SDL_ACTIVE = 1; 722 $SDL_ACTIVE = 1;
400 723
401 $LAST_REFRESH = time - 0.01; 724 $LAST_REFRESH = time - 0.01;
402 725
403 CFClient::gl_init; 726 CFClient::gl_init;
404 727
405 $FONTSIZE = int $HEIGHT / 40; 728 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
406 729
407 ############################################################################# 730 #############################################################################
408 731
409 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 732 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
410 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 733 $DEBUG_STATUS->show;
411 734
412 $STATUS_LINE = new CFClient::UI::Label 735 $STATUS_LINE = new CFClient::UI::Label
413 padding => 0, 736 padding => 0,
414 y => $HEIGHT * 44 / 45 - $FONTSIZE; 737 y => $HEIGHT - $FONTSIZE * 1.8;
415 $CFClient::UI::ROOT->add ($STATUS_LINE); 738 $STATUS_LINE->show;
416 739
417 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 740 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
418 padding => 0, 741 padding => 0,
419 y => $HEIGHT * 44 / 45,
420 fontsize => $HEIGHT / 45, 742 fontsize => 0.8,
421 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 743 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
422 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 744 $ALT_ENTER_MESSAGE->show;
745 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
423 746
424 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 747 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
425 $MAPWIDGET->focus_in; 748 $MAPWIDGET->focus_in;
426 $MAPWIDGET->connect (activate_console => sub { 749 $MAPWIDGET->connect (activate_console => sub {
427 my ($mapwidget, $preset) = @_; 750 my ($mapwidget, $preset) = @_;
428 751
429 if ($CONSOLE) { 752 if ($CONSOLE) {
439 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); 762 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
440 763
441 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 764 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
442 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 765 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
443 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 766 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
767
768 $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
769 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
444 770
445 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 771 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
446 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 772 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
447 status "Configuration Saved"; 773 status "Configuration Saved";
448 }); 774 });
449 775
450 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 776 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
451
452 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
453 $tgw->add (my $hbox = new CFClient::UI::HBox ());
454
455 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
456 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
457 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
458 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
459
460 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
461 $CFClient::UI::ROOT->add ($tgw);
462} 777}
463 778
464sub video_shutdown { 779sub video_shutdown {
465 $CFClient::UI::ROOT->{children} = []; 780 $CFClient::UI::ROOT->{children} = [];
466 undef $SDL_ACTIVE; 781 undef $SDL_ACTIVE;
467 undef $SDL_EV; 782}
783
784my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
785my $bgmusic;#TODO#hack#d#
786
787sub audio_music_finished {
788 return unless $CFG->{bgm_enable};
789
790 # TODO: hack, do play loop and mood music
791 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
792 $bgmusic->play (0);
793
794 push @bgmusic, shift @bgmusic;
468} 795}
469 796
470sub audio_init { 797sub audio_init {
471 if ($CFG->{sound} || 1) { 798 if ($CFG->{audio_enable}) {
472 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 799 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
473 $SDL_MIXER = new SDL::Mixer; 800 $SDL_MIXER = !CFClient::Mix_OpenAudio;
474 $SDL_MIXER->allocate_channels (8); 801 CFClient::Mix_AllocateChannels 8;
802 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
803
804 audio_music_finished;
475 805
476 while (<$fh>) { 806 while (<$fh>) {
477 next if /^\s*#/; 807 next if /^\s*#/;
478 next if /^\s*$/; 808 next if /^\s*$/;
479 809
480 my ($file, $volume, $event) = split /\s+/, $_, 3; 810 my ($file, $volume, $event) = split /\s+/, $_, 3;
481 811
482 push @SOUNDS, "$volume,$file"; 812 push @SOUNDS, "$volume,$file";
483 813
484 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 814 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
485 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 815 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
486 $chunk->volume ($volume * 128 / 100); 816 $chunk->volume ($volume * 128 / 100);
487 $chunk 817 $chunk
488 }; 818 };
489 } 819 }
490 } else { 820 } else {
492 } 822 }
493 } 823 }
494} 824}
495 825
496sub audio_shutdown { 826sub audio_shutdown {
827 CFClient::Mix_CloseAudio if $SDL_MIXER;
497 undef $SDL_MIXER; 828 undef $SDL_MIXER;
498 @SOUNDS = (); 829 @SOUNDS = ();
499 %AUDIO_CHUNKS = (); 830 %AUDIO_CHUNKS = ();
500} 831}
501 832
514 $want_refresh = 0; 845 $want_refresh = 0;
515 $can_refresh = 0; 846 $can_refresh = 0;
516 847
517 $CFClient::UI::ROOT->draw; 848 $CFClient::UI::ROOT->draw;
518 849
519 SDL::GLSwapBuffers; 850 CFClient::SDL_GL_SwapBuffers;
520 851
521 $LAST_REFRESH = $NOW; 852 $LAST_REFRESH = $NOW;
522} 853}
523 854
524my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 855my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
525 $NOW = time; 856 $NOW = time;
526 857
527 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 858 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
528 while $SDL_EV->poll; 859 for CFClient::SDL_PollEvent;
529 860
530 if (%animate_object) { 861 if (%animate_object) {
531 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 862 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
532 $want_refresh++; 863 $want_refresh++;
533 } 864 }
556@conn::ISA = Crossfire::Protocol::; 887@conn::ISA = Crossfire::Protocol::;
557 888
558sub conn::stats_update { 889sub conn::stats_update {
559 my ($self, $stats) = @_; 890 my ($self, $stats) = @_;
560 891
561 # i love text protocols!!! 892 update_stats_window ($stats);
562 # FIXME: the stats are somehow weird
563 my $hp = $stats->{1};
564 my $hp_m = $stats->{2};
565 my $sp = $stats->{3};
566 my $sp_m = $stats->{4};
567 my $fo = $stats->{18};
568 my $fo_m = 1000;
569 my $gr = $stats->{23};
570 my $gr_m = $stats->{24};
571
572 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
573 $GAUGES->{hp}->set_value ($hp, $hp_m);
574 $GAUGES->{mana}->set_value ($sp, $sp_m);
575 $GAUGES->{food}->set_value ($fo, $fo_m);
576 $GAUGES->{grace}->set_value ($gr, $gr_m);
577} 893}
578 894
579sub conn::user_send { 895sub conn::user_send {
580 my ($self, $command) = @_; 896 my ($self, $command) = @_;
581 897
606 922
607 my ($hash, $x, $y, $w, $h) = @$map_info; 923 my ($hash, $x, $y, $w, $h) = @$map_info;
608 924
609 my $data = $MAP->get_rect ($x, $y, $w, $h); 925 my $data = $MAP->get_rect ($x, $y, $w, $h);
610 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 926 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
611
612 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 927 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
613
614} 928}
615 929
616sub conn::map_clear { 930sub conn::map_clear {
617 my ($self) = @_; 931 my ($self) = @_;
618 932
619 $self->flush_map; 933 $self->flush_map;
620 delete $self->{neigh}; 934 delete $self->{neigh_map};
621 935
622 $MAP->clear; 936 $MAP->clear;
623} 937}
624 938
625 939
626sub conn::load_map($$$) { 940sub conn::load_map($$$) {
627 my ($self, $hash, $x, $y) = @_; 941 my ($self, $hash, $x, $y) = @_;
628 942
629 if (defined (my $data = $MAPCACHE->get ($hash))) { 943 if (defined (my $data = $MAPCACHE->get ($hash))) {
630 $data = Compress::LZF::decompress $data; 944 $data = Compress::LZF::decompress $data;
631 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 945 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
632 for my $id ($MAP->set_rect ($x, $y, $data)) { 946 for my $id ($MAP->set_rect ($x, $y, $data)) {
633 my $data = $TILECACHE->get ($id) 947 my $data = $TILECACHE->get ($id)
634 or next; 948 or next;
635 949
636 $self->set_texture ($id => $data); 950 $self->set_texture ($id => $data);
637 } 951 }
638 } 952 }
639} 953}
640 954
955# this method does a "flood fill" into every tile direction
956# it assumes that tiles are arranged in a rectangular grid,
957# i.e. a map is the same as the left of the right map etc.
958# failure to comply are harmless and result in display errors
959# at worst.
641sub conn::flood_fill { 960sub conn::flood_fill {
642 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 961 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
643 962
644 # the server does not allow map paths > 6 963 # the server does not allow map paths > 6
645 return if 6 <= length $path; 964 return if 6 <= length $path;
646 965
647 for my $tile (1..4) { 966 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
648 next if $self->{neigh}{$hash}[$tile]; 967
968 for (
969 [1, 0, -1],
970 [2, 1, 0],
971 [3, 0, 1],
972 [4, -1, 0],
973 ) {
974 my ($tile, $dx, $dy) = @$_;
975
976 my $gx = $gx + $dx;
977 my $gy = $gy + $dy;
978
649 next unless $flags & (1 << ($tile - 1)); 979 next unless $flags & (1 << ($tile - 1));
980 next if $self->{neigh_grid}{$gx, $gy}++;
650 981
651 my $neigh = $self->{neigh}{$hash} ||= []; 982 my $neigh = $self->{neigh_map}{$hash} ||= [];
652 983 if (my $info = $neigh->[$tile]) {
653 $self->send_mapinfo ("spatial $path$tile", sub {
654 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 984 my ($flags, $x, $y, $w, $h, $hash) = @$info;
655 985
656 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
657 return if $mode ne "spatial";
658
659 $x += $MAP->ox;
660 $y += $MAP->oy;
661
662 $self->load_map ($hash, $x, $y)
663 unless $self->{neigh}{$hash}[5]++;#d#
664
665 $neigh->[$tile] = [$x, $y, $w, $h];
666
667 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 986 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
668 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 987 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
988
989 } else {
990 $self->send_mapinfo ("spatial $path$tile", sub {
991 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
992
993 return if $mode ne "spatial";
994
995 $x += $MAP->ox;
996 $y += $MAP->oy;
997
998 $self->load_map ($hash, $x, $y)
999 unless $self->{neigh_map}{$hash}[5]++;#d#
1000
1001 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
1002
1003 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
1004 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
1005 });
669 }); 1006 }
670 } 1007 }
671} 1008}
672 1009
673sub conn::map_change { 1010sub conn::map_change {
674 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 1011 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
677 1014
678 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 1015 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
679 1016
680 my $mapmapw = 250; 1017 my $mapmapw = 250;
681 my $mapmaph = 250; 1018 my $mapmaph = 250;
1019
1020 $self->{neigh_rect} = [
1021 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
1022 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
1023 ];
682 1024
1025 delete $self->{neigh_grid};
683 $self->flood_fill ("", $hash, $flags, 1026 $self->flood_fill (0, 0, "", $hash, $flags);
684 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
685 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
686 1027
687 $x += $ox; 1028 $x += $ox;
688 $y += $oy; 1029 $y += $oy;
689 1030
690 $self->{map_info} = [$hash, $x, $y, $w, $h]; 1031 $self->{map_info} = [$hash, $x, $y, $w, $h];
1032
1033 my $map = $self->{map_info}[0];
1034 $map =~ s/^.*?\/([^\/]+)$/\1/;
1035 $STATWIDS->{map}->set_text ("Map: " . $map);
691 1036
692 $self->load_map ($hash, $x, $y); 1037 $self->load_map ($hash, $x, $y);
693} 1038}
694 1039
695sub conn::face_find { 1040sub conn::face_find {
750} 1095}
751 1096
752sub conn::sound_play { 1097sub conn::sound_play {
753 my ($self, $x, $y, $soundnum, $type) = @_; 1098 my ($self, $x, $y, $soundnum, $type) = @_;
754 1099
1100 $SDL_MIXER
1101 or return;
1102
755 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 1103 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
756 or return; 1104 or return;
757 1105
758 $SDL_MIXER->play_channel (-1, $chunk); 1106 $chunk->play;
759 warn "sound $x,$y,$soundnum,$type\n";#d# 1107# warn "sound $x,$y,$soundnum,$type\n";#d#
760} 1108}
761 1109
762sub conn::query { 1110sub conn::query {
763 my ($self, $flags, $prompt) = @_; 1111 my ($self, $flags, $prompt) = @_;
764 1112
765 #TODO 1113 #TODO, display dialog with relevant information
766 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 1114 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
767} 1115}
768 1116
769sub conn::drawinfo { 1117sub conn::drawinfo {
770 my ($self, $color, $text) = @_; 1118 my ($self, $color, $text) = @_;
786 ); 1134 );
787 1135
788 $LOGVIEW->add_paragraph ($color[$color], $text); 1136 $LOGVIEW->add_paragraph ($color[$color], $text);
789} 1137}
790 1138
1139sub conn::spell_add {
1140 my ($self, $spell) = @_;
1141
1142 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
1143 });
1144 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
1145 });
1146}
1147
1148sub conn::spell_delete {
1149 my ($self, $spell) = @_;
1150}
1151
1152sub conn::addme_success {
1153 my ($self) = @_;
1154
1155 for my $skill (values %{$self->{skill_info}}) {
1156 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
1157 });
1158 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
1159 });
1160 }
1161}
1162
791%SDL_CB = ( 1163%SDL_CB = (
792 SDL_QUIT() => sub { 1164 CFClient::SDL_QUIT => sub {
793 Event::unloop -1; 1165 Event::unloop -1;
794 }, 1166 },
795 SDL_VIDEORESIZE() => sub { 1167 CFClient::SDL_VIDEORESIZE => sub {
796 }, 1168 },
797 SDL_VIDEOEXPOSE() => sub { 1169 CFClient::SDL_VIDEOEXPOSE => \&refresh,
798 refresh; 1170 CFClient::SDL_ACTIVEEVENT => sub {
1171# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
799 }, 1172 },
800 SDL_KEYDOWN() => sub { 1173 CFClient::SDL_KEYDOWN => sub {
801 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 1174 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
802 # alt-enter 1175 # alt-enter
803 video_shutdown; 1176 video_shutdown;
804 $CFG->{fullscreen} = !$CFG->{fullscreen}; 1177 $CFG->{fullscreen} = !$CFG->{fullscreen};
805 video_init; 1178 video_init;
806 } else { 1179 } else {
807 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 1180 CFClient::UI::feed_sdl_key_down_event ($_[0]);
808 } 1181 }
809 }, 1182 },
810 SDL_KEYUP() => sub { 1183 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
811 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 1184 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
812 }, 1185 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
813 SDL_MOUSEMOTION() => sub { 1186 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
814 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 1187 CFClient::SDL_USEREVENT => \&audio_music_finished,
815 },
816 SDL_MOUSEBUTTONDOWN() => sub {
817 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
818 },
819 SDL_MOUSEBUTTONUP() => sub {
820 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
821 },
822 SDL_ACTIVEEVENT() => sub {
823# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
824 },
825); 1188);
826 1189
827############################################################################# 1190#############################################################################
828 1191
829$SIG{INT} = $SIG{TERM} = sub { exit }; 1192$SIG{INT} = $SIG{TERM} = sub { exit };
840 fullscreen => 0, 1203 fullscreen => 0,
841 fast => 0, 1204 fast => 0,
842 fow_enable => 1, 1205 fow_enable => 1,
843 fow_intensity => 0.45, 1206 fow_intensity => 0.45,
844 fow_smooth => 0, 1207 fow_smooth => 0,
1208 gui_fontsize => 1,
845 log_fontsize => 14, 1209 log_fontsize => 1,
1210 gauge_fontsize => 1,
1211 gauge_size => 0.35,
1212 stat_fontsize => 1,
846 mapsize => 100, 1213 mapsize => 100,
847 host => "crossfire.schmorp.de", 1214 host => "crossfire.schmorp.de",
848 say_command => 'say', 1215 say_command => 'say',
1216 audio_enable => 1,
1217 bgm_enable => 1,
1218 bgm_volume => 0.25,
849); 1219);
850 1220
851while (my ($k, $v) = each %DEF_CFG) { 1221while (my ($k, $v) = each %DEF_CFG) {
852 $CFG->{$k} = $v unless exists $CFG->{$k}; 1222 $CFG->{$k} = $v unless exists $CFG->{$k};
853} 1223}
854 1224
855sdl_init; 1225sdl_init;
856 1226
857@SDL_MODES = reverse 1227@SDL_MODES = reverse
858 grep $_->[0] >= 640 && $_->[1] >= 480, 1228 grep $_->[0] >= 640 && $_->[1] >= 480,
859 map [SDL::RectW ($_), SDL::RectH ($_)], 1229 CFClient::SDL_ListModes;
860 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
861 1230
862@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 1231@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
863 1232
864$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 1233$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
865 1234
866{ 1235{
867 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 1236 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1237 DejaVuSans.ttf
1238 DejaVuSansMono.ttf
1239 DejaVuSans-Bold.ttf
1240 DejaVuSansMono-Bold.ttf
1241 DejaVuSans-Oblique.ttf
1242 DejaVuSansMono-Oblique.ttf
1243 DejaVuSans-BoldOblique.ttf
1244 DejaVuSansMono-BoldOblique.ttf
1245 );
868 1246
869 CFClient::add_font $_ for @fonts; 1247 CFClient::add_font $_ for @fonts;
870 CFClient::set_font $fonts[0]; 1248
1249 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1250 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1251
1252 $FONT_PROP->make_default;
871} 1253}
872 1254
873video_init; 1255video_init;
874audio_init; 1256audio_init;
875 1257
876Event::loop; 1258Event::loop;
877 1259
878END { SDL::Quit } 1260END { CFClient::SDL_Quit }
879 1261
880 1262

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines