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.113 by root, Sat Apr 15 19:35:22 2006 UTC vs.
Revision 1.169 by root, Mon Apr 24 02:41:48 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
12use Compress::LZF;
13
18use CFClient; 14use CFClient;
19use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
20 17
21our $VERSION = '0.1'; 18our $VERSION = '0.1';
22 19
23my $MAX_FPS = 60; 20my $MAX_FPS = 60;
24my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
25 22
26our $META_SERVER = "crossfire.real-time.com:13326"; 23our $META_SERVER = "crossfire.real-time.com:13326";
27 24
25our $FACEMAP;
26our $TILECACHE;
28our $FACECACHE; 27our $MAPCACHE;
29 28
30our $LAST_REFRESH; 29our $LAST_REFRESH;
31our $NOW; 30our $NOW;
32 31
33our $CFG; 32our $CFG;
37our @SDL_MODES; 36our @SDL_MODES;
38our $WIDTH; 37our $WIDTH;
39our $HEIGHT; 38our $HEIGHT;
40our $FULLSCREEN; 39our $FULLSCREEN;
41our $FONTSIZE; 40our $FONTSIZE;
41
42our $FONT_PROP;
43our $FONT_FIXED;
42 44
43our $MAP; 45our $MAP;
44our $MAPWIDGET; 46our $MAPWIDGET;
45our $BUTTONBAR; 47our $BUTTONBAR;
46our $LOGVIEW; 48our $LOGVIEW;
47our $CONSOLE; 49our $CONSOLE;
48our $METASERVER; 50our $METASERVER;
49 51
52our $GAUGES;
53our $STATWIDS;
54
50our $SDL_ACTIVE; 55our $SDL_ACTIVE;
51our $SDL_EV;
52our %SDL_CB; 56our %SDL_CB;
57
58our $SDL_MIXER;
59our @SOUNDS; # event => file mapping
60our %AUDIO_CHUNKS; # audio files
53 61
54our $ALT_ENTER_MESSAGE; 62our $ALT_ENTER_MESSAGE;
55our $STATUS_LINE; 63our $STATUS_LINE;
56our $DEBUG_STATUS; 64our $DEBUG_STATUS;
57 65
58sub status { 66sub status {
59 $STATUS_LINE->set_text ($_[0]); 67 $STATUS_LINE->set_text ($_[0]);
60 my ($w, $h) = $STATUS_LINE->size_request;
61 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 68 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
62} 69}
63 70
64sub debug { 71sub debug {
65 $DEBUG_STATUS->set_text ($_[0]); 72 $DEBUG_STATUS->set_text ($_[0]);
66 my ($w, $h) = $DEBUG_STATUS->size_request; 73 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
67 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
68} 74}
69 75
70sub start_game { 76sub start_game {
71 status "logging in..."; 77 status "logging in...";
72 78
73 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 79 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
80
81 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
74 82
75 $MAP = new CFClient::Map $mapsize, $mapsize; 83 $MAP = new CFClient::Map $mapsize, $mapsize;
76 84
77 my ($host, $port) = split /:/, $CFG->{host}; 85 my ($host, $port) = split /:/, $CFG->{host};
78 86
94 undef $CONN; 102 undef $CONN;
95} 103}
96 104
97sub client_setup { 105sub client_setup {
98 my $dialog = new CFClient::UI::FancyFrame 106 my $dialog = new CFClient::UI::FancyFrame
107 title => "Client Setup",
99 child => (my $vbox = new CFClient::UI::VBox); 108 child => (my $vbox = new CFClient::UI::VBox);
100 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
101 $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]);
102 110
103 $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");
104 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 112 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
105 113
106 $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]);
107 $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");
108 116
109 $mode_slider->connect (changed => sub { 117 $mode_slider->connect (changed => sub {
110 my ($self, $value) = @_; 118 my ($self, $value) = @_;
111 119
112 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 120 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
113 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 121 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
114 }); 122 });
115 $mode_slider->emit (changed => $mode_slider->{range}[0]); 123 $mode_slider->emit (changed => $mode_slider->{range}[0]);
116 124
125 my $row = 1;
126
117 $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");
118 $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 {
119 my ($self, $value) = @_; 132 my ($self, $value) = @_;
120 $CFG->{fullscreen} = $value; 133 $CFG->{fullscreen} = $value;
134 }
121 }); 135 );
122 136
123 $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");
124 $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 {
125 my ($self, $value) = @_; 142 my ($self, $value) = @_;
126 $CFG->{fast} = $value; 143 $CFG->{fast} = $value;
144 }
127 }); 145 );
128 146
129 $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");
130 $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 {
131 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) = @_;
132 $CFG->{fow_enable} = $value; 163 $CFG->{fow_enable} = $value;
164 }
133 }); 165 );
134 166
135 $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");
136 $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 {
137 my ($self, $value) = @_; 172 my ($self, $value) = @_;
138 $CFG->{fow_intensity} = $value; 173 $CFG->{fow_intensity} = $value;
174 }
139 }); 175 );
140 176
141 $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");
142 $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 {
143 my ($self, $value) = @_; 182 my ($self, $value) = @_;
144 $CFG->{fow_smooth} = $value; 183 $CFG->{fow_smooth} = $value;
184 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
185 }
186 );
187
188 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
189 $table->add (1, $row++, new CFClient::UI::Slider
190 range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1],
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 }
196 );
197
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 {
244 video_shutdown ();
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];
145 }); 260# });
146
147 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 261 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
148 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 262 $table->add (1, $row++, my $hbox = new CFClient::UI::HBox);
149 my ($self, $value) = @_; 263 $hbox->add (new CFClient::UI::CheckBox
150 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 264 expand => 1, state => $CFG->{bgm_enable},
265 tooltip => "Enable background music playing",
266 connect_changed => sub {
267 $CFG->{bgm_enable} = $_[1];
268 }
151 }); 269 );
152 270 $hbox->add (new CFClient::UI::Slider
153 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 271 expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1],
154 destroy_screen (); 272 tooltip => "The volume of the background music",
155 init_screen (); 273 connect_changed => sub {
274 $CFG->{bgm_volume} = $_[1];
275 CFClient::MixMusic::volume $_[1] * 128;
276 }
156 }); 277 );
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 {
283 audio_shutdown ();
284 audio_init ();
285 }
286 );
157 287
158 $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
159} 504}
160 505
161sub metaserver_dialog { 506sub metaserver_dialog {
162 my $dialog = new CFClient::UI::FancyFrame 507 my $dialog = new CFClient::UI::FancyFrame
508 title => "Metaserver",
163 child => (my $vbox = new CFClient::UI::VBox); 509 child => (my $vbox = new CFClient::UI::VBox);
164 510
165 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 511 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
166 512
167 $dialog 513 $dialog
168} 514}
169 515
170sub update_metaserver { 516sub update_metaserver {
517 my ($HOST) = @_;
518
171 status "fetching metaserver list..."; 519 status "fetching metaserver list...";
172 520
173 my $buf; 521 my $buf;
174 522
175 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; 523 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
186 534
187 my $table = $METASERVER->{table}; 535 my $table = $METASERVER->{table};
188 536
189 $table->clear; 537 $table->clear;
190 538
191 my @col = qw(#Users Host Uptime Version Description); 539 my @col = qw(Use #Users Host Uptime Version Description);
192 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) 540 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_])
193 for 0 .. $#col; 541 for 0 .. $#col;
194 542
195 my @align = qw(1 0 1 1 -1); 543 my @align = qw(1 0 1 1 -1);
196 544
197 my $y = 0; 545 my $y = 0;
198 for my $m (map [split /\|/], split /\015?\012/, $buf) { 546 for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) {
199 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; 547 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m;
200 548
201 for ($desc) { 549 for ($desc) {
202 s/<br>/\n/gi; 550 s/<br>/\n/gi;
203 s/<li>/\n· /gi; 551 s/<li>/\n· /gi;
214 $m->[8] % 60; 562 $m->[8] % 60;
215 563
216 $m = [$users, $host, $uptime, $version, $desc]; 564 $m = [$users, $host, $uptime, $version, $desc];
217 565
218 $y++; 566 $y++;
567
568 $table->add (0, $y, new CFClient::UI::VBox children => [
569 (new CFClient::UI::Button text => " ", connect_activate => sub {
570 $HOST->set_text ($CFG->{host} = $host);
571 }),
572 (new CFClient::UI::Empty expand => 1),
573 ]);
574
219 $table->add ($_, $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)
220 for 0 .. $#$m; 576 for 0 .. $#$m;
221 } 577 }
222 } 578 }
223 }); 579 });
224} 580}
225 581
226sub server_setup { 582sub server_setup {
227 my $dialog = new CFClient::UI::FancyFrame 583 my $dialog = new CFClient::UI::FancyFrame
584 title => "Server Setup",
228 child => (my $vbox = new CFClient::UI::VBox); 585 child => (my $vbox = new CFClient::UI::VBox);
229 586
230 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
231 $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]);
232 $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");
233 589
234 { 590 {
235 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 591 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
236 592
237 $vbox->add (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 {
238 my ($self, $value) = @_; 622 my ($self, $value) = @_;
239 $CFG->{host} = $value; 623 $CFG->{user} = $value;
240 }); 624 }
625 );
241 626
242 $METASERVER = metaserver_dialog;
243
244 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub {
245 update_metaserver;
246 });
247 }
248
249 $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");
250 $table->add (1, 4, my $user = 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 {
251 my ($self, $value) = @_; 633 my ($self, $value) = @_;
252 $CFG->{user} = $value;
253 });
254
255 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
256 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
257 my ($self, $value) = @_;
258 $CFG->{password} = $value; 634 $CFG->{password} = $value;
635 }
259 }); 636 );
260 637
261 $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");
262 $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 {
263 my ($self, $value) = @_; 645 my ($self, $value) = @_;
264 $CFG->{say_command} = $value; 646 $CFG->{say_command} = $value;
647 }
265 }); 648 );
266 649
267 $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");
268 $table->add (1, 7, new CFClient::UI::Slider 651 $table->add (1, 7, new CFClient::UI::Slider
269 req_w => 100, 652 req_w => 100,
270 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.",
271 connect_changed => sub { 656 connect_changed => sub {
272 my ($self, $value) = @_; 657 my ($self, $value) = @_;
273 658
274 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 659 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
275 }, 660 },
282 $dialog 667 $dialog
283} 668}
284 669
285sub message_window { 670sub message_window {
286 my $window = new CFClient::UI::FancyFrame 671 my $window = new CFClient::UI::FancyFrame
672 title => "Messages",
287 border_bg => [1, 1, 1, 0.5], 673 border_bg => [1, 1, 1, 0.5],
288 bg => [0.3, 0.3, 0.3, 0.8], 674 bg => [0.3, 0.3, 0.3, 0.8],
289 user_w => $::WIDTH/4, 675 user_w => int $::WIDTH / 3,
290 user_h => $::HEIGHT, 676 user_h => int $::HEIGHT / 5,
291 child => (my $vbox = new CFClient::UI::VBox); 677 child => (my $vbox = new CFClient::UI::VBox);
292 678
293 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 679 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
294 expand => 1, 680 expand => 1,
681 font => $FONT_FIXED,
295 fontsize => $::CFG->{log_fontsize}, 682 fontsize => $::CFG->{log_fontsize},
296 ); 683 );
297 684
298 $vbox->add (my $input = new CFClient::UI::LineEntry); 685 $vbox->add (my $input = new CFClient::UI::Entry
686 connect_focus_in => sub {
687 my ($input, $prev_focus) = @_;
688
689 delete $input->{refocus_map};
690
691 if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
692 $input->{refocus_map} = 1;
693 }
694 delete $input->{auto_activated};
695 },
299 $input->connect (activate => sub { 696 connect_activate => sub {
300 my ($input, $text) = @_; 697 my ($input, $text) = @_;
301 $input->set_text (''); 698 $input->set_text ('');
302 699
303 if ($text =~ /^\/(.*)/) { 700 if ($text =~ /^\/(.*)/) {
304 $::CONN->user_send ("command $1"); 701 $::CONN->user_send ($1);
305 } else { 702 } else {
306 my $say_cmd = $::CFG->{say_command} || 'say'; 703 my $say_cmd = $::CFG->{say_command} || 'say';
307 $::CONN->user_send ("command $say_cmd $text"); 704 $::CONN->user_send ("$say_cmd $text");
308 } 705 }
706 if ($input->{refocus_map}) {
707 delete $input->{refocus_map};
708 $MAPWIDGET->focus_in
309 1 709 }
310 }); 710 },
311 $input->connect (escape => sub { 711 connect_escape => sub {
312 $MAPWIDGET->focus_in 712 $MAPWIDGET->focus_in
313 }); 713 },
314 $input->focus_in; 714 );
315 715
316 $CONSOLE = { 716 $CONSOLE = {
317 window => $window, 717 window => $window,
318 input => $input 718 input => $input
319 }; 719 };
320 720
321 $window 721 $window
322} 722}
323 723
324sub sdl_init { 724sub sdl_init {
325 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 725 CFClient::SDL_Init
326 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
327 and die "SDL::Init failed!\n"; 726 and die "SDL::Init failed!\n";
328} 727}
329 728
330sub init_screen { 729sub video_init {
331 sdl_init; 730 sdl_init;
332 731
333 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 732 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
334 $FULLSCREEN = $CFG->{fullscreen}; 733 $FULLSCREEN = $CFG->{fullscreen};
335 $FAST = $CFG->{fast}; 734 $FAST = $CFG->{fast};
336 735
337 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 736 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
338 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
339 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
340 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 0;
341
342 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
343 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
344 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
345 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
346
347 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
348 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
349 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
350
351 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
352 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
353 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
354 or die "SDL::SetVideoMode failed!\n"; 737 or die "SDL_SetVideoMode failed!\n";
355
356 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
357
358 $SDL_EV = new SDL::Event;
359 $SDL_EV->set_unicode (1);
360 738
361 $SDL_ACTIVE = 1; 739 $SDL_ACTIVE = 1;
362 740
363 $LAST_REFRESH = time - 0.01; 741 $LAST_REFRESH = time - 0.01;
364 742
365 CFClient::gl_init; 743 CFClient::gl_init;
366 744
367 $FONTSIZE = int $HEIGHT / 40; 745 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
368 746
369 ############################################################################# 747 #############################################################################
370 748
371 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 749 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
372 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 750 $DEBUG_STATUS->show;
373 751
374 $STATUS_LINE = new CFClient::UI::Label 752 $STATUS_LINE = new CFClient::UI::Label
375 padding => 0, 753 padding => 0,
376 y => $HEIGHT * 44 / 45 - $FONTSIZE; 754 y => $HEIGHT - $FONTSIZE * 1.8;
377 $CFClient::UI::ROOT->add ($STATUS_LINE); 755 $STATUS_LINE->show;
378 756
379 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 757 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
380 padding => 0, 758 padding => 0,
381 y => $HEIGHT * 44 / 45, 759 fontsize => 0.8,
382 height => $HEIGHT / 45,
383 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 760 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
384 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 761 $ALT_ENTER_MESSAGE->show;
762 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
385 763
386 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 764 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
387 $MAPWIDGET->focus_in; 765 $MAPWIDGET->focus_in;
388 $MAPWIDGET->connect (activate_console => sub { 766 $MAPWIDGET->connect (activate_console => sub {
389 my ($mapwidget, $preset) = @_; 767 my ($mapwidget, $preset) = @_;
390 768
391 if ($CONSOLE) { 769 if ($CONSOLE) {
770 $CONSOLE->{input}->{auto_activated} = 1;
392 $CONSOLE->{input}->focus_in; 771 $CONSOLE->{input}->focus_in;
393 772
394 if ($preset && $CONSOLE->{input}->get_text eq '') { 773 if ($preset && $CONSOLE->{input}->get_text eq '') {
395 $CONSOLE->{input}->set_text ($preset); 774 $CONSOLE->{input}->set_text ($preset);
396 } 775 }
400 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); 779 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
401 780
402 $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);
403 $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);
404 $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);
405 787
406 $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 {
407 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 789 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
408 status "Configuration Saved"; 790 status "Configuration Saved";
409 }); 791 });
410 792
411 $BUTTONBAR->{children}[0]->emit ("activate"); 793 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
412} 794}
413 795
414sub destroy_screen { 796sub video_shutdown {
415 $CFClient::UI::ROOT->{children} = []; 797 $CFClient::UI::ROOT->{children} = [];
416 undef $SDL_ACTIVE; 798 undef $SDL_ACTIVE;
799}
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#
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}
813
814sub audio_init {
815 if ($CFG->{audio_enable}) {
816 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
817 $SDL_MIXER = !CFClient::Mix_OpenAudio;
818 CFClient::Mix_AllocateChannels 8;
819 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
820
821 audio_music_finished;
822
823 while (<$fh>) {
824 next if /^\s*#/;
825 next if /^\s*$/;
826
827 my ($file, $volume, $event) = split /\s+/, $_, 3;
828
829 push @SOUNDS, "$volume,$file";
830
831 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
832 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
833 $chunk->volume ($volume * 128 / 100);
834 $chunk
835 };
836 }
837 } else {
838 status "unable to open sound config: $!";
839 }
840 }
841}
842
843sub audio_shutdown {
844 CFClient::Mix_CloseAudio if $SDL_MIXER;
417 undef $SDL_EV; 845 undef $SDL_MIXER;
418 SDL::Quit; 846 @SOUNDS = ();
847 %AUDIO_CHUNKS = ();
419} 848}
420 849
421my %animate_object; 850my %animate_object;
422my $animate_timer; 851my $animate_timer;
423 852
433 $want_refresh = 0; 862 $want_refresh = 0;
434 $can_refresh = 0; 863 $can_refresh = 0;
435 864
436 $CFClient::UI::ROOT->draw; 865 $CFClient::UI::ROOT->draw;
437 866
438 SDL::GLSwapBuffers; 867 CFClient::SDL_GL_SwapBuffers;
439 868
440 $LAST_REFRESH = $NOW; 869 $LAST_REFRESH = $NOW;
441} 870}
442 871
443my $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 {
444 $NOW = time; 873 $NOW = time;
445 874
446 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 875 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
447 while $SDL_EV->poll; 876 for CFClient::SDL_PollEvent;
448 877
449 if (%animate_object) { 878 if (%animate_object) {
450 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 879 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
451 $want_refresh++; 880 $want_refresh++;
452 } 881 }
472 delete $animate_object{$widget}; 901 delete $animate_object{$widget};
473} 902}
474 903
475@conn::ISA = Crossfire::Protocol::; 904@conn::ISA = Crossfire::Protocol::;
476 905
906sub conn::stats_update {
907 my ($self, $stats) = @_;
908
909 update_stats_window ($stats);
910}
911
477sub conn::user_send { 912sub conn::user_send {
478 my ($self, $command) = @_; 913 my ($self, $command) = @_;
479 914
480 $self->send ($command); 915 $self->send_command ($command);
481 status $command; 916 status $command;
917}
918
919sub conn::map_scroll {
920 my ($self, $dx, $dy) = @_;
921
922 $MAP->scroll ($dx, $dy);
482} 923}
483 924
484sub conn::feed_map1a { 925sub conn::feed_map1a {
485 my ($self, $data) = @_; 926 my ($self, $data) = @_;
486 927
487# $self->Crossfire::Protocol::feed_map1a ($data); 928# $self->Crossfire::Protocol::feed_map1a ($data);
488 929
489 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y});
490 $MAP->map1a_update ($data); 930 $MAP->map1a_update ($data);
491 $MAPWIDGET->update; 931 $MAPWIDGET->update;
492} 932}
493 933
494#sub conn::map_update { 934sub conn::flush_map {
495# my ($self, $dirty) = @_; 935 my ($self) = @_;
496# 936
497# $MAPWIDGET->update; 937 my $map_info = delete $self->{map_info}
498#} 938 or return;
939
940 my ($hash, $x, $y, $w, $h) = @$map_info;
941
942 my $data = $MAP->get_rect ($x, $y, $w, $h);
943 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
944 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
945}
499 946
500sub conn::map_clear { 947sub conn::map_clear {
501 my ($self) = @_; 948 my ($self) = @_;
502 949
950 $self->flush_map;
951 delete $self->{neigh_map};
952
503 $MAP->clear; 953 $MAP->clear;
954}
504 955
505# refresh; 956
957sub conn::load_map($$$) {
958 my ($self, $hash, $x, $y) = @_;
959
960 if (defined (my $data = $MAPCACHE->get ($hash))) {
961 $data = Compress::LZF::decompress $data;
962 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
963 for my $id ($MAP->set_rect ($x, $y, $data)) {
964 my $data = $TILECACHE->get ($id)
965 or next;
966
967 $self->set_texture ($id => $data);
968 }
969 }
970}
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.
977sub conn::flood_fill {
978 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
979
980 # the server does not allow map paths > 6
981 return if 6 <= length $path;
982
983 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
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
996 next unless $flags & (1 << ($tile - 1));
997 next if $self->{neigh_grid}{$gx, $gy}++;
998
999 my $neigh = $self->{neigh_map}{$hash} ||= [];
1000 if (my $info = $neigh->[$tile]) {
1001 my ($flags, $x, $y, $w, $h, $hash) = @$info;
1002
1003 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
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 });
1023 }
1024 }
1025}
1026
1027sub conn::map_change {
1028 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
1029
1030 $self->flush_map;
1031
1032 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
1033
1034 my $mapmapw = 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 ];
1041
1042 delete $self->{neigh_grid};
1043 $self->flood_fill (0, 0, "", $hash, $flags);
1044
1045 $x += $ox;
1046 $y += $oy;
1047
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);
1053
1054 $self->load_map ($hash, $x, $y);
506} 1055}
507 1056
508sub conn::face_find { 1057sub conn::face_find {
509 my ($self, $face) = @_; 1058 my ($self, $facenum, $face) = @_;
510 1059
511 $FACECACHE->{"$face->{chksum},$face->{name}"} 1060 my $hash = "$face->{chksum},$face->{name}";
1061
1062 my $id = $FACEMAP->get ($hash);
1063
1064 unless ($id) {
1065 # create new id for face
1066 # i love transactions
1067 for (1..100) {
1068 my $txn = $CFClient::DB_ENV->txn_begin;
1069 my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW);
1070 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
1071 $id++;
1072 if ($FACEMAP->put (id => $id) == 0
1073 && $FACEMAP->put ($hash => $id) == 0) {
1074 $txn->txn_commit;
1075
1076 goto gotid;
1077 }
1078 }
1079 $txn->abort;
1080 }
1081
1082 CFClient::fatal "maximum number of transaction retries reached - database problems?";
1083 }
1084
1085gotid:
1086 $face->{id} = $id;
1087 $MAP->set_face ($facenum => $id);
1088 $TILECACHE->get ($id)
512} 1089}
513 1090
514sub conn::face_update { 1091sub conn::face_update {
515 my ($self, $facenum, $face) = @_; 1092 my ($self, $facenum, $face) = @_;
516 1093
517 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 1094 $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes
518 1095
519 my $tex = $face->{texture} = 1096 $self->set_texture ($face->{id} => delete $face->{image});
1097}
1098
1099sub conn::set_texture {
1100 my ($self, $id, $data) = @_;
1101
1102 $self->{texture}[$id] ||= do {
1103 my $tex =
520 new_from_image CFClient::Texture 1104 new_from_image CFClient::Texture
521 delete $face->{image}, minify => 1; 1105 $data, minify => 1;
522 1106
523 $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}, @{$tex->{minified}}); 1107 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
524 $MAPWIDGET->update; 1108 $MAPWIDGET->update;
1109
1110 $tex
1111 };
1112}
1113
1114sub conn::sound_play {
1115 my ($self, $x, $y, $soundnum, $type) = @_;
1116
1117 $SDL_MIXER
1118 or return;
1119
1120 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
1121 or return;
1122
1123 $chunk->play;
1124# warn "sound $x,$y,$soundnum,$type\n";#d#
525} 1125}
526 1126
527sub conn::query { 1127sub conn::query {
528 my ($self, $flags, $prompt) = @_; 1128 my ($self, $flags, $prompt) = @_;
529 1129
530 #TODO 1130 #TODO, display dialog with relevant information
531 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 1131 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
532} 1132}
533 1133
534sub conn::drawinfo { 1134sub conn::drawinfo {
535 my ($self, $color, $text) = @_; 1135 my ($self, $color, $text) = @_;
536 1136
537 my @color = ( 1137 my @color = (
538 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 1138 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
539 [1.00, 1.00, 1.00], 1139 [1.00, 1.00, 1.00],
540 [0.00, 0.00, 0.55], 1140 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
541 [1.00, 0.00, 0.00], 1141 [1.00, 0.00, 0.00],
542 [1.00, 0.54, 0.00], 1142 [1.00, 0.54, 0.00],
543 [0.11, 0.56, 1.00], 1143 [0.11, 0.56, 1.00],
544 [0.93, 0.46, 0.00], 1144 [0.93, 0.46, 0.00],
545 [0.18, 0.54, 0.34], 1145 [0.18, 0.54, 0.34],
551 ); 1151 );
552 1152
553 $LOGVIEW->add_paragraph ($color[$color], $text); 1153 $LOGVIEW->add_paragraph ($color[$color], $text);
554} 1154}
555 1155
1156sub conn::spell_add {
1157 my ($self, $spell) = @_;
1158
1159 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
1160 });
1161 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
1162 });
1163}
1164
1165sub conn::spell_delete {
1166 my ($self, $spell) = @_;
1167}
1168
1169sub conn::addme_success {
1170 my ($self) = @_;
1171
1172 for my $skill (values %{$self->{skill_info}}) {
1173 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
1174 });
1175 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
1176 });
1177 }
1178}
1179
1180sub conn::container_add {
1181 my ($self, $id, $items) = @_;
1182
1183 # 0 floor
1184 # $self-<{player}{tag} => player inv
1185 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1186}
1187
1188sub conn::container_clear {
1189 my ($self, $id) = @_;
1190# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1191}
1192
556%SDL_CB = ( 1193%SDL_CB = (
557 SDL_QUIT() => sub { 1194 CFClient::SDL_QUIT => sub {
558 Event::unloop -1; 1195 Event::unloop -1;
559 }, 1196 },
560 SDL_VIDEORESIZE() => sub { 1197 CFClient::SDL_VIDEORESIZE => sub {
561 }, 1198 },
562 SDL_VIDEOEXPOSE() => sub { 1199 CFClient::SDL_VIDEOEXPOSE => \&refresh,
563 refresh;
564 },
565 SDL_KEYDOWN() => sub {
566 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
567 # alt-enter
568 destroy_screen;
569 $CFG->{fullscreen} = !$CFG->{fullscreen};
570 init_screen;
571 } else {
572 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
573 }
574 },
575 SDL_KEYUP() => sub {
576 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
577 },
578 SDL_MOUSEMOTION() => sub {
579 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
580 },
581 SDL_MOUSEBUTTONDOWN() => sub {
582 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
583 },
584 SDL_MOUSEBUTTONUP() => sub {
585 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
586 },
587 SDL_ACTIVEEVENT() => sub { 1200 CFClient::SDL_ACTIVEEVENT => sub {
588# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1201# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
589 }, 1202 },
1203 CFClient::SDL_KEYDOWN => sub {
1204 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1205 # alt-enter
1206 video_shutdown;
1207 $CFG->{fullscreen} = !$CFG->{fullscreen};
1208 video_init;
1209 } else {
1210 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1211 }
1212 },
1213 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1214 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1215 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1216 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1217 CFClient::SDL_USEREVENT => \&audio_music_finished,
590); 1218);
591 1219
592############################################################################# 1220#############################################################################
1221
1222$SIG{INT} = $SIG{TERM} = sub { exit };
1223
1224$TILECACHE = CFClient::db_table "tilecache";
1225$FACEMAP = CFClient::db_table "facemap";
593 1226
594CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 1227CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
595 1228
596my %DEF_CFG = ( 1229my %DEF_CFG = (
597 sdl_mode => 0, 1230 sdl_mode => 0,
598 width => 640, 1231 width => 640,
599 height => 480, 1232 height => 480,
600 fullscreen => 0, 1233 fullscreen => 0,
601 fast => 0, 1234 fast => 0,
1235 map_scale => 0.5,
602 fow_enable => 1, 1236 fow_enable => 1,
603 fow_intensity => 0.45, 1237 fow_intensity => 0.45,
604 fow_smooth => 0, 1238 fow_smooth => 0,
1239 gui_fontsize => 1,
605 log_fontsize => 14, 1240 log_fontsize => 1,
1241 gauge_fontsize => 1,
1242 gauge_size => 0.35,
1243 stat_fontsize => 1,
606 mapsize => 100, 1244 mapsize => 100,
607 host => "crossfire.schmorp.de", 1245 host => "crossfire.schmorp.de",
608 say_command => 'say', 1246 say_command => 'say',
1247 audio_enable => 1,
1248 bgm_enable => 1,
1249 bgm_volume => 0.25,
609); 1250);
610 1251
611while (my ($k, $v) = each %DEF_CFG) { 1252while (my ($k, $v) = each %DEF_CFG) {
612 $CFG->{$k} = $v unless exists $CFG->{$k}; 1253 $CFG->{$k} = $v unless exists $CFG->{$k};
613} 1254}
614 1255
615sdl_init; 1256sdl_init;
616 1257
617@SDL_MODES = reverse 1258@SDL_MODES = reverse
618 grep $_->[0] >= 640 && $_->[1] >= 480, 1259 grep $_->[0] >= 640 && $_->[1] >= 480,
619 map [SDL::RectW ($_), SDL::RectH ($_)], 1260 CFClient::SDL_ListModes;
620 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
621 1261
622@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 1262@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
623 1263
624$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 1264$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
625 1265
626init_screen;
627
628{ 1266{
629 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 1267 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1268 DejaVuSans.ttf
1269 DejaVuSansMono.ttf
1270 DejaVuSans-Bold.ttf
1271 DejaVuSansMono-Bold.ttf
1272 DejaVuSans-Oblique.ttf
1273 DejaVuSansMono-Oblique.ttf
1274 DejaVuSans-BoldOblique.ttf
1275 DejaVuSansMono-BoldOblique.ttf
1276 );
630 1277
631 CFClient::add_font $_ for @fonts; 1278 CFClient::add_font $_ for @fonts;
632 CFClient::set_font $fonts[0]; 1279
633} 1280 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1281 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
634 1282
635$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 1283 $FONT_PROP->make_default;
1284}
1285
1286video_init;
1287audio_init;
636 1288
637Event::loop; 1289Event::loop;
638 1290
639Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; 1291END { CFClient::SDL_Quit }
640 1292
1293

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines