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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines