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.121 by root, Mon Apr 17 09:33:12 2006 UTC vs.
Revision 1.155 by root, Thu Apr 20 21:28:51 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
49our $BUTTONBAR; 44our $BUTTONBAR;
50our $LOGVIEW; 45our $LOGVIEW;
51our $CONSOLE; 46our $CONSOLE;
52our $METASERVER; 47our $METASERVER;
53 48
49our $GAUGES;
50our $STATWIDS;
51
54our $SDL_ACTIVE; 52our $SDL_ACTIVE;
55our $SDL_EV;
56our %SDL_CB; 53our %SDL_CB;
54
55our $SDL_MIXER;
56our @SOUNDS; # event => file mapping
57our %AUDIO_CHUNKS; # audio files
57 58
58our $ALT_ENTER_MESSAGE; 59our $ALT_ENTER_MESSAGE;
59our $STATUS_LINE; 60our $STATUS_LINE;
60our $DEBUG_STATUS; 61our $DEBUG_STATUS;
61 62
62sub status { 63sub status {
63 $STATUS_LINE->set_text ($_[0]); 64 $STATUS_LINE->set_text ($_[0]);
64 my ($w, $h) = $STATUS_LINE->size_request;
65 $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});
66} 66}
67 67
68sub debug { 68sub debug {
69 $DEBUG_STATUS->set_text ($_[0]); 69 $DEBUG_STATUS->set_text ($_[0]);
70 my ($w, $h) = $DEBUG_STATUS->size_request; 70 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
71 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
72} 71}
73 72
74sub start_game { 73sub start_game {
75 status "logging in..."; 74 status "logging in...";
76 75
100 undef $CONN; 99 undef $CONN;
101} 100}
102 101
103sub client_setup { 102sub client_setup {
104 my $dialog = new CFClient::UI::FancyFrame 103 my $dialog = new CFClient::UI::FancyFrame
104 title => "Client Setup",
105 child => (my $vbox = new CFClient::UI::VBox); 105 child => (my $vbox = new CFClient::UI::VBox);
106 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
107 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 106 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
108 107
109 $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");
110 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 109 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
111 110
112 $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]);
113 $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");
114 113
115 $mode_slider->connect (changed => sub { 114 $mode_slider->connect (changed => sub {
116 my ($self, $value) = @_; 115 my ($self, $value) = @_;
117 116
118 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 117 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
119 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 118 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
120 }); 119 });
121 $mode_slider->emit (changed => $mode_slider->{range}[0]); 120 $mode_slider->emit (changed => $mode_slider->{range}[0]);
122 121
123 $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");
124 $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 {
125 my ($self, $value) = @_; 124 my ($self, $value) = @_;
126 $CFG->{fullscreen} = $value; 125 $CFG->{fullscreen} = $value;
127 }); 126 });
128 127
129 $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");
130 $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 {
131 my ($self, $value) = @_; 130 my ($self, $value) = @_;
132 $CFG->{fast} = $value; 131 $CFG->{fast} = $value;
133 }); 132 });
134 133
135 $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");
136 $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 {
137 my ($self, $value) = @_; 136 my ($self, $value) = @_;
138 $CFG->{fow_enable} = $value; 137 $CFG->{fow_enable} = $value;
139 }); 138 });
140 139
141 $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");
142 $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 {
143 my ($self, $value) = @_; 142 my ($self, $value) = @_;
144 $CFG->{fow_intensity} = $value; 143 $CFG->{fow_intensity} = $value;
145 }); 144 });
146 145
147 $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");
148 $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 {
149 my ($self, $value) = @_; 148 my ($self, $value) = @_;
150 $CFG->{fow_smooth} = $value; 149 $CFG->{fow_smooth} = $value;
150 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 }); 151 });
152 152
153 $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");
154 $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 {
155 my ($self, $value) = @_;
156 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 161 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
157 }); 162 });
158 163
159 $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 {
160 destroy_screen (); 165 video_shutdown ();
161 init_screen (); 166 video_init ();
167 });
168
169 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
170 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
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];
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
187 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
188 audio_shutdown ();
189 audio_init ();
162 }); 190 });
163 191
164 $dialog 192 $dialog
193}
194
195sub make_stats_window {
196 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/3, y => 0, title => "Stats");
197
198 $tgw->add (my $vb = new CFClient::UI::VBox);
199
200 $vb->add ($STATWIDS->{stat} = new CFClient::UI::Label valign => 0, align => -1);
201
202 $vb->add (my $hb2 = new CFClient::UI::HBox expand => 1);
203
204 $hb2->add (my $hg = new CFClient::UI::Gauge type => 'hp', expand => 1);
205 $hb2->add (my $mg = new CFClient::UI::Gauge type => 'mana', expand => 1);
206 $hb2->add (my $gg = new CFClient::UI::Gauge type => 'grace', expand => 1);
207 $hb2->add (my $fg = new CFClient::UI::Gauge type => 'food', expand => 1);
208 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
209
210 $tgw
211}
212
213sub update_stats_window {
214 my ($stats) = @_;
215
216 $STATWIDS->{stat}->set_text (
217 "Title: $stats->{21}\nExp.: " . ($stats->{11} || $stats->{28})
218 . " Level: $stats->{12}\n"
219 . (sprintf "S%d D%d Co%d I%d W%d P%d Ch%2d, Wc%d Ac%d\n",
220 @$stats{5,8,9,6,7,22,10, 13, 14})
221 . (sprintf "Dam %d Arm %d Speed %.2f/%.2f",
222 @$stats{15,16,17,19})
223 );
165} 224}
166 225
167sub metaserver_dialog { 226sub metaserver_dialog {
168 my $dialog = new CFClient::UI::FancyFrame 227 my $dialog = new CFClient::UI::FancyFrame
228 title => "Metaserver",
169 child => (my $vbox = new CFClient::UI::VBox); 229 child => (my $vbox = new CFClient::UI::VBox);
170 230
171 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 231 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
172 232
173 $dialog 233 $dialog
230 $HOST->set_text ($CFG->{host} = $host); 290 $HOST->set_text ($CFG->{host} = $host);
231 }), 291 }),
232 (new CFClient::UI::Empty expand => 1), 292 (new CFClient::UI::Empty expand => 1),
233 ]); 293 ]);
234 294
235 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 295 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
236 for 0 .. $#$m; 296 for 0 .. $#$m;
237 } 297 }
238 } 298 }
239 }); 299 });
240} 300}
241 301
242sub server_setup { 302sub server_setup {
243 my $dialog = new CFClient::UI::FancyFrame 303 my $dialog = new CFClient::UI::FancyFrame
304 title => "Server Setup",
244 child => (my $vbox = new CFClient::UI::VBox); 305 child => (my $vbox = new CFClient::UI::VBox);
245 306
246 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
247 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 307 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
248 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 308 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
249 309
250 { 310 {
251 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 311 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
252 312
253 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 313 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
254 my ($self, $value) = @_; 314 my ($self, $value) = @_;
255 $CFG->{host} = $value; 315 $CFG->{host} = $value;
256 }); 316 });
257 317
258 $METASERVER = metaserver_dialog; 318 $METASERVER = metaserver_dialog;
259 319
260 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 320 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
261 update_metaserver $HOST; 321 update_metaserver $HOST;
262 }); 322 });
263 } 323 }
264 324
265 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 325 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
266 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 326 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
267 my ($self, $value) = @_; 327 my ($self, $value) = @_;
268 $CFG->{user} = $value; 328 $CFG->{user} = $value;
269 }); 329 });
270 330
271 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 331 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
272 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 332 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
273 my ($self, $value) = @_; 333 my ($self, $value) = @_;
274 $CFG->{password} = $value; 334 $CFG->{password} = $value;
275 }); 335 });
276 336
277 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 337 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
278 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 338 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
279 my ($self, $value) = @_; 339 my ($self, $value) = @_;
280 $CFG->{say_command} = $value; 340 $CFG->{say_command} = $value;
281 }); 341 });
282 342
283 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 343 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
284 $table->add (1, 7, new CFClient::UI::Slider 344 $table->add (1, 7, new CFClient::UI::Slider
285 req_w => 100, 345 req_w => 100,
286 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 346 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
287 connect_changed => sub { 347 connect_changed => sub {
288 my ($self, $value) = @_; 348 my ($self, $value) = @_;
298 $dialog 358 $dialog
299} 359}
300 360
301sub message_window { 361sub message_window {
302 my $window = new CFClient::UI::FancyFrame 362 my $window = new CFClient::UI::FancyFrame
363 title => "Messages",
303 border_bg => [1, 1, 1, 0.5], 364 border_bg => [1, 1, 1, 0.5],
304 bg => [0.3, 0.3, 0.3, 0.8], 365 bg => [0.3, 0.3, 0.3, 0.8],
305 user_w => $::WIDTH/4, 366 user_w => int $::WIDTH / 3,
306 user_h => $::HEIGHT, 367 user_h => int $::HEIGHT / 5,
307 child => (my $vbox = new CFClient::UI::VBox); 368 child => (my $vbox = new CFClient::UI::VBox);
308 369
309 $vbox->add ($LOGVIEW = new CFClient::UI::TextView 370 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
310 expand => 1, 371 expand => 1,
311 fontsize => $::CFG->{log_fontsize}, 372 fontsize => $::CFG->{log_fontsize},
312 ); 373 );
313 374
314 $vbox->add (my $input = new CFClient::UI::LineEntry 375 $vbox->add (my $input = new CFClient::UI::Entry
315 connect_focus_in => sub { 376 connect_focus_in => sub {
316 my ($input, $prev_focus) = @_; 377 my ($input, $prev_focus) = @_;
317 378
318 delete $input->{refocus_map}; 379 delete $input->{refocus_map};
319 380
325 connect_activate => sub { 386 connect_activate => sub {
326 my ($input, $text) = @_; 387 my ($input, $text) = @_;
327 $input->set_text (''); 388 $input->set_text ('');
328 389
329 if ($text =~ /^\/(.*)/) { 390 if ($text =~ /^\/(.*)/) {
330 $::CONN->user_send ("command $1"); 391 $::CONN->user_send ($1);
331 } else { 392 } else {
332 my $say_cmd = $::CFG->{say_command} || 'say'; 393 my $say_cmd = $::CFG->{say_command} || 'say';
333 $::CONN->user_send ("command $say_cmd $text"); 394 $::CONN->user_send ("$say_cmd $text");
334 } 395 }
335 if ($input->{refocus_map}) { 396 if ($input->{refocus_map}) {
336 delete $input->{refocus_map}; 397 delete $input->{refocus_map};
337 $MAPWIDGET->focus_in 398 $MAPWIDGET->focus_in
338 } 399 }
349 410
350 $window 411 $window
351} 412}
352 413
353sub sdl_init { 414sub sdl_init {
354 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 415 CFClient::SDL_Init
355 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
356 and die "SDL::Init failed!\n"; 416 and die "SDL::Init failed!\n";
357} 417}
358 418
359sub init_screen { 419sub video_init {
360 sdl_init; 420 sdl_init;
361 421
362 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 422 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
363 $FULLSCREEN = $CFG->{fullscreen}; 423 $FULLSCREEN = $CFG->{fullscreen};
364 $FAST = $CFG->{fast}; 424 $FAST = $CFG->{fast};
365 425
366 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 426 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
367 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
368 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
369 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
370
371 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
372 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
373 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
374 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
375
376 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
377 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
378 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
379
380 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
381 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
382 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
383 or die "SDL::SetVideoMode failed!\n"; 427 or die "SDL_SetVideoMode failed!\n";
384
385 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
386
387 $SDL_EV = new SDL::Event;
388 $SDL_EV->set_unicode (1);
389 428
390 $SDL_ACTIVE = 1; 429 $SDL_ACTIVE = 1;
391 430
392 $LAST_REFRESH = time - 0.01; 431 $LAST_REFRESH = time - 0.01;
393 432
394 CFClient::gl_init; 433 CFClient::gl_init;
395 434
396 $FONTSIZE = int $HEIGHT / 40; 435 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
397 436
398 ############################################################################# 437 #############################################################################
399 438
400 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 439 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
401 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 440 $DEBUG_STATUS->show;
402 441
403 $STATUS_LINE = new CFClient::UI::Label 442 $STATUS_LINE = new CFClient::UI::Label
404 padding => 0, 443 padding => 0,
405 y => $HEIGHT * 44 / 45 - $FONTSIZE; 444 y => $HEIGHT - $FONTSIZE * 1.8;
406 $CFClient::UI::ROOT->add ($STATUS_LINE); 445 $STATUS_LINE->show;
407 446
408 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 447 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
409 padding => 0, 448 padding => 0,
410 y => $HEIGHT * 44 / 45, 449 fontsize => 0.8,
411 height => $HEIGHT / 45,
412 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 450 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
413 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 451 $ALT_ENTER_MESSAGE->show;
452 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
414 453
415 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 454 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
416 $MAPWIDGET->focus_in; 455 $MAPWIDGET->focus_in;
417 $MAPWIDGET->connect (activate_console => sub { 456 $MAPWIDGET->connect (activate_console => sub {
418 my ($mapwidget, $preset) = @_; 457 my ($mapwidget, $preset) = @_;
419 458
420 if ($CONSOLE) { 459 if ($CONSOLE) {
437 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 476 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
438 status "Configuration Saved"; 477 status "Configuration Saved";
439 }); 478 });
440 479
441 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 480 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442}
443 481
444sub destroy_screen { 482
483 $CFClient::UI::ROOT->add (make_stats_window);
484}
485
486sub video_shutdown {
445 $CFClient::UI::ROOT->{children} = []; 487 $CFClient::UI::ROOT->{children} = [];
446 undef $SDL_ACTIVE; 488 undef $SDL_ACTIVE;
489}
490
491my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
492my $bgmusic;#TODO#hack#d#
493
494sub audio_music_finished {
495 return unless $CFG->{bgm_enable};
496
497 # TODO: hack, do play loop and mood music
498 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
499 $bgmusic->play (0);
500
501 push @bgmusic, shift @bgmusic;
502}
503
504sub audio_init {
505 if ($CFG->{audio_enable}) {
506 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
507 $SDL_MIXER = !CFClient::Mix_OpenAudio;
508 CFClient::Mix_AllocateChannels 8;
509 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
510
511 audio_music_finished;
512
513 while (<$fh>) {
514 next if /^\s*#/;
515 next if /^\s*$/;
516
517 my ($file, $volume, $event) = split /\s+/, $_, 3;
518
519 push @SOUNDS, "$volume,$file";
520
521 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
522 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
523 $chunk->volume ($volume * 128 / 100);
524 $chunk
525 };
526 }
527 } else {
528 status "unable to open sound config: $!";
529 }
530 }
531}
532
533sub audio_shutdown {
534 CFClient::Mix_CloseAudio if $SDL_MIXER;
447 undef $SDL_EV; 535 undef $SDL_MIXER;
448 SDL::Quit; 536 @SOUNDS = ();
537 %AUDIO_CHUNKS = ();
449} 538}
450 539
451my %animate_object; 540my %animate_object;
452my $animate_timer; 541my $animate_timer;
453 542
463 $want_refresh = 0; 552 $want_refresh = 0;
464 $can_refresh = 0; 553 $can_refresh = 0;
465 554
466 $CFClient::UI::ROOT->draw; 555 $CFClient::UI::ROOT->draw;
467 556
468 SDL::GLSwapBuffers; 557 CFClient::SDL_GL_SwapBuffers;
469 558
470 $LAST_REFRESH = $NOW; 559 $LAST_REFRESH = $NOW;
471} 560}
472 561
473my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 562my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
474 $NOW = time; 563 $NOW = time;
475 564
476 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 565 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
477 while $SDL_EV->poll; 566 for CFClient::SDL_PollEvent;
478 567
479 if (%animate_object) { 568 if (%animate_object) {
480 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 569 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
481 $want_refresh++; 570 $want_refresh++;
482 } 571 }
502 delete $animate_object{$widget}; 591 delete $animate_object{$widget};
503} 592}
504 593
505@conn::ISA = Crossfire::Protocol::; 594@conn::ISA = Crossfire::Protocol::;
506 595
596sub conn::stats_update {
597 my ($self, $stats) = @_;
598
599 # i love text protocols!!!
600 # FIXME: the stats are somehow weird
601 my $hp = $stats->{1};
602 my $hp_m = $stats->{2};
603 my $sp = $stats->{3};
604 my $sp_m = $stats->{4};
605 my $fo = $stats->{18};
606 my $fo_m = 999;
607 my $gr = $stats->{23};
608 my $gr_m = $stats->{24};
609
610 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
611 $GAUGES->{hp} ->set_value ($hp, $hp_m);
612 $GAUGES->{mana} ->set_value ($sp, $sp_m);
613 $GAUGES->{food} ->set_value ($fo, $fo_m);
614 $GAUGES->{grace}->set_value ($gr, $gr_m);
615
616 update_stats_window ($stats);
617}
618
507sub conn::user_send { 619sub conn::user_send {
508 my ($self, $command) = @_; 620 my ($self, $command) = @_;
509 621
510 $self->send ($command); 622 $self->send_command ($command);
511 status $command; 623 status $command;
512} 624}
513 625
514sub conn::map_scroll { 626sub conn::map_scroll {
515 my ($self, $dx, $dy) = @_; 627 my ($self, $dx, $dy) = @_;
534 646
535 my ($hash, $x, $y, $w, $h) = @$map_info; 647 my ($hash, $x, $y, $w, $h) = @$map_info;
536 648
537 my $data = $MAP->get_rect ($x, $y, $w, $h); 649 my $data = $MAP->get_rect ($x, $y, $w, $h);
538 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 650 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
539
540 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 651 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
541
542} 652}
543 653
544sub conn::map_clear { 654sub conn::map_clear {
545 my ($self) = @_; 655 my ($self) = @_;
546 656
547 $self->flush_map; 657 $self->flush_map;
548 delete $self->{neigh}; 658 delete $self->{neigh_map};
549 659
550 $MAP->clear; 660 $MAP->clear;
551} 661}
552 662
553 663
554sub conn::load_map($$$) { 664sub conn::load_map($$$) {
555 my ($self, $hash, $x, $y) = @_; 665 my ($self, $hash, $x, $y) = @_;
556 666
557 if (defined (my $data = $MAPCACHE->get ($hash))) { 667 if (defined (my $data = $MAPCACHE->get ($hash))) {
558 $data = Compress::LZF::decompress $data; 668 $data = Compress::LZF::decompress $data;
559 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 669 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
560 for my $id ($MAP->set_rect ($x, $y, $data)) { 670 for my $id ($MAP->set_rect ($x, $y, $data)) {
561 my $data = $TILECACHE->get ($id) 671 my $data = $TILECACHE->get ($id)
562 or next; 672 or next;
563 673
564 $self->set_texture ($id => $data); 674 $self->set_texture ($id => $data);
565 } 675 }
566 } 676 }
567} 677}
568 678
679# this method does a "flood fill" into every tile direction
680# it assumes that tiles are arranged in a rectangular grid,
681# i.e. a map is the same as the left of the right map etc.
682# failure to comply are harmless and result in display errors
683# at worst.
569sub conn::flood_fill { 684sub conn::flood_fill {
570 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 685 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
571 686
572 # the server does not allow map paths > 6 687 # the server does not allow map paths > 6
573 return if 6 <= length $path; 688 return if 6 <= length $path;
574 689
575 for my $tile (1..4) { 690 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
576 next if $self->{neigh}{$hash}[$tile]; 691
692 for (
693 [1, 0, -1],
694 [2, 1, 0],
695 [3, 0, 1],
696 [4, -1, 0],
697 ) {
698 my ($tile, $dx, $dy) = @$_;
699
700 my $gx = $gx + $dx;
701 my $gy = $gy + $dy;
702
577 next unless $flags & (1 << ($tile - 1)); 703 next unless $flags & (1 << ($tile - 1));
704 next if $self->{neigh_grid}{$gx, $gy}++;
578 705
579 my $neigh = $self->{neigh}{$hash} ||= []; 706 my $neigh = $self->{neigh_map}{$hash} ||= [];
580 707 if (my $info = $neigh->[$tile]) {
581 $self->send_mapinfo ("spatial $path$tile", sub {
582 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 708 my ($flags, $x, $y, $w, $h, $hash) = @$info;
583 709
584 warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
585 return if $mode ne "spatial";
586
587 $x += $MAP->ox;
588 $y += $MAP->oy;
589
590 $self->load_map ($hash, $x, $y);
591
592 $neigh->[$tile] = [$x, $y, $w, $h];
593
594 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 710 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
595 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 711 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
712
713 } else {
714 $self->send_mapinfo ("spatial $path$tile", sub {
715 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
716
717 return if $mode ne "spatial";
718
719 $x += $MAP->ox;
720 $y += $MAP->oy;
721
722 $self->load_map ($hash, $x, $y)
723 unless $self->{neigh_map}{$hash}[5]++;#d#
724
725 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
726
727 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
728 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
729 });
596 }); 730 }
597 } 731 }
598} 732}
599 733
600sub conn::map_change { 734sub conn::map_change {
601 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 735 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
602 736
603 $self->flush_map; 737 $self->flush_map;
604 738
605 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 739 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
606 740
607 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
608
609 my $mapmapw = 250; 741 my $mapmapw = 250;
610 my $mapmaph = 250; 742 my $mapmaph = 250;
743
744 $self->{neigh_rect} = [
745 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
746 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
747 ];
611 748
749 delete $self->{neigh_grid};
612 $self->flood_fill ("", $hash, $flags, 750 $self->flood_fill (0, 0, "", $hash, $flags);
613 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
614 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
615 751
616 $x += $ox; 752 $x += $ox;
617 $y += $oy; 753 $y += $oy;
618 754
619 $self->{map_info} = [$hash, $x, $y, $w, $h]; 755 $self->{map_info} = [$hash, $x, $y, $w, $h];
676 812
677 $tex 813 $tex
678 }; 814 };
679} 815}
680 816
817sub conn::sound_play {
818 my ($self, $x, $y, $soundnum, $type) = @_;
819
820 $SDL_MIXER
821 or return;
822
823 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
824 or return;
825
826 $chunk->play;
827# warn "sound $x,$y,$soundnum,$type\n";#d#
828}
829
681sub conn::query { 830sub conn::query {
682 my ($self, $flags, $prompt) = @_; 831 my ($self, $flags, $prompt) = @_;
683 832
684 #TODO 833 #TODO, display dialog with relevant information
685 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 834 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
686} 835}
687 836
688sub conn::drawinfo { 837sub conn::drawinfo {
689 my ($self, $color, $text) = @_; 838 my ($self, $color, $text) = @_;
705 ); 854 );
706 855
707 $LOGVIEW->add_paragraph ($color[$color], $text); 856 $LOGVIEW->add_paragraph ($color[$color], $text);
708} 857}
709 858
859sub conn::spell_add {
860 my ($self, $spell) = @_;
861
862 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
863 });
864 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
865 });
866}
867
868sub conn::spell_delete {
869 my ($self, $spell) = @_;
870}
871
872sub conn::addme_success {
873 my ($self) = @_;
874
875 for my $skill (values %{$self->{skill_info}}) {
876 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
877 });
878 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
879 });
880 }
881}
882
710%SDL_CB = ( 883%SDL_CB = (
711 SDL_QUIT() => sub { 884 CFClient::SDL_QUIT => sub {
712 Event::unloop -1; 885 Event::unloop -1;
713 }, 886 },
714 SDL_VIDEORESIZE() => sub { 887 CFClient::SDL_VIDEORESIZE => sub {
715 }, 888 },
716 SDL_VIDEOEXPOSE() => sub { 889 CFClient::SDL_VIDEOEXPOSE => \&refresh,
717 refresh; 890 CFClient::SDL_ACTIVEEVENT => sub {
891# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
718 }, 892 },
719 SDL_KEYDOWN() => sub { 893 CFClient::SDL_KEYDOWN => sub {
720 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 894 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
721 # alt-enter 895 # alt-enter
722 destroy_screen; 896 video_shutdown;
723 $CFG->{fullscreen} = !$CFG->{fullscreen}; 897 $CFG->{fullscreen} = !$CFG->{fullscreen};
724 init_screen; 898 video_init;
725 } else { 899 } else {
726 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 900 CFClient::UI::feed_sdl_key_down_event ($_[0]);
727 } 901 }
728 }, 902 },
729 SDL_KEYUP() => sub { 903 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
730 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 904 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
731 }, 905 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
732 SDL_MOUSEMOTION() => sub { 906 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
733 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 907 CFClient::SDL_USEREVENT => \&audio_music_finished,
734 },
735 SDL_MOUSEBUTTONDOWN() => sub {
736 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
737 },
738 SDL_MOUSEBUTTONUP() => sub {
739 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
740 },
741 SDL_ACTIVEEVENT() => sub {
742# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
743 },
744); 908);
745 909
746############################################################################# 910#############################################################################
911
912$SIG{INT} = $SIG{TERM} = sub { exit };
747 913
748$TILECACHE = CFClient::db_table "tilecache"; 914$TILECACHE = CFClient::db_table "tilecache";
749$FACEMAP = CFClient::db_table "facemap"; 915$FACEMAP = CFClient::db_table "facemap";
750 916
751CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 917CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
757 fullscreen => 0, 923 fullscreen => 0,
758 fast => 0, 924 fast => 0,
759 fow_enable => 1, 925 fow_enable => 1,
760 fow_intensity => 0.45, 926 fow_intensity => 0.45,
761 fow_smooth => 0, 927 fow_smooth => 0,
928 gui_fontsize => 1,
762 log_fontsize => 14, 929 log_fontsize => 14,
763 mapsize => 100, 930 mapsize => 100,
764 host => "crossfire.schmorp.de", 931 host => "crossfire.schmorp.de",
765 say_command => 'say', 932 say_command => 'say',
933 audio_enable => 1,
934 bgm_enable => 1,
935 bgm_volume => 0.25,
766); 936);
767 937
768while (my ($k, $v) = each %DEF_CFG) { 938while (my ($k, $v) = each %DEF_CFG) {
769 $CFG->{$k} = $v unless exists $CFG->{$k}; 939 $CFG->{$k} = $v unless exists $CFG->{$k};
770} 940}
771 941
772sdl_init; 942sdl_init;
773 943
774@SDL_MODES = reverse 944@SDL_MODES = reverse
775 grep $_->[0] >= 640 && $_->[1] >= 480, 945 grep $_->[0] >= 640 && $_->[1] >= 480,
776 map [SDL::RectW ($_), SDL::RectH ($_)], 946 CFClient::SDL_ListModes;
777 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
778 947
779@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 948@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
780 949
781$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 950$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
782
783init_screen;
784 951
785{ 952{
786 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 953 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
787 954
788 CFClient::add_font $_ for @fonts; 955 CFClient::add_font $_ for @fonts;
789 CFClient::set_font $fonts[0]; 956 CFClient::set_font $fonts[0];
790} 957}
791 958
959video_init;
960audio_init;
961
792Event::loop; 962Event::loop;
793 963
964END { CFClient::SDL_Quit }
794 965
966

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines