… | |
… | |
3 | use strict; |
3 | use strict; |
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 | |
|
|
9 | use SDL::Event; |
|
|
10 | |
|
|
11 | use SDL::Mixer; |
|
|
12 | use SDL::Sound; |
|
|
13 | use SDL::Music; |
|
|
14 | |
|
|
15 | use SDL::OpenGL; |
|
|
16 | |
8 | |
17 | use Crossfire; |
9 | use Crossfire; |
18 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
19 | |
11 | |
20 | use Compress::LZF; |
12 | use Compress::LZF; |
… | |
… | |
53 | our $LOGVIEW; |
45 | our $LOGVIEW; |
54 | our $CONSOLE; |
46 | our $CONSOLE; |
55 | our $METASERVER; |
47 | our $METASERVER; |
56 | |
48 | |
57 | our $GAUGES; |
49 | our $GAUGES; |
|
|
50 | our $STATWIDS; |
58 | |
51 | |
59 | our $SDL_ACTIVE; |
52 | our $SDL_ACTIVE; |
60 | our $SDL_EV; |
|
|
61 | our %SDL_CB; |
53 | our %SDL_CB; |
62 | |
54 | |
63 | our $SDL_MIXER; |
55 | our $SDL_MIXER; |
64 | our @SOUNDS; # event => file mapping |
56 | our @SOUNDS; # event => file mapping |
65 | our %AUDIO_CHUNKS; # audio files |
57 | our %AUDIO_CHUNKS; # audio files |
… | |
… | |
107 | undef $CONN; |
99 | undef $CONN; |
108 | } |
100 | } |
109 | |
101 | |
110 | sub client_setup { |
102 | sub client_setup { |
111 | my $dialog = new CFClient::UI::FancyFrame |
103 | my $dialog = new CFClient::UI::FancyFrame |
|
|
104 | title => "Client Setup", |
112 | child => (my $vbox = new CFClient::UI::VBox); |
105 | child => (my $vbox = new CFClient::UI::VBox); |
113 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup"); |
|
|
114 | $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]); |
115 | |
107 | |
116 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
108 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
117 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
109 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
118 | |
110 | |
119 | $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]); |
120 | $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); |
112 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
121 | |
113 | |
122 | $mode_slider->connect (changed => sub { |
114 | $mode_slider->connect (changed => sub { |
123 | my ($self, $value) = @_; |
115 | my ($self, $value) = @_; |
124 | |
116 | |
125 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
117 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
126 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
118 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
127 | }); |
119 | }); |
128 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
120 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
129 | |
121 | |
|
|
122 | my $row = 1; |
|
|
123 | |
130 | $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
124 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
131 | $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
125 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
132 | my ($self, $value) = @_; |
126 | my ($self, $value) = @_; |
133 | $CFG->{fullscreen} = $value; |
127 | $CFG->{fullscreen} = $value; |
134 | }); |
128 | }); |
135 | |
129 | |
136 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
130 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
137 | $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
131 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
138 | my ($self, $value) = @_; |
132 | my ($self, $value) = @_; |
139 | $CFG->{fast} = $value; |
133 | $CFG->{fast} = $value; |
140 | }); |
134 | }); |
141 | |
135 | |
142 | $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
136 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
143 | $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
137 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
144 | my ($self, $value) = @_; |
138 | my ($self, $value) = @_; |
145 | $CFG->{fow_enable} = $value; |
139 | $CFG->{fow_enable} = $value; |
146 | }); |
140 | }); |
147 | |
141 | |
148 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
142 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
149 | $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
143 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
150 | my ($self, $value) = @_; |
144 | my ($self, $value) = @_; |
151 | $CFG->{fow_intensity} = $value; |
145 | $CFG->{fow_intensity} = $value; |
152 | }); |
146 | }); |
153 | |
147 | |
154 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
148 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
155 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
149 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
156 | my ($self, $value) = @_; |
150 | my ($self, $value) = @_; |
157 | $CFG->{fow_smooth} = $value; |
151 | $CFG->{fow_smooth} = $value; |
158 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
152 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
159 | }); |
153 | }); |
160 | |
154 | |
161 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
155 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
162 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
156 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
163 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
157 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
164 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
158 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
165 | }); |
159 | }); |
166 | |
160 | |
167 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
161 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
168 | $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
162 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
169 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
163 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
170 | }); |
164 | }); |
171 | |
165 | |
|
|
166 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize"); |
|
|
167 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{stat_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
168 | $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10; |
|
|
169 | &set_stats_window_fontsize; |
|
|
170 | }); |
|
|
171 | |
|
|
172 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge height"); |
|
|
173 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], connect_changed => sub { |
|
|
174 | $CFG->{gauge_size} = $_[1]; |
|
|
175 | my $h = int ($HEIGHT * $CFG->{gauge_size}); |
|
|
176 | $GAUGES->{win}->set_size ($WIDTH, $h); |
|
|
177 | $GAUGES->{win}->{y} = $HEIGHT - $h; |
|
|
178 | $GAUGES->{win}->{x} = 0; |
|
|
179 | $GAUGES->{win}->update; |
|
|
180 | }); |
|
|
181 | |
|
|
182 | |
|
|
183 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
|
|
184 | $table->add (1, $row++, new CFClient::UI::Slider range => [$CFG->{gauge_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
185 | $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10; |
|
|
186 | &set_gauge_window_fontsize; |
|
|
187 | $GAUGES->{win}->check_size; |
|
|
188 | $GAUGES->{win}->update; |
|
|
189 | }); |
|
|
190 | |
|
|
191 | |
|
|
192 | |
172 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
193 | $table->add (1, $row++, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
173 | video_shutdown (); |
194 | video_shutdown (); |
174 | video_init (); |
195 | video_init (); |
175 | }); |
196 | }); |
176 | |
197 | |
177 | $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
198 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
178 | $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
199 | $table->add (1, $row++, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
179 | $CFG->{audio_enable} = $_[1]; |
200 | $CFG->{audio_enable} = $_[1]; |
180 | }); |
201 | }); |
181 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
202 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
182 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
203 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
183 | # $CFG->{effects_volume} = $_[1]; |
204 | # $CFG->{effects_volume} = $_[1]; |
184 | # }); |
205 | # }); |
185 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
206 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
186 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
207 | $table->add (1, $row++, my $hbox = new CFClient::UI::HBox); |
187 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
208 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
188 | $CFG->{bgm_enable} = $_[1]; |
209 | $CFG->{bgm_enable} = $_[1]; |
189 | }); |
210 | }); |
190 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { |
211 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
191 | $CFG->{bgm_volume} = $_[1]; |
212 | $CFG->{bgm_volume} = $_[1]; |
192 | $SDL_MIXER->music_volume ($_[1]); |
213 | CFClient::MixMusic::volume $_[1] * 128; |
193 | }); |
214 | }); |
194 | |
215 | |
195 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
216 | $table->add (1, $row++, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
196 | audio_shutdown (); |
217 | audio_shutdown (); |
197 | audio_init (); |
218 | audio_init (); |
198 | }); |
219 | }); |
199 | |
220 | |
200 | $dialog |
221 | $dialog |
201 | } |
222 | } |
202 | |
223 | |
|
|
224 | sub set_stats_window_fontsize { |
|
|
225 | for (values %{$STATWIDS}) { |
|
|
226 | $_->set_fontsize ($::CFG->{stat_fontsize}); |
|
|
227 | } |
|
|
228 | } |
|
|
229 | |
|
|
230 | sub set_gauge_window_fontsize { |
|
|
231 | for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) { |
|
|
232 | $_->set_fontsize ($::CFG->{gauge_fontsize}); |
|
|
233 | } |
|
|
234 | } |
|
|
235 | |
|
|
236 | sub make_gauge_window { |
|
|
237 | my $gh = int ($HEIGHT * $CFG->{gauge_size}); |
|
|
238 | # my $gw = int ($WIDTH * $CFG->{gauge_w_size}); |
|
|
239 | |
|
|
240 | my $win = new CFClient::UI::Frame ( |
|
|
241 | y => $HEIGHT - $gh, x => 0, req_w => $WIDTH, req_h => $gh |
|
|
242 | ); |
|
|
243 | $win->add (my $vb = new CFClient::UI::VBox); |
|
|
244 | |
|
|
245 | $vb->add (my $hbg = new CFClient::UI::HBox expand => 1); |
|
|
246 | |
|
|
247 | |
|
|
248 | $hbg->add (new CFClient::UI::Empty expand => 1); |
|
|
249 | $hbg->add (my $hb = new CFClient::UI::HBox); |
|
|
250 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp'); |
|
|
251 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana'); |
|
|
252 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace'); |
|
|
253 | $hb->add (my $fg = new CFClient::UI::Gauge type => 'food'); |
|
|
254 | |
|
|
255 | $vb->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, text => "XP:"); |
|
|
256 | # $vb->add (my $lvl = new CFClient::UI::Label valign => 0, align => 1, text => "Lvl:"); |
|
|
257 | $vb->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, text => "Rng:"); |
|
|
258 | |
|
|
259 | |
|
|
260 | $GAUGES = { |
|
|
261 | exp => $exp,# lvl => $lvl, |
|
|
262 | win => $win, range => $rng, |
|
|
263 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
|
|
264 | }; |
|
|
265 | $win |
|
|
266 | } |
|
|
267 | |
|
|
268 | sub make_stats_window { |
|
|
269 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
|
|
270 | |
|
|
271 | $tgw->add (my $vb = new CFClient::UI::VBox); |
|
|
272 | $vb->add (my $uhb = new CFClient::UI::HBox); |
|
|
273 | $uhb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); |
|
|
274 | $uhb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); |
|
|
275 | |
|
|
276 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
|
|
277 | |
|
|
278 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
|
|
279 | |
|
|
280 | $tbl->add (0, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Str"); |
|
|
281 | $tbl->add (0, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Dex"); |
|
|
282 | $tbl->add (0, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Con"); |
|
|
283 | $tbl->add (0, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Int"); |
|
|
284 | $tbl->add (0, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Wis"); |
|
|
285 | $tbl->add (0, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Pow"); |
|
|
286 | $tbl->add (0, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Cha"); |
|
|
287 | |
|
|
288 | $tbl->add (1, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
289 | $tbl->add (1, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
290 | $tbl->add (1, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
291 | $tbl->add (1, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
292 | $tbl->add (1, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
293 | $tbl->add (1, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
294 | $tbl->add (1, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
295 | |
|
|
296 | $tbl->add (2, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Wc"); |
|
|
297 | $tbl->add (2, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Ac"); |
|
|
298 | $tbl->add (2, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Dam"); |
|
|
299 | $tbl->add (2, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Arm"); |
|
|
300 | $tbl->add (2, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Sp"); |
|
|
301 | $tbl->add (2, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "WSp"); |
|
|
302 | |
|
|
303 | $tbl->add (3, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
304 | $tbl->add (3, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
305 | $tbl->add (3, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
306 | $tbl->add (3, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
307 | $tbl->add (3, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
308 | $tbl->add (3, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, text => ""); |
|
|
309 | |
|
|
310 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
|
|
311 | |
|
|
312 | my $row = 0; |
|
|
313 | my $col = 0; |
|
|
314 | |
|
|
315 | for (qw/slow holyw conf fire depl magic |
|
|
316 | drain acid pois para deat phys |
|
|
317 | blind fear tund elec cold ghit/) |
|
|
318 | { |
|
|
319 | $tbl2->add ($col , $row, |
|
|
320 | $STATWIDS->{"res_$_"} = |
|
|
321 | new CFClient::UI::Label text => "0", align => +1, valign => 0 |
|
|
322 | ); |
|
|
323 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image image => "ui/resist/resist_$_.png"); |
|
|
324 | |
|
|
325 | $row++; |
|
|
326 | if ($row % 6 == 0) { |
|
|
327 | $col += 2; |
|
|
328 | $row = 0; |
|
|
329 | } |
|
|
330 | } |
|
|
331 | |
|
|
332 | &set_stats_window_fontsize; |
|
|
333 | update_stats_window ({}); |
|
|
334 | |
|
|
335 | $tgw |
|
|
336 | } |
|
|
337 | |
|
|
338 | sub update_stats_window { |
|
|
339 | my ($stats) = @_; |
|
|
340 | |
|
|
341 | # i love text protocols!!! |
|
|
342 | my $hp = $stats->{1} * 1; |
|
|
343 | my $hp_m = $stats->{2} * 1; |
|
|
344 | my $sp = $stats->{3} * 1; |
|
|
345 | my $sp_m = $stats->{4} * 1; |
|
|
346 | my $fo = $stats->{18} * 1; |
|
|
347 | my $fo_m = 999; |
|
|
348 | my $gr = $stats->{23} * 1; |
|
|
349 | my $gr_m = $stats->{24} * 1; |
|
|
350 | |
|
|
351 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
352 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
353 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
354 | $GAUGES->{grace} ->set_value ($gr, $gr_m); |
|
|
355 | $GAUGES->{exp} ->set_text ("XP: " . ($stats->{11} || $stats->{28}) * 1 |
|
|
356 | ." LVL: " . $stats->{12} * 1); |
|
|
357 | my $rng = $stats->{20}; |
|
|
358 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
359 | $GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
360 | # $GAUGES->{lvl} ->set_text ("LVL: " . $stats->{12}); |
|
|
361 | $STATWIDS->{title} ->set_text ("Title: " . $stats->{21}); |
|
|
362 | |
|
|
363 | if (0) { # this code can vanish, just wanted to preserver it for a checkin |
|
|
364 | $STATWIDS->{st_str} ->set_text (sprintf "S%d", $stats->{5}); |
|
|
365 | $STATWIDS->{st_dex} ->set_text (sprintf "D%d", $stats->{8}); |
|
|
366 | $STATWIDS->{st_con} ->set_text (sprintf "Co%d", $stats->{9}); |
|
|
367 | $STATWIDS->{st_int} ->set_text (sprintf "I%d", $stats->{6}); |
|
|
368 | $STATWIDS->{st_wis} ->set_text (sprintf "W%d", $stats->{7}); |
|
|
369 | $STATWIDS->{st_pow} ->set_text (sprintf "P%d", $stats->{22}); |
|
|
370 | $STATWIDS->{st_cha} ->set_text (sprintf "Ch%d", $stats->{10}); |
|
|
371 | $STATWIDS->{st_wc} ->set_text (sprintf "Wc%d", $stats->{13}); |
|
|
372 | $STATWIDS->{st_ac} ->set_text (sprintf "Ac%d", $stats->{14}); |
|
|
373 | $STATWIDS->{st_dam} ->set_text (sprintf "Dam%d", $stats->{15}); |
|
|
374 | $STATWIDS->{st_arm} ->set_text (sprintf "Arm%d", $stats->{16}); |
|
|
375 | $STATWIDS->{st_spd} ->set_text (sprintf "Sp%.1f", $stats->{17}); |
|
|
376 | $STATWIDS->{st_wspd}->set_text (sprintf "WSp%.1f", $stats->{19}); |
|
|
377 | } else { |
|
|
378 | $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5}); |
|
|
379 | $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8}); |
|
|
380 | $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9}); |
|
|
381 | $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6}); |
|
|
382 | $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7}); |
|
|
383 | $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22}); |
|
|
384 | $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10}); |
|
|
385 | $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13}); |
|
|
386 | $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14}); |
|
|
387 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
|
|
388 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
|
|
389 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17}); |
|
|
390 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19}); |
|
|
391 | } |
|
|
392 | |
|
|
393 | my %tbl = ( |
|
|
394 | phys => 100, |
|
|
395 | magic => 101, |
|
|
396 | fire => 102, |
|
|
397 | elec => 103, |
|
|
398 | cold => 104, |
|
|
399 | conf => 105, |
|
|
400 | acid => 106, |
|
|
401 | drain => 107, |
|
|
402 | ghit => 108, |
|
|
403 | pois => 109, |
|
|
404 | slow => 110, |
|
|
405 | para => 111, |
|
|
406 | tund => 112, |
|
|
407 | fear => 113, |
|
|
408 | deat => 115, |
|
|
409 | holyw => 116, |
|
|
410 | blind => 117 |
|
|
411 | ); |
|
|
412 | |
|
|
413 | for (keys %tbl) { |
|
|
414 | $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}}); |
|
|
415 | } |
|
|
416 | |
|
|
417 | } |
|
|
418 | |
203 | sub metaserver_dialog { |
419 | sub metaserver_dialog { |
204 | my $dialog = new CFClient::UI::FancyFrame |
420 | my $dialog = new CFClient::UI::FancyFrame |
|
|
421 | title => "Metaserver", |
205 | child => (my $vbox = new CFClient::UI::VBox); |
422 | child => (my $vbox = new CFClient::UI::VBox); |
206 | |
423 | |
207 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
424 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
208 | |
425 | |
209 | $dialog |
426 | $dialog |
… | |
… | |
275 | }); |
492 | }); |
276 | } |
493 | } |
277 | |
494 | |
278 | sub server_setup { |
495 | sub server_setup { |
279 | my $dialog = new CFClient::UI::FancyFrame |
496 | my $dialog = new CFClient::UI::FancyFrame |
|
|
497 | title => "Server Setup", |
280 | child => (my $vbox = new CFClient::UI::VBox); |
498 | child => (my $vbox = new CFClient::UI::VBox); |
281 | |
499 | |
282 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup"); |
|
|
283 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
500 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
284 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
501 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
285 | |
502 | |
286 | { |
503 | { |
287 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
504 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
… | |
… | |
334 | $dialog |
551 | $dialog |
335 | } |
552 | } |
336 | |
553 | |
337 | sub message_window { |
554 | sub message_window { |
338 | my $window = new CFClient::UI::FancyFrame |
555 | my $window = new CFClient::UI::FancyFrame |
|
|
556 | title => "Messages", |
339 | border_bg => [1, 1, 1, 0.5], |
557 | border_bg => [1, 1, 1, 0.5], |
340 | bg => [0.3, 0.3, 0.3, 0.8], |
558 | bg => [0.3, 0.3, 0.3, 0.8], |
341 | user_w => int $::WIDTH / 3, |
559 | user_w => int $::WIDTH / 3, |
342 | user_h => int $::HEIGHT / 5, |
560 | user_h => int $::HEIGHT / 5, |
343 | child => (my $vbox = new CFClient::UI::VBox); |
561 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
399 | $FAST = $CFG->{fast}; |
617 | $FAST = $CFG->{fast}; |
400 | |
618 | |
401 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
619 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
402 | or die "SDL_SetVideoMode failed!\n"; |
620 | or die "SDL_SetVideoMode failed!\n"; |
403 | |
621 | |
404 | $SDL_EV = new SDL::Event; |
|
|
405 | $SDL_EV->set_unicode (1); |
|
|
406 | |
|
|
407 | $SDL_ACTIVE = 1; |
622 | $SDL_ACTIVE = 1; |
408 | |
623 | |
409 | $LAST_REFRESH = time - 0.01; |
624 | $LAST_REFRESH = time - 0.01; |
410 | |
625 | |
411 | CFClient::gl_init; |
626 | CFClient::gl_init; |
… | |
… | |
453 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
668 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
454 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
669 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
455 | status "Configuration Saved"; |
670 | status "Configuration Saved"; |
456 | }); |
671 | }); |
457 | |
672 | |
|
|
673 | $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D |
|
|
674 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
|
|
675 | |
458 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
676 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
459 | |
677 | |
460 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
461 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
462 | |
678 | |
463 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
464 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
465 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
466 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
467 | |
|
|
468 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
469 | $CFClient::UI::ROOT->add ($tgw); |
|
|
470 | } |
679 | } |
471 | |
680 | |
472 | sub video_shutdown { |
681 | sub video_shutdown { |
473 | $CFClient::UI::ROOT->{children} = []; |
682 | $CFClient::UI::ROOT->{children} = []; |
474 | undef $SDL_ACTIVE; |
683 | undef $SDL_ACTIVE; |
475 | undef $SDL_EV; |
|
|
476 | } |
684 | } |
477 | |
685 | |
|
|
686 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
478 | my $bgmusic;#TODO#hack#d# |
687 | my $bgmusic;#TODO#hack#d# |
|
|
688 | |
|
|
689 | sub audio_music_finished { |
|
|
690 | return unless $CFG->{bgm_enable}; |
|
|
691 | |
|
|
692 | # TODO: hack, do play loop and mood music |
|
|
693 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
694 | $bgmusic->play (0); |
|
|
695 | |
|
|
696 | push @bgmusic, shift @bgmusic; |
|
|
697 | } |
479 | |
698 | |
480 | sub audio_init { |
699 | sub audio_init { |
481 | if ($CFG->{audio_enable}) { |
700 | if ($CFG->{audio_enable}) { |
482 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
701 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
483 | |
702 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
484 | $SDL_MIXER = new SDL::Mixer |
703 | CFClient::Mix_AllocateChannels 8; |
485 | -rate => 22050, |
704 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
486 | -channels => 1, # mono |
|
|
487 | -size => 512; |
|
|
488 | |
705 | |
489 | $SDL_MIXER->allocate_channels (8); |
706 | audio_music_finished; |
490 | |
|
|
491 | # TODO: hack, do play loop and mood music |
|
|
492 | if ($CFG->{bgm_enable}) { |
|
|
493 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
|
|
494 | $SDL_MIXER->play_music ($bgmusic, -1); |
|
|
495 | $SDL_MIXER->music_volume ($CFG->{bgm_volume}); |
|
|
496 | } |
|
|
497 | |
707 | |
498 | while (<$fh>) { |
708 | while (<$fh>) { |
499 | next if /^\s*#/; |
709 | next if /^\s*#/; |
500 | next if /^\s*$/; |
710 | next if /^\s*$/; |
501 | |
711 | |
502 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
712 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
503 | |
713 | |
504 | push @SOUNDS, "$volume,$file"; |
714 | push @SOUNDS, "$volume,$file"; |
505 | |
715 | |
506 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
716 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
507 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
717 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
508 | $chunk->volume ($volume * 128 / 100); |
718 | $chunk->volume ($volume * 128 / 100); |
509 | $chunk |
719 | $chunk |
510 | }; |
720 | }; |
511 | } |
721 | } |
512 | } else { |
722 | } else { |
… | |
… | |
514 | } |
724 | } |
515 | } |
725 | } |
516 | } |
726 | } |
517 | |
727 | |
518 | sub audio_shutdown { |
728 | sub audio_shutdown { |
|
|
729 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
519 | undef $SDL_MIXER; |
730 | undef $SDL_MIXER; |
520 | @SOUNDS = (); |
731 | @SOUNDS = (); |
521 | %AUDIO_CHUNKS = (); |
732 | %AUDIO_CHUNKS = (); |
522 | } |
733 | } |
523 | |
734 | |
… | |
… | |
536 | $want_refresh = 0; |
747 | $want_refresh = 0; |
537 | $can_refresh = 0; |
748 | $can_refresh = 0; |
538 | |
749 | |
539 | $CFClient::UI::ROOT->draw; |
750 | $CFClient::UI::ROOT->draw; |
540 | |
751 | |
541 | SDL::GLSwapBuffers; |
752 | CFClient::SDL_GL_SwapBuffers; |
542 | |
753 | |
543 | $LAST_REFRESH = $NOW; |
754 | $LAST_REFRESH = $NOW; |
544 | } |
755 | } |
545 | |
756 | |
546 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
757 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
547 | $NOW = time; |
758 | $NOW = time; |
548 | |
759 | |
549 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
760 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
550 | while $SDL_EV->poll; |
761 | for CFClient::SDL_PollEvent; |
551 | |
762 | |
552 | if (%animate_object) { |
763 | if (%animate_object) { |
553 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
764 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
554 | $want_refresh++; |
765 | $want_refresh++; |
555 | } |
766 | } |
… | |
… | |
578 | @conn::ISA = Crossfire::Protocol::; |
789 | @conn::ISA = Crossfire::Protocol::; |
579 | |
790 | |
580 | sub conn::stats_update { |
791 | sub conn::stats_update { |
581 | my ($self, $stats) = @_; |
792 | my ($self, $stats) = @_; |
582 | |
793 | |
583 | # i love text protocols!!! |
794 | update_stats_window ($stats); |
584 | # FIXME: the stats are somehow weird |
|
|
585 | my $hp = $stats->{1}; |
|
|
586 | my $hp_m = $stats->{2}; |
|
|
587 | my $sp = $stats->{3}; |
|
|
588 | my $sp_m = $stats->{4}; |
|
|
589 | my $fo = $stats->{18}; |
|
|
590 | my $fo_m = 1000; |
|
|
591 | my $gr = $stats->{23}; |
|
|
592 | my $gr_m = $stats->{24}; |
|
|
593 | |
|
|
594 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
|
|
595 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
|
|
596 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
|
|
597 | $GAUGES->{food}->set_value ($fo, $fo_m); |
|
|
598 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
599 | } |
795 | } |
600 | |
796 | |
601 | sub conn::user_send { |
797 | sub conn::user_send { |
602 | my ($self, $command) = @_; |
798 | my ($self, $command) = @_; |
603 | |
799 | |
… | |
… | |
628 | |
824 | |
629 | my ($hash, $x, $y, $w, $h) = @$map_info; |
825 | my ($hash, $x, $y, $w, $h) = @$map_info; |
630 | |
826 | |
631 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
827 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
632 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
828 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
633 | |
|
|
634 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
829 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
635 | |
|
|
636 | } |
830 | } |
637 | |
831 | |
638 | sub conn::map_clear { |
832 | sub conn::map_clear { |
639 | my ($self) = @_; |
833 | my ($self) = @_; |
640 | |
834 | |
641 | $self->flush_map; |
835 | $self->flush_map; |
642 | delete $self->{neigh}; |
836 | delete $self->{neigh_map}; |
643 | |
837 | |
644 | $MAP->clear; |
838 | $MAP->clear; |
645 | } |
839 | } |
646 | |
840 | |
647 | |
841 | |
648 | sub conn::load_map($$$) { |
842 | sub conn::load_map($$$) { |
649 | my ($self, $hash, $x, $y) = @_; |
843 | my ($self, $hash, $x, $y) = @_; |
650 | |
844 | |
651 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
845 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
652 | $data = Compress::LZF::decompress $data; |
846 | $data = Compress::LZF::decompress $data; |
653 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
847 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
654 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
848 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
655 | my $data = $TILECACHE->get ($id) |
849 | my $data = $TILECACHE->get ($id) |
656 | or next; |
850 | or next; |
657 | |
851 | |
658 | $self->set_texture ($id => $data); |
852 | $self->set_texture ($id => $data); |
659 | } |
853 | } |
660 | } |
854 | } |
661 | } |
855 | } |
662 | |
856 | |
|
|
857 | # this method does a "flood fill" into every tile direction |
|
|
858 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
859 | # i.e. a map is the same as the left of the right map etc. |
|
|
860 | # failure to comply are harmless and result in display errors |
|
|
861 | # at worst. |
663 | sub conn::flood_fill { |
862 | sub conn::flood_fill { |
664 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
863 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
665 | |
864 | |
666 | # the server does not allow map paths > 6 |
865 | # the server does not allow map paths > 6 |
667 | return if 6 <= length $path; |
866 | return if 6 <= length $path; |
668 | |
867 | |
669 | for my $tile (1..4) { |
868 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
670 | next if $self->{neigh}{$hash}[$tile]; |
869 | |
|
|
870 | for ( |
|
|
871 | [1, 0, -1], |
|
|
872 | [2, 1, 0], |
|
|
873 | [3, 0, 1], |
|
|
874 | [4, -1, 0], |
|
|
875 | ) { |
|
|
876 | my ($tile, $dx, $dy) = @$_; |
|
|
877 | |
|
|
878 | my $gx = $gx + $dx; |
|
|
879 | my $gy = $gy + $dy; |
|
|
880 | |
671 | next unless $flags & (1 << ($tile - 1)); |
881 | next unless $flags & (1 << ($tile - 1)); |
|
|
882 | next if $self->{neigh_grid}{$gx, $gy}++; |
672 | |
883 | |
673 | my $neigh = $self->{neigh}{$hash} ||= []; |
884 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
674 | |
885 | if (my $info = $neigh->[$tile]) { |
675 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
676 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
886 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
677 | |
887 | |
678 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
679 | return if $mode ne "spatial"; |
|
|
680 | |
|
|
681 | $x += $MAP->ox; |
|
|
682 | $y += $MAP->oy; |
|
|
683 | |
|
|
684 | $self->load_map ($hash, $x, $y) |
|
|
685 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
686 | |
|
|
687 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
688 | |
|
|
689 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
888 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
690 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
889 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
890 | |
|
|
891 | } else { |
|
|
892 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
893 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
894 | |
|
|
895 | return if $mode ne "spatial"; |
|
|
896 | |
|
|
897 | $x += $MAP->ox; |
|
|
898 | $y += $MAP->oy; |
|
|
899 | |
|
|
900 | $self->load_map ($hash, $x, $y) |
|
|
901 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
902 | |
|
|
903 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
904 | |
|
|
905 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
906 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
907 | }); |
691 | }); |
908 | } |
692 | } |
909 | } |
693 | } |
910 | } |
694 | |
911 | |
695 | sub conn::map_change { |
912 | sub conn::map_change { |
696 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
913 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
699 | |
916 | |
700 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
917 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
701 | |
918 | |
702 | my $mapmapw = 250; |
919 | my $mapmapw = 250; |
703 | my $mapmaph = 250; |
920 | my $mapmaph = 250; |
|
|
921 | |
|
|
922 | $self->{neigh_rect} = [ |
|
|
923 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
924 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
925 | ]; |
704 | |
926 | |
|
|
927 | delete $self->{neigh_grid}; |
705 | $self->flood_fill ("", $hash, $flags, |
928 | $self->flood_fill (0, 0, "", $hash, $flags); |
706 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
707 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
708 | |
929 | |
709 | $x += $ox; |
930 | $x += $ox; |
710 | $y += $oy; |
931 | $y += $oy; |
711 | |
932 | |
712 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
933 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
934 | |
|
|
935 | my $map = $self->{map_info}[0]; |
|
|
936 | $map =~ s/^.*?\/([^\/]+)$/\1/; |
|
|
937 | $STATWIDS->{map}->set_text ("Map: " . $map); |
713 | |
938 | |
714 | $self->load_map ($hash, $x, $y); |
939 | $self->load_map ($hash, $x, $y); |
715 | } |
940 | } |
716 | |
941 | |
717 | sub conn::face_find { |
942 | sub conn::face_find { |
… | |
… | |
778 | or return; |
1003 | or return; |
779 | |
1004 | |
780 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
1005 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
781 | or return; |
1006 | or return; |
782 | |
1007 | |
783 | $SDL_MIXER->play_channel (-1, $chunk); |
1008 | $chunk->play; |
784 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
1009 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
785 | } |
1010 | } |
786 | |
1011 | |
787 | sub conn::query { |
1012 | sub conn::query { |
788 | my ($self, $flags, $prompt) = @_; |
1013 | my ($self, $flags, $prompt) = @_; |
… | |
… | |
841 | CFClient::SDL_QUIT => sub { |
1066 | CFClient::SDL_QUIT => sub { |
842 | Event::unloop -1; |
1067 | Event::unloop -1; |
843 | }, |
1068 | }, |
844 | CFClient::SDL_VIDEORESIZE => sub { |
1069 | CFClient::SDL_VIDEORESIZE => sub { |
845 | }, |
1070 | }, |
846 | CFClient::SDL_VIDEOEXPOSE => sub { |
1071 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
847 | refresh; |
1072 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
1073 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
848 | }, |
1074 | }, |
849 | CFClient::SDL_KEYDOWN => sub { |
1075 | CFClient::SDL_KEYDOWN => sub { |
850 | if ($SDL_EV->key_mod & CFClient::KMOD_ALT && $SDL_EV->key_sym == 13) { |
1076 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
851 | # alt-enter |
1077 | # alt-enter |
852 | video_shutdown; |
1078 | video_shutdown; |
853 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
1079 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
854 | video_init; |
1080 | video_init; |
855 | } else { |
1081 | } else { |
856 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
1082 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
857 | } |
1083 | } |
858 | }, |
1084 | }, |
859 | CFClient::SDL_KEYUP => sub { |
1085 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
860 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
1086 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
861 | }, |
1087 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
862 | CFClient::SDL_MOUSEMOTION => sub { |
1088 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
863 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
1089 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
864 | }, |
|
|
865 | CFClient::SDL_MOUSEBUTTONDOWN => sub { |
|
|
866 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
867 | }, |
|
|
868 | CFClient::SDL_MOUSEBUTTONUP => sub { |
|
|
869 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
870 | }, |
|
|
871 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
872 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
873 | }, |
|
|
874 | ); |
1090 | ); |
875 | |
1091 | |
876 | ############################################################################# |
1092 | ############################################################################# |
877 | |
1093 | |
878 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1094 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
… | |
… | |
890 | fast => 0, |
1106 | fast => 0, |
891 | fow_enable => 1, |
1107 | fow_enable => 1, |
892 | fow_intensity => 0.45, |
1108 | fow_intensity => 0.45, |
893 | fow_smooth => 0, |
1109 | fow_smooth => 0, |
894 | gui_fontsize => 1, |
1110 | gui_fontsize => 1, |
895 | log_fontsize => 14, |
1111 | log_fontsize => 1, |
|
|
1112 | gauge_fontsize => 1, |
|
|
1113 | gauge_size => 0.35, |
|
|
1114 | stat_fontsize => 1, |
896 | mapsize => 100, |
1115 | mapsize => 100, |
897 | host => "crossfire.schmorp.de", |
1116 | host => "crossfire.schmorp.de", |
898 | say_command => 'say', |
1117 | say_command => 'say', |
899 | audio_enable => 1, |
1118 | audio_enable => 1, |
900 | bgm_enable => 1, |
1119 | bgm_enable => 1, |
901 | bgm_volume => 64, |
1120 | bgm_volume => 0.25, |
902 | ); |
1121 | ); |
903 | |
1122 | |
904 | while (my ($k, $v) = each %DEF_CFG) { |
1123 | while (my ($k, $v) = each %DEF_CFG) { |
905 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
1124 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
906 | } |
1125 | } |
… | |
… | |
925 | video_init; |
1144 | video_init; |
926 | audio_init; |
1145 | audio_init; |
927 | |
1146 | |
928 | Event::loop; |
1147 | Event::loop; |
929 | |
1148 | |
930 | END { SDL::Quit } |
1149 | END { CFClient::SDL_Quit } |
931 | |
1150 | |
932 | |
1151 | |