… | |
… | |
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 | |
174 | $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound"); |
169 | $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
175 | $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{sound}, connect_changed => sub { |
|
|
176 | my ($self, $value) = @_; |
|
|
177 | $CFG->{sound} = $value; |
|
|
178 | }); |
|
|
179 | $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music"); |
|
|
180 | $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bg_music_enable}, connect_changed => sub { |
170 | $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
181 | my ($self, $value) = @_; |
|
|
182 | $CFG->{bg_music_enable} = $value; |
171 | $CFG->{audio_enable} = $_[1]; |
|
|
172 | }); |
|
|
173 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
174 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
175 | # $CFG->{effects_volume} = $_[1]; |
183 | }); |
176 | # }); |
|
|
177 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
178 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
|
|
179 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
|
|
180 | $CFG->{bgm_enable} = $_[1]; |
|
|
181 | }); |
|
|
182 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
|
|
183 | $CFG->{bgm_volume} = $_[1]; |
|
|
184 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
185 | }); |
|
|
186 | |
184 | $table->add (1, 10, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
187 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
185 | audio_shutdown (); |
188 | audio_shutdown (); |
186 | audio_init (); |
189 | audio_init (); |
187 | }); |
190 | }); |
188 | |
191 | |
189 | $dialog |
192 | $dialog |
190 | } |
193 | } |
191 | |
194 | |
|
|
195 | sub 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 | |
|
|
213 | sub 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 | ); |
|
|
224 | } |
|
|
225 | |
192 | sub metaserver_dialog { |
226 | sub metaserver_dialog { |
193 | my $dialog = new CFClient::UI::FancyFrame |
227 | my $dialog = new CFClient::UI::FancyFrame |
|
|
228 | title => "Metaserver", |
194 | child => (my $vbox = new CFClient::UI::VBox); |
229 | child => (my $vbox = new CFClient::UI::VBox); |
195 | |
230 | |
196 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
231 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
197 | |
232 | |
198 | $dialog |
233 | $dialog |
… | |
… | |
255 | $HOST->set_text ($CFG->{host} = $host); |
290 | $HOST->set_text ($CFG->{host} = $host); |
256 | }), |
291 | }), |
257 | (new CFClient::UI::Empty expand => 1), |
292 | (new CFClient::UI::Empty expand => 1), |
258 | ]); |
293 | ]); |
259 | |
294 | |
260 | $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) |
261 | for 0 .. $#$m; |
296 | for 0 .. $#$m; |
262 | } |
297 | } |
263 | } |
298 | } |
264 | }); |
299 | }); |
265 | } |
300 | } |
266 | |
301 | |
267 | sub server_setup { |
302 | sub server_setup { |
268 | my $dialog = new CFClient::UI::FancyFrame |
303 | my $dialog = new CFClient::UI::FancyFrame |
|
|
304 | title => "Server Setup", |
269 | child => (my $vbox = new CFClient::UI::VBox); |
305 | child => (my $vbox = new CFClient::UI::VBox); |
270 | |
306 | |
271 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
|
|
272 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
307 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
273 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); |
308 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
274 | |
309 | |
275 | { |
310 | { |
276 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
311 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
277 | |
312 | |
278 | $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 { |
279 | my ($self, $value) = @_; |
314 | my ($self, $value) = @_; |
280 | $CFG->{host} = $value; |
315 | $CFG->{host} = $value; |
281 | }); |
316 | }); |
282 | |
317 | |
283 | $METASERVER = metaserver_dialog; |
318 | $METASERVER = metaserver_dialog; |
284 | |
319 | |
285 | $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 { |
286 | update_metaserver $HOST; |
321 | update_metaserver $HOST; |
287 | }); |
322 | }); |
288 | } |
323 | } |
289 | |
324 | |
290 | $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"); |
291 | $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 { |
292 | my ($self, $value) = @_; |
327 | my ($self, $value) = @_; |
293 | $CFG->{user} = $value; |
328 | $CFG->{user} = $value; |
294 | }); |
329 | }); |
295 | |
330 | |
296 | $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"); |
297 | $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 { |
298 | my ($self, $value) = @_; |
333 | my ($self, $value) = @_; |
299 | $CFG->{password} = $value; |
334 | $CFG->{password} = $value; |
300 | }); |
335 | }); |
301 | |
336 | |
302 | $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"); |
303 | $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 { |
304 | my ($self, $value) = @_; |
339 | my ($self, $value) = @_; |
305 | $CFG->{say_command} = $value; |
340 | $CFG->{say_command} = $value; |
306 | }); |
341 | }); |
307 | |
342 | |
308 | $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"); |
309 | $table->add (1, 7, new CFClient::UI::Slider |
344 | $table->add (1, 7, new CFClient::UI::Slider |
310 | req_w => 100, |
345 | req_w => 100, |
311 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
346 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
312 | connect_changed => sub { |
347 | connect_changed => sub { |
313 | my ($self, $value) = @_; |
348 | my ($self, $value) = @_; |
… | |
… | |
323 | $dialog |
358 | $dialog |
324 | } |
359 | } |
325 | |
360 | |
326 | sub message_window { |
361 | sub message_window { |
327 | my $window = new CFClient::UI::FancyFrame |
362 | my $window = new CFClient::UI::FancyFrame |
|
|
363 | title => "Messages", |
328 | border_bg => [1, 1, 1, 0.5], |
364 | border_bg => [1, 1, 1, 0.5], |
329 | bg => [0.3, 0.3, 0.3, 0.8], |
365 | bg => [0.3, 0.3, 0.3, 0.8], |
330 | user_w => int $::WIDTH / 3, |
366 | user_w => int $::WIDTH / 3, |
331 | user_h => int $::HEIGHT / 5, |
367 | user_h => int $::HEIGHT / 5, |
332 | child => (my $vbox = new CFClient::UI::VBox); |
368 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
374 | |
410 | |
375 | $window |
411 | $window |
376 | } |
412 | } |
377 | |
413 | |
378 | sub sdl_init { |
414 | sub sdl_init { |
379 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
415 | CFClient::SDL_Init |
380 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
381 | and die "SDL::Init failed!\n"; |
416 | and die "SDL::Init failed!\n"; |
382 | } |
417 | } |
383 | |
418 | |
384 | sub video_init { |
419 | sub video_init { |
385 | sdl_init; |
420 | sdl_init; |
386 | |
421 | |
387 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
422 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
388 | $FULLSCREEN = $CFG->{fullscreen}; |
423 | $FULLSCREEN = $CFG->{fullscreen}; |
389 | $FAST = $CFG->{fast}; |
424 | $FAST = $CFG->{fast}; |
390 | |
425 | |
391 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
426 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
392 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
393 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
394 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
|
|
395 | |
|
|
396 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
397 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
398 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
399 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
400 | |
|
|
401 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
402 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
403 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
404 | |
|
|
405 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
406 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
407 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
408 | or die "SDL::SetVideoMode failed!\n"; |
427 | or die "SDL_SetVideoMode failed!\n"; |
409 | |
|
|
410 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
411 | |
|
|
412 | $SDL_EV = new SDL::Event; |
|
|
413 | $SDL_EV->set_unicode (1); |
|
|
414 | |
428 | |
415 | $SDL_ACTIVE = 1; |
429 | $SDL_ACTIVE = 1; |
416 | |
430 | |
417 | $LAST_REFRESH = time - 0.01; |
431 | $LAST_REFRESH = time - 0.01; |
418 | |
432 | |
419 | CFClient::gl_init; |
433 | CFClient::gl_init; |
420 | |
434 | |
421 | $FONTSIZE = int $HEIGHT / 40; |
435 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
422 | |
436 | |
423 | ############################################################################# |
437 | ############################################################################# |
424 | |
438 | |
425 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
439 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
426 | $CFClient::UI::ROOT->add ($DEBUG_STATUS); |
440 | $DEBUG_STATUS->show; |
427 | |
441 | |
428 | $STATUS_LINE = new CFClient::UI::Label |
442 | $STATUS_LINE = new CFClient::UI::Label |
429 | padding => 0, |
443 | padding => 0, |
430 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
444 | y => $HEIGHT - $FONTSIZE * 1.8; |
431 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
445 | $STATUS_LINE->show; |
432 | |
446 | |
433 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
447 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
434 | padding => 0, |
448 | padding => 0, |
435 | y => $HEIGHT * 44 / 45, |
|
|
436 | fontsize => $HEIGHT / 45, |
449 | fontsize => 0.8, |
437 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
450 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
438 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
451 | $ALT_ENTER_MESSAGE->show; |
|
|
452 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
439 | |
453 | |
440 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
454 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
441 | $MAPWIDGET->focus_in; |
455 | $MAPWIDGET->focus_in; |
442 | $MAPWIDGET->connect (activate_console => sub { |
456 | $MAPWIDGET->connect (activate_console => sub { |
443 | my ($mapwidget, $preset) = @_; |
457 | my ($mapwidget, $preset) = @_; |
444 | |
458 | |
445 | if ($CONSOLE) { |
459 | if ($CONSOLE) { |
… | |
… | |
463 | status "Configuration Saved"; |
477 | status "Configuration Saved"; |
464 | }); |
478 | }); |
465 | |
479 | |
466 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
480 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
467 | |
481 | |
468 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
469 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
470 | |
482 | |
471 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
472 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
473 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
474 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
475 | |
|
|
476 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
477 | $CFClient::UI::ROOT->add ($tgw); |
483 | $CFClient::UI::ROOT->add (make_stats_window); |
478 | } |
484 | } |
479 | |
485 | |
480 | sub video_shutdown { |
486 | sub video_shutdown { |
481 | $CFClient::UI::ROOT->{children} = []; |
487 | $CFClient::UI::ROOT->{children} = []; |
482 | undef $SDL_ACTIVE; |
488 | undef $SDL_ACTIVE; |
483 | undef $SDL_EV; |
|
|
484 | } |
489 | } |
485 | |
490 | |
|
|
491 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
486 | my $bgmusic;#TODO#hack#d# |
492 | my $bgmusic;#TODO#hack#d# |
487 | |
493 | |
|
|
494 | sub 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 | |
488 | sub audio_init { |
504 | sub audio_init { |
489 | if ($CFG->{sound} || 1) { |
505 | if ($CFG->{audio_enable}) { |
490 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
506 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
491 | $SDL_MIXER = new SDL::Mixer; |
507 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
492 | $SDL_MIXER->allocate_channels (8); |
508 | CFClient::Mix_AllocateChannels 8; |
|
|
509 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
493 | |
510 | |
494 | if ($CFG->{bg_music_enable}) { |
511 | audio_music_finished; |
495 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
|
|
496 | $SDL_MIXER->play_music ($bgmusic, -1); |
|
|
497 | } |
|
|
498 | |
512 | |
499 | while (<$fh>) { |
513 | while (<$fh>) { |
500 | next if /^\s*#/; |
514 | next if /^\s*#/; |
501 | next if /^\s*$/; |
515 | next if /^\s*$/; |
502 | |
516 | |
503 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
517 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
504 | |
518 | |
505 | push @SOUNDS, "$volume,$file"; |
519 | push @SOUNDS, "$volume,$file"; |
506 | |
520 | |
507 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
521 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
508 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
522 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
509 | $chunk->volume ($volume * 128 / 100); |
523 | $chunk->volume ($volume * 128 / 100); |
510 | $chunk |
524 | $chunk |
511 | }; |
525 | }; |
512 | } |
526 | } |
513 | } else { |
527 | } else { |
… | |
… | |
515 | } |
529 | } |
516 | } |
530 | } |
517 | } |
531 | } |
518 | |
532 | |
519 | sub audio_shutdown { |
533 | sub audio_shutdown { |
|
|
534 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
520 | undef $SDL_MIXER; |
535 | undef $SDL_MIXER; |
521 | @SOUNDS = (); |
536 | @SOUNDS = (); |
522 | %AUDIO_CHUNKS = (); |
537 | %AUDIO_CHUNKS = (); |
523 | } |
538 | } |
524 | |
539 | |
… | |
… | |
537 | $want_refresh = 0; |
552 | $want_refresh = 0; |
538 | $can_refresh = 0; |
553 | $can_refresh = 0; |
539 | |
554 | |
540 | $CFClient::UI::ROOT->draw; |
555 | $CFClient::UI::ROOT->draw; |
541 | |
556 | |
542 | SDL::GLSwapBuffers; |
557 | CFClient::SDL_GL_SwapBuffers; |
543 | |
558 | |
544 | $LAST_REFRESH = $NOW; |
559 | $LAST_REFRESH = $NOW; |
545 | } |
560 | } |
546 | |
561 | |
547 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
562 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
548 | $NOW = time; |
563 | $NOW = time; |
549 | |
564 | |
550 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
565 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
551 | while $SDL_EV->poll; |
566 | for CFClient::SDL_PollEvent; |
552 | |
567 | |
553 | if (%animate_object) { |
568 | if (%animate_object) { |
554 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
569 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
555 | $want_refresh++; |
570 | $want_refresh++; |
556 | } |
571 | } |
… | |
… | |
586 | my $hp = $stats->{1}; |
601 | my $hp = $stats->{1}; |
587 | my $hp_m = $stats->{2}; |
602 | my $hp_m = $stats->{2}; |
588 | my $sp = $stats->{3}; |
603 | my $sp = $stats->{3}; |
589 | my $sp_m = $stats->{4}; |
604 | my $sp_m = $stats->{4}; |
590 | my $fo = $stats->{18}; |
605 | my $fo = $stats->{18}; |
591 | my $fo_m = 1000; |
606 | my $fo_m = 999; |
592 | my $gr = $stats->{23}; |
607 | my $gr = $stats->{23}; |
593 | my $gr_m = $stats->{24}; |
608 | my $gr_m = $stats->{24}; |
594 | |
609 | |
595 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
610 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
596 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
611 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
597 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
612 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
598 | $GAUGES->{food}->set_value ($fo, $fo_m); |
613 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
599 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
614 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
615 | |
|
|
616 | update_stats_window ($stats); |
600 | } |
617 | } |
601 | |
618 | |
602 | sub conn::user_send { |
619 | sub conn::user_send { |
603 | my ($self, $command) = @_; |
620 | my ($self, $command) = @_; |
604 | |
621 | |
… | |
… | |
629 | |
646 | |
630 | my ($hash, $x, $y, $w, $h) = @$map_info; |
647 | my ($hash, $x, $y, $w, $h) = @$map_info; |
631 | |
648 | |
632 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
649 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
633 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
650 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
634 | |
|
|
635 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
651 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
636 | |
|
|
637 | } |
652 | } |
638 | |
653 | |
639 | sub conn::map_clear { |
654 | sub conn::map_clear { |
640 | my ($self) = @_; |
655 | my ($self) = @_; |
641 | |
656 | |
642 | $self->flush_map; |
657 | $self->flush_map; |
643 | delete $self->{neigh}; |
658 | delete $self->{neigh_map}; |
644 | |
659 | |
645 | $MAP->clear; |
660 | $MAP->clear; |
646 | } |
661 | } |
647 | |
662 | |
648 | |
663 | |
649 | sub conn::load_map($$$) { |
664 | sub conn::load_map($$$) { |
650 | my ($self, $hash, $x, $y) = @_; |
665 | my ($self, $hash, $x, $y) = @_; |
651 | |
666 | |
652 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
667 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
653 | $data = Compress::LZF::decompress $data; |
668 | $data = Compress::LZF::decompress $data; |
654 | 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# |
655 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
670 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
656 | my $data = $TILECACHE->get ($id) |
671 | my $data = $TILECACHE->get ($id) |
657 | or next; |
672 | or next; |
658 | |
673 | |
659 | $self->set_texture ($id => $data); |
674 | $self->set_texture ($id => $data); |
660 | } |
675 | } |
661 | } |
676 | } |
662 | } |
677 | } |
663 | |
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. |
664 | sub conn::flood_fill { |
684 | sub conn::flood_fill { |
665 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
685 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
666 | |
686 | |
667 | # the server does not allow map paths > 6 |
687 | # the server does not allow map paths > 6 |
668 | return if 6 <= length $path; |
688 | return if 6 <= length $path; |
669 | |
689 | |
670 | for my $tile (1..4) { |
690 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
671 | 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 | |
672 | next unless $flags & (1 << ($tile - 1)); |
703 | next unless $flags & (1 << ($tile - 1)); |
|
|
704 | next if $self->{neigh_grid}{$gx, $gy}++; |
673 | |
705 | |
674 | my $neigh = $self->{neigh}{$hash} ||= []; |
706 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
675 | |
707 | if (my $info = $neigh->[$tile]) { |
676 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
677 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
708 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
678 | |
709 | |
679 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
680 | return if $mode ne "spatial"; |
|
|
681 | |
|
|
682 | $x += $MAP->ox; |
|
|
683 | $y += $MAP->oy; |
|
|
684 | |
|
|
685 | $self->load_map ($hash, $x, $y) |
|
|
686 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
687 | |
|
|
688 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
689 | |
|
|
690 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
710 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
691 | 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 | }); |
692 | }); |
730 | } |
693 | } |
731 | } |
694 | } |
732 | } |
695 | |
733 | |
696 | sub conn::map_change { |
734 | sub conn::map_change { |
697 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
735 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
700 | |
738 | |
701 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
739 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
702 | |
740 | |
703 | my $mapmapw = 250; |
741 | my $mapmapw = 250; |
704 | 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 | ]; |
705 | |
748 | |
|
|
749 | delete $self->{neigh_grid}; |
706 | $self->flood_fill ("", $hash, $flags, |
750 | $self->flood_fill (0, 0, "", $hash, $flags); |
707 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
708 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
709 | |
751 | |
710 | $x += $ox; |
752 | $x += $ox; |
711 | $y += $oy; |
753 | $y += $oy; |
712 | |
754 | |
713 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
755 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
… | |
… | |
773 | } |
815 | } |
774 | |
816 | |
775 | sub conn::sound_play { |
817 | sub conn::sound_play { |
776 | my ($self, $x, $y, $soundnum, $type) = @_; |
818 | my ($self, $x, $y, $soundnum, $type) = @_; |
777 | |
819 | |
|
|
820 | $SDL_MIXER |
|
|
821 | or return; |
|
|
822 | |
778 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
823 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
779 | or return; |
824 | or return; |
780 | |
825 | |
781 | $SDL_MIXER->play_channel (-1, $chunk); |
826 | $chunk->play; |
782 | warn "sound $x,$y,$soundnum,$type\n";#d# |
827 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
783 | } |
828 | } |
784 | |
829 | |
785 | sub conn::query { |
830 | sub conn::query { |
786 | my ($self, $flags, $prompt) = @_; |
831 | my ($self, $flags, $prompt) = @_; |
787 | |
832 | |
788 | #TODO |
833 | #TODO, display dialog with relevant information |
789 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
834 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
790 | } |
835 | } |
791 | |
836 | |
792 | sub conn::drawinfo { |
837 | sub conn::drawinfo { |
793 | my ($self, $color, $text) = @_; |
838 | my ($self, $color, $text) = @_; |
… | |
… | |
809 | ); |
854 | ); |
810 | |
855 | |
811 | $LOGVIEW->add_paragraph ($color[$color], $text); |
856 | $LOGVIEW->add_paragraph ($color[$color], $text); |
812 | } |
857 | } |
813 | |
858 | |
|
|
859 | sub 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 | |
|
|
868 | sub conn::spell_delete { |
|
|
869 | my ($self, $spell) = @_; |
|
|
870 | } |
|
|
871 | |
|
|
872 | sub 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 | |
814 | %SDL_CB = ( |
883 | %SDL_CB = ( |
815 | SDL_QUIT() => sub { |
884 | CFClient::SDL_QUIT => sub { |
816 | Event::unloop -1; |
885 | Event::unloop -1; |
817 | }, |
886 | }, |
818 | SDL_VIDEORESIZE() => sub { |
887 | CFClient::SDL_VIDEORESIZE => sub { |
819 | }, |
888 | }, |
820 | SDL_VIDEOEXPOSE() => sub { |
889 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
821 | refresh; |
890 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
891 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
822 | }, |
892 | }, |
823 | SDL_KEYDOWN() => sub { |
893 | CFClient::SDL_KEYDOWN => sub { |
824 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
894 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
825 | # alt-enter |
895 | # alt-enter |
826 | video_shutdown; |
896 | video_shutdown; |
827 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
897 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
828 | video_init; |
898 | video_init; |
829 | } else { |
899 | } else { |
830 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
900 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
831 | } |
901 | } |
832 | }, |
902 | }, |
833 | SDL_KEYUP() => sub { |
903 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
834 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
904 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
835 | }, |
905 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
836 | SDL_MOUSEMOTION() => sub { |
906 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
837 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
907 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
838 | }, |
|
|
839 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
840 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
841 | }, |
|
|
842 | SDL_MOUSEBUTTONUP() => sub { |
|
|
843 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
844 | }, |
|
|
845 | SDL_ACTIVEEVENT() => sub { |
|
|
846 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
847 | }, |
|
|
848 | ); |
908 | ); |
849 | |
909 | |
850 | ############################################################################# |
910 | ############################################################################# |
851 | |
911 | |
852 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
912 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
… | |
… | |
863 | fullscreen => 0, |
923 | fullscreen => 0, |
864 | fast => 0, |
924 | fast => 0, |
865 | fow_enable => 1, |
925 | fow_enable => 1, |
866 | fow_intensity => 0.45, |
926 | fow_intensity => 0.45, |
867 | fow_smooth => 0, |
927 | fow_smooth => 0, |
|
|
928 | gui_fontsize => 1, |
868 | log_fontsize => 14, |
929 | log_fontsize => 14, |
869 | mapsize => 100, |
930 | mapsize => 100, |
870 | host => "crossfire.schmorp.de", |
931 | host => "crossfire.schmorp.de", |
871 | say_command => 'say', |
932 | say_command => 'say', |
872 | sound => 1, |
933 | audio_enable => 1, |
873 | bg_music_enable => 1, |
934 | bgm_enable => 1, |
|
|
935 | bgm_volume => 0.25, |
874 | ); |
936 | ); |
875 | |
937 | |
876 | while (my ($k, $v) = each %DEF_CFG) { |
938 | while (my ($k, $v) = each %DEF_CFG) { |
877 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
939 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
878 | } |
940 | } |
879 | |
941 | |
880 | sdl_init; |
942 | sdl_init; |
881 | |
943 | |
882 | @SDL_MODES = reverse |
944 | @SDL_MODES = reverse |
883 | grep $_->[0] >= 640 && $_->[1] >= 480, |
945 | grep $_->[0] >= 640 && $_->[1] >= 480, |
884 | map [SDL::RectW ($_), SDL::RectH ($_)], |
946 | CFClient::SDL_ListModes; |
885 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
886 | |
947 | |
887 | @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)"; |
888 | |
949 | |
889 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
950 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
890 | |
951 | |
… | |
… | |
898 | video_init; |
959 | video_init; |
899 | audio_init; |
960 | audio_init; |
900 | |
961 | |
901 | Event::loop; |
962 | Event::loop; |
902 | |
963 | |
903 | END { SDL::Quit } |
964 | END { CFClient::SDL_Quit } |
904 | |
965 | |
905 | |
966 | |