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