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.125 by elmex, Mon Apr 17 20:29:37 2006 UTC vs.
Revision 1.161 by elmex, Sun Apr 23 00:08:31 2006 UTC

4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL;
10use SDL::App;
11use SDL::Event;
12use SDL::Surface;
13use SDL::OpenGL;
14
15use Crossfire; 9use Crossfire;
16use Crossfire::Protocol; 10use Crossfire::Protocol;
17 11
18use Compress::LZF; 12use Compress::LZF;
19 13
20use CFClient; 14use CFClient;
21use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
22 17
23our $VERSION = '0.1'; 18our $VERSION = '0.1';
24 19
25my $MAX_FPS = 60; 20my $MAX_FPS = 60;
26my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
50our $LOGVIEW; 45our $LOGVIEW;
51our $CONSOLE; 46our $CONSOLE;
52our $METASERVER; 47our $METASERVER;
53 48
54our $GAUGES; 49our $GAUGES;
50our $STATWIDS;
55 51
56our $SDL_ACTIVE; 52our $SDL_ACTIVE;
57our $SDL_EV;
58our %SDL_CB; 53our %SDL_CB;
54
55our $SDL_MIXER;
56our @SOUNDS; # event => file mapping
57our %AUDIO_CHUNKS; # audio files
59 58
60our $ALT_ENTER_MESSAGE; 59our $ALT_ENTER_MESSAGE;
61our $STATUS_LINE; 60our $STATUS_LINE;
62our $DEBUG_STATUS; 61our $DEBUG_STATUS;
63 62
64sub status { 63sub status {
65 $STATUS_LINE->set_text ($_[0]); 64 $STATUS_LINE->set_text ($_[0]);
66 my ($w, $h) = $STATUS_LINE->size_request;
67 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 65 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
68} 66}
69 67
70sub debug { 68sub debug {
71 $DEBUG_STATUS->set_text ($_[0]); 69 $DEBUG_STATUS->set_text ($_[0]);
72 my ($w, $h) = $DEBUG_STATUS->size_request; 70 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
73 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
74} 71}
75 72
76sub start_game { 73sub start_game {
77 status "logging in..."; 74 status "logging in...";
78 75
102 undef $CONN; 99 undef $CONN;
103} 100}
104 101
105sub client_setup { 102sub client_setup {
106 my $dialog = new CFClient::UI::FancyFrame 103 my $dialog = new CFClient::UI::FancyFrame
104 title => "Client Setup",
107 child => (my $vbox = new CFClient::UI::VBox); 105 child => (my $vbox = new CFClient::UI::VBox);
108 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
109 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 106 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
110 107
111 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 108 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
112 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 109 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
113 110
114 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 111 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
115 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 112 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
116 113
117 $mode_slider->connect (changed => sub { 114 $mode_slider->connect (changed => sub {
118 my ($self, $value) = @_; 115 my ($self, $value) = @_;
119 116
120 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 117 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
121 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 118 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
122 }); 119 });
123 $mode_slider->emit (changed => $mode_slider->{range}[0]); 120 $mode_slider->emit (changed => $mode_slider->{range}[0]);
124 121
122 my $row = 1;
123
125 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 124 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
126 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 125 $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
127 my ($self, $value) = @_; 126 my ($self, $value) = @_;
128 $CFG->{fullscreen} = $value; 127 $CFG->{fullscreen} = $value;
129 }); 128 });
130 129
131 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 130 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
132 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 131 $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
133 my ($self, $value) = @_; 132 my ($self, $value) = @_;
134 $CFG->{fast} = $value; 133 $CFG->{fast} = $value;
135 }); 134 });
136 135
137 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 136 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
138 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 137 $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
139 my ($self, $value) = @_; 138 my ($self, $value) = @_;
140 $CFG->{fow_enable} = $value; 139 $CFG->{fow_enable} = $value;
141 }); 140 });
142 141
143 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 142 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
144 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 143 $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
145 my ($self, $value) = @_; 144 my ($self, $value) = @_;
146 $CFG->{fow_intensity} = $value; 145 $CFG->{fow_intensity} = $value;
147 }); 146 });
148 147
149 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 148 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
150 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 149 $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
151 my ($self, $value) = @_; 150 my ($self, $value) = @_;
152 $CFG->{fow_smooth} = $value; 151 $CFG->{fow_smooth} = $value;
152 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
153 }); 153 });
154 154
155 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 155 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
156 $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
157 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
158# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
159 });
160
161 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
156 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 162 $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
157 my ($self, $value) = @_;
158 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 163 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
159 }); 164 });
160 165
166 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize");
167 $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{stat_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
168 $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10;
169 &set_stats_window_fontsize;
170 });
171
172 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge height");
173 $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], connect_changed => sub {
174 $CFG->{gauge_size} = $_[1];
175 my $h = int ($HEIGHT * $CFG->{gauge_size});
176 $GAUGES->{win}->set_size ($WIDTH, $h);
177 $GAUGES->{win}->{y} = $HEIGHT - $h;
178 $GAUGES->{win}->{x} = 0;
179 $GAUGES->{win}->update;
180 });
181
182
183 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
184 $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gauge_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
185 $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10;
186 &set_gauge_window_fontsize;
187 $GAUGES->{win}->check_size;
188 $GAUGES->{win}->update;
189 });
190
191
192
161 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 193 $table->add (1, $row++, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
162 destroy_screen (); 194 video_shutdown ();
163 init_screen (); 195 video_init ();
196 });
197
198 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
199 $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
200 $CFG->{audio_enable} = $_[1];
201 });
202# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
203# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
204# $CFG->{effects_volume} = $_[1];
205# });
206 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
207 $table->add (1, $row++, my $hbox = new CFClient::UI::HBox);
208 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
209 $CFG->{bgm_enable} = $_[1];
210 });
211 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
212 $CFG->{bgm_volume} = $_[1];
213 CFClient::MixMusic::volume $_[1] * 128;
214 });
215
216 $table->add (1, $row++, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
217 audio_shutdown ();
218 audio_init ();
164 }); 219 });
165 220
166 $dialog 221 $dialog
222}
223
224sub set_stats_window_fontsize {
225 for (values %{$STATWIDS}) {
226 $_->set_fontsize ($::CFG->{stat_fontsize});
227 }
228}
229
230sub set_gauge_window_fontsize {
231 for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) {
232 $_->set_fontsize ($::CFG->{gauge_fontsize});
233 }
234}
235
236sub make_gauge_window {
237 my $gh = int ($HEIGHT * $CFG->{gauge_size});
238# my $gw = int ($WIDTH * $CFG->{gauge_w_size});
239
240 my $win = new CFClient::UI::Frame (
241 y => $HEIGHT - $gh, x => 0, req_w => $WIDTH, req_h => $gh
242 );
243 $win->add (my $vb = new CFClient::UI::VBox);
244
245 $vb->add (my $hbg = new CFClient::UI::HBox expand => 1);
246
247
248 $hbg->add (new CFClient::UI::Empty expand => 1);
249 $hbg->add (my $hb = new CFClient::UI::HBox);
250 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp');
251 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana');
252 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace');
253 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food');
254
255 $vb->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, text => "XP:");
256# $vb->add (my $lvl = new CFClient::UI::Label valign => 0, align => 1, text => "Lvl:");
257 $vb->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, text => "Rng:");
258
259
260 $GAUGES = {
261 exp => $exp,# lvl => $lvl,
262 win => $win, range => $rng,
263 food => $fg, mana => $mg, hp => $hg, grace => $gg
264 };
265 $win
266}
267
268sub make_stats_window {
269 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats");
270
271 $tgw->add (my $vb = new CFClient::UI::VBox);
272 $vb->add (my $uhb = new CFClient::UI::HBox);
273 $uhb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1);
274 $uhb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
275
276 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
277
278 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
279
280 $tbl->add (0, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Str");
281 $tbl->add (0, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Dex");
282 $tbl->add (0, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Con");
283 $tbl->add (0, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Int");
284 $tbl->add (0, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Wis");
285 $tbl->add (0, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Pow");
286 $tbl->add (0, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Cha");
287
288 $tbl->add (1, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, text => "");
289 $tbl->add (1, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, text => "");
290 $tbl->add (1, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, text => "");
291 $tbl->add (1, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, text => "");
292 $tbl->add (1, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, text => "");
293 $tbl->add (1, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, text => "");
294 $tbl->add (1, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, text => "");
295
296 $tbl->add (2, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Wc");
297 $tbl->add (2, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Ac");
298 $tbl->add (2, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Dam");
299 $tbl->add (2, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Arm");
300 $tbl->add (2, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Sp");
301 $tbl->add (2, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "WSp");
302
303 $tbl->add (3, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, text => "");
304 $tbl->add (3, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, text => "");
305 $tbl->add (3, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, text => "");
306 $tbl->add (3, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, text => "");
307 $tbl->add (3, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, text => "");
308 $tbl->add (3, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, text => "");
309
310 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1);
311
312 my $row = 0;
313 my $col = 0;
314
315 for (qw/slow holyw conf fire depl magic
316 drain acid pois para deat phys
317 blind fear tund elec cold ghit/)
318 {
319 $tbl2->add ($col , $row,
320 $STATWIDS->{"res_$_"} =
321 new CFClient::UI::Label text => "0", align => +1, valign => 0
322 );
323 $tbl2->add ($col + 1, $row, new CFClient::UI::Image image => "ui/resist/resist_$_.png");
324
325 $row++;
326 if ($row % 6 == 0) {
327 $col += 2;
328 $row = 0;
329 }
330 }
331
332 &set_stats_window_fontsize;
333 update_stats_window ({});
334
335 $tgw
336}
337
338sub update_stats_window {
339 my ($stats) = @_;
340
341 # i love text protocols!!!
342 my $hp = $stats->{1} * 1;
343 my $hp_m = $stats->{2} * 1;
344 my $sp = $stats->{3} * 1;
345 my $sp_m = $stats->{4} * 1;
346 my $fo = $stats->{18} * 1;
347 my $fo_m = 999;
348 my $gr = $stats->{23} * 1;
349 my $gr_m = $stats->{24} * 1;
350
351 $GAUGES->{hp} ->set_value ($hp, $hp_m);
352 $GAUGES->{mana} ->set_value ($sp, $sp_m);
353 $GAUGES->{food} ->set_value ($fo, $fo_m);
354 $GAUGES->{grace} ->set_value ($gr, $gr_m);
355 $GAUGES->{exp} ->set_text ("XP: " . ($stats->{11} || $stats->{28}) * 1
356 ." LVL: " . $stats->{12} * 1);
357 my $rng = $stats->{20};
358 $rng =~ s/^Range: //; # thank you so much dear server
359 $GAUGES->{range} ->set_text ("Rng: " . $rng);
360# $GAUGES->{lvl} ->set_text ("LVL: " . $stats->{12});
361 $STATWIDS->{title} ->set_text ("Title: " . $stats->{21});
362
363 if (0) { # this code can vanish, just wanted to preserver it for a checkin
364 $STATWIDS->{st_str} ->set_text (sprintf "S%d", $stats->{5});
365 $STATWIDS->{st_dex} ->set_text (sprintf "D%d", $stats->{8});
366 $STATWIDS->{st_con} ->set_text (sprintf "Co%d", $stats->{9});
367 $STATWIDS->{st_int} ->set_text (sprintf "I%d", $stats->{6});
368 $STATWIDS->{st_wis} ->set_text (sprintf "W%d", $stats->{7});
369 $STATWIDS->{st_pow} ->set_text (sprintf "P%d", $stats->{22});
370 $STATWIDS->{st_cha} ->set_text (sprintf "Ch%d", $stats->{10});
371 $STATWIDS->{st_wc} ->set_text (sprintf "Wc%d", $stats->{13});
372 $STATWIDS->{st_ac} ->set_text (sprintf "Ac%d", $stats->{14});
373 $STATWIDS->{st_dam} ->set_text (sprintf "Dam%d", $stats->{15});
374 $STATWIDS->{st_arm} ->set_text (sprintf "Arm%d", $stats->{16});
375 $STATWIDS->{st_spd} ->set_text (sprintf "Sp%.1f", $stats->{17});
376 $STATWIDS->{st_wspd}->set_text (sprintf "WSp%.1f", $stats->{19});
377 } else {
378 $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5});
379 $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8});
380 $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9});
381 $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6});
382 $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7});
383 $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22});
384 $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10});
385 $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13});
386 $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14});
387 $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15});
388 $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16});
389 $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17});
390 $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19});
391 }
392
393 my %tbl = (
394 phys => 100,
395 magic => 101,
396 fire => 102,
397 elec => 103,
398 cold => 104,
399 conf => 105,
400 acid => 106,
401 drain => 107,
402 ghit => 108,
403 pois => 109,
404 slow => 110,
405 para => 111,
406 tund => 112,
407 fear => 113,
408 deat => 115,
409 holyw => 116,
410 blind => 117
411 );
412
413 for (keys %tbl) {
414 $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}});
415 }
416
167} 417}
168 418
169sub metaserver_dialog { 419sub metaserver_dialog {
170 my $dialog = new CFClient::UI::FancyFrame 420 my $dialog = new CFClient::UI::FancyFrame
421 title => "Metaserver",
171 child => (my $vbox = new CFClient::UI::VBox); 422 child => (my $vbox = new CFClient::UI::VBox);
172 423
173 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 424 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
174 425
175 $dialog 426 $dialog
232 $HOST->set_text ($CFG->{host} = $host); 483 $HOST->set_text ($CFG->{host} = $host);
233 }), 484 }),
234 (new CFClient::UI::Empty expand => 1), 485 (new CFClient::UI::Empty expand => 1),
235 ]); 486 ]);
236 487
237 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 488 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
238 for 0 .. $#$m; 489 for 0 .. $#$m;
239 } 490 }
240 } 491 }
241 }); 492 });
242} 493}
243 494
244sub server_setup { 495sub server_setup {
245 my $dialog = new CFClient::UI::FancyFrame 496 my $dialog = new CFClient::UI::FancyFrame
497 title => "Server Setup",
246 child => (my $vbox = new CFClient::UI::VBox); 498 child => (my $vbox = new CFClient::UI::VBox);
247 499
248 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
249 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 500 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
250 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 501 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
251 502
252 { 503 {
253 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 504 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
254 505
255 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 506 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
256 my ($self, $value) = @_; 507 my ($self, $value) = @_;
257 $CFG->{host} = $value; 508 $CFG->{host} = $value;
258 }); 509 });
259 510
260 $METASERVER = metaserver_dialog; 511 $METASERVER = metaserver_dialog;
261 512
262 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 513 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
263 update_metaserver $HOST; 514 update_metaserver $HOST;
264 }); 515 });
265 } 516 }
266 517
267 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 518 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
268 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 519 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
269 my ($self, $value) = @_; 520 my ($self, $value) = @_;
270 $CFG->{user} = $value; 521 $CFG->{user} = $value;
271 }); 522 });
272 523
273 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 524 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
274 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 525 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
275 my ($self, $value) = @_; 526 my ($self, $value) = @_;
276 $CFG->{password} = $value; 527 $CFG->{password} = $value;
277 }); 528 });
278 529
279 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 530 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
280 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 531 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
281 my ($self, $value) = @_; 532 my ($self, $value) = @_;
282 $CFG->{say_command} = $value; 533 $CFG->{say_command} = $value;
283 }); 534 });
284 535
285 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 536 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
286 $table->add (1, 7, new CFClient::UI::Slider 537 $table->add (1, 7, new CFClient::UI::Slider
287 req_w => 100, 538 req_w => 100,
288 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 539 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
289 connect_changed => sub { 540 connect_changed => sub {
290 my ($self, $value) = @_; 541 my ($self, $value) = @_;
300 $dialog 551 $dialog
301} 552}
302 553
303sub message_window { 554sub message_window {
304 my $window = new CFClient::UI::FancyFrame 555 my $window = new CFClient::UI::FancyFrame
556 title => "Messages",
305 border_bg => [1, 1, 1, 0.5], 557 border_bg => [1, 1, 1, 0.5],
306 bg => [0.3, 0.3, 0.3, 0.8], 558 bg => [0.3, 0.3, 0.3, 0.8],
307 user_w => int $::WIDTH / 3, 559 user_w => int $::WIDTH / 3,
308 user_h => int $::HEIGHT / 5, 560 user_h => int $::HEIGHT / 5,
309 child => (my $vbox = new CFClient::UI::VBox); 561 child => (my $vbox = new CFClient::UI::VBox);
351 603
352 $window 604 $window
353} 605}
354 606
355sub sdl_init { 607sub sdl_init {
356 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 608 CFClient::SDL_Init
357 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
358 and die "SDL::Init failed!\n"; 609 and die "SDL::Init failed!\n";
359} 610}
360 611
361sub init_screen { 612sub video_init {
362 sdl_init; 613 sdl_init;
363 614
364 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 615 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
365 $FULLSCREEN = $CFG->{fullscreen}; 616 $FULLSCREEN = $CFG->{fullscreen};
366 $FAST = $CFG->{fast}; 617 $FAST = $CFG->{fast};
367 618
368 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 619 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
369 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
370 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
371 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
372
373 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
374 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
375 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
376 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
377
378 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
379 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
380 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
381
382 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
383 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
384 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
385 or die "SDL::SetVideoMode failed!\n"; 620 or die "SDL_SetVideoMode failed!\n";
386
387 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
388
389 $SDL_EV = new SDL::Event;
390 $SDL_EV->set_unicode (1);
391 621
392 $SDL_ACTIVE = 1; 622 $SDL_ACTIVE = 1;
393 623
394 $LAST_REFRESH = time - 0.01; 624 $LAST_REFRESH = time - 0.01;
395 625
396 CFClient::gl_init; 626 CFClient::gl_init;
397 627
398 $FONTSIZE = int $HEIGHT / 40; 628 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
399 629
400 ############################################################################# 630 #############################################################################
401 631
402 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 632 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
403 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 633 $DEBUG_STATUS->show;
404 634
405 $STATUS_LINE = new CFClient::UI::Label 635 $STATUS_LINE = new CFClient::UI::Label
406 padding => 0, 636 padding => 0,
407 y => $HEIGHT * 44 / 45 - $FONTSIZE; 637 y => $HEIGHT - $FONTSIZE * 1.8;
408 $CFClient::UI::ROOT->add ($STATUS_LINE); 638 $STATUS_LINE->show;
409 639
410 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 640 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
411 padding => 0, 641 padding => 0,
412 y => $HEIGHT * 44 / 45,
413 fontsize => $HEIGHT / 45, 642 fontsize => 0.8,
414 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 643 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
415 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 644 $ALT_ENTER_MESSAGE->show;
645 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
416 646
417 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 647 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
418 $MAPWIDGET->focus_in; 648 $MAPWIDGET->focus_in;
419 $MAPWIDGET->connect (activate_console => sub { 649 $MAPWIDGET->connect (activate_console => sub {
420 my ($mapwidget, $preset) = @_; 650 my ($mapwidget, $preset) = @_;
421 651
422 if ($CONSOLE) { 652 if ($CONSOLE) {
438 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 668 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
439 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 669 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
440 status "Configuration Saved"; 670 status "Configuration Saved";
441 }); 671 });
442 672
673 $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
674 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
675
443 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 676 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
444 677
445 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 150, y => 0);
446 $tgw->add (my $hb = new CFClient::UI::HBox (req_w => 60, req_h => 150));
447 $hb->add (my $fg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'food', expand => 1));
448 $hb->add (my $mg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'mana', expand => 1));
449 $hb->add (my $hg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'hp', expand => 1));
450 $hb->add (my $gg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'grace', expand => 1));
451 678
452 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
453 $CFClient::UI::ROOT->add ($tgw);
454} 679}
455 680
456sub destroy_screen { 681sub video_shutdown {
457 $CFClient::UI::ROOT->{children} = []; 682 $CFClient::UI::ROOT->{children} = [];
458 undef $SDL_ACTIVE; 683 undef $SDL_ACTIVE;
684}
685
686my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
687my $bgmusic;#TODO#hack#d#
688
689sub audio_music_finished {
690 return unless $CFG->{bgm_enable};
691
692 # TODO: hack, do play loop and mood music
693 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
694 $bgmusic->play (0);
695
696 push @bgmusic, shift @bgmusic;
697}
698
699sub audio_init {
700 if ($CFG->{audio_enable}) {
701 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
702 $SDL_MIXER = !CFClient::Mix_OpenAudio;
703 CFClient::Mix_AllocateChannels 8;
704 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
705
706 audio_music_finished;
707
708 while (<$fh>) {
709 next if /^\s*#/;
710 next if /^\s*$/;
711
712 my ($file, $volume, $event) = split /\s+/, $_, 3;
713
714 push @SOUNDS, "$volume,$file";
715
716 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
717 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
718 $chunk->volume ($volume * 128 / 100);
719 $chunk
720 };
721 }
722 } else {
723 status "unable to open sound config: $!";
724 }
725 }
726}
727
728sub audio_shutdown {
729 CFClient::Mix_CloseAudio if $SDL_MIXER;
459 undef $SDL_EV; 730 undef $SDL_MIXER;
460 SDL::Quit; 731 @SOUNDS = ();
732 %AUDIO_CHUNKS = ();
461} 733}
462 734
463my %animate_object; 735my %animate_object;
464my $animate_timer; 736my $animate_timer;
465 737
475 $want_refresh = 0; 747 $want_refresh = 0;
476 $can_refresh = 0; 748 $can_refresh = 0;
477 749
478 $CFClient::UI::ROOT->draw; 750 $CFClient::UI::ROOT->draw;
479 751
480 SDL::GLSwapBuffers; 752 CFClient::SDL_GL_SwapBuffers;
481 753
482 $LAST_REFRESH = $NOW; 754 $LAST_REFRESH = $NOW;
483} 755}
484 756
485my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 757my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
486 $NOW = time; 758 $NOW = time;
487 759
488 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 760 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
489 while $SDL_EV->poll; 761 for CFClient::SDL_PollEvent;
490 762
491 if (%animate_object) { 763 if (%animate_object) {
492 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 764 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
493 $want_refresh++; 765 $want_refresh++;
494 } 766 }
517@conn::ISA = Crossfire::Protocol::; 789@conn::ISA = Crossfire::Protocol::;
518 790
519sub conn::stats_update { 791sub conn::stats_update {
520 my ($self, $stats) = @_; 792 my ($self, $stats) = @_;
521 793
522 # i love text protocols!!! 794 update_stats_window ($stats);
523 # FIXME: the stats are somehow weird
524 my $hp = $stats->{1};
525 my $hp_m = $stats->{2};
526 my $sp = $stats->{3};
527 my $sp_m = $stats->{4};
528 my $fo = $stats->{18};
529 my $fo_m = 1000;
530 my $gr = $stats->{23};
531 my $gr_m = $stats->{24};
532
533 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
534 $GAUGES->{hp}->set_value ($hp, $hp_m);
535 $GAUGES->{mana}->set_value ($sp, $sp_m);
536 $GAUGES->{food}->set_value ($fo, $fo_m);
537 $GAUGES->{grace}->set_value ($gr, $gr_m);
538} 795}
539 796
540sub conn::user_send { 797sub conn::user_send {
541 my ($self, $command) = @_; 798 my ($self, $command) = @_;
542 799
567 824
568 my ($hash, $x, $y, $w, $h) = @$map_info; 825 my ($hash, $x, $y, $w, $h) = @$map_info;
569 826
570 my $data = $MAP->get_rect ($x, $y, $w, $h); 827 my $data = $MAP->get_rect ($x, $y, $w, $h);
571 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 828 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
572
573 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 829 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
574
575} 830}
576 831
577sub conn::map_clear { 832sub conn::map_clear {
578 my ($self) = @_; 833 my ($self) = @_;
579 834
580 $self->flush_map; 835 $self->flush_map;
581 delete $self->{neigh}; 836 delete $self->{neigh_map};
582 837
583 $MAP->clear; 838 $MAP->clear;
584} 839}
585 840
586 841
587sub conn::load_map($$$) { 842sub conn::load_map($$$) {
588 my ($self, $hash, $x, $y) = @_; 843 my ($self, $hash, $x, $y) = @_;
589 844
590 if (defined (my $data = $MAPCACHE->get ($hash))) { 845 if (defined (my $data = $MAPCACHE->get ($hash))) {
591 $data = Compress::LZF::decompress $data; 846 $data = Compress::LZF::decompress $data;
592 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 847 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
593 for my $id ($MAP->set_rect ($x, $y, $data)) { 848 for my $id ($MAP->set_rect ($x, $y, $data)) {
594 my $data = $TILECACHE->get ($id) 849 my $data = $TILECACHE->get ($id)
595 or next; 850 or next;
596 851
597 $self->set_texture ($id => $data); 852 $self->set_texture ($id => $data);
598 } 853 }
599 } 854 }
600} 855}
601 856
857# this method does a "flood fill" into every tile direction
858# it assumes that tiles are arranged in a rectangular grid,
859# i.e. a map is the same as the left of the right map etc.
860# failure to comply are harmless and result in display errors
861# at worst.
602sub conn::flood_fill { 862sub conn::flood_fill {
603 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 863 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
604 864
605 # the server does not allow map paths > 6 865 # the server does not allow map paths > 6
606 return if 6 <= length $path; 866 return if 6 <= length $path;
607 867
608 for my $tile (1..4) { 868 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
609 next if $self->{neigh}{$hash}[$tile]; 869
870 for (
871 [1, 0, -1],
872 [2, 1, 0],
873 [3, 0, 1],
874 [4, -1, 0],
875 ) {
876 my ($tile, $dx, $dy) = @$_;
877
878 my $gx = $gx + $dx;
879 my $gy = $gy + $dy;
880
610 next unless $flags & (1 << ($tile - 1)); 881 next unless $flags & (1 << ($tile - 1));
882 next if $self->{neigh_grid}{$gx, $gy}++;
611 883
612 my $neigh = $self->{neigh}{$hash} ||= []; 884 my $neigh = $self->{neigh_map}{$hash} ||= [];
613 885 if (my $info = $neigh->[$tile]) {
614 $self->send_mapinfo ("spatial $path$tile", sub {
615 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 886 my ($flags, $x, $y, $w, $h, $hash) = @$info;
616 887
617 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
618 return if $mode ne "spatial";
619
620 $x += $MAP->ox;
621 $y += $MAP->oy;
622
623 $self->load_map ($hash, $x, $y)
624 unless $self->{neigh}{$hash}[5]++;#d#
625
626 $neigh->[$tile] = [$x, $y, $w, $h];
627
628 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 888 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
629 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 889 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
890
891 } else {
892 $self->send_mapinfo ("spatial $path$tile", sub {
893 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
894
895 return if $mode ne "spatial";
896
897 $x += $MAP->ox;
898 $y += $MAP->oy;
899
900 $self->load_map ($hash, $x, $y)
901 unless $self->{neigh_map}{$hash}[5]++;#d#
902
903 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
904
905 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
906 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
907 });
630 }); 908 }
631 } 909 }
632} 910}
633 911
634sub conn::map_change { 912sub conn::map_change {
635 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 913 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
636 914
637 $self->flush_map; 915 $self->flush_map;
638 916
639 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 917 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
640 918
641 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
642
643 my $mapmapw = 250; 919 my $mapmapw = 250;
644 my $mapmaph = 250; 920 my $mapmaph = 250;
921
922 $self->{neigh_rect} = [
923 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
924 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
925 ];
645 926
927 delete $self->{neigh_grid};
646 $self->flood_fill ("", $hash, $flags, 928 $self->flood_fill (0, 0, "", $hash, $flags);
647 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
648 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
649 929
650 $x += $ox; 930 $x += $ox;
651 $y += $oy; 931 $y += $oy;
652 932
653 $self->{map_info} = [$hash, $x, $y, $w, $h]; 933 $self->{map_info} = [$hash, $x, $y, $w, $h];
934
935 my $map = $self->{map_info}[0];
936 $map =~ s/^.*?\/([^\/]+)$/\1/;
937 $STATWIDS->{map}->set_text ("Map: " . $map);
654 938
655 $self->load_map ($hash, $x, $y); 939 $self->load_map ($hash, $x, $y);
656} 940}
657 941
658sub conn::face_find { 942sub conn::face_find {
710 994
711 $tex 995 $tex
712 }; 996 };
713} 997}
714 998
999sub conn::sound_play {
1000 my ($self, $x, $y, $soundnum, $type) = @_;
1001
1002 $SDL_MIXER
1003 or return;
1004
1005 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
1006 or return;
1007
1008 $chunk->play;
1009# warn "sound $x,$y,$soundnum,$type\n";#d#
1010}
1011
715sub conn::query { 1012sub conn::query {
716 my ($self, $flags, $prompt) = @_; 1013 my ($self, $flags, $prompt) = @_;
717 1014
718 #TODO 1015 #TODO, display dialog with relevant information
719 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 1016 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
720} 1017}
721 1018
722sub conn::drawinfo { 1019sub conn::drawinfo {
723 my ($self, $color, $text) = @_; 1020 my ($self, $color, $text) = @_;
739 ); 1036 );
740 1037
741 $LOGVIEW->add_paragraph ($color[$color], $text); 1038 $LOGVIEW->add_paragraph ($color[$color], $text);
742} 1039}
743 1040
1041sub conn::spell_add {
1042 my ($self, $spell) = @_;
1043
1044 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
1045 });
1046 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
1047 });
1048}
1049
1050sub conn::spell_delete {
1051 my ($self, $spell) = @_;
1052}
1053
1054sub conn::addme_success {
1055 my ($self) = @_;
1056
1057 for my $skill (values %{$self->{skill_info}}) {
1058 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
1059 });
1060 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
1061 });
1062 }
1063}
1064
744%SDL_CB = ( 1065%SDL_CB = (
745 SDL_QUIT() => sub { 1066 CFClient::SDL_QUIT => sub {
746 Event::unloop -1; 1067 Event::unloop -1;
747 }, 1068 },
748 SDL_VIDEORESIZE() => sub { 1069 CFClient::SDL_VIDEORESIZE => sub {
749 }, 1070 },
750 SDL_VIDEOEXPOSE() => sub { 1071 CFClient::SDL_VIDEOEXPOSE => \&refresh,
751 refresh; 1072 CFClient::SDL_ACTIVEEVENT => sub {
1073# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
752 }, 1074 },
753 SDL_KEYDOWN() => sub { 1075 CFClient::SDL_KEYDOWN => sub {
754 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 1076 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
755 # alt-enter 1077 # alt-enter
756 destroy_screen; 1078 video_shutdown;
757 $CFG->{fullscreen} = !$CFG->{fullscreen}; 1079 $CFG->{fullscreen} = !$CFG->{fullscreen};
758 init_screen; 1080 video_init;
759 } else { 1081 } else {
760 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 1082 CFClient::UI::feed_sdl_key_down_event ($_[0]);
761 } 1083 }
762 }, 1084 },
763 SDL_KEYUP() => sub { 1085 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
764 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 1086 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
765 }, 1087 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
766 SDL_MOUSEMOTION() => sub { 1088 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
767 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 1089 CFClient::SDL_USEREVENT => \&audio_music_finished,
768 },
769 SDL_MOUSEBUTTONDOWN() => sub {
770 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
771 },
772 SDL_MOUSEBUTTONUP() => sub {
773 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
774 },
775 SDL_ACTIVEEVENT() => sub {
776# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
777 },
778); 1090);
779 1091
780############################################################################# 1092#############################################################################
1093
1094$SIG{INT} = $SIG{TERM} = sub { exit };
781 1095
782$TILECACHE = CFClient::db_table "tilecache"; 1096$TILECACHE = CFClient::db_table "tilecache";
783$FACEMAP = CFClient::db_table "facemap"; 1097$FACEMAP = CFClient::db_table "facemap";
784 1098
785CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 1099CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
791 fullscreen => 0, 1105 fullscreen => 0,
792 fast => 0, 1106 fast => 0,
793 fow_enable => 1, 1107 fow_enable => 1,
794 fow_intensity => 0.45, 1108 fow_intensity => 0.45,
795 fow_smooth => 0, 1109 fow_smooth => 0,
1110 gui_fontsize => 1,
796 log_fontsize => 14, 1111 log_fontsize => 1,
1112 gauge_fontsize => 1,
1113 gauge_size => 0.35,
1114 stat_fontsize => 1,
797 mapsize => 100, 1115 mapsize => 100,
798 host => "crossfire.schmorp.de", 1116 host => "crossfire.schmorp.de",
799 say_command => 'say', 1117 say_command => 'say',
1118 audio_enable => 1,
1119 bgm_enable => 1,
1120 bgm_volume => 0.25,
800); 1121);
801 1122
802while (my ($k, $v) = each %DEF_CFG) { 1123while (my ($k, $v) = each %DEF_CFG) {
803 $CFG->{$k} = $v unless exists $CFG->{$k}; 1124 $CFG->{$k} = $v unless exists $CFG->{$k};
804} 1125}
805 1126
806sdl_init; 1127sdl_init;
807 1128
808@SDL_MODES = reverse 1129@SDL_MODES = reverse
809 grep $_->[0] >= 640 && $_->[1] >= 480, 1130 grep $_->[0] >= 640 && $_->[1] >= 480,
810 map [SDL::RectW ($_), SDL::RectH ($_)], 1131 CFClient::SDL_ListModes;
811 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
812 1132
813@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 1133@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
814 1134
815$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 1135$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
816 1136
819 1139
820 CFClient::add_font $_ for @fonts; 1140 CFClient::add_font $_ for @fonts;
821 CFClient::set_font $fonts[0]; 1141 CFClient::set_font $fonts[0];
822} 1142}
823 1143
824init_screen; 1144video_init;
1145audio_init;
825 1146
826Event::loop; 1147Event::loop;
827 1148
1149END { CFClient::SDL_Quit }
828 1150
1151

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines