… | |
… | |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Time::HiRes 'time'; |
6 | use Time::HiRes 'time'; |
7 | use Event; |
7 | use Event; |
8 | |
8 | |
9 | use SDL; |
|
|
10 | use SDL::App; |
|
|
11 | use SDL::Event; |
|
|
12 | use SDL::Surface; |
|
|
13 | use SDL::OpenGL; |
|
|
14 | |
|
|
15 | use Crossfire; |
9 | use Crossfire; |
16 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
17 | |
11 | |
18 | use Compress::LZF; |
12 | use Compress::LZF; |
19 | |
13 | |
20 | use CFClient; |
14 | use CFClient; |
21 | use CFClient::UI; |
15 | use CFClient::UI; |
|
|
16 | use CFClient::MapWidget; |
22 | |
17 | |
23 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
24 | |
19 | |
25 | my $MAX_FPS = 60; |
20 | my $MAX_FPS = 60; |
26 | my $MIN_FPS = 5; # unused as of yet |
21 | my $MIN_FPS = 5; # unused as of yet |
… | |
… | |
52 | our $METASERVER; |
47 | our $METASERVER; |
53 | |
48 | |
54 | our $GAUGES; |
49 | our $GAUGES; |
55 | |
50 | |
56 | our $SDL_ACTIVE; |
51 | our $SDL_ACTIVE; |
57 | our $SDL_EV; |
|
|
58 | our %SDL_CB; |
52 | our %SDL_CB; |
|
|
53 | |
|
|
54 | our $SDL_MIXER; |
|
|
55 | our @SOUNDS; # event => file mapping |
|
|
56 | our %AUDIO_CHUNKS; # audio files |
59 | |
57 | |
60 | our $ALT_ENTER_MESSAGE; |
58 | our $ALT_ENTER_MESSAGE; |
61 | our $STATUS_LINE; |
59 | our $STATUS_LINE; |
62 | our $DEBUG_STATUS; |
60 | our $DEBUG_STATUS; |
63 | |
61 | |
… | |
… | |
100 | undef $CONN; |
98 | undef $CONN; |
101 | } |
99 | } |
102 | |
100 | |
103 | sub client_setup { |
101 | sub client_setup { |
104 | my $dialog = new CFClient::UI::FancyFrame |
102 | my $dialog = new CFClient::UI::FancyFrame |
|
|
103 | title => "Client Setup", |
105 | child => (my $vbox = new CFClient::UI::VBox); |
104 | 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]); |
105 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
108 | |
106 | |
109 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
107 | $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); |
108 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
111 | |
109 | |
112 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
110 | $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); |
111 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
114 | |
112 | |
115 | $mode_slider->connect (changed => sub { |
113 | $mode_slider->connect (changed => sub { |
116 | my ($self, $value) = @_; |
114 | my ($self, $value) = @_; |
117 | |
115 | |
118 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
116 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
119 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
117 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
120 | }); |
118 | }); |
121 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
119 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
122 | |
120 | |
123 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); |
121 | $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 { |
122 | $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
125 | my ($self, $value) = @_; |
123 | my ($self, $value) = @_; |
126 | $CFG->{fullscreen} = $value; |
124 | $CFG->{fullscreen} = $value; |
127 | }); |
125 | }); |
128 | |
126 | |
129 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); |
127 | $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 { |
128 | $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
131 | my ($self, $value) = @_; |
129 | my ($self, $value) = @_; |
132 | $CFG->{fast} = $value; |
130 | $CFG->{fast} = $value; |
133 | }); |
131 | }); |
134 | |
132 | |
135 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); |
133 | $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 { |
134 | $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
137 | my ($self, $value) = @_; |
135 | my ($self, $value) = @_; |
138 | $CFG->{fow_enable} = $value; |
136 | $CFG->{fow_enable} = $value; |
139 | }); |
137 | }); |
140 | |
138 | |
141 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); |
139 | $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 { |
140 | $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) = @_; |
141 | my ($self, $value) = @_; |
144 | $CFG->{fow_intensity} = $value; |
142 | $CFG->{fow_intensity} = $value; |
145 | }); |
143 | }); |
146 | |
144 | |
147 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
145 | $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 { |
146 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
149 | my ($self, $value) = @_; |
147 | my ($self, $value) = @_; |
150 | $CFG->{fow_smooth} = $value; |
148 | $CFG->{fow_smooth} = $value; |
151 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
149 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
152 | }); |
150 | }); |
153 | |
151 | |
154 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
152 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
|
|
153 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
154 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
155 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
156 | }); |
|
|
157 | |
|
|
158 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
155 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
159 | $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
156 | my ($self, $value) = @_; |
|
|
157 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
160 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
158 | }); |
161 | }); |
159 | |
162 | |
160 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
163 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
161 | destroy_screen (); |
164 | video_shutdown (); |
162 | init_screen (); |
165 | video_init (); |
|
|
166 | }); |
|
|
167 | |
|
|
168 | $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
|
|
169 | $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
|
|
170 | $CFG->{audio_enable} = $_[1]; |
|
|
171 | }); |
|
|
172 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
173 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
174 | # $CFG->{effects_volume} = $_[1]; |
|
|
175 | # }); |
|
|
176 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
177 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
|
|
178 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
|
|
179 | $CFG->{bgm_enable} = $_[1]; |
|
|
180 | }); |
|
|
181 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
|
|
182 | $CFG->{bgm_volume} = $_[1]; |
|
|
183 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
184 | }); |
|
|
185 | |
|
|
186 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
187 | audio_shutdown (); |
|
|
188 | audio_init (); |
163 | }); |
189 | }); |
164 | |
190 | |
165 | $dialog |
191 | $dialog |
166 | } |
192 | } |
167 | |
193 | |
168 | sub metaserver_dialog { |
194 | sub metaserver_dialog { |
169 | my $dialog = new CFClient::UI::FancyFrame |
195 | my $dialog = new CFClient::UI::FancyFrame |
|
|
196 | title => "Metaserver", |
170 | child => (my $vbox = new CFClient::UI::VBox); |
197 | child => (my $vbox = new CFClient::UI::VBox); |
171 | |
198 | |
172 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
199 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
173 | |
200 | |
174 | $dialog |
201 | $dialog |
… | |
… | |
231 | $HOST->set_text ($CFG->{host} = $host); |
258 | $HOST->set_text ($CFG->{host} = $host); |
232 | }), |
259 | }), |
233 | (new CFClient::UI::Empty expand => 1), |
260 | (new CFClient::UI::Empty expand => 1), |
234 | ]); |
261 | ]); |
235 | |
262 | |
236 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) |
263 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
237 | for 0 .. $#$m; |
264 | for 0 .. $#$m; |
238 | } |
265 | } |
239 | } |
266 | } |
240 | }); |
267 | }); |
241 | } |
268 | } |
242 | |
269 | |
243 | sub server_setup { |
270 | sub server_setup { |
244 | my $dialog = new CFClient::UI::FancyFrame |
271 | my $dialog = new CFClient::UI::FancyFrame |
|
|
272 | title => "Server Setup", |
245 | child => (my $vbox = new CFClient::UI::VBox); |
273 | child => (my $vbox = new CFClient::UI::VBox); |
246 | |
274 | |
247 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
|
|
248 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
275 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
249 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); |
276 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
250 | |
277 | |
251 | { |
278 | { |
252 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
279 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
253 | |
280 | |
254 | $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { |
281 | $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub { |
255 | my ($self, $value) = @_; |
282 | my ($self, $value) = @_; |
256 | $CFG->{host} = $value; |
283 | $CFG->{host} = $value; |
257 | }); |
284 | }); |
258 | |
285 | |
259 | $METASERVER = metaserver_dialog; |
286 | $METASERVER = metaserver_dialog; |
260 | |
287 | |
261 | $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { |
288 | $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub { |
262 | update_metaserver $HOST; |
289 | update_metaserver $HOST; |
263 | }); |
290 | }); |
264 | } |
291 | } |
265 | |
292 | |
266 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
293 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
267 | $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
294 | $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
268 | my ($self, $value) = @_; |
295 | my ($self, $value) = @_; |
269 | $CFG->{user} = $value; |
296 | $CFG->{user} = $value; |
270 | }); |
297 | }); |
271 | |
298 | |
272 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); |
299 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
273 | $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
300 | $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
274 | my ($self, $value) = @_; |
301 | my ($self, $value) = @_; |
275 | $CFG->{password} = $value; |
302 | $CFG->{password} = $value; |
276 | }); |
303 | }); |
277 | |
304 | |
278 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); |
305 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
279 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
306 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
280 | my ($self, $value) = @_; |
307 | my ($self, $value) = @_; |
281 | $CFG->{say_command} = $value; |
308 | $CFG->{say_command} = $value; |
282 | }); |
309 | }); |
283 | |
310 | |
284 | $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); |
311 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
285 | $table->add (1, 7, new CFClient::UI::Slider |
312 | $table->add (1, 7, new CFClient::UI::Slider |
286 | req_w => 100, |
313 | req_w => 100, |
287 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
314 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
288 | connect_changed => sub { |
315 | connect_changed => sub { |
289 | my ($self, $value) = @_; |
316 | my ($self, $value) = @_; |
… | |
… | |
299 | $dialog |
326 | $dialog |
300 | } |
327 | } |
301 | |
328 | |
302 | sub message_window { |
329 | sub message_window { |
303 | my $window = new CFClient::UI::FancyFrame |
330 | my $window = new CFClient::UI::FancyFrame |
|
|
331 | title => "Messages", |
304 | border_bg => [1, 1, 1, 0.5], |
332 | border_bg => [1, 1, 1, 0.5], |
305 | bg => [0.3, 0.3, 0.3, 0.8], |
333 | bg => [0.3, 0.3, 0.3, 0.8], |
306 | user_w => int $::WIDTH / 3, |
334 | user_w => int $::WIDTH / 3, |
307 | user_h => int $::HEIGHT / 5, |
335 | user_h => int $::HEIGHT / 5, |
308 | child => (my $vbox = new CFClient::UI::VBox); |
336 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
350 | |
378 | |
351 | $window |
379 | $window |
352 | } |
380 | } |
353 | |
381 | |
354 | sub sdl_init { |
382 | sub sdl_init { |
355 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
383 | CFClient::SDL_Init |
356 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
357 | and die "SDL::Init failed!\n"; |
384 | and die "SDL::Init failed!\n"; |
358 | } |
385 | } |
359 | |
386 | |
360 | sub init_screen { |
387 | sub video_init { |
361 | sdl_init; |
388 | sdl_init; |
362 | |
389 | |
363 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
390 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
364 | $FULLSCREEN = $CFG->{fullscreen}; |
391 | $FULLSCREEN = $CFG->{fullscreen}; |
365 | $FAST = $CFG->{fast}; |
392 | $FAST = $CFG->{fast}; |
366 | |
393 | |
367 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
394 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
368 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
369 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
370 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
|
|
371 | |
|
|
372 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
373 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
374 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
375 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
376 | |
|
|
377 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
378 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
379 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
380 | |
|
|
381 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
382 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
383 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
384 | or die "SDL::SetVideoMode failed!\n"; |
395 | or die "SDL_SetVideoMode failed!\n"; |
385 | |
|
|
386 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
387 | |
|
|
388 | $SDL_EV = new SDL::Event; |
|
|
389 | $SDL_EV->set_unicode (1); |
|
|
390 | |
396 | |
391 | $SDL_ACTIVE = 1; |
397 | $SDL_ACTIVE = 1; |
392 | |
398 | |
393 | $LAST_REFRESH = time - 0.01; |
399 | $LAST_REFRESH = time - 0.01; |
394 | |
400 | |
395 | CFClient::gl_init; |
401 | CFClient::gl_init; |
396 | |
402 | |
397 | $FONTSIZE = int $HEIGHT / 40; |
403 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
398 | |
404 | |
399 | ############################################################################# |
405 | ############################################################################# |
400 | |
406 | |
401 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
407 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
402 | $CFClient::UI::ROOT->add ($DEBUG_STATUS); |
408 | $DEBUG_STATUS->show; |
403 | |
409 | |
404 | $STATUS_LINE = new CFClient::UI::Label |
410 | $STATUS_LINE = new CFClient::UI::Label |
405 | padding => 0, |
411 | padding => 0, |
406 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
412 | y => $HEIGHT - $FONTSIZE * 1.8; |
407 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
413 | $STATUS_LINE->show; |
408 | |
414 | |
409 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
415 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
410 | padding => 0, |
416 | padding => 0, |
411 | y => $HEIGHT * 44 / 45, |
|
|
412 | fontsize => $HEIGHT / 45, |
417 | fontsize => 0.8, |
413 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
418 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
414 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
419 | $ALT_ENTER_MESSAGE->show; |
|
|
420 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
415 | |
421 | |
416 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
422 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
417 | $MAPWIDGET->focus_in; |
423 | $MAPWIDGET->focus_in; |
418 | $MAPWIDGET->connect (activate_console => sub { |
424 | $MAPWIDGET->connect (activate_console => sub { |
419 | my ($mapwidget, $preset) = @_; |
425 | my ($mapwidget, $preset) = @_; |
420 | |
426 | |
421 | if ($CONSOLE) { |
427 | if ($CONSOLE) { |
… | |
… | |
439 | status "Configuration Saved"; |
445 | status "Configuration Saved"; |
440 | }); |
446 | }); |
441 | |
447 | |
442 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
448 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
443 | |
449 | |
444 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
450 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats"); |
445 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
451 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
446 | |
452 | |
447 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
453 | $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp')); |
448 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
454 | $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana')); |
449 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
455 | $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace')); |
450 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
456 | $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food')); |
451 | |
457 | |
452 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
458 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
453 | $CFClient::UI::ROOT->add ($tgw); |
459 | $CFClient::UI::ROOT->add ($tgw); |
454 | } |
460 | } |
455 | |
461 | |
456 | sub destroy_screen { |
462 | sub video_shutdown { |
457 | $CFClient::UI::ROOT->{children} = []; |
463 | $CFClient::UI::ROOT->{children} = []; |
458 | undef $SDL_ACTIVE; |
464 | undef $SDL_ACTIVE; |
|
|
465 | } |
|
|
466 | |
|
|
467 | my $bgmusic;#TODO#hack#d# |
|
|
468 | |
|
|
469 | sub audio_init { |
|
|
470 | if ($CFG->{audio_enable}) { |
|
|
471 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
472 | |
|
|
473 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
|
|
474 | CFClient::Mix_AllocateChannels 8; |
|
|
475 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
|
|
476 | |
|
|
477 | # TODO: hack, do play loop and mood music |
|
|
478 | if ($CFG->{bgm_enable}) { |
|
|
479 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg"; |
|
|
480 | $bgmusic->play; |
|
|
481 | } |
|
|
482 | |
|
|
483 | while (<$fh>) { |
|
|
484 | next if /^\s*#/; |
|
|
485 | next if /^\s*$/; |
|
|
486 | |
|
|
487 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
488 | |
|
|
489 | push @SOUNDS, "$volume,$file"; |
|
|
490 | |
|
|
491 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
492 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
|
|
493 | $chunk->volume ($volume * 128 / 100); |
|
|
494 | $chunk |
|
|
495 | }; |
|
|
496 | } |
|
|
497 | } else { |
|
|
498 | status "unable to open sound config: $!"; |
|
|
499 | } |
|
|
500 | } |
|
|
501 | } |
|
|
502 | |
|
|
503 | sub audio_shutdown { |
|
|
504 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
459 | undef $SDL_EV; |
505 | undef $SDL_MIXER; |
460 | SDL::Quit; |
506 | @SOUNDS = (); |
|
|
507 | %AUDIO_CHUNKS = (); |
461 | } |
508 | } |
462 | |
509 | |
463 | my %animate_object; |
510 | my %animate_object; |
464 | my $animate_timer; |
511 | my $animate_timer; |
465 | |
512 | |
… | |
… | |
475 | $want_refresh = 0; |
522 | $want_refresh = 0; |
476 | $can_refresh = 0; |
523 | $can_refresh = 0; |
477 | |
524 | |
478 | $CFClient::UI::ROOT->draw; |
525 | $CFClient::UI::ROOT->draw; |
479 | |
526 | |
480 | SDL::GLSwapBuffers; |
527 | CFClient::SDL_GL_SwapBuffers; |
481 | |
528 | |
482 | $LAST_REFRESH = $NOW; |
529 | $LAST_REFRESH = $NOW; |
483 | } |
530 | } |
484 | |
531 | |
485 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
532 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
486 | $NOW = time; |
533 | $NOW = time; |
487 | |
534 | |
488 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
535 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
489 | while $SDL_EV->poll; |
536 | for CFClient::SDL_PollEvent; |
490 | |
537 | |
491 | if (%animate_object) { |
538 | if (%animate_object) { |
492 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
539 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
493 | $want_refresh++; |
540 | $want_refresh++; |
494 | } |
541 | } |
… | |
… | |
524 | my $hp = $stats->{1}; |
571 | my $hp = $stats->{1}; |
525 | my $hp_m = $stats->{2}; |
572 | my $hp_m = $stats->{2}; |
526 | my $sp = $stats->{3}; |
573 | my $sp = $stats->{3}; |
527 | my $sp_m = $stats->{4}; |
574 | my $sp_m = $stats->{4}; |
528 | my $fo = $stats->{18}; |
575 | my $fo = $stats->{18}; |
529 | my $fo_m = 1000; |
576 | my $fo_m = 999; |
530 | my $gr = $stats->{23}; |
577 | my $gr = $stats->{23}; |
531 | my $gr_m = $stats->{24}; |
578 | my $gr_m = $stats->{24}; |
532 | |
579 | |
533 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
580 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
534 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
581 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
535 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
582 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
536 | $GAUGES->{food}->set_value ($fo, $fo_m); |
583 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
537 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
584 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
538 | } |
585 | } |
539 | |
586 | |
540 | sub conn::user_send { |
587 | sub conn::user_send { |
541 | my ($self, $command) = @_; |
588 | my ($self, $command) = @_; |
… | |
… | |
576 | |
623 | |
577 | sub conn::map_clear { |
624 | sub conn::map_clear { |
578 | my ($self) = @_; |
625 | my ($self) = @_; |
579 | |
626 | |
580 | $self->flush_map; |
627 | $self->flush_map; |
581 | delete $self->{neigh}; |
628 | delete $self->{neigh_map}; |
582 | |
629 | |
583 | $MAP->clear; |
630 | $MAP->clear; |
584 | } |
631 | } |
585 | |
632 | |
586 | |
633 | |
… | |
… | |
598 | } |
645 | } |
599 | } |
646 | } |
600 | } |
647 | } |
601 | |
648 | |
602 | sub conn::flood_fill { |
649 | sub conn::flood_fill { |
603 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
650 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
604 | |
651 | |
605 | # the server does not allow map paths > 6 |
652 | # the server does not allow map paths > 6 |
606 | return if 6 <= length $path; |
653 | return if 6 <= length $path; |
607 | |
654 | |
608 | for my $tile (1..4) { |
655 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
609 | next if $self->{neigh}{$hash}[$tile]; |
656 | |
|
|
657 | for ( |
|
|
658 | [1, 0, -1], |
|
|
659 | [2, 1, 0], |
|
|
660 | [3, 0, 1], |
|
|
661 | [4, -1, 0], |
|
|
662 | ) { |
|
|
663 | my ($tile, $dx, $dy) = @$_; |
|
|
664 | |
|
|
665 | my $gx = $gx + $dx; |
|
|
666 | my $gy = $gy + $dy; |
|
|
667 | |
610 | next unless $flags & (1 << ($tile - 1)); |
668 | next unless $flags & (1 << ($tile - 1)); |
|
|
669 | next if $self->{neigh_grid}{$gx, $gy}++; |
611 | |
670 | |
612 | my $neigh = $self->{neigh}{$hash} ||= []; |
671 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
613 | |
672 | if (my $info = $neigh->[$tile]) { |
614 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
615 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
673 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
616 | |
674 | |
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) |
675 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
629 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
676 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
677 | |
|
|
678 | } else { |
|
|
679 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
680 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
681 | |
|
|
682 | return if $mode ne "spatial"; |
|
|
683 | |
|
|
684 | $x += $MAP->ox; |
|
|
685 | $y += $MAP->oy; |
|
|
686 | |
|
|
687 | $self->load_map ($hash, $x, $y) |
|
|
688 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
689 | |
|
|
690 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
691 | |
|
|
692 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
693 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
694 | }); |
630 | }); |
695 | } |
631 | } |
696 | } |
632 | } |
697 | } |
633 | |
698 | |
634 | sub conn::map_change { |
699 | sub conn::map_change { |
635 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
700 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
638 | |
703 | |
639 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
704 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
640 | |
705 | |
641 | my $mapmapw = 250; |
706 | my $mapmapw = 250; |
642 | my $mapmaph = 250; |
707 | my $mapmaph = 250; |
|
|
708 | |
|
|
709 | $self->{neigh_rect} = [ |
|
|
710 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
711 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5, |
|
|
712 | ]; |
643 | |
713 | |
|
|
714 | delete $self->{neigh_grid}; |
644 | $self->flood_fill ("", $hash, $flags, |
715 | $self->flood_fill (0, 0, "", $hash, $flags); |
645 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
646 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
647 | |
716 | |
648 | $x += $ox; |
717 | $x += $ox; |
649 | $y += $oy; |
718 | $y += $oy; |
650 | |
719 | |
651 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
720 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
… | |
… | |
708 | |
777 | |
709 | $tex |
778 | $tex |
710 | }; |
779 | }; |
711 | } |
780 | } |
712 | |
781 | |
|
|
782 | sub conn::sound_play { |
|
|
783 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
784 | |
|
|
785 | $SDL_MIXER |
|
|
786 | or return; |
|
|
787 | |
|
|
788 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
789 | or return; |
|
|
790 | |
|
|
791 | $chunk->play; |
|
|
792 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
|
|
793 | } |
|
|
794 | |
713 | sub conn::query { |
795 | sub conn::query { |
714 | my ($self, $flags, $prompt) = @_; |
796 | my ($self, $flags, $prompt) = @_; |
715 | |
797 | |
716 | #TODO |
798 | #TODO, display dialog with relevant information |
717 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
799 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
718 | } |
800 | } |
719 | |
801 | |
720 | sub conn::drawinfo { |
802 | sub conn::drawinfo { |
721 | my ($self, $color, $text) = @_; |
803 | my ($self, $color, $text) = @_; |
… | |
… | |
737 | ); |
819 | ); |
738 | |
820 | |
739 | $LOGVIEW->add_paragraph ($color[$color], $text); |
821 | $LOGVIEW->add_paragraph ($color[$color], $text); |
740 | } |
822 | } |
741 | |
823 | |
|
|
824 | sub conn::spell_add { |
|
|
825 | my ($self, $spell) = @_; |
|
|
826 | |
|
|
827 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub { |
|
|
828 | }); |
|
|
829 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub { |
|
|
830 | }); |
|
|
831 | } |
|
|
832 | |
|
|
833 | sub conn::spell_delete { |
|
|
834 | my ($self, $spell) = @_; |
|
|
835 | } |
|
|
836 | |
|
|
837 | sub conn::addme_success { |
|
|
838 | my ($self) = @_; |
|
|
839 | |
|
|
840 | for my $skill (values %{$self->{skill_info}}) { |
|
|
841 | $MAPWIDGET->add_command ("ready_skill $skill", "", sub { |
|
|
842 | }); |
|
|
843 | $MAPWIDGET->add_command ("use_skill $skill", "", sub { |
|
|
844 | }); |
|
|
845 | } |
|
|
846 | } |
|
|
847 | |
742 | %SDL_CB = ( |
848 | %SDL_CB = ( |
743 | SDL_QUIT() => sub { |
849 | CFClient::SDL_QUIT => sub { |
744 | Event::unloop -1; |
850 | Event::unloop -1; |
745 | }, |
851 | }, |
746 | SDL_VIDEORESIZE() => sub { |
852 | CFClient::SDL_VIDEORESIZE => sub { |
747 | }, |
853 | }, |
748 | SDL_VIDEOEXPOSE() => sub { |
854 | CFClient::SDL_VIDEOEXPOSE => sub { |
749 | refresh; |
855 | refresh; |
750 | }, |
856 | }, |
751 | SDL_KEYDOWN() => sub { |
857 | CFClient::SDL_KEYDOWN => sub { |
752 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
858 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
753 | # alt-enter |
859 | # alt-enter |
754 | destroy_screen; |
860 | video_shutdown; |
755 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
861 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
756 | init_screen; |
862 | video_init; |
757 | } else { |
863 | } else { |
758 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
864 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
759 | } |
865 | } |
760 | }, |
866 | }, |
761 | SDL_KEYUP() => sub { |
867 | CFClient::SDL_KEYUP => sub { |
762 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
868 | CFClient::UI::feed_sdl_key_up_event ($_[0]); |
763 | }, |
869 | }, |
764 | SDL_MOUSEMOTION() => sub { |
870 | CFClient::SDL_MOUSEMOTION => sub { |
765 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
871 | CFClient::UI::feed_sdl_motion_event ($_[0]); |
766 | }, |
872 | }, |
767 | SDL_MOUSEBUTTONDOWN() => sub { |
873 | CFClient::SDL_MOUSEBUTTONDOWN => sub { |
768 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
874 | CFClient::UI::feed_sdl_button_down_event ($_[0]); |
769 | }, |
875 | }, |
770 | SDL_MOUSEBUTTONUP() => sub { |
876 | CFClient::SDL_MOUSEBUTTONUP => sub { |
771 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
877 | CFClient::UI::feed_sdl_button_up_event ($_[0]); |
772 | }, |
878 | }, |
773 | SDL_ACTIVEEVENT() => sub { |
879 | CFClient::SDL_ACTIVEEVENT => sub { |
774 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
880 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
775 | }, |
881 | }, |
776 | ); |
882 | ); |
777 | |
883 | |
778 | ############################################################################# |
884 | ############################################################################# |
… | |
… | |
791 | fullscreen => 0, |
897 | fullscreen => 0, |
792 | fast => 0, |
898 | fast => 0, |
793 | fow_enable => 1, |
899 | fow_enable => 1, |
794 | fow_intensity => 0.45, |
900 | fow_intensity => 0.45, |
795 | fow_smooth => 0, |
901 | fow_smooth => 0, |
|
|
902 | gui_fontsize => 1, |
796 | log_fontsize => 14, |
903 | log_fontsize => 14, |
797 | mapsize => 100, |
904 | mapsize => 100, |
798 | host => "crossfire.schmorp.de", |
905 | host => "crossfire.schmorp.de", |
799 | say_command => 'say', |
906 | say_command => 'say', |
|
|
907 | audio_enable => 1, |
|
|
908 | bgm_enable => 1, |
|
|
909 | bgm_volume => 0.25, |
800 | ); |
910 | ); |
801 | |
911 | |
802 | while (my ($k, $v) = each %DEF_CFG) { |
912 | while (my ($k, $v) = each %DEF_CFG) { |
803 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
913 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
804 | } |
914 | } |
805 | |
915 | |
806 | sdl_init; |
916 | sdl_init; |
807 | |
917 | |
808 | @SDL_MODES = reverse |
918 | @SDL_MODES = reverse |
809 | grep $_->[0] >= 640 && $_->[1] >= 480, |
919 | grep $_->[0] >= 640 && $_->[1] >= 480, |
810 | map [SDL::RectW ($_), SDL::RectH ($_)], |
920 | CFClient::SDL_ListModes; |
811 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
812 | |
921 | |
813 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
922 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
814 | |
923 | |
815 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
924 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
816 | |
925 | |
… | |
… | |
819 | |
928 | |
820 | CFClient::add_font $_ for @fonts; |
929 | CFClient::add_font $_ for @fonts; |
821 | CFClient::set_font $fonts[0]; |
930 | CFClient::set_font $fonts[0]; |
822 | } |
931 | } |
823 | |
932 | |
824 | init_screen; |
933 | video_init; |
|
|
934 | audio_init; |
825 | |
935 | |
826 | Event::loop; |
936 | Event::loop; |
827 | |
937 | |
828 | END { SDL::Quit } |
938 | END { CFClient::SDL_Quit } |
829 | |
939 | |
830 | |
940 | |