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.138 by elmex, Tue Apr 18 21:37:48 2006 UTC vs.
Revision 1.156 by elmex, Fri Apr 21 12:27:20 2006 UTC

4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL;
10use SDL::App;
11use SDL::Event;
12use SDL::Surface;
13
14use SDL::Mixer;
15use SDL::Sound;
16use SDL::Music;
17
18use SDL::OpenGL;
19
20use Crossfire; 9use Crossfire;
21use Crossfire::Protocol; 10use Crossfire::Protocol;
22 11
23use Compress::LZF; 12use Compress::LZF;
24 13
25use CFClient; 14use CFClient;
26use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
27 17
28our $VERSION = '0.1'; 18our $VERSION = '0.1';
29 19
30my $MAX_FPS = 60; 20my $MAX_FPS = 60;
31my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
55our $LOGVIEW; 45our $LOGVIEW;
56our $CONSOLE; 46our $CONSOLE;
57our $METASERVER; 47our $METASERVER;
58 48
59our $GAUGES; 49our $GAUGES;
50our $STATWIDS;
60 51
61our $SDL_ACTIVE; 52our $SDL_ACTIVE;
62our $SDL_EV;
63our %SDL_CB; 53our %SDL_CB;
64 54
65our $SDL_MIXER; 55our $SDL_MIXER;
66our @SOUNDS; # event => file mapping 56our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files 57our %AUDIO_CHUNKS; # audio files
109 undef $CONN; 99 undef $CONN;
110} 100}
111 101
112sub client_setup { 102sub client_setup {
113 my $dialog = new CFClient::UI::FancyFrame 103 my $dialog = new CFClient::UI::FancyFrame
104 title => "Client Setup",
114 child => (my $vbox = new CFClient::UI::VBox); 105 child => (my $vbox = new CFClient::UI::VBox);
115 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
116 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 106 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
117 107
118 $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");
119 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 109 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
120 110
121 $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]);
122 $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");
123 113
124 $mode_slider->connect (changed => sub { 114 $mode_slider->connect (changed => sub {
125 my ($self, $value) = @_; 115 my ($self, $value) = @_;
126 116
127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 117 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
128 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 118 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
129 }); 119 });
130 $mode_slider->emit (changed => $mode_slider->{range}[0]); 120 $mode_slider->emit (changed => $mode_slider->{range}[0]);
131 121
132 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 122 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
133 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 123 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
134 my ($self, $value) = @_; 124 my ($self, $value) = @_;
135 $CFG->{fullscreen} = $value; 125 $CFG->{fullscreen} = $value;
136 }); 126 });
137 127
138 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 128 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
139 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 129 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
140 my ($self, $value) = @_; 130 my ($self, $value) = @_;
141 $CFG->{fast} = $value; 131 $CFG->{fast} = $value;
142 }); 132 });
143 133
144 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 134 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
145 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 135 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
146 my ($self, $value) = @_; 136 my ($self, $value) = @_;
147 $CFG->{fow_enable} = $value; 137 $CFG->{fow_enable} = $value;
148 }); 138 });
149 139
150 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 140 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
151 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 141 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
152 my ($self, $value) = @_; 142 my ($self, $value) = @_;
153 $CFG->{fow_intensity} = $value; 143 $CFG->{fow_intensity} = $value;
154 }); 144 });
155 145
156 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 146 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
157 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 147 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
158 my ($self, $value) = @_; 148 my ($self, $value) = @_;
159 $CFG->{fow_smooth} = $value; 149 $CFG->{fow_smooth} = $value;
160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 150 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
161 }); 151 });
162 152
163 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 153 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
154 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
155 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
156# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
157 });
158
159 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 160 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
165 my ($self, $value) = @_;
166 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 161 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
167 }); 162 });
168 163
169 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 164 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
170 video_shutdown (); 165 video_shutdown ();
171 video_init (); 166 video_init ();
172 }); 167 });
173 168
174 $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound"); 169 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
175 $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{sound}, connect_changed => sub {
176 my ($self, $value) = @_;
177 $CFG->{sound} = $value;
178 });
179 $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music");
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bg_music_enable}, connect_changed => sub { 170 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
181 my ($self, $value) = @_;
182 $CFG->{bg_music_enable} = $value; 171 $CFG->{audio_enable} = $_[1];
172 });
173# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
174# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
175# $CFG->{effects_volume} = $_[1];
183 }); 176# });
177 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
178 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
179 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
180 $CFG->{bgm_enable} = $_[1];
181 });
182 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
183 $CFG->{bgm_volume} = $_[1];
184 CFClient::MixMusic::volume $_[1] * 128;
185 });
186
184 $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 187 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
185 audio_shutdown (); 188 audio_shutdown ();
186 audio_init (); 189 audio_init ();
187 }); 190 });
188 191
189 $dialog 192 $dialog
190} 193}
191 194
195sub make_stats_window {
196 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats");
197
198 $tgw->add (my $vb = new CFClient::UI::VBox);
199 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:");
200 $vb->add (my $lhb = new CFClient::UI::HBox);
201 $lhb->add ($STATWIDS->{exp} = new CFClient::UI::Label valign => 0, align => -1, text => "Exp:", expand => 1);
202 $lhb->add ($STATWIDS->{lvl} = new CFClient::UI::Label valign => 0, align => -1, text => "Level:", expand => 1);
203
204 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
205 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', expand => 1);
206 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', expand => 1);
207 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', expand => 1);
208 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', expand => 1);
209 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
210
211 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
212
213 if (0) { # this code can vanish, just wanted to preserver it for a checkin
214 $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => -1, text => "S");
215 $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => -1, text => "D");
216 $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => -1, text => "Co");
217 $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => -1, text => "I");
218 $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => -1, text => "W");
219 $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => -1, text => "P");
220 $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => -1, text => "Ch");
221
222 $tbl->add (1, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc");
223 $tbl->add (1, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac");
224 $tbl->add (1, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam");
225 $tbl->add (1, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm");
226 $tbl->add (1, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp");
227 $tbl->add (1, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp");
228 } else {
229 $tbl->add (0, 0, new CFClient::UI::Label valign => 0, align => +1, text => "S");
230 $tbl->add (0, 1, new CFClient::UI::Label valign => 0, align => +1, text => "D");
231 $tbl->add (0, 2, new CFClient::UI::Label valign => 0, align => +1, text => "Co");
232 $tbl->add (0, 3, new CFClient::UI::Label valign => 0, align => +1, text => "I");
233 $tbl->add (0, 4, new CFClient::UI::Label valign => 0, align => +1, text => "W");
234 $tbl->add (0, 5, new CFClient::UI::Label valign => 0, align => +1, text => "P");
235 $tbl->add (0, 6, new CFClient::UI::Label valign => 0, align => +1, text => "Ch");
236
237 $tbl->add (1, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => -1, text => "");
238 $tbl->add (1, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => -1, text => "");
239 $tbl->add (1, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => -1, text => "");
240 $tbl->add (1, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => -1, text => "");
241 $tbl->add (1, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => -1, text => "");
242 $tbl->add (1, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => -1, text => "");
243 $tbl->add (1, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => -1, text => "");
244
245 $tbl->add (2, 0, new CFClient::UI::Label valign => 0, align => +1, text => "Wc");
246 $tbl->add (2, 1, new CFClient::UI::Label valign => 0, align => +1, text => "Ac");
247 $tbl->add (2, 2, new CFClient::UI::Label valign => 0, align => +1, text => "Dam");
248 $tbl->add (2, 3, new CFClient::UI::Label valign => 0, align => +1, text => "Arm");
249 $tbl->add (2, 4, new CFClient::UI::Label valign => 0, align => +1, text => "Sp");
250 $tbl->add (2, 5, new CFClient::UI::Label valign => 0, align => +1, text => "WSp");
251
252 $tbl->add (3, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => -1, text => "");
253 $tbl->add (3, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => -1, text => "");
254 $tbl->add (3, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => -1, text => "");
255 $tbl->add (3, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => -1, text => "");
256 $tbl->add (3, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => -1, text => "");
257 $tbl->add (3, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => -1, text => "");
258 }
259
260 $hb->add (my $tbl2 = new CFClient::UI::Table);
261
262 my $row = 0;
263 my $col = 0;
264
265 for (qw/slow holyw conf fire depl magic
266 drain acid pois para deat phys
267 blind fear tund elec cold ghit/)
268 {
269 $tbl2->add ($col, $row, new CFClient::UI::Image image => "ui/resist/resist_$_.png");
270 $tbl2->add ($col + 1, $row,
271 $STATWIDS->{"res_$_"} =
272 new CFClient::UI::Label text => "0", align => -1, valign => 0
273 );
274
275 $row++;
276 if ($row % 6 == 0) {
277 $col += 2;
278 $row = 0;
279 }
280 }
281
282 update_stats_window ({});
283
284 $tgw
285}
286
287sub update_stats_window {
288 my ($stats) = @_;
289
290 # i love text protocols!!!
291 my $hp = $stats->{1};
292 my $hp_m = $stats->{2};
293 my $sp = $stats->{3};
294 my $sp_m = $stats->{4};
295 my $fo = $stats->{18};
296 my $fo_m = 999;
297 my $gr = $stats->{23};
298 my $gr_m = $stats->{24};
299
300 $GAUGES->{hp} ->set_value ($hp, $hp_m);
301 $GAUGES->{mana} ->set_value ($sp, $sp_m);
302 $GAUGES->{food} ->set_value ($fo, $fo_m);
303 $GAUGES->{grace} ->set_value ($gr, $gr_m);
304 $STATWIDS->{title} ->set_text ("Title: " . $stats->{21});
305 $STATWIDS->{exp} ->set_text ("Exp.: " . ($stats->{11} || $stats->{28}));
306 $STATWIDS->{lvl} ->set_text ("Level: " . $stats->{12});
307
308 if (0) { # this code can vanish, just wanted to preserver it for a checkin
309 $STATWIDS->{st_str} ->set_text (sprintf "S%d", $stats->{5});
310 $STATWIDS->{st_dex} ->set_text (sprintf "D%d", $stats->{8});
311 $STATWIDS->{st_con} ->set_text (sprintf "Co%d", $stats->{9});
312 $STATWIDS->{st_int} ->set_text (sprintf "I%d", $stats->{6});
313 $STATWIDS->{st_wis} ->set_text (sprintf "W%d", $stats->{7});
314 $STATWIDS->{st_pow} ->set_text (sprintf "P%d", $stats->{22});
315 $STATWIDS->{st_cha} ->set_text (sprintf "Ch%d", $stats->{10});
316 $STATWIDS->{st_wc} ->set_text (sprintf "Wc%d", $stats->{13});
317 $STATWIDS->{st_ac} ->set_text (sprintf "Ac%d", $stats->{14});
318 $STATWIDS->{st_dam} ->set_text (sprintf "Dam%d", $stats->{15});
319 $STATWIDS->{st_arm} ->set_text (sprintf "Arm%d", $stats->{16});
320 $STATWIDS->{st_spd} ->set_text (sprintf "Sp%.1f", $stats->{17});
321 $STATWIDS->{st_wspd}->set_text (sprintf "WSp%.1f", $stats->{19});
322 } else {
323 $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5});
324 $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8});
325 $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9});
326 $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6});
327 $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7});
328 $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22});
329 $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10});
330 $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13});
331 $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14});
332 $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15});
333 $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16});
334 $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17});
335 $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19});
336 }
337
338 my %tbl = (
339 phys => 100,
340 magic => 101,
341 fire => 102,
342 elec => 103,
343 cold => 104,
344 conf => 105,
345 acid => 106,
346 drain => 107,
347 ghit => 108,
348 pois => 109,
349 slow => 110,
350 para => 111,
351 tund => 112,
352 fear => 113,
353 deat => 115,
354 holyw => 116,
355 blind => 117
356 );
357
358 for (keys %tbl) {
359 $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}});
360 }
361
362}
363
192sub metaserver_dialog { 364sub metaserver_dialog {
193 my $dialog = new CFClient::UI::FancyFrame 365 my $dialog = new CFClient::UI::FancyFrame
366 title => "Metaserver",
194 child => (my $vbox = new CFClient::UI::VBox); 367 child => (my $vbox = new CFClient::UI::VBox);
195 368
196 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 369 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
197 370
198 $dialog 371 $dialog
255 $HOST->set_text ($CFG->{host} = $host); 428 $HOST->set_text ($CFG->{host} = $host);
256 }), 429 }),
257 (new CFClient::UI::Empty expand => 1), 430 (new CFClient::UI::Empty expand => 1),
258 ]); 431 ]);
259 432
260 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 433 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
261 for 0 .. $#$m; 434 for 0 .. $#$m;
262 } 435 }
263 } 436 }
264 }); 437 });
265} 438}
266 439
267sub server_setup { 440sub server_setup {
268 my $dialog = new CFClient::UI::FancyFrame 441 my $dialog = new CFClient::UI::FancyFrame
442 title => "Server Setup",
269 child => (my $vbox = new CFClient::UI::VBox); 443 child => (my $vbox = new CFClient::UI::VBox);
270 444
271 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
272 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 445 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
273 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 446 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
274 447
275 { 448 {
276 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 449 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
277 450
278 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 451 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
279 my ($self, $value) = @_; 452 my ($self, $value) = @_;
280 $CFG->{host} = $value; 453 $CFG->{host} = $value;
281 }); 454 });
282 455
283 $METASERVER = metaserver_dialog; 456 $METASERVER = metaserver_dialog;
284 457
285 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 458 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
286 update_metaserver $HOST; 459 update_metaserver $HOST;
287 }); 460 });
288 } 461 }
289 462
290 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 463 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
291 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 464 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
292 my ($self, $value) = @_; 465 my ($self, $value) = @_;
293 $CFG->{user} = $value; 466 $CFG->{user} = $value;
294 }); 467 });
295 468
296 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 469 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
297 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 470 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
298 my ($self, $value) = @_; 471 my ($self, $value) = @_;
299 $CFG->{password} = $value; 472 $CFG->{password} = $value;
300 }); 473 });
301 474
302 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 475 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
303 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 476 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
304 my ($self, $value) = @_; 477 my ($self, $value) = @_;
305 $CFG->{say_command} = $value; 478 $CFG->{say_command} = $value;
306 }); 479 });
307 480
308 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 481 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
309 $table->add (1, 7, new CFClient::UI::Slider 482 $table->add (1, 7, new CFClient::UI::Slider
310 req_w => 100, 483 req_w => 100,
311 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 484 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
312 connect_changed => sub { 485 connect_changed => sub {
313 my ($self, $value) = @_; 486 my ($self, $value) = @_;
323 $dialog 496 $dialog
324} 497}
325 498
326sub message_window { 499sub message_window {
327 my $window = new CFClient::UI::FancyFrame 500 my $window = new CFClient::UI::FancyFrame
501 title => "Messages",
328 border_bg => [1, 1, 1, 0.5], 502 border_bg => [1, 1, 1, 0.5],
329 bg => [0.3, 0.3, 0.3, 0.8], 503 bg => [0.3, 0.3, 0.3, 0.8],
330 user_w => int $::WIDTH / 3, 504 user_w => int $::WIDTH / 3,
331 user_h => int $::HEIGHT / 5, 505 user_h => int $::HEIGHT / 5,
332 child => (my $vbox = new CFClient::UI::VBox); 506 child => (my $vbox = new CFClient::UI::VBox);
374 548
375 $window 549 $window
376} 550}
377 551
378sub sdl_init { 552sub sdl_init {
379 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 553 CFClient::SDL_Init
380 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
381 and die "SDL::Init failed!\n"; 554 and die "SDL::Init failed!\n";
382} 555}
383 556
384sub video_init { 557sub video_init {
385 sdl_init; 558 sdl_init;
386 559
387 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 560 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
388 $FULLSCREEN = $CFG->{fullscreen}; 561 $FULLSCREEN = $CFG->{fullscreen};
389 $FAST = $CFG->{fast}; 562 $FAST = $CFG->{fast};
390 563
391 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 564 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
392 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
393 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
394 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
395
396 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
397 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
398 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
399 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
400
401 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
402 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
403 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
404
405 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
406 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
407 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
408 or die "SDL::SetVideoMode failed!\n"; 565 or die "SDL_SetVideoMode failed!\n";
409
410 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
411
412 $SDL_EV = new SDL::Event;
413 $SDL_EV->set_unicode (1);
414 566
415 $SDL_ACTIVE = 1; 567 $SDL_ACTIVE = 1;
416 568
417 $LAST_REFRESH = time - 0.01; 569 $LAST_REFRESH = time - 0.01;
418 570
419 CFClient::gl_init; 571 CFClient::gl_init;
420 572
421 $FONTSIZE = int $HEIGHT / 40; 573 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
422 574
423 ############################################################################# 575 #############################################################################
424 576
425 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 577 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
426 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 578 $DEBUG_STATUS->show;
427 579
428 $STATUS_LINE = new CFClient::UI::Label 580 $STATUS_LINE = new CFClient::UI::Label
429 padding => 0, 581 padding => 0,
430 y => $HEIGHT * 44 / 45 - $FONTSIZE; 582 y => $HEIGHT - $FONTSIZE * 1.8;
431 $CFClient::UI::ROOT->add ($STATUS_LINE); 583 $STATUS_LINE->show;
432 584
433 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 585 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
434 padding => 0, 586 padding => 0,
435 y => $HEIGHT * 44 / 45,
436 fontsize => $HEIGHT / 45, 587 fontsize => 0.8,
437 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 588 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
438 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 589 $ALT_ENTER_MESSAGE->show;
590 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
439 591
440 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 592 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
441 $MAPWIDGET->focus_in; 593 $MAPWIDGET->focus_in;
442 $MAPWIDGET->connect (activate_console => sub { 594 $MAPWIDGET->connect (activate_console => sub {
443 my ($mapwidget, $preset) = @_; 595 my ($mapwidget, $preset) = @_;
444 596
445 if ($CONSOLE) { 597 if ($CONSOLE) {
463 status "Configuration Saved"; 615 status "Configuration Saved";
464 }); 616 });
465 617
466 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 618 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
467 619
468 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
469 $tgw->add (my $hbox = new CFClient::UI::HBox ());
470 620
471 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
472 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
473 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
474 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
475
476 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
477 $CFClient::UI::ROOT->add ($tgw); 621 $CFClient::UI::ROOT->add (make_stats_window);
478} 622}
479 623
480sub video_shutdown { 624sub video_shutdown {
481 $CFClient::UI::ROOT->{children} = []; 625 $CFClient::UI::ROOT->{children} = [];
482 undef $SDL_ACTIVE; 626 undef $SDL_ACTIVE;
483 undef $SDL_EV;
484} 627}
485 628
629my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
486my $bgmusic;#TODO#hack#d# 630my $bgmusic;#TODO#hack#d#
487 631
632sub audio_music_finished {
633 return unless $CFG->{bgm_enable};
634
635 # TODO: hack, do play loop and mood music
636 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
637 $bgmusic->play (0);
638
639 push @bgmusic, shift @bgmusic;
640}
641
488sub audio_init { 642sub audio_init {
489 if ($CFG->{sound} || 1) { 643 if ($CFG->{audio_enable}) {
490 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 644 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
491 $SDL_MIXER = new SDL::Mixer; 645 $SDL_MIXER = !CFClient::Mix_OpenAudio;
492 $SDL_MIXER->allocate_channels (8); 646 CFClient::Mix_AllocateChannels 8;
647 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
493 648
494 if ($CFG->{bg_music_enable}) { 649 audio_music_finished;
495 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
496 $SDL_MIXER->play_music ($bgmusic, -1);
497 }
498 650
499 while (<$fh>) { 651 while (<$fh>) {
500 next if /^\s*#/; 652 next if /^\s*#/;
501 next if /^\s*$/; 653 next if /^\s*$/;
502 654
503 my ($file, $volume, $event) = split /\s+/, $_, 3; 655 my ($file, $volume, $event) = split /\s+/, $_, 3;
504 656
505 push @SOUNDS, "$volume,$file"; 657 push @SOUNDS, "$volume,$file";
506 658
507 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 659 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
508 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 660 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
509 $chunk->volume ($volume * 128 / 100); 661 $chunk->volume ($volume * 128 / 100);
510 $chunk 662 $chunk
511 }; 663 };
512 } 664 }
513 } else { 665 } else {
515 } 667 }
516 } 668 }
517} 669}
518 670
519sub audio_shutdown { 671sub audio_shutdown {
672 CFClient::Mix_CloseAudio if $SDL_MIXER;
520 undef $SDL_MIXER; 673 undef $SDL_MIXER;
521 @SOUNDS = (); 674 @SOUNDS = ();
522 %AUDIO_CHUNKS = (); 675 %AUDIO_CHUNKS = ();
523} 676}
524 677
537 $want_refresh = 0; 690 $want_refresh = 0;
538 $can_refresh = 0; 691 $can_refresh = 0;
539 692
540 $CFClient::UI::ROOT->draw; 693 $CFClient::UI::ROOT->draw;
541 694
542 SDL::GLSwapBuffers; 695 CFClient::SDL_GL_SwapBuffers;
543 696
544 $LAST_REFRESH = $NOW; 697 $LAST_REFRESH = $NOW;
545} 698}
546 699
547my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 700my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
548 $NOW = time; 701 $NOW = time;
549 702
550 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 703 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
551 while $SDL_EV->poll; 704 for CFClient::SDL_PollEvent;
552 705
553 if (%animate_object) { 706 if (%animate_object) {
554 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 707 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
555 $want_refresh++; 708 $want_refresh++;
556 } 709 }
579@conn::ISA = Crossfire::Protocol::; 732@conn::ISA = Crossfire::Protocol::;
580 733
581sub conn::stats_update { 734sub conn::stats_update {
582 my ($self, $stats) = @_; 735 my ($self, $stats) = @_;
583 736
584 # i love text protocols!!! 737 update_stats_window ($stats);
585 # FIXME: the stats are somehow weird
586 my $hp = $stats->{1};
587 my $hp_m = $stats->{2};
588 my $sp = $stats->{3};
589 my $sp_m = $stats->{4};
590 my $fo = $stats->{18};
591 my $fo_m = 1000;
592 my $gr = $stats->{23};
593 my $gr_m = $stats->{24};
594
595 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
596 $GAUGES->{hp}->set_value ($hp, $hp_m);
597 $GAUGES->{mana}->set_value ($sp, $sp_m);
598 $GAUGES->{food}->set_value ($fo, $fo_m);
599 $GAUGES->{grace}->set_value ($gr, $gr_m);
600} 738}
601 739
602sub conn::user_send { 740sub conn::user_send {
603 my ($self, $command) = @_; 741 my ($self, $command) = @_;
604 742
629 767
630 my ($hash, $x, $y, $w, $h) = @$map_info; 768 my ($hash, $x, $y, $w, $h) = @$map_info;
631 769
632 my $data = $MAP->get_rect ($x, $y, $w, $h); 770 my $data = $MAP->get_rect ($x, $y, $w, $h);
633 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 771 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
634
635 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 772 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
636
637} 773}
638 774
639sub conn::map_clear { 775sub conn::map_clear {
640 my ($self) = @_; 776 my ($self) = @_;
641 777
642 $self->flush_map; 778 $self->flush_map;
643 delete $self->{neigh}; 779 delete $self->{neigh_map};
644 780
645 $MAP->clear; 781 $MAP->clear;
646} 782}
647 783
648 784
649sub conn::load_map($$$) { 785sub conn::load_map($$$) {
650 my ($self, $hash, $x, $y) = @_; 786 my ($self, $hash, $x, $y) = @_;
651 787
652 if (defined (my $data = $MAPCACHE->get ($hash))) { 788 if (defined (my $data = $MAPCACHE->get ($hash))) {
653 $data = Compress::LZF::decompress $data; 789 $data = Compress::LZF::decompress $data;
654 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 790 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
655 for my $id ($MAP->set_rect ($x, $y, $data)) { 791 for my $id ($MAP->set_rect ($x, $y, $data)) {
656 my $data = $TILECACHE->get ($id) 792 my $data = $TILECACHE->get ($id)
657 or next; 793 or next;
658 794
659 $self->set_texture ($id => $data); 795 $self->set_texture ($id => $data);
660 } 796 }
661 } 797 }
662} 798}
663 799
800# this method does a "flood fill" into every tile direction
801# it assumes that tiles are arranged in a rectangular grid,
802# i.e. a map is the same as the left of the right map etc.
803# failure to comply are harmless and result in display errors
804# at worst.
664sub conn::flood_fill { 805sub conn::flood_fill {
665 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 806 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
666 807
667 # the server does not allow map paths > 6 808 # the server does not allow map paths > 6
668 return if 6 <= length $path; 809 return if 6 <= length $path;
669 810
670 for my $tile (1..4) { 811 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
671 next if $self->{neigh}{$hash}[$tile]; 812
813 for (
814 [1, 0, -1],
815 [2, 1, 0],
816 [3, 0, 1],
817 [4, -1, 0],
818 ) {
819 my ($tile, $dx, $dy) = @$_;
820
821 my $gx = $gx + $dx;
822 my $gy = $gy + $dy;
823
672 next unless $flags & (1 << ($tile - 1)); 824 next unless $flags & (1 << ($tile - 1));
825 next if $self->{neigh_grid}{$gx, $gy}++;
673 826
674 my $neigh = $self->{neigh}{$hash} ||= []; 827 my $neigh = $self->{neigh_map}{$hash} ||= [];
675 828 if (my $info = $neigh->[$tile]) {
676 $self->send_mapinfo ("spatial $path$tile", sub {
677 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 829 my ($flags, $x, $y, $w, $h, $hash) = @$info;
678 830
679 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
680 return if $mode ne "spatial";
681
682 $x += $MAP->ox;
683 $y += $MAP->oy;
684
685 $self->load_map ($hash, $x, $y)
686 unless $self->{neigh}{$hash}[5]++;#d#
687
688 $neigh->[$tile] = [$x, $y, $w, $h];
689
690 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 831 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
691 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 832 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
833
834 } else {
835 $self->send_mapinfo ("spatial $path$tile", sub {
836 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
837
838 return if $mode ne "spatial";
839
840 $x += $MAP->ox;
841 $y += $MAP->oy;
842
843 $self->load_map ($hash, $x, $y)
844 unless $self->{neigh_map}{$hash}[5]++;#d#
845
846 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
847
848 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
849 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
850 });
692 }); 851 }
693 } 852 }
694} 853}
695 854
696sub conn::map_change { 855sub conn::map_change {
697 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 856 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
700 859
701 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 860 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
702 861
703 my $mapmapw = 250; 862 my $mapmapw = 250;
704 my $mapmaph = 250; 863 my $mapmaph = 250;
864
865 $self->{neigh_rect} = [
866 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
867 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
868 ];
705 869
870 delete $self->{neigh_grid};
706 $self->flood_fill ("", $hash, $flags, 871 $self->flood_fill (0, 0, "", $hash, $flags);
707 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
708 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
709 872
710 $x += $ox; 873 $x += $ox;
711 $y += $oy; 874 $y += $oy;
712 875
713 $self->{map_info} = [$hash, $x, $y, $w, $h]; 876 $self->{map_info} = [$hash, $x, $y, $w, $h];
773} 936}
774 937
775sub conn::sound_play { 938sub conn::sound_play {
776 my ($self, $x, $y, $soundnum, $type) = @_; 939 my ($self, $x, $y, $soundnum, $type) = @_;
777 940
941 $SDL_MIXER
942 or return;
943
778 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 944 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
779 or return; 945 or return;
780 946
781 $SDL_MIXER->play_channel (-1, $chunk); 947 $chunk->play;
782 warn "sound $x,$y,$soundnum,$type\n";#d# 948# warn "sound $x,$y,$soundnum,$type\n";#d#
783} 949}
784 950
785sub conn::query { 951sub conn::query {
786 my ($self, $flags, $prompt) = @_; 952 my ($self, $flags, $prompt) = @_;
787 953
788 #TODO 954 #TODO, display dialog with relevant information
789 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 955 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
790} 956}
791 957
792sub conn::drawinfo { 958sub conn::drawinfo {
793 my ($self, $color, $text) = @_; 959 my ($self, $color, $text) = @_;
809 ); 975 );
810 976
811 $LOGVIEW->add_paragraph ($color[$color], $text); 977 $LOGVIEW->add_paragraph ($color[$color], $text);
812} 978}
813 979
980sub conn::spell_add {
981 my ($self, $spell) = @_;
982
983 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
984 });
985 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
986 });
987}
988
989sub conn::spell_delete {
990 my ($self, $spell) = @_;
991}
992
993sub conn::addme_success {
994 my ($self) = @_;
995
996 for my $skill (values %{$self->{skill_info}}) {
997 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
998 });
999 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
1000 });
1001 }
1002}
1003
814%SDL_CB = ( 1004%SDL_CB = (
815 SDL_QUIT() => sub { 1005 CFClient::SDL_QUIT => sub {
816 Event::unloop -1; 1006 Event::unloop -1;
817 }, 1007 },
818 SDL_VIDEORESIZE() => sub { 1008 CFClient::SDL_VIDEORESIZE => sub {
819 }, 1009 },
820 SDL_VIDEOEXPOSE() => sub { 1010 CFClient::SDL_VIDEOEXPOSE => \&refresh,
821 refresh; 1011 CFClient::SDL_ACTIVEEVENT => sub {
1012# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
822 }, 1013 },
823 SDL_KEYDOWN() => sub { 1014 CFClient::SDL_KEYDOWN => sub {
824 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 1015 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
825 # alt-enter 1016 # alt-enter
826 video_shutdown; 1017 video_shutdown;
827 $CFG->{fullscreen} = !$CFG->{fullscreen}; 1018 $CFG->{fullscreen} = !$CFG->{fullscreen};
828 video_init; 1019 video_init;
829 } else { 1020 } else {
830 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 1021 CFClient::UI::feed_sdl_key_down_event ($_[0]);
831 } 1022 }
832 }, 1023 },
833 SDL_KEYUP() => sub { 1024 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
834 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 1025 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
835 }, 1026 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
836 SDL_MOUSEMOTION() => sub { 1027 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
837 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 1028 CFClient::SDL_USEREVENT => \&audio_music_finished,
838 },
839 SDL_MOUSEBUTTONDOWN() => sub {
840 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
841 },
842 SDL_MOUSEBUTTONUP() => sub {
843 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
844 },
845 SDL_ACTIVEEVENT() => sub {
846# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
847 },
848); 1029);
849 1030
850############################################################################# 1031#############################################################################
851 1032
852$SIG{INT} = $SIG{TERM} = sub { exit }; 1033$SIG{INT} = $SIG{TERM} = sub { exit };
863 fullscreen => 0, 1044 fullscreen => 0,
864 fast => 0, 1045 fast => 0,
865 fow_enable => 1, 1046 fow_enable => 1,
866 fow_intensity => 0.45, 1047 fow_intensity => 0.45,
867 fow_smooth => 0, 1048 fow_smooth => 0,
1049 gui_fontsize => 1,
868 log_fontsize => 14, 1050 log_fontsize => 14,
869 mapsize => 100, 1051 mapsize => 100,
870 host => "crossfire.schmorp.de", 1052 host => "crossfire.schmorp.de",
871 say_command => 'say', 1053 say_command => 'say',
872 sound => 1, 1054 audio_enable => 1,
873 bg_music_enable => 1, 1055 bgm_enable => 1,
1056 bgm_volume => 0.25,
874); 1057);
875 1058
876while (my ($k, $v) = each %DEF_CFG) { 1059while (my ($k, $v) = each %DEF_CFG) {
877 $CFG->{$k} = $v unless exists $CFG->{$k}; 1060 $CFG->{$k} = $v unless exists $CFG->{$k};
878} 1061}
879 1062
880sdl_init; 1063sdl_init;
881 1064
882@SDL_MODES = reverse 1065@SDL_MODES = reverse
883 grep $_->[0] >= 640 && $_->[1] >= 480, 1066 grep $_->[0] >= 640 && $_->[1] >= 480,
884 map [SDL::RectW ($_), SDL::RectH ($_)], 1067 CFClient::SDL_ListModes;
885 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
886 1068
887@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 1069@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
888 1070
889$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 1071$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
890 1072
898video_init; 1080video_init;
899audio_init; 1081audio_init;
900 1082
901Event::loop; 1083Event::loop;
902 1084
903END { SDL::Quit } 1085END { CFClient::SDL_Quit }
904 1086
905 1087

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines