… | |
… | |
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 | |
|
|
14 | use SDL::Mixer; |
|
|
15 | use SDL::Sound; |
|
|
16 | use SDL::Music; |
|
|
17 | |
|
|
18 | use SDL::OpenGL; |
|
|
19 | |
|
|
20 | use Crossfire; |
9 | use Crossfire; |
21 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
22 | |
11 | |
23 | use Compress::LZF; |
12 | use Compress::LZF; |
24 | |
13 | |
25 | use CFClient; |
14 | use CFClient; |
26 | use CFClient::UI; |
15 | use CFClient::UI; |
|
|
16 | use CFClient::MapWidget; |
27 | |
17 | |
28 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
29 | |
19 | |
30 | my $MAX_FPS = 60; |
20 | my $MAX_FPS = 60; |
31 | my $MIN_FPS = 5; # unused as of yet |
21 | my $MIN_FPS = 5; # unused as of yet |
… | |
… | |
55 | our $LOGVIEW; |
45 | our $LOGVIEW; |
56 | our $CONSOLE; |
46 | our $CONSOLE; |
57 | our $METASERVER; |
47 | our $METASERVER; |
58 | |
48 | |
59 | our $GAUGES; |
49 | our $GAUGES; |
|
|
50 | our $STATWIDS; |
60 | |
51 | |
61 | our $SDL_ACTIVE; |
52 | our $SDL_ACTIVE; |
62 | our $SDL_EV; |
|
|
63 | our %SDL_CB; |
53 | our %SDL_CB; |
64 | |
54 | |
65 | our $SDL_MIXER; |
55 | our $SDL_MIXER; |
66 | our @SOUNDS; # event => file mapping |
56 | our @SOUNDS; # event => file mapping |
67 | our %AUDIO_CHUNKS; # audio files |
57 | our %AUDIO_CHUNKS; # audio files |
… | |
… | |
109 | undef $CONN; |
99 | undef $CONN; |
110 | } |
100 | } |
111 | |
101 | |
112 | sub client_setup { |
102 | sub 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 | |
|
|
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 (); |
|
|
190 | }); |
|
|
191 | |
174 | $dialog |
192 | $dialog |
|
|
193 | } |
|
|
194 | |
|
|
195 | sub make_stats_window { |
|
|
196 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/3, y => 0, title => "Stats"); |
|
|
197 | $tgw->add (my $vb = new CFClient::UI::VBox ()); |
|
|
198 | $vb->add ($STATWIDS->{stat} = new CFClient::UI::Label valign => 0, align => -1); |
|
|
199 | $vb->add (my $hb2 = new CFClient::UI::HBox); |
|
|
200 | $hb2->add (my $hg = new CFClient::UI::Gauge (type => 'hp')); |
|
|
201 | $hb2->add (my $mg = new CFClient::UI::Gauge (type => 'mana')); |
|
|
202 | $hb2->add (my $gg = new CFClient::UI::Gauge (type => 'grace')); |
|
|
203 | $hb2->add (my $fg = new CFClient::UI::Gauge (type => 'food')); |
|
|
204 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
205 | $tgw |
|
|
206 | } |
|
|
207 | |
|
|
208 | sub update_stats_window { |
|
|
209 | my ($stats) = @_; |
|
|
210 | |
|
|
211 | $STATWIDS->{stat}->set_text ( |
|
|
212 | "Title: $stats->{21}\nExp.: " . ($stats->{11} || $stats->{28}) |
|
|
213 | . " Level: $stats->{12}\n" |
|
|
214 | . (sprintf "S%d D%d Co%d I%d W%d P%d Ch%2d, Wc%d Ac%d\n", |
|
|
215 | @$stats{5,8,9,6,7,22,10, 13, 14}) |
|
|
216 | . (sprintf "Dam %d Arm %d Speed %.2f/%.2f", |
|
|
217 | @$stats{15,16,17,19}) |
|
|
218 | ); |
175 | } |
219 | } |
176 | |
220 | |
177 | sub metaserver_dialog { |
221 | sub metaserver_dialog { |
178 | my $dialog = new CFClient::UI::FancyFrame |
222 | my $dialog = new CFClient::UI::FancyFrame |
|
|
223 | title => "Metaserver", |
179 | child => (my $vbox = new CFClient::UI::VBox); |
224 | child => (my $vbox = new CFClient::UI::VBox); |
180 | |
225 | |
181 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
226 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
182 | |
227 | |
183 | $dialog |
228 | $dialog |
… | |
… | |
240 | $HOST->set_text ($CFG->{host} = $host); |
285 | $HOST->set_text ($CFG->{host} = $host); |
241 | }), |
286 | }), |
242 | (new CFClient::UI::Empty expand => 1), |
287 | (new CFClient::UI::Empty expand => 1), |
243 | ]); |
288 | ]); |
244 | |
289 | |
245 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) |
290 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
246 | for 0 .. $#$m; |
291 | for 0 .. $#$m; |
247 | } |
292 | } |
248 | } |
293 | } |
249 | }); |
294 | }); |
250 | } |
295 | } |
251 | |
296 | |
252 | sub server_setup { |
297 | sub server_setup { |
253 | my $dialog = new CFClient::UI::FancyFrame |
298 | my $dialog = new CFClient::UI::FancyFrame |
|
|
299 | title => "Server Setup", |
254 | child => (my $vbox = new CFClient::UI::VBox); |
300 | child => (my $vbox = new CFClient::UI::VBox); |
255 | |
301 | |
256 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
|
|
257 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
302 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
258 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); |
303 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
259 | |
304 | |
260 | { |
305 | { |
261 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
306 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
262 | |
307 | |
263 | $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { |
308 | $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub { |
264 | my ($self, $value) = @_; |
309 | my ($self, $value) = @_; |
265 | $CFG->{host} = $value; |
310 | $CFG->{host} = $value; |
266 | }); |
311 | }); |
267 | |
312 | |
268 | $METASERVER = metaserver_dialog; |
313 | $METASERVER = metaserver_dialog; |
269 | |
314 | |
270 | $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { |
315 | $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub { |
271 | update_metaserver $HOST; |
316 | update_metaserver $HOST; |
272 | }); |
317 | }); |
273 | } |
318 | } |
274 | |
319 | |
275 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
320 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
276 | $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
321 | $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
277 | my ($self, $value) = @_; |
322 | my ($self, $value) = @_; |
278 | $CFG->{user} = $value; |
323 | $CFG->{user} = $value; |
279 | }); |
324 | }); |
280 | |
325 | |
281 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); |
326 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
282 | $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
327 | $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
283 | my ($self, $value) = @_; |
328 | my ($self, $value) = @_; |
284 | $CFG->{password} = $value; |
329 | $CFG->{password} = $value; |
285 | }); |
330 | }); |
286 | |
331 | |
287 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); |
332 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
288 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
333 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
289 | my ($self, $value) = @_; |
334 | my ($self, $value) = @_; |
290 | $CFG->{say_command} = $value; |
335 | $CFG->{say_command} = $value; |
291 | }); |
336 | }); |
292 | |
337 | |
293 | $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); |
338 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
294 | $table->add (1, 7, new CFClient::UI::Slider |
339 | $table->add (1, 7, new CFClient::UI::Slider |
295 | req_w => 100, |
340 | req_w => 100, |
296 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
341 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
297 | connect_changed => sub { |
342 | connect_changed => sub { |
298 | my ($self, $value) = @_; |
343 | my ($self, $value) = @_; |
… | |
… | |
308 | $dialog |
353 | $dialog |
309 | } |
354 | } |
310 | |
355 | |
311 | sub message_window { |
356 | sub message_window { |
312 | my $window = new CFClient::UI::FancyFrame |
357 | my $window = new CFClient::UI::FancyFrame |
|
|
358 | title => "Messages", |
313 | border_bg => [1, 1, 1, 0.5], |
359 | border_bg => [1, 1, 1, 0.5], |
314 | bg => [0.3, 0.3, 0.3, 0.8], |
360 | bg => [0.3, 0.3, 0.3, 0.8], |
315 | user_w => int $::WIDTH / 3, |
361 | user_w => int $::WIDTH / 3, |
316 | user_h => int $::HEIGHT / 5, |
362 | user_h => int $::HEIGHT / 5, |
317 | child => (my $vbox = new CFClient::UI::VBox); |
363 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
359 | |
405 | |
360 | $window |
406 | $window |
361 | } |
407 | } |
362 | |
408 | |
363 | sub sdl_init { |
409 | sub sdl_init { |
364 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
410 | CFClient::SDL_Init |
365 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
366 | and die "SDL::Init failed!\n"; |
411 | and die "SDL::Init failed!\n"; |
367 | } |
412 | } |
368 | |
413 | |
369 | sub video_init { |
414 | sub video_init { |
370 | sdl_init; |
415 | sdl_init; |
371 | |
416 | |
372 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
417 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
373 | $FULLSCREEN = $CFG->{fullscreen}; |
418 | $FULLSCREEN = $CFG->{fullscreen}; |
374 | $FAST = $CFG->{fast}; |
419 | $FAST = $CFG->{fast}; |
375 | |
420 | |
376 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
421 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
377 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
378 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
379 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
|
|
380 | |
|
|
381 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
382 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
383 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
384 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
385 | |
|
|
386 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
387 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
388 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
389 | |
|
|
390 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
391 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
392 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
393 | or die "SDL::SetVideoMode failed!\n"; |
422 | or die "SDL_SetVideoMode failed!\n"; |
394 | |
|
|
395 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
396 | |
|
|
397 | $SDL_EV = new SDL::Event; |
|
|
398 | $SDL_EV->set_unicode (1); |
|
|
399 | |
423 | |
400 | $SDL_ACTIVE = 1; |
424 | $SDL_ACTIVE = 1; |
401 | |
425 | |
402 | $LAST_REFRESH = time - 0.01; |
426 | $LAST_REFRESH = time - 0.01; |
403 | |
427 | |
404 | CFClient::gl_init; |
428 | CFClient::gl_init; |
405 | |
429 | |
406 | $FONTSIZE = int $HEIGHT / 40; |
430 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
407 | |
431 | |
408 | ############################################################################# |
432 | ############################################################################# |
409 | |
433 | |
410 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
434 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
411 | $CFClient::UI::ROOT->add ($DEBUG_STATUS); |
435 | $DEBUG_STATUS->show; |
412 | |
436 | |
413 | $STATUS_LINE = new CFClient::UI::Label |
437 | $STATUS_LINE = new CFClient::UI::Label |
414 | padding => 0, |
438 | padding => 0, |
415 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
439 | y => $HEIGHT - $FONTSIZE * 1.8; |
416 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
440 | $STATUS_LINE->show; |
417 | |
441 | |
418 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
442 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
419 | padding => 0, |
443 | padding => 0, |
420 | y => $HEIGHT * 44 / 45, |
|
|
421 | fontsize => $HEIGHT / 45, |
444 | fontsize => 0.8, |
422 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
445 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
423 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
446 | $ALT_ENTER_MESSAGE->show; |
|
|
447 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
424 | |
448 | |
425 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
449 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
426 | $MAPWIDGET->focus_in; |
450 | $MAPWIDGET->focus_in; |
427 | $MAPWIDGET->connect (activate_console => sub { |
451 | $MAPWIDGET->connect (activate_console => sub { |
428 | my ($mapwidget, $preset) = @_; |
452 | my ($mapwidget, $preset) = @_; |
429 | |
453 | |
430 | if ($CONSOLE) { |
454 | if ($CONSOLE) { |
… | |
… | |
448 | status "Configuration Saved"; |
472 | status "Configuration Saved"; |
449 | }); |
473 | }); |
450 | |
474 | |
451 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
475 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
452 | |
476 | |
453 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
454 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
455 | |
477 | |
456 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
457 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
458 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
459 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
460 | |
|
|
461 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
462 | $CFClient::UI::ROOT->add ($tgw); |
478 | $CFClient::UI::ROOT->add (make_stats_window); |
463 | } |
479 | } |
464 | |
480 | |
465 | sub video_shutdown { |
481 | sub video_shutdown { |
466 | $CFClient::UI::ROOT->{children} = []; |
482 | $CFClient::UI::ROOT->{children} = []; |
467 | undef $SDL_ACTIVE; |
483 | undef $SDL_ACTIVE; |
468 | undef $SDL_EV; |
|
|
469 | } |
484 | } |
470 | |
485 | |
|
|
486 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
471 | my $bgmusic;#TODO#hack#d# |
487 | my $bgmusic;#TODO#hack#d# |
472 | |
488 | |
|
|
489 | sub audio_music_finished { |
|
|
490 | return unless $CFG->{bgm_enable}; |
|
|
491 | |
|
|
492 | # TODO: hack, do play loop and mood music |
|
|
493 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
494 | $bgmusic->play (0); |
|
|
495 | |
|
|
496 | push @bgmusic, shift @bgmusic; |
|
|
497 | } |
|
|
498 | |
473 | sub audio_init { |
499 | sub audio_init { |
474 | if ($CFG->{sound} || 1) { |
500 | if ($CFG->{audio_enable}) { |
475 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
501 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
476 | $SDL_MIXER = new SDL::Mixer; |
502 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
477 | $SDL_MIXER->allocate_channels (8); |
503 | CFClient::Mix_AllocateChannels 8; |
|
|
504 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
478 | |
505 | |
479 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
506 | audio_music_finished; |
480 | $SDL_MIXER->play_music ($bgmusic, -1); |
|
|
481 | |
507 | |
482 | while (<$fh>) { |
508 | while (<$fh>) { |
483 | next if /^\s*#/; |
509 | next if /^\s*#/; |
484 | next if /^\s*$/; |
510 | next if /^\s*$/; |
485 | |
511 | |
486 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
512 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
487 | |
513 | |
488 | push @SOUNDS, "$volume,$file"; |
514 | push @SOUNDS, "$volume,$file"; |
489 | |
515 | |
490 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
516 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
491 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
517 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
492 | $chunk->volume ($volume * 128 / 100); |
518 | $chunk->volume ($volume * 128 / 100); |
493 | $chunk |
519 | $chunk |
494 | }; |
520 | }; |
495 | } |
521 | } |
496 | } else { |
522 | } else { |
… | |
… | |
498 | } |
524 | } |
499 | } |
525 | } |
500 | } |
526 | } |
501 | |
527 | |
502 | sub audio_shutdown { |
528 | sub audio_shutdown { |
|
|
529 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
503 | undef $SDL_MIXER; |
530 | undef $SDL_MIXER; |
504 | @SOUNDS = (); |
531 | @SOUNDS = (); |
505 | %AUDIO_CHUNKS = (); |
532 | %AUDIO_CHUNKS = (); |
506 | } |
533 | } |
507 | |
534 | |
… | |
… | |
520 | $want_refresh = 0; |
547 | $want_refresh = 0; |
521 | $can_refresh = 0; |
548 | $can_refresh = 0; |
522 | |
549 | |
523 | $CFClient::UI::ROOT->draw; |
550 | $CFClient::UI::ROOT->draw; |
524 | |
551 | |
525 | SDL::GLSwapBuffers; |
552 | CFClient::SDL_GL_SwapBuffers; |
526 | |
553 | |
527 | $LAST_REFRESH = $NOW; |
554 | $LAST_REFRESH = $NOW; |
528 | } |
555 | } |
529 | |
556 | |
530 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
557 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
531 | $NOW = time; |
558 | $NOW = time; |
532 | |
559 | |
533 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
560 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
534 | while $SDL_EV->poll; |
561 | for CFClient::SDL_PollEvent; |
535 | |
562 | |
536 | if (%animate_object) { |
563 | if (%animate_object) { |
537 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
564 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
538 | $want_refresh++; |
565 | $want_refresh++; |
539 | } |
566 | } |
… | |
… | |
569 | my $hp = $stats->{1}; |
596 | my $hp = $stats->{1}; |
570 | my $hp_m = $stats->{2}; |
597 | my $hp_m = $stats->{2}; |
571 | my $sp = $stats->{3}; |
598 | my $sp = $stats->{3}; |
572 | my $sp_m = $stats->{4}; |
599 | my $sp_m = $stats->{4}; |
573 | my $fo = $stats->{18}; |
600 | my $fo = $stats->{18}; |
574 | my $fo_m = 1000; |
601 | my $fo_m = 999; |
575 | my $gr = $stats->{23}; |
602 | my $gr = $stats->{23}; |
576 | my $gr_m = $stats->{24}; |
603 | my $gr_m = $stats->{24}; |
577 | |
604 | |
578 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
605 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
579 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
606 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
580 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
607 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
581 | $GAUGES->{food}->set_value ($fo, $fo_m); |
608 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
582 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
609 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
610 | |
|
|
611 | update_stats_window ($stats); |
583 | } |
612 | } |
584 | |
613 | |
585 | sub conn::user_send { |
614 | sub conn::user_send { |
586 | my ($self, $command) = @_; |
615 | my ($self, $command) = @_; |
587 | |
616 | |
… | |
… | |
612 | |
641 | |
613 | my ($hash, $x, $y, $w, $h) = @$map_info; |
642 | my ($hash, $x, $y, $w, $h) = @$map_info; |
614 | |
643 | |
615 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
644 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
616 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
645 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
617 | |
|
|
618 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
646 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
619 | |
|
|
620 | } |
647 | } |
621 | |
648 | |
622 | sub conn::map_clear { |
649 | sub conn::map_clear { |
623 | my ($self) = @_; |
650 | my ($self) = @_; |
624 | |
651 | |
625 | $self->flush_map; |
652 | $self->flush_map; |
626 | delete $self->{neigh}; |
653 | delete $self->{neigh_map}; |
627 | |
654 | |
628 | $MAP->clear; |
655 | $MAP->clear; |
629 | } |
656 | } |
630 | |
657 | |
631 | |
658 | |
632 | sub conn::load_map($$$) { |
659 | sub conn::load_map($$$) { |
633 | my ($self, $hash, $x, $y) = @_; |
660 | my ($self, $hash, $x, $y) = @_; |
634 | |
661 | |
635 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
662 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
636 | $data = Compress::LZF::decompress $data; |
663 | $data = Compress::LZF::decompress $data; |
637 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
664 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
638 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
665 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
639 | my $data = $TILECACHE->get ($id) |
666 | my $data = $TILECACHE->get ($id) |
640 | or next; |
667 | or next; |
641 | |
668 | |
642 | $self->set_texture ($id => $data); |
669 | $self->set_texture ($id => $data); |
643 | } |
670 | } |
644 | } |
671 | } |
645 | } |
672 | } |
646 | |
673 | |
|
|
674 | # this method does a "flood fill" into every tile direction |
|
|
675 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
676 | # i.e. a map is the same as the left of the right map etc. |
|
|
677 | # failure to comply are harmless and result in display errors |
|
|
678 | # at worst. |
647 | sub conn::flood_fill { |
679 | sub conn::flood_fill { |
648 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
680 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
649 | |
681 | |
650 | # the server does not allow map paths > 6 |
682 | # the server does not allow map paths > 6 |
651 | return if 6 <= length $path; |
683 | return if 6 <= length $path; |
652 | |
684 | |
653 | for my $tile (1..4) { |
685 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
654 | next if $self->{neigh}{$hash}[$tile]; |
686 | |
|
|
687 | for ( |
|
|
688 | [1, 0, -1], |
|
|
689 | [2, 1, 0], |
|
|
690 | [3, 0, 1], |
|
|
691 | [4, -1, 0], |
|
|
692 | ) { |
|
|
693 | my ($tile, $dx, $dy) = @$_; |
|
|
694 | |
|
|
695 | my $gx = $gx + $dx; |
|
|
696 | my $gy = $gy + $dy; |
|
|
697 | |
655 | next unless $flags & (1 << ($tile - 1)); |
698 | next unless $flags & (1 << ($tile - 1)); |
|
|
699 | next if $self->{neigh_grid}{$gx, $gy}++; |
656 | |
700 | |
657 | my $neigh = $self->{neigh}{$hash} ||= []; |
701 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
658 | |
702 | if (my $info = $neigh->[$tile]) { |
659 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
660 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
703 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
661 | |
704 | |
662 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
663 | return if $mode ne "spatial"; |
|
|
664 | |
|
|
665 | $x += $MAP->ox; |
|
|
666 | $y += $MAP->oy; |
|
|
667 | |
|
|
668 | $self->load_map ($hash, $x, $y) |
|
|
669 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
670 | |
|
|
671 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
672 | |
|
|
673 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
705 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
674 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
706 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
707 | |
|
|
708 | } else { |
|
|
709 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
710 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
711 | |
|
|
712 | return if $mode ne "spatial"; |
|
|
713 | |
|
|
714 | $x += $MAP->ox; |
|
|
715 | $y += $MAP->oy; |
|
|
716 | |
|
|
717 | $self->load_map ($hash, $x, $y) |
|
|
718 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
719 | |
|
|
720 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
721 | |
|
|
722 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
723 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
724 | }); |
675 | }); |
725 | } |
676 | } |
726 | } |
677 | } |
727 | } |
678 | |
728 | |
679 | sub conn::map_change { |
729 | sub conn::map_change { |
680 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
730 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
683 | |
733 | |
684 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
734 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
685 | |
735 | |
686 | my $mapmapw = 250; |
736 | my $mapmapw = 250; |
687 | my $mapmaph = 250; |
737 | my $mapmaph = 250; |
|
|
738 | |
|
|
739 | $self->{neigh_rect} = [ |
|
|
740 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
741 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
742 | ]; |
688 | |
743 | |
|
|
744 | delete $self->{neigh_grid}; |
689 | $self->flood_fill ("", $hash, $flags, |
745 | $self->flood_fill (0, 0, "", $hash, $flags); |
690 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
691 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
692 | |
746 | |
693 | $x += $ox; |
747 | $x += $ox; |
694 | $y += $oy; |
748 | $y += $oy; |
695 | |
749 | |
696 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
750 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
… | |
… | |
756 | } |
810 | } |
757 | |
811 | |
758 | sub conn::sound_play { |
812 | sub conn::sound_play { |
759 | my ($self, $x, $y, $soundnum, $type) = @_; |
813 | my ($self, $x, $y, $soundnum, $type) = @_; |
760 | |
814 | |
|
|
815 | $SDL_MIXER |
|
|
816 | or return; |
|
|
817 | |
761 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
818 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
762 | or return; |
819 | or return; |
763 | |
820 | |
764 | $SDL_MIXER->play_channel (-1, $chunk); |
821 | $chunk->play; |
765 | warn "sound $x,$y,$soundnum,$type\n";#d# |
822 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
766 | } |
823 | } |
767 | |
824 | |
768 | sub conn::query { |
825 | sub conn::query { |
769 | my ($self, $flags, $prompt) = @_; |
826 | my ($self, $flags, $prompt) = @_; |
770 | |
827 | |
771 | #TODO |
828 | #TODO, display dialog with relevant information |
772 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
829 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
773 | } |
830 | } |
774 | |
831 | |
775 | sub conn::drawinfo { |
832 | sub conn::drawinfo { |
776 | my ($self, $color, $text) = @_; |
833 | my ($self, $color, $text) = @_; |
… | |
… | |
792 | ); |
849 | ); |
793 | |
850 | |
794 | $LOGVIEW->add_paragraph ($color[$color], $text); |
851 | $LOGVIEW->add_paragraph ($color[$color], $text); |
795 | } |
852 | } |
796 | |
853 | |
|
|
854 | sub conn::spell_add { |
|
|
855 | my ($self, $spell) = @_; |
|
|
856 | |
|
|
857 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub { |
|
|
858 | }); |
|
|
859 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub { |
|
|
860 | }); |
|
|
861 | } |
|
|
862 | |
|
|
863 | sub conn::spell_delete { |
|
|
864 | my ($self, $spell) = @_; |
|
|
865 | } |
|
|
866 | |
|
|
867 | sub conn::addme_success { |
|
|
868 | my ($self) = @_; |
|
|
869 | |
|
|
870 | for my $skill (values %{$self->{skill_info}}) { |
|
|
871 | $MAPWIDGET->add_command ("ready_skill $skill", "", sub { |
|
|
872 | }); |
|
|
873 | $MAPWIDGET->add_command ("use_skill $skill", "", sub { |
|
|
874 | }); |
|
|
875 | } |
|
|
876 | } |
|
|
877 | |
797 | %SDL_CB = ( |
878 | %SDL_CB = ( |
798 | SDL_QUIT() => sub { |
879 | CFClient::SDL_QUIT => sub { |
799 | Event::unloop -1; |
880 | Event::unloop -1; |
800 | }, |
881 | }, |
801 | SDL_VIDEORESIZE() => sub { |
882 | CFClient::SDL_VIDEORESIZE => sub { |
802 | }, |
883 | }, |
803 | SDL_VIDEOEXPOSE() => sub { |
884 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
804 | refresh; |
885 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
886 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
805 | }, |
887 | }, |
806 | SDL_KEYDOWN() => sub { |
888 | CFClient::SDL_KEYDOWN => sub { |
807 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
889 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
808 | # alt-enter |
890 | # alt-enter |
809 | video_shutdown; |
891 | video_shutdown; |
810 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
892 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
811 | video_init; |
893 | video_init; |
812 | } else { |
894 | } else { |
813 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
895 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
814 | } |
896 | } |
815 | }, |
897 | }, |
816 | SDL_KEYUP() => sub { |
898 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
817 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
899 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
818 | }, |
900 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
819 | SDL_MOUSEMOTION() => sub { |
901 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
820 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
902 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
821 | }, |
|
|
822 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
823 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
824 | }, |
|
|
825 | SDL_MOUSEBUTTONUP() => sub { |
|
|
826 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
827 | }, |
|
|
828 | SDL_ACTIVEEVENT() => sub { |
|
|
829 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
830 | }, |
|
|
831 | ); |
903 | ); |
832 | |
904 | |
833 | ############################################################################# |
905 | ############################################################################# |
834 | |
906 | |
835 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
907 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
… | |
… | |
846 | fullscreen => 0, |
918 | fullscreen => 0, |
847 | fast => 0, |
919 | fast => 0, |
848 | fow_enable => 1, |
920 | fow_enable => 1, |
849 | fow_intensity => 0.45, |
921 | fow_intensity => 0.45, |
850 | fow_smooth => 0, |
922 | fow_smooth => 0, |
|
|
923 | gui_fontsize => 1, |
851 | log_fontsize => 14, |
924 | log_fontsize => 14, |
852 | mapsize => 100, |
925 | mapsize => 100, |
853 | host => "crossfire.schmorp.de", |
926 | host => "crossfire.schmorp.de", |
854 | say_command => 'say', |
927 | say_command => 'say', |
|
|
928 | audio_enable => 1, |
|
|
929 | bgm_enable => 1, |
|
|
930 | bgm_volume => 0.25, |
855 | ); |
931 | ); |
856 | |
932 | |
857 | while (my ($k, $v) = each %DEF_CFG) { |
933 | while (my ($k, $v) = each %DEF_CFG) { |
858 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
934 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
859 | } |
935 | } |
860 | |
936 | |
861 | sdl_init; |
937 | sdl_init; |
862 | |
938 | |
863 | @SDL_MODES = reverse |
939 | @SDL_MODES = reverse |
864 | grep $_->[0] >= 640 && $_->[1] >= 480, |
940 | grep $_->[0] >= 640 && $_->[1] >= 480, |
865 | map [SDL::RectW ($_), SDL::RectH ($_)], |
941 | CFClient::SDL_ListModes; |
866 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
867 | |
942 | |
868 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
943 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
869 | |
944 | |
870 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
945 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
871 | |
946 | |
… | |
… | |
879 | video_init; |
954 | video_init; |
880 | audio_init; |
955 | audio_init; |
881 | |
956 | |
882 | Event::loop; |
957 | Event::loop; |
883 | |
958 | |
884 | END { SDL::Quit } |
959 | END { CFClient::SDL_Quit } |
885 | |
960 | |
886 | |
961 | |