… | |
… | |
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 | |
|
|
12 | use Compress::LZF; |
|
|
13 | |
18 | use CFClient; |
14 | use CFClient; |
19 | use CFClient::UI; |
15 | use CFClient::UI; |
|
|
16 | use CFClient::MapWidget; |
20 | |
17 | |
21 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
22 | |
19 | |
23 | my $MAX_FPS = 60; |
20 | my $MAX_FPS = 60; |
24 | my $MIN_FPS = 5; # unused as of yet |
21 | my $MIN_FPS = 5; # unused as of yet |
25 | |
22 | |
26 | our $META_SERVER = "crossfire.real-time.com:13326"; |
23 | our $META_SERVER = "crossfire.real-time.com:13326"; |
27 | |
24 | |
|
|
25 | our $FACEMAP; |
|
|
26 | our $TILECACHE; |
28 | our $FACECACHE; |
27 | our $MAPCACHE; |
29 | |
28 | |
30 | our $LAST_REFRESH; |
29 | our $LAST_REFRESH; |
31 | our $NOW; |
30 | our $NOW; |
32 | |
31 | |
33 | our $CFG; |
32 | our $CFG; |
… | |
… | |
45 | our $BUTTONBAR; |
44 | our $BUTTONBAR; |
46 | our $LOGVIEW; |
45 | our $LOGVIEW; |
47 | our $CONSOLE; |
46 | our $CONSOLE; |
48 | our $METASERVER; |
47 | our $METASERVER; |
49 | |
48 | |
|
|
49 | our $GAUGES; |
|
|
50 | |
50 | our $SDL_ACTIVE; |
51 | our $SDL_ACTIVE; |
51 | our $SDL_EV; |
|
|
52 | our %SDL_CB; |
52 | our %SDL_CB; |
|
|
53 | |
|
|
54 | our $SDL_MIXER; |
|
|
55 | our @SOUNDS; # event => file mapping |
|
|
56 | our %AUDIO_CHUNKS; # audio files |
53 | |
57 | |
54 | our $ALT_ENTER_MESSAGE; |
58 | our $ALT_ENTER_MESSAGE; |
55 | our $STATUS_LINE; |
59 | our $STATUS_LINE; |
56 | our $DEBUG_STATUS; |
60 | our $DEBUG_STATUS; |
57 | |
61 | |
58 | sub status { |
62 | sub status { |
59 | $STATUS_LINE->set_text ($_[0]); |
63 | $STATUS_LINE->set_text ($_[0]); |
60 | my ($w, $h) = $STATUS_LINE->size_request; |
|
|
61 | $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}); |
62 | } |
65 | } |
63 | |
66 | |
64 | sub debug { |
67 | sub debug { |
65 | $DEBUG_STATUS->set_text ($_[0]); |
68 | $DEBUG_STATUS->set_text ($_[0]); |
66 | my ($w, $h) = $DEBUG_STATUS->size_request; |
69 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
67 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
68 | } |
70 | } |
69 | |
71 | |
70 | sub start_game { |
72 | sub start_game { |
71 | status "logging in..."; |
73 | status "logging in..."; |
72 | |
74 | |
73 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
75 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
76 | |
|
|
77 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
74 | |
78 | |
75 | $MAP = new CFClient::Map $mapsize, $mapsize; |
79 | $MAP = new CFClient::Map $mapsize, $mapsize; |
76 | |
80 | |
77 | my ($host, $port) = split /:/, $CFG->{host}; |
81 | my ($host, $port) = split /:/, $CFG->{host}; |
78 | |
82 | |
… | |
… | |
94 | undef $CONN; |
98 | undef $CONN; |
95 | } |
99 | } |
96 | |
100 | |
97 | sub client_setup { |
101 | sub client_setup { |
98 | my $dialog = new CFClient::UI::FancyFrame |
102 | my $dialog = new CFClient::UI::FancyFrame |
|
|
103 | title => "Client Setup", |
99 | child => (my $vbox = new CFClient::UI::VBox); |
104 | child => (my $vbox = new CFClient::UI::VBox); |
100 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
|
|
101 | $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]); |
102 | |
106 | |
103 | $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"); |
104 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
108 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
105 | |
109 | |
106 | $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]); |
107 | $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"); |
108 | |
112 | |
109 | $mode_slider->connect (changed => sub { |
113 | $mode_slider->connect (changed => sub { |
110 | my ($self, $value) = @_; |
114 | my ($self, $value) = @_; |
111 | |
115 | |
112 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
116 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
113 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
117 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
114 | }); |
118 | }); |
115 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
119 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
116 | |
120 | |
117 | $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"); |
118 | $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 { |
119 | my ($self, $value) = @_; |
123 | my ($self, $value) = @_; |
120 | $CFG->{fullscreen} = $value; |
124 | $CFG->{fullscreen} = $value; |
121 | }); |
125 | }); |
122 | |
126 | |
123 | $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"); |
124 | $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 { |
125 | my ($self, $value) = @_; |
129 | my ($self, $value) = @_; |
126 | $CFG->{fast} = $value; |
130 | $CFG->{fast} = $value; |
127 | }); |
131 | }); |
128 | |
132 | |
129 | $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"); |
130 | $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 { |
131 | my ($self, $value) = @_; |
135 | my ($self, $value) = @_; |
132 | $CFG->{fow_enable} = $value; |
136 | $CFG->{fow_enable} = $value; |
133 | }); |
137 | }); |
134 | |
138 | |
135 | $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"); |
136 | $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 { |
137 | my ($self, $value) = @_; |
141 | my ($self, $value) = @_; |
138 | $CFG->{fow_intensity} = $value; |
142 | $CFG->{fow_intensity} = $value; |
139 | }); |
143 | }); |
140 | |
144 | |
141 | $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"); |
142 | $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 { |
143 | my ($self, $value) = @_; |
147 | my ($self, $value) = @_; |
144 | $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; |
145 | }); |
150 | }); |
146 | |
151 | |
147 | $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"); |
148 | $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 { |
149 | my ($self, $value) = @_; |
|
|
150 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
160 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
151 | }); |
161 | }); |
152 | |
162 | |
153 | $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 { |
154 | destroy_screen (); |
164 | video_shutdown (); |
155 | 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 (); |
156 | }); |
189 | }); |
157 | |
190 | |
158 | $dialog |
191 | $dialog |
159 | } |
192 | } |
160 | |
193 | |
161 | sub metaserver_dialog { |
194 | sub metaserver_dialog { |
162 | my $dialog = new CFClient::UI::FancyFrame |
195 | my $dialog = new CFClient::UI::FancyFrame |
|
|
196 | title => "Metaserver", |
163 | child => (my $vbox = new CFClient::UI::VBox); |
197 | child => (my $vbox = new CFClient::UI::VBox); |
164 | |
198 | |
165 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
199 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
166 | |
200 | |
167 | $dialog |
201 | $dialog |
… | |
… | |
224 | $HOST->set_text ($CFG->{host} = $host); |
258 | $HOST->set_text ($CFG->{host} = $host); |
225 | }), |
259 | }), |
226 | (new CFClient::UI::Empty expand => 1), |
260 | (new CFClient::UI::Empty expand => 1), |
227 | ]); |
261 | ]); |
228 | |
262 | |
229 | $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) |
230 | for 0 .. $#$m; |
264 | for 0 .. $#$m; |
231 | } |
265 | } |
232 | } |
266 | } |
233 | }); |
267 | }); |
234 | } |
268 | } |
235 | |
269 | |
236 | sub server_setup { |
270 | sub server_setup { |
237 | my $dialog = new CFClient::UI::FancyFrame |
271 | my $dialog = new CFClient::UI::FancyFrame |
|
|
272 | title => "Server Setup", |
238 | child => (my $vbox = new CFClient::UI::VBox); |
273 | child => (my $vbox = new CFClient::UI::VBox); |
239 | |
274 | |
240 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
|
|
241 | $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]); |
242 | $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"); |
243 | |
277 | |
244 | { |
278 | { |
245 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
279 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
246 | |
280 | |
247 | $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 { |
248 | my ($self, $value) = @_; |
282 | my ($self, $value) = @_; |
249 | $CFG->{host} = $value; |
283 | $CFG->{host} = $value; |
250 | }); |
284 | }); |
251 | |
285 | |
252 | $METASERVER = metaserver_dialog; |
286 | $METASERVER = metaserver_dialog; |
253 | |
287 | |
254 | $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 { |
255 | update_metaserver $HOST; |
289 | update_metaserver $HOST; |
256 | }); |
290 | }); |
257 | } |
291 | } |
258 | |
292 | |
259 | $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"); |
260 | $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 { |
261 | my ($self, $value) = @_; |
295 | my ($self, $value) = @_; |
262 | $CFG->{user} = $value; |
296 | $CFG->{user} = $value; |
263 | }); |
297 | }); |
264 | |
298 | |
265 | $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"); |
266 | $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 { |
267 | my ($self, $value) = @_; |
301 | my ($self, $value) = @_; |
268 | $CFG->{password} = $value; |
302 | $CFG->{password} = $value; |
269 | }); |
303 | }); |
270 | |
304 | |
271 | $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"); |
272 | $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 { |
273 | my ($self, $value) = @_; |
307 | my ($self, $value) = @_; |
274 | $CFG->{say_command} = $value; |
308 | $CFG->{say_command} = $value; |
275 | }); |
309 | }); |
276 | |
310 | |
277 | $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"); |
278 | $table->add (1, 7, new CFClient::UI::Slider |
312 | $table->add (1, 7, new CFClient::UI::Slider |
279 | req_w => 100, |
313 | req_w => 100, |
280 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
314 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
281 | connect_changed => sub { |
315 | connect_changed => sub { |
282 | my ($self, $value) = @_; |
316 | my ($self, $value) = @_; |
… | |
… | |
292 | $dialog |
326 | $dialog |
293 | } |
327 | } |
294 | |
328 | |
295 | sub message_window { |
329 | sub message_window { |
296 | my $window = new CFClient::UI::FancyFrame |
330 | my $window = new CFClient::UI::FancyFrame |
|
|
331 | title => "Messages", |
297 | border_bg => [1, 1, 1, 0.5], |
332 | border_bg => [1, 1, 1, 0.5], |
298 | bg => [0.3, 0.3, 0.3, 0.8], |
333 | bg => [0.3, 0.3, 0.3, 0.8], |
299 | user_w => $::WIDTH/4, |
334 | user_w => int $::WIDTH / 3, |
300 | user_h => $::HEIGHT, |
335 | user_h => int $::HEIGHT / 5, |
301 | child => (my $vbox = new CFClient::UI::VBox); |
336 | child => (my $vbox = new CFClient::UI::VBox); |
302 | |
337 | |
303 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
338 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
304 | expand => 1, |
339 | expand => 1, |
305 | fontsize => $::CFG->{log_fontsize}, |
340 | fontsize => $::CFG->{log_fontsize}, |
306 | ); |
341 | ); |
307 | |
342 | |
308 | $vbox->add (my $input = new CFClient::UI::LineEntry); |
343 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
344 | connect_focus_in => sub { |
|
|
345 | my ($input, $prev_focus) = @_; |
|
|
346 | |
|
|
347 | delete $input->{refocus_map}; |
|
|
348 | |
|
|
349 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
350 | $input->{refocus_map} = 1; |
|
|
351 | } |
|
|
352 | delete $input->{auto_activated}; |
|
|
353 | }, |
309 | $input->connect (activate => sub { |
354 | connect_activate => sub { |
310 | my ($input, $text) = @_; |
355 | my ($input, $text) = @_; |
311 | $input->set_text (''); |
356 | $input->set_text (''); |
312 | |
357 | |
313 | if ($text =~ /^\/(.*)/) { |
358 | if ($text =~ /^\/(.*)/) { |
314 | $::CONN->user_send ("command $1"); |
359 | $::CONN->user_send ($1); |
315 | } else { |
360 | } else { |
316 | my $say_cmd = $::CFG->{say_command} || 'say'; |
361 | my $say_cmd = $::CFG->{say_command} || 'say'; |
317 | $::CONN->user_send ("command $say_cmd $text"); |
362 | $::CONN->user_send ("$say_cmd $text"); |
318 | } |
363 | } |
|
|
364 | if ($input->{refocus_map}) { |
|
|
365 | delete $input->{refocus_map}; |
|
|
366 | $MAPWIDGET->focus_in |
319 | 1 |
367 | } |
320 | }); |
368 | }, |
321 | $input->connect (escape => sub { |
369 | connect_escape => sub { |
322 | $MAPWIDGET->focus_in |
370 | $MAPWIDGET->focus_in |
323 | }); |
371 | }, |
324 | $input->focus_in; |
372 | ); |
325 | |
373 | |
326 | $CONSOLE = { |
374 | $CONSOLE = { |
327 | window => $window, |
375 | window => $window, |
328 | input => $input |
376 | input => $input |
329 | }; |
377 | }; |
330 | |
378 | |
331 | $window |
379 | $window |
332 | } |
380 | } |
333 | |
381 | |
334 | sub sdl_init { |
382 | sub sdl_init { |
335 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
383 | CFClient::SDL_Init |
336 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
337 | and die "SDL::Init failed!\n"; |
384 | and die "SDL::Init failed!\n"; |
338 | } |
385 | } |
339 | |
386 | |
340 | sub init_screen { |
387 | sub video_init { |
341 | sdl_init; |
388 | sdl_init; |
342 | |
389 | |
343 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
390 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
344 | $FULLSCREEN = $CFG->{fullscreen}; |
391 | $FULLSCREEN = $CFG->{fullscreen}; |
345 | $FAST = $CFG->{fast}; |
392 | $FAST = $CFG->{fast}; |
346 | |
393 | |
347 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
394 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
348 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
349 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
350 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
|
|
351 | |
|
|
352 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
353 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
354 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
355 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
356 | |
|
|
357 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
358 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
359 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
360 | |
|
|
361 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
362 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
363 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
364 | or die "SDL::SetVideoMode failed!\n"; |
395 | or die "SDL_SetVideoMode failed!\n"; |
365 | |
|
|
366 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
367 | |
|
|
368 | $SDL_EV = new SDL::Event; |
|
|
369 | $SDL_EV->set_unicode (1); |
|
|
370 | |
396 | |
371 | $SDL_ACTIVE = 1; |
397 | $SDL_ACTIVE = 1; |
372 | |
398 | |
373 | $LAST_REFRESH = time - 0.01; |
399 | $LAST_REFRESH = time - 0.01; |
374 | |
400 | |
375 | CFClient::gl_init; |
401 | CFClient::gl_init; |
376 | |
402 | |
377 | $FONTSIZE = int $HEIGHT / 40; |
403 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
378 | |
404 | |
379 | ############################################################################# |
405 | ############################################################################# |
380 | |
406 | |
381 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
407 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
382 | $CFClient::UI::ROOT->add ($DEBUG_STATUS); |
408 | $DEBUG_STATUS->show; |
383 | |
409 | |
384 | $STATUS_LINE = new CFClient::UI::Label |
410 | $STATUS_LINE = new CFClient::UI::Label |
385 | padding => 0, |
411 | padding => 0, |
386 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
412 | y => $HEIGHT - $FONTSIZE * 1.8; |
387 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
413 | $STATUS_LINE->show; |
388 | |
414 | |
389 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
415 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
390 | padding => 0, |
416 | padding => 0, |
391 | y => $HEIGHT * 44 / 45, |
417 | fontsize => 0.8, |
392 | height => $HEIGHT / 45, |
|
|
393 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
418 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
394 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
419 | $ALT_ENTER_MESSAGE->show; |
|
|
420 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
395 | |
421 | |
396 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
422 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
397 | $MAPWIDGET->focus_in; |
423 | $MAPWIDGET->focus_in; |
398 | $MAPWIDGET->connect (activate_console => sub { |
424 | $MAPWIDGET->connect (activate_console => sub { |
399 | my ($mapwidget, $preset) = @_; |
425 | my ($mapwidget, $preset) = @_; |
400 | |
426 | |
401 | if ($CONSOLE) { |
427 | if ($CONSOLE) { |
|
|
428 | $CONSOLE->{input}->{auto_activated} = 1; |
402 | $CONSOLE->{input}->focus_in; |
429 | $CONSOLE->{input}->focus_in; |
403 | |
430 | |
404 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
431 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
405 | $CONSOLE->{input}->set_text ($preset); |
432 | $CONSOLE->{input}->set_text ($preset); |
406 | } |
433 | } |
… | |
… | |
416 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
443 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
417 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
444 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
418 | status "Configuration Saved"; |
445 | status "Configuration Saved"; |
419 | }); |
446 | }); |
420 | |
447 | |
421 | $BUTTONBAR->{children}[0]->emit ("activate"); |
448 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
422 | } |
|
|
423 | |
449 | |
424 | sub destroy_screen { |
450 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats"); |
|
|
451 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
452 | |
|
|
453 | $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp')); |
|
|
454 | $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana')); |
|
|
455 | $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace')); |
|
|
456 | $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food')); |
|
|
457 | |
|
|
458 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
459 | $CFClient::UI::ROOT->add ($tgw); |
|
|
460 | } |
|
|
461 | |
|
|
462 | sub video_shutdown { |
425 | $CFClient::UI::ROOT->{children} = []; |
463 | $CFClient::UI::ROOT->{children} = []; |
426 | 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; |
427 | undef $SDL_EV; |
512 | undef $SDL_MIXER; |
428 | SDL::Quit; |
513 | @SOUNDS = (); |
|
|
514 | %AUDIO_CHUNKS = (); |
429 | } |
515 | } |
430 | |
516 | |
431 | my %animate_object; |
517 | my %animate_object; |
432 | my $animate_timer; |
518 | my $animate_timer; |
433 | |
519 | |
… | |
… | |
443 | $want_refresh = 0; |
529 | $want_refresh = 0; |
444 | $can_refresh = 0; |
530 | $can_refresh = 0; |
445 | |
531 | |
446 | $CFClient::UI::ROOT->draw; |
532 | $CFClient::UI::ROOT->draw; |
447 | |
533 | |
448 | SDL::GLSwapBuffers; |
534 | CFClient::SDL_GL_SwapBuffers; |
449 | |
535 | |
450 | $LAST_REFRESH = $NOW; |
536 | $LAST_REFRESH = $NOW; |
451 | } |
537 | } |
452 | |
538 | |
453 | 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 { |
454 | $NOW = time; |
540 | $NOW = time; |
455 | |
541 | |
456 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
542 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
457 | while $SDL_EV->poll; |
543 | for CFClient::SDL_PollEvent; |
458 | |
544 | |
459 | if (%animate_object) { |
545 | if (%animate_object) { |
460 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
546 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
461 | $want_refresh++; |
547 | $want_refresh++; |
462 | } |
548 | } |
… | |
… | |
482 | delete $animate_object{$widget}; |
568 | delete $animate_object{$widget}; |
483 | } |
569 | } |
484 | |
570 | |
485 | @conn::ISA = Crossfire::Protocol::; |
571 | @conn::ISA = Crossfire::Protocol::; |
486 | |
572 | |
|
|
573 | sub conn::stats_update { |
|
|
574 | my ($self, $stats) = @_; |
|
|
575 | |
|
|
576 | # i love text protocols!!! |
|
|
577 | # FIXME: the stats are somehow weird |
|
|
578 | my $hp = $stats->{1}; |
|
|
579 | my $hp_m = $stats->{2}; |
|
|
580 | my $sp = $stats->{3}; |
|
|
581 | my $sp_m = $stats->{4}; |
|
|
582 | my $fo = $stats->{18}; |
|
|
583 | my $fo_m = 999; |
|
|
584 | my $gr = $stats->{23}; |
|
|
585 | my $gr_m = $stats->{24}; |
|
|
586 | |
|
|
587 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
|
|
588 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
589 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
590 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
591 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
592 | } |
|
|
593 | |
487 | sub conn::user_send { |
594 | sub conn::user_send { |
488 | my ($self, $command) = @_; |
595 | my ($self, $command) = @_; |
489 | |
596 | |
490 | $self->send ($command); |
597 | $self->send_command ($command); |
491 | status $command; |
598 | status $command; |
|
|
599 | } |
|
|
600 | |
|
|
601 | sub conn::map_scroll { |
|
|
602 | my ($self, $dx, $dy) = @_; |
|
|
603 | |
|
|
604 | $MAP->scroll ($dx, $dy); |
492 | } |
605 | } |
493 | |
606 | |
494 | sub conn::feed_map1a { |
607 | sub conn::feed_map1a { |
495 | my ($self, $data) = @_; |
608 | my ($self, $data) = @_; |
496 | |
609 | |
497 | # $self->Crossfire::Protocol::feed_map1a ($data); |
610 | # $self->Crossfire::Protocol::feed_map1a ($data); |
498 | |
611 | |
499 | $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y}); |
|
|
500 | $MAP->map1a_update ($data); |
612 | $MAP->map1a_update ($data); |
501 | $MAPWIDGET->update; |
613 | $MAPWIDGET->update; |
502 | } |
614 | } |
503 | |
615 | |
504 | #sub conn::map_update { |
616 | sub conn::flush_map { |
505 | # my ($self, $dirty) = @_; |
617 | my ($self) = @_; |
506 | # |
618 | |
507 | # $MAPWIDGET->update; |
619 | my $map_info = delete $self->{map_info} |
508 | #} |
620 | or return; |
|
|
621 | |
|
|
622 | my ($hash, $x, $y, $w, $h) = @$map_info; |
|
|
623 | |
|
|
624 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
|
|
625 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
|
|
626 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
627 | } |
509 | |
628 | |
510 | sub conn::map_clear { |
629 | sub conn::map_clear { |
511 | my ($self) = @_; |
630 | my ($self) = @_; |
512 | |
631 | |
|
|
632 | $self->flush_map; |
|
|
633 | delete $self->{neigh_map}; |
|
|
634 | |
513 | $MAP->clear; |
635 | $MAP->clear; |
|
|
636 | } |
514 | |
637 | |
515 | # refresh; |
638 | |
|
|
639 | sub conn::load_map($$$) { |
|
|
640 | my ($self, $hash, $x, $y) = @_; |
|
|
641 | |
|
|
642 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
|
|
643 | $data = Compress::LZF::decompress $data; |
|
|
644 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
645 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
|
|
646 | my $data = $TILECACHE->get ($id) |
|
|
647 | or next; |
|
|
648 | |
|
|
649 | $self->set_texture ($id => $data); |
|
|
650 | } |
|
|
651 | } |
|
|
652 | } |
|
|
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. |
|
|
659 | sub conn::flood_fill { |
|
|
660 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
|
|
661 | |
|
|
662 | # the server does not allow map paths > 6 |
|
|
663 | return if 6 <= length $path; |
|
|
664 | |
|
|
665 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
|
|
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 | |
|
|
678 | next unless $flags & (1 << ($tile - 1)); |
|
|
679 | next if $self->{neigh_grid}{$gx, $gy}++; |
|
|
680 | |
|
|
681 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
|
|
682 | if (my $info = $neigh->[$tile]) { |
|
|
683 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
|
|
684 | |
|
|
685 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
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 | }); |
|
|
705 | } |
|
|
706 | } |
|
|
707 | } |
|
|
708 | |
|
|
709 | sub conn::map_change { |
|
|
710 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
711 | |
|
|
712 | $self->flush_map; |
|
|
713 | |
|
|
714 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
715 | |
|
|
716 | my $mapmapw = 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 | ]; |
|
|
723 | |
|
|
724 | delete $self->{neigh_grid}; |
|
|
725 | $self->flood_fill (0, 0, "", $hash, $flags); |
|
|
726 | |
|
|
727 | $x += $ox; |
|
|
728 | $y += $oy; |
|
|
729 | |
|
|
730 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
731 | |
|
|
732 | $self->load_map ($hash, $x, $y); |
516 | } |
733 | } |
517 | |
734 | |
518 | sub conn::face_find { |
735 | sub conn::face_find { |
519 | my ($self, $face) = @_; |
736 | my ($self, $facenum, $face) = @_; |
520 | |
737 | |
521 | my $data; |
738 | my $hash = "$face->{chksum},$face->{name}"; |
522 | |
739 | |
523 | $FACECACHE->get ("$face->{chksum},$face->{name}") |
740 | my $id = $FACEMAP->get ($hash); |
|
|
741 | |
|
|
742 | unless ($id) { |
|
|
743 | # create new id for face |
|
|
744 | # i love transactions |
|
|
745 | for (1..100) { |
|
|
746 | my $txn = $CFClient::DB_ENV->txn_begin; |
|
|
747 | my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW); |
|
|
748 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
|
|
749 | $id++; |
|
|
750 | if ($FACEMAP->put (id => $id) == 0 |
|
|
751 | && $FACEMAP->put ($hash => $id) == 0) { |
|
|
752 | $txn->txn_commit; |
|
|
753 | |
|
|
754 | goto gotid; |
|
|
755 | } |
|
|
756 | } |
|
|
757 | $txn->abort; |
|
|
758 | } |
|
|
759 | |
|
|
760 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
|
|
761 | } |
|
|
762 | |
|
|
763 | gotid: |
|
|
764 | $face->{id} = $id; |
|
|
765 | $MAP->set_face ($facenum => $id); |
|
|
766 | $TILECACHE->get ($id) |
524 | } |
767 | } |
525 | |
768 | |
526 | sub conn::face_update { |
769 | sub conn::face_update { |
527 | my ($self, $facenum, $face) = @_; |
770 | my ($self, $facenum, $face) = @_; |
528 | |
771 | |
529 | $FACECACHE->put ("$face->{chksum},$face->{name}" => $face->{image}); |
772 | $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
530 | |
773 | |
531 | my $tex = $face->{texture} = |
774 | $self->set_texture ($face->{id} => delete $face->{image}); |
|
|
775 | } |
|
|
776 | |
|
|
777 | sub conn::set_texture { |
|
|
778 | my ($self, $id, $data) = @_; |
|
|
779 | |
|
|
780 | $self->{texture}[$id] ||= do { |
|
|
781 | my $tex = |
532 | new_from_image CFClient::Texture |
782 | new_from_image CFClient::Texture |
533 | delete $face->{image}, minify => 1; |
783 | $data, minify => 1; |
534 | |
784 | |
535 | $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
785 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
536 | $MAPWIDGET->update; |
786 | $MAPWIDGET->update; |
|
|
787 | |
|
|
788 | $tex |
|
|
789 | }; |
|
|
790 | } |
|
|
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# |
537 | } |
803 | } |
538 | |
804 | |
539 | sub conn::query { |
805 | sub conn::query { |
540 | my ($self, $flags, $prompt) = @_; |
806 | my ($self, $flags, $prompt) = @_; |
541 | |
807 | |
542 | #TODO |
808 | #TODO, display dialog with relevant information |
543 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
809 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
544 | } |
810 | } |
545 | |
811 | |
546 | sub conn::drawinfo { |
812 | sub conn::drawinfo { |
547 | my ($self, $color, $text) = @_; |
813 | my ($self, $color, $text) = @_; |
548 | |
814 | |
549 | my @color = ( |
815 | my @color = ( |
550 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
816 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
551 | [1.00, 1.00, 1.00], |
817 | [1.00, 1.00, 1.00], |
552 | [0.00, 0.00, 0.55], |
818 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
553 | [1.00, 0.00, 0.00], |
819 | [1.00, 0.00, 0.00], |
554 | [1.00, 0.54, 0.00], |
820 | [1.00, 0.54, 0.00], |
555 | [0.11, 0.56, 1.00], |
821 | [0.11, 0.56, 1.00], |
556 | [0.93, 0.46, 0.00], |
822 | [0.93, 0.46, 0.00], |
557 | [0.18, 0.54, 0.34], |
823 | [0.18, 0.54, 0.34], |
… | |
… | |
563 | ); |
829 | ); |
564 | |
830 | |
565 | $LOGVIEW->add_paragraph ($color[$color], $text); |
831 | $LOGVIEW->add_paragraph ($color[$color], $text); |
566 | } |
832 | } |
567 | |
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 | |
568 | %SDL_CB = ( |
858 | %SDL_CB = ( |
569 | SDL_QUIT() => sub { |
859 | CFClient::SDL_QUIT => sub { |
570 | Event::unloop -1; |
860 | Event::unloop -1; |
571 | }, |
861 | }, |
572 | SDL_VIDEORESIZE() => sub { |
862 | CFClient::SDL_VIDEORESIZE => sub { |
573 | }, |
863 | }, |
574 | SDL_VIDEOEXPOSE() => sub { |
864 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
575 | refresh; |
865 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
866 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
576 | }, |
867 | }, |
577 | SDL_KEYDOWN() => sub { |
868 | CFClient::SDL_KEYDOWN => sub { |
578 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
869 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
579 | # alt-enter |
870 | # alt-enter |
580 | destroy_screen; |
871 | video_shutdown; |
581 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
872 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
582 | init_screen; |
873 | video_init; |
583 | } else { |
874 | } else { |
584 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
875 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
585 | } |
876 | } |
586 | }, |
877 | }, |
587 | SDL_KEYUP() => sub { |
878 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
588 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
879 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
589 | }, |
880 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
590 | SDL_MOUSEMOTION() => sub { |
881 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
591 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
882 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
592 | }, |
|
|
593 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
594 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
595 | }, |
|
|
596 | SDL_MOUSEBUTTONUP() => sub { |
|
|
597 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
598 | }, |
|
|
599 | SDL_ACTIVEEVENT() => sub { |
|
|
600 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
601 | }, |
|
|
602 | ); |
883 | ); |
603 | |
884 | |
604 | ############################################################################# |
885 | ############################################################################# |
605 | |
886 | |
|
|
887 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
888 | |
606 | $FACECACHE = CFClient::db_table "facecache"; |
889 | $TILECACHE = CFClient::db_table "tilecache"; |
|
|
890 | $FACEMAP = CFClient::db_table "facemap"; |
607 | |
891 | |
608 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
892 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
609 | |
893 | |
610 | my %DEF_CFG = ( |
894 | my %DEF_CFG = ( |
611 | sdl_mode => 0, |
895 | sdl_mode => 0, |
… | |
… | |
614 | fullscreen => 0, |
898 | fullscreen => 0, |
615 | fast => 0, |
899 | fast => 0, |
616 | fow_enable => 1, |
900 | fow_enable => 1, |
617 | fow_intensity => 0.45, |
901 | fow_intensity => 0.45, |
618 | fow_smooth => 0, |
902 | fow_smooth => 0, |
|
|
903 | gui_fontsize => 1, |
619 | log_fontsize => 14, |
904 | log_fontsize => 14, |
620 | mapsize => 100, |
905 | mapsize => 100, |
621 | host => "crossfire.schmorp.de", |
906 | host => "crossfire.schmorp.de", |
622 | say_command => 'say', |
907 | say_command => 'say', |
|
|
908 | audio_enable => 1, |
|
|
909 | bgm_enable => 1, |
|
|
910 | bgm_volume => 0.25, |
623 | ); |
911 | ); |
624 | |
912 | |
625 | while (my ($k, $v) = each %DEF_CFG) { |
913 | while (my ($k, $v) = each %DEF_CFG) { |
626 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
914 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
627 | } |
915 | } |
628 | |
916 | |
629 | sdl_init; |
917 | sdl_init; |
630 | |
918 | |
631 | @SDL_MODES = reverse |
919 | @SDL_MODES = reverse |
632 | grep $_->[0] >= 640 && $_->[1] >= 480, |
920 | grep $_->[0] >= 640 && $_->[1] >= 480, |
633 | map [SDL::RectW ($_), SDL::RectH ($_)], |
921 | CFClient::SDL_ListModes; |
634 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
635 | |
922 | |
636 | @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)"; |
637 | |
924 | |
638 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
925 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
639 | |
|
|
640 | init_screen; |
|
|
641 | |
926 | |
642 | { |
927 | { |
643 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
928 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
644 | |
929 | |
645 | CFClient::add_font $_ for @fonts; |
930 | CFClient::add_font $_ for @fonts; |
646 | CFClient::set_font $fonts[0]; |
931 | CFClient::set_font $fonts[0]; |
647 | } |
932 | } |
648 | |
933 | |
|
|
934 | video_init; |
|
|
935 | audio_init; |
|
|
936 | |
649 | Event::loop; |
937 | Event::loop; |
650 | |
938 | |
|
|
939 | END { CFClient::SDL_Quit } |
651 | |
940 | |
|
|
941 | |