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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines