… | |
… | |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Time::HiRes 'time'; |
6 | use Time::HiRes 'time'; |
7 | use Event; |
7 | use Event; |
8 | |
8 | |
9 | use SDL; |
|
|
10 | use SDL::App; |
|
|
11 | use SDL::Event; |
|
|
12 | use SDL::Surface; |
|
|
13 | |
|
|
14 | use SDL::Mixer; |
|
|
15 | use SDL::Sound; |
|
|
16 | use SDL::Music; |
|
|
17 | |
|
|
18 | use SDL::OpenGL; |
|
|
19 | |
|
|
20 | use Crossfire; |
9 | use Crossfire; |
21 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
22 | |
11 | |
23 | use Compress::LZF; |
12 | use Compress::LZF; |
24 | |
13 | |
25 | use CFClient; |
14 | use CFClient; |
26 | use CFClient::UI; |
15 | use CFClient::UI; |
|
|
16 | use CFClient::MapWidget; |
27 | |
17 | |
28 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
29 | |
19 | |
30 | my $MAX_FPS = 60; |
20 | my $MAX_FPS = 60; |
31 | my $MIN_FPS = 5; # unused as of yet |
21 | my $MIN_FPS = 5; # unused as of yet |
… | |
… | |
46 | our @SDL_MODES; |
36 | our @SDL_MODES; |
47 | our $WIDTH; |
37 | our $WIDTH; |
48 | our $HEIGHT; |
38 | our $HEIGHT; |
49 | our $FULLSCREEN; |
39 | our $FULLSCREEN; |
50 | our $FONTSIZE; |
40 | our $FONTSIZE; |
|
|
41 | |
|
|
42 | our $FONT_PROP; |
|
|
43 | our $FONT_FIXED; |
51 | |
44 | |
52 | our $MAP; |
45 | our $MAP; |
53 | our $MAPWIDGET; |
46 | our $MAPWIDGET; |
54 | our $BUTTONBAR; |
47 | our $BUTTONBAR; |
55 | our $LOGVIEW; |
48 | our $LOGVIEW; |
56 | our $CONSOLE; |
49 | our $CONSOLE; |
57 | our $METASERVER; |
50 | our $METASERVER; |
58 | |
51 | |
|
|
52 | our $FLOORBOX; |
59 | our $GAUGES; |
53 | our $GAUGES; |
|
|
54 | our $STATWIDS; |
60 | |
55 | |
61 | our $SDL_ACTIVE; |
56 | our $SDL_ACTIVE; |
62 | our $SDL_EV; |
|
|
63 | our %SDL_CB; |
57 | our %SDL_CB; |
64 | |
58 | |
65 | our $SDL_MIXER; |
59 | our $SDL_MIXER; |
66 | our @SOUNDS; # event => file mapping |
60 | our @SOUNDS; # event => file mapping |
67 | our %AUDIO_CHUNKS; # audio files |
61 | our %AUDIO_CHUNKS; # audio files |
… | |
… | |
109 | undef $CONN; |
103 | undef $CONN; |
110 | } |
104 | } |
111 | |
105 | |
112 | sub client_setup { |
106 | sub client_setup { |
113 | my $dialog = new CFClient::UI::FancyFrame |
107 | my $dialog = new CFClient::UI::FancyFrame |
|
|
108 | title => "Client Setup", |
114 | child => (my $vbox = new CFClient::UI::VBox); |
109 | child => (my $vbox = new CFClient::UI::VBox); |
115 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
|
|
116 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
110 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
117 | |
111 | |
118 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
112 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
119 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
113 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
120 | |
114 | |
121 | $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_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
122 | $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); |
116 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
123 | |
117 | |
124 | $mode_slider->connect (changed => sub { |
118 | $mode_slider->connect (changed => sub { |
125 | my ($self, $value) = @_; |
119 | my ($self, $value) = @_; |
126 | |
120 | |
127 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
121 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
128 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
122 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
129 | }); |
123 | }); |
130 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
124 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
131 | |
125 | |
|
|
126 | my $row = 1; |
|
|
127 | |
132 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); |
128 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
133 | $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
129 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
130 | state => $CFG->{fullscreen}, |
|
|
131 | tooltip => "Bring the client into fullscreen mode", |
|
|
132 | connect_changed => sub { |
134 | my ($self, $value) = @_; |
133 | my ($self, $value) = @_; |
135 | $CFG->{fullscreen} = $value; |
134 | $CFG->{fullscreen} = $value; |
|
|
135 | } |
136 | }); |
136 | ); |
137 | |
137 | |
138 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); |
138 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
139 | $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
139 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
140 | state => $CFG->{fast}, |
|
|
141 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
|
|
142 | connect_changed => sub { |
140 | my ($self, $value) = @_; |
143 | my ($self, $value) = @_; |
141 | $CFG->{fast} = $value; |
144 | $CFG->{fast} = $value; |
|
|
145 | } |
142 | }); |
146 | ); |
143 | |
147 | |
144 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); |
148 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale"); |
145 | $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
149 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
150 | range => [$CFG->{map_scale}, 0.25, 2, 0.05], |
|
|
151 | tooltip => "Enlarge or shrink the displayed map", |
|
|
152 | connect_changed => sub { |
146 | my ($self, $value) = @_; |
153 | my ($self, $value) = @_; |
|
|
154 | $CFG->{map_scale} = 0.05 * int $value / 0.05; |
|
|
155 | } |
|
|
156 | ); |
|
|
157 | |
|
|
158 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
|
|
159 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
160 | state => $CFG->{fow_enable}, |
|
|
161 | tooltip => "Fog-of-War marks areas that cannot be seen by the player", |
|
|
162 | connect_changed => sub { |
|
|
163 | my ($self, $value) = @_; |
147 | $CFG->{fow_enable} = $value; |
164 | $CFG->{fow_enable} = $value; |
|
|
165 | } |
148 | }); |
166 | ); |
149 | |
167 | |
150 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); |
168 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
151 | $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
169 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
170 | range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], |
|
|
171 | tooltip => "The higher the intensity, the lighter the Fog-of-War color", |
|
|
172 | connect_changed => sub { |
152 | my ($self, $value) = @_; |
173 | my ($self, $value) = @_; |
153 | $CFG->{fow_intensity} = $value; |
174 | $CFG->{fow_intensity} = $value; |
|
|
175 | } |
154 | }); |
176 | ); |
155 | |
177 | |
156 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
178 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
157 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
179 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
180 | state => $CFG->{fow_smooth}, |
|
|
181 | tooltip => "Smooth the Fog-of-War a bit to make it more realistic", |
|
|
182 | connect_changed => sub { |
158 | my ($self, $value) = @_; |
183 | my ($self, $value) = @_; |
159 | $CFG->{fow_smooth} = $value; |
184 | $CFG->{fow_smooth} = $value; |
160 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
185 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
|
|
186 | } |
161 | }); |
187 | ); |
162 | |
188 | |
163 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
189 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
164 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
190 | $table->add (1, $row++, new CFClient::UI::Slider |
165 | my ($self, $value) = @_; |
191 | range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1], |
166 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
192 | tooltip => "The font size used by most GUI elements", |
|
|
193 | connect_changed => sub { |
|
|
194 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
195 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
196 | } |
167 | }); |
197 | ); |
168 | |
198 | |
169 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
199 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
|
|
200 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
201 | range => [$CFG->{log_fontsize}, 0.5, 2, 0.1], |
|
|
202 | tooltip => "The font size used by the server log window only", |
|
|
203 | connect_changed => sub { |
|
|
204 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
|
|
205 | } |
|
|
206 | ); |
|
|
207 | |
|
|
208 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize"); |
|
|
209 | |
|
|
210 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
211 | range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1], |
|
|
212 | tooltip => "The font size used by the statistics window only", |
|
|
213 | connect_changed => sub { |
|
|
214 | $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10; |
|
|
215 | &set_stats_window_fontsize; |
|
|
216 | } |
|
|
217 | ); |
|
|
218 | |
|
|
219 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size"); |
|
|
220 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
221 | range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], |
|
|
222 | tooltip => "Adjust the size of the stats gauges at the bottom right", |
|
|
223 | connect_changed => sub { |
|
|
224 | $CFG->{gauge_size} = $_[1]; |
|
|
225 | my $h = int $HEIGHT * $CFG->{gauge_size}; |
|
|
226 | $GAUGES->{win}->set_size ($WIDTH, $h); |
|
|
227 | $GAUGES->{win}->move (0, $HEIGHT - $h); |
|
|
228 | } |
|
|
229 | ); |
|
|
230 | |
|
|
231 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
|
|
232 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
233 | range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1], |
|
|
234 | tooltip => "Adjusts the fontsize of the gauges at the bottom right", |
|
|
235 | connect_changed => sub { |
|
|
236 | $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10; |
|
|
237 | &set_gauge_window_fontsize; |
|
|
238 | } |
|
|
239 | ); |
|
|
240 | |
|
|
241 | $table->add (1, $row++, new CFClient::UI::Button |
|
|
242 | expand => 1, align => 0, text => "Apply", |
|
|
243 | tooltip => "Apply the video settings", |
|
|
244 | connect_activate => sub { |
170 | video_shutdown (); |
245 | video_shutdown (); |
171 | video_init (); |
246 | video_init (); |
|
|
247 | } |
|
|
248 | ); |
|
|
249 | |
|
|
250 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
|
|
251 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
252 | state => $CFG->{audio_enable}, |
|
|
253 | tooltip => "If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.", |
|
|
254 | connect_changed => sub { |
|
|
255 | $CFG->{audio_enable} = $_[1]; |
|
|
256 | } |
|
|
257 | ); |
|
|
258 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
259 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
260 | # $CFG->{effects_volume} = $_[1]; |
172 | }); |
261 | # }); |
|
|
262 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
263 | $table->add (1, $row++, my $hbox = new CFClient::UI::HBox); |
|
|
264 | $hbox->add (new CFClient::UI::CheckBox |
|
|
265 | expand => 1, state => $CFG->{bgm_enable}, |
|
|
266 | tooltip => "Enable background music playing", |
|
|
267 | connect_changed => sub { |
|
|
268 | $CFG->{bgm_enable} = $_[1]; |
|
|
269 | } |
|
|
270 | ); |
|
|
271 | $hbox->add (new CFClient::UI::Slider |
|
|
272 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], |
|
|
273 | tooltip => "The volume of the background music", |
|
|
274 | connect_changed => sub { |
|
|
275 | $CFG->{bgm_volume} = $_[1]; |
|
|
276 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
277 | } |
|
|
278 | ); |
|
|
279 | |
|
|
280 | $table->add (1, $row++, new CFClient::UI::Button |
|
|
281 | expand => 1, align => 0, text => "Apply", |
|
|
282 | tooltip => "Apply the audio settings", |
|
|
283 | connect_activate => sub { |
|
|
284 | audio_shutdown (); |
|
|
285 | audio_init (); |
|
|
286 | } |
|
|
287 | ); |
173 | |
288 | |
174 | $dialog |
289 | $dialog |
|
|
290 | } |
|
|
291 | |
|
|
292 | sub set_stats_window_fontsize { |
|
|
293 | for (values %{$STATWIDS}) { |
|
|
294 | $_->set_fontsize ($::CFG->{stat_fontsize}); |
|
|
295 | } |
|
|
296 | } |
|
|
297 | |
|
|
298 | sub set_gauge_window_fontsize { |
|
|
299 | for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) { |
|
|
300 | $_->set_fontsize ($::CFG->{gauge_fontsize}); |
|
|
301 | } |
|
|
302 | |
|
|
303 | # local $GAUGES->{win}{parent};#d# |
|
|
304 | # use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D; |
|
|
305 | } |
|
|
306 | |
|
|
307 | sub make_gauge_window { |
|
|
308 | my $gh = int ($HEIGHT * $CFG->{gauge_size}); |
|
|
309 | # my $gw = int ($WIDTH * $CFG->{gauge_w_size}); |
|
|
310 | |
|
|
311 | my $win = new CFClient::UI::Frame ( |
|
|
312 | y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh |
|
|
313 | ); |
|
|
314 | $win->add (my $hbox = new CFClient::UI::HBox |
|
|
315 | children => [ |
|
|
316 | (new CFClient::UI::HBox expand => 1), |
|
|
317 | ($FLOORBOX = new CFClient::UI::VBox), |
|
|
318 | (my $vbox = new CFClient::UI::VBox), |
|
|
319 | ], |
|
|
320 | ); |
|
|
321 | |
|
|
322 | $vbox->add (new CFClient::UI::HBox |
|
|
323 | expand => 1, |
|
|
324 | children => [ |
|
|
325 | (new CFClient::UI::Empty expand => 1), |
|
|
326 | (my $hb = new CFClient::UI::HBox), |
|
|
327 | ], |
|
|
328 | ); |
|
|
329 | |
|
|
330 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', |
|
|
331 | tooltip => "Health points - depletes when you get wounded, refills when you heal or idle"); |
|
|
332 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', |
|
|
333 | tooltip => "Spell points - deplete when you cast wizard spells, refills when you idle"); |
|
|
334 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', |
|
|
335 | tooltip => "Grace points - deplete when you cast priest spells, refills when you pray"); |
|
|
336 | $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', |
|
|
337 | tooltip => "Food - depletes with time, faster when you heal or build mana, refills when you eat healthy food"); |
|
|
338 | |
|
|
339 | $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, |
|
|
340 | tooltip => "Experience points and level - increases when you kill monsters or successfully use skills"); |
|
|
341 | $vbox->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, |
|
|
342 | tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)"); |
|
|
343 | |
|
|
344 | $GAUGES = { |
|
|
345 | exp => $exp, win => $win, range => $rng, |
|
|
346 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
|
|
347 | }; |
|
|
348 | |
|
|
349 | &set_gauge_window_fontsize; |
|
|
350 | |
|
|
351 | $win |
|
|
352 | } |
|
|
353 | |
|
|
354 | sub make_stats_window { |
|
|
355 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
|
|
356 | |
|
|
357 | $tgw->add (my $vb = new CFClient::UI::VBox); |
|
|
358 | $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); |
|
|
359 | $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); |
|
|
360 | |
|
|
361 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
|
|
362 | |
|
|
363 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
|
|
364 | |
|
|
365 | $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
366 | $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
367 | $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
368 | $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
369 | $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
370 | $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
371 | $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
372 | |
|
|
373 | $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Str"); |
|
|
374 | $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dex"); |
|
|
375 | $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Con"); |
|
|
376 | $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Int"); |
|
|
377 | $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wis"); |
|
|
378 | $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Pow"); |
|
|
379 | $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Cha"); |
|
|
380 | |
|
|
381 | $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
382 | $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
383 | $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
384 | $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
385 | $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54"); |
|
|
386 | $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9"); |
|
|
387 | |
|
|
388 | $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc"); |
|
|
389 | $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac"); |
|
|
390 | $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam"); |
|
|
391 | $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm"); |
|
|
392 | $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp"); |
|
|
393 | $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp"); |
|
|
394 | |
|
|
395 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
|
|
396 | |
|
|
397 | my $row = 0; |
|
|
398 | my $col = 0; |
|
|
399 | |
|
|
400 | my %resist_names = ( |
|
|
401 | slow => "Slow", |
|
|
402 | holyw => "Holy Word", |
|
|
403 | conf => "Confusion", |
|
|
404 | fire => "Fire", |
|
|
405 | depl => "Depletion", |
|
|
406 | magic => "Magic", |
|
|
407 | drain => "Draining", |
|
|
408 | acid => "Acid", |
|
|
409 | pois => "Poison", |
|
|
410 | para => "Paralysation", |
|
|
411 | deat => "Death", |
|
|
412 | phys => "Physical", |
|
|
413 | blind => "Blind", |
|
|
414 | fear => "Fear", |
|
|
415 | tund => "Turn undead", |
|
|
416 | elec => "Electricity", |
|
|
417 | cold => "Cold", |
|
|
418 | ghit => "Ghost hit", |
|
|
419 | ); |
|
|
420 | for (qw/slow holyw conf fire depl magic |
|
|
421 | drain acid pois para deat phys |
|
|
422 | blind fear tund elec cold ghit/) |
|
|
423 | { |
|
|
424 | $tbl2->add ($col, $row, |
|
|
425 | $STATWIDS->{"res_$_"} = |
|
|
426 | new CFClient::UI::Label |
|
|
427 | template => "-100%", |
|
|
428 | align => +1, |
|
|
429 | valign => 0, |
|
|
430 | tooltip => $resist_names{$_} |
|
|
431 | ); |
|
|
432 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image |
|
|
433 | can_hover => 1, |
|
|
434 | can_events => 1, |
|
|
435 | image => "ui/resist/resist_$_.png", |
|
|
436 | tooltip => $resist_names{$_} |
|
|
437 | ); |
|
|
438 | |
|
|
439 | $row++; |
|
|
440 | if ($row % 6 == 0) { |
|
|
441 | $col += 2; |
|
|
442 | $row = 0; |
|
|
443 | } |
|
|
444 | } |
|
|
445 | |
|
|
446 | &set_stats_window_fontsize; |
|
|
447 | update_stats_window ({}); |
|
|
448 | |
|
|
449 | $tgw |
|
|
450 | } |
|
|
451 | |
|
|
452 | sub formsep { |
|
|
453 | reverse join ",", grep length, split /(...)/, reverse $_[0] * 1 |
|
|
454 | } |
|
|
455 | |
|
|
456 | sub update_stats_window { |
|
|
457 | my ($stats) = @_; |
|
|
458 | |
|
|
459 | # i love text protocols!!! |
|
|
460 | my $hp = $stats->{Crossfire::Protocol::CS_STAT_HP} * 1; |
|
|
461 | my $hp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXHP} * 1; |
|
|
462 | my $sp = $stats->{Crossfire::Protocol::CS_STAT_SP} * 1; |
|
|
463 | my $sp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXSP} * 1; |
|
|
464 | my $fo = $stats->{Crossfire::Protocol::CS_STAT_FOOD} * 1; |
|
|
465 | my $fo_m = 999; |
|
|
466 | my $gr = $stats->{Crossfire::Protocol::CS_STAT_GRACE} * 1; |
|
|
467 | my $gr_m = $stats->{Crossfire::Protocol::CS_STAT_MAXGRACE} * 1; |
|
|
468 | |
|
|
469 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
470 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
471 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
472 | $GAUGES->{grace} ->set_value ($gr, $gr_m); |
|
|
473 | $GAUGES->{exp} ->set_text ("Exp: " . (formsep $stats->{Crossfire::Protocol::CS_STAT_EXP64}) |
|
|
474 | . " (lvl " . ($stats->{Crossfire::Protocol::CS_STAT_LEVEL} * 1) . ")"); |
|
|
475 | my $rng = $stats->{Crossfire::Protocol::CS_STAT_RANGE}; |
|
|
476 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
477 | $GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
478 | my $title = $stats->{Crossfire::Protocol::CS_STAT_TITLE}; |
|
|
479 | $title =~ s/^Player: //; |
|
|
480 | $STATWIDS->{title} ->set_text ("Title: " . $title); |
|
|
481 | |
|
|
482 | $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5}); |
|
|
483 | $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8}); |
|
|
484 | $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9}); |
|
|
485 | $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6}); |
|
|
486 | $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7}); |
|
|
487 | $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22}); |
|
|
488 | $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10}); |
|
|
489 | $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13}); |
|
|
490 | $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14}); |
|
|
491 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
|
|
492 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
|
|
493 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_SPEED}); |
|
|
494 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_WEAP_SP}); |
|
|
495 | |
|
|
496 | my %tbl = ( |
|
|
497 | phys => 100, |
|
|
498 | magic => 101, |
|
|
499 | fire => 102, |
|
|
500 | elec => 103, |
|
|
501 | cold => 104, |
|
|
502 | conf => 105, |
|
|
503 | acid => 106, |
|
|
504 | drain => 107, |
|
|
505 | ghit => 108, |
|
|
506 | pois => 109, |
|
|
507 | slow => 110, |
|
|
508 | para => 111, |
|
|
509 | tund => 112, |
|
|
510 | fear => 113, |
|
|
511 | depl => 113, |
|
|
512 | deat => 115, |
|
|
513 | holyw => 116, |
|
|
514 | blind => 117 |
|
|
515 | ); |
|
|
516 | |
|
|
517 | for (keys %tbl) { |
|
|
518 | $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}}); |
|
|
519 | } |
|
|
520 | |
175 | } |
521 | } |
176 | |
522 | |
177 | sub metaserver_dialog { |
523 | sub metaserver_dialog { |
178 | my $dialog = new CFClient::UI::FancyFrame |
524 | my $dialog = new CFClient::UI::FancyFrame |
|
|
525 | title => "Metaserver", |
179 | child => (my $vbox = new CFClient::UI::VBox); |
526 | child => (my $vbox = new CFClient::UI::VBox); |
180 | |
527 | |
181 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
528 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
182 | |
529 | |
183 | $dialog |
530 | $dialog |
… | |
… | |
240 | $HOST->set_text ($CFG->{host} = $host); |
587 | $HOST->set_text ($CFG->{host} = $host); |
241 | }), |
588 | }), |
242 | (new CFClient::UI::Empty expand => 1), |
589 | (new CFClient::UI::Empty expand => 1), |
243 | ]); |
590 | ]); |
244 | |
591 | |
245 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) |
592 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
246 | for 0 .. $#$m; |
593 | for 0 .. $#$m; |
247 | } |
594 | } |
248 | } |
595 | } |
249 | }); |
596 | }); |
250 | } |
597 | } |
251 | |
598 | |
252 | sub server_setup { |
599 | sub server_setup { |
253 | my $dialog = new CFClient::UI::FancyFrame |
600 | my $dialog = new CFClient::UI::FancyFrame |
|
|
601 | title => "Server Setup", |
254 | child => (my $vbox = new CFClient::UI::VBox); |
602 | child => (my $vbox = new CFClient::UI::VBox); |
255 | |
603 | |
256 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
|
|
257 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
604 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
258 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); |
605 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
259 | |
606 | |
260 | { |
607 | { |
261 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
608 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
262 | |
609 | |
263 | $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { |
610 | $vbox->add ( |
|
|
611 | my $HOST = new CFClient::UI::Entry |
|
|
612 | expand => 1, |
|
|
613 | text => $CFG->{host}, |
|
|
614 | tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", |
|
|
615 | connect_changed => sub { |
|
|
616 | my ($self, $value) = @_; |
|
|
617 | $CFG->{host} = $value; |
|
|
618 | } |
|
|
619 | ); |
|
|
620 | |
|
|
621 | $METASERVER = metaserver_dialog; |
|
|
622 | |
|
|
623 | $vbox->add (new CFClient::UI::Flopper |
|
|
624 | expand => 1, |
|
|
625 | text => "Metaserver", |
|
|
626 | other => $METASERVER, |
|
|
627 | tooltip => "Show a list of avaible crossfire servers", |
|
|
628 | connect_open => sub { |
|
|
629 | update_metaserver $HOST; |
|
|
630 | } |
|
|
631 | ); |
|
|
632 | } |
|
|
633 | |
|
|
634 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
|
|
635 | $table->add (1, 4, new CFClient::UI::Entry |
|
|
636 | text => $CFG->{user}, |
|
|
637 | tooltip => "The name of your character on the server", |
|
|
638 | connect_changed => sub { |
264 | my ($self, $value) = @_; |
639 | my ($self, $value) = @_; |
265 | $CFG->{host} = $value; |
640 | $CFG->{user} = $value; |
266 | }); |
641 | } |
|
|
642 | ); |
267 | |
643 | |
268 | $METASERVER = metaserver_dialog; |
|
|
269 | |
|
|
270 | $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { |
|
|
271 | update_metaserver $HOST; |
|
|
272 | }); |
|
|
273 | } |
|
|
274 | |
|
|
275 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
644 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
276 | $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
645 | $table->add (1, 5, new CFClient::UI::Entry |
|
|
646 | text => $CFG->{password}, |
|
|
647 | hidden => 1, |
|
|
648 | tooltip => "The password for your character", |
|
|
649 | connect_changed => sub { |
277 | my ($self, $value) = @_; |
650 | my ($self, $value) = @_; |
278 | $CFG->{user} = $value; |
|
|
279 | }); |
|
|
280 | |
|
|
281 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); |
|
|
282 | $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
|
|
283 | my ($self, $value) = @_; |
|
|
284 | $CFG->{password} = $value; |
651 | $CFG->{password} = $value; |
|
|
652 | } |
285 | }); |
653 | ); |
286 | |
654 | |
287 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); |
655 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
288 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
656 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry |
|
|
657 | text => $CFG->{say_command}, |
|
|
658 | tooltip => "This is the command that will be used if you write a line in the message window entry. " |
|
|
659 | ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " |
|
|
660 | ."But you could also set it to 'tell <playername>' to only chat with that user.", |
|
|
661 | connect_changed => sub { |
289 | my ($self, $value) = @_; |
662 | my ($self, $value) = @_; |
290 | $CFG->{say_command} = $value; |
663 | $CFG->{say_command} = $value; |
|
|
664 | } |
291 | }); |
665 | ); |
292 | |
666 | |
293 | $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); |
667 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
294 | $table->add (1, 7, new CFClient::UI::Slider |
668 | $table->add (1, 7, new CFClient::UI::Slider |
295 | req_w => 100, |
669 | req_w => 100, |
296 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
670 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
671 | tooltip => "This is the size of the portion of the map update the server sends you. " |
|
|
672 | ."If you set this to a high value you will be able to see further for example.", |
297 | connect_changed => sub { |
673 | connect_changed => sub { |
298 | my ($self, $value) = @_; |
674 | my ($self, $value) = @_; |
299 | |
675 | |
300 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
676 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
301 | }, |
677 | }, |
… | |
… | |
308 | $dialog |
684 | $dialog |
309 | } |
685 | } |
310 | |
686 | |
311 | sub message_window { |
687 | sub message_window { |
312 | my $window = new CFClient::UI::FancyFrame |
688 | my $window = new CFClient::UI::FancyFrame |
|
|
689 | title => "Messages", |
313 | border_bg => [1, 1, 1, 0.5], |
690 | border_bg => [1, 1, 1, 0.5], |
314 | bg => [0.3, 0.3, 0.3, 0.8], |
691 | bg => [0.3, 0.3, 0.3, 0.8], |
315 | user_w => int $::WIDTH / 3, |
692 | user_w => int $::WIDTH / 3, |
316 | user_h => int $::HEIGHT / 5, |
693 | user_h => int $::HEIGHT / 5, |
317 | child => (my $vbox = new CFClient::UI::VBox); |
694 | child => (my $vbox = new CFClient::UI::VBox); |
318 | |
695 | |
319 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
696 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
320 | expand => 1, |
697 | expand => 1, |
|
|
698 | font => $FONT_FIXED, |
321 | fontsize => $::CFG->{log_fontsize}, |
699 | fontsize => $::CFG->{log_fontsize}, |
322 | ); |
700 | ); |
323 | |
701 | |
324 | $vbox->add (my $input = new CFClient::UI::Entry |
702 | $vbox->add (my $input = new CFClient::UI::Entry |
325 | connect_focus_in => sub { |
703 | connect_focus_in => sub { |
… | |
… | |
359 | |
737 | |
360 | $window |
738 | $window |
361 | } |
739 | } |
362 | |
740 | |
363 | sub sdl_init { |
741 | sub sdl_init { |
364 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
742 | CFClient::SDL_Init |
365 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
366 | and die "SDL::Init failed!\n"; |
743 | and die "SDL::Init failed!\n"; |
367 | } |
744 | } |
368 | |
745 | |
369 | sub video_init { |
746 | sub video_init { |
370 | sdl_init; |
747 | sdl_init; |
371 | |
748 | |
372 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
749 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
373 | $FULLSCREEN = $CFG->{fullscreen}; |
750 | $FULLSCREEN = $CFG->{fullscreen}; |
374 | $FAST = $CFG->{fast}; |
751 | $FAST = $CFG->{fast}; |
375 | |
752 | |
376 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
753 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
377 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
378 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
379 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
|
|
380 | |
|
|
381 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
382 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
383 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
384 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
385 | |
|
|
386 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
387 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
388 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
389 | |
|
|
390 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
391 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
392 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
393 | or die "SDL::SetVideoMode failed!\n"; |
754 | or die "SDL_SetVideoMode failed!\n"; |
394 | |
|
|
395 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
396 | |
|
|
397 | $SDL_EV = new SDL::Event; |
|
|
398 | $SDL_EV->set_unicode (1); |
|
|
399 | |
755 | |
400 | $SDL_ACTIVE = 1; |
756 | $SDL_ACTIVE = 1; |
401 | |
757 | |
402 | $LAST_REFRESH = time - 0.01; |
758 | $LAST_REFRESH = time - 0.01; |
403 | |
759 | |
404 | CFClient::gl_init; |
760 | CFClient::gl_init; |
405 | |
761 | |
406 | $FONTSIZE = int $HEIGHT / 40; |
762 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
407 | |
763 | |
408 | ############################################################################# |
764 | ############################################################################# |
409 | |
765 | |
410 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
766 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
411 | $CFClient::UI::ROOT->add ($DEBUG_STATUS); |
767 | $DEBUG_STATUS->show; |
412 | |
768 | |
413 | $STATUS_LINE = new CFClient::UI::Label |
769 | $STATUS_LINE = new CFClient::UI::Label |
414 | padding => 0, |
770 | padding => 0, |
415 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
771 | y => $HEIGHT - $FONTSIZE * 1.8; |
416 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
772 | $STATUS_LINE->show; |
417 | |
773 | |
418 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
774 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
419 | padding => 0, |
775 | padding => 0, |
420 | y => $HEIGHT * 44 / 45, |
|
|
421 | fontsize => $HEIGHT / 45, |
776 | fontsize => 0.8, |
422 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
777 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
423 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
778 | $ALT_ENTER_MESSAGE->show; |
|
|
779 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
424 | |
780 | |
425 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
781 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
426 | $MAPWIDGET->focus_in; |
782 | $MAPWIDGET->focus_in; |
427 | $MAPWIDGET->connect (activate_console => sub { |
783 | $MAPWIDGET->connect (activate_console => sub { |
428 | my ($mapwidget, $preset) = @_; |
784 | my ($mapwidget, $preset) = @_; |
429 | |
785 | |
430 | if ($CONSOLE) { |
786 | if ($CONSOLE) { |
… | |
… | |
440 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
796 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
441 | |
797 | |
442 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
798 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
443 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
799 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
444 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
800 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
|
|
801 | |
|
|
802 | $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 |
|
|
803 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
445 | |
804 | |
446 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
805 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
447 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
806 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
448 | status "Configuration Saved"; |
807 | status "Configuration Saved"; |
449 | }); |
808 | }); |
450 | |
809 | |
451 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
810 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
452 | |
|
|
453 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
454 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
455 | |
|
|
456 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
457 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
458 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
459 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
460 | |
|
|
461 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
462 | $CFClient::UI::ROOT->add ($tgw); |
|
|
463 | } |
811 | } |
464 | |
812 | |
465 | sub video_shutdown { |
813 | sub video_shutdown { |
466 | $CFClient::UI::ROOT->{children} = []; |
814 | $CFClient::UI::ROOT->{children} = []; |
467 | undef $SDL_ACTIVE; |
815 | undef $SDL_ACTIVE; |
468 | undef $SDL_EV; |
|
|
469 | } |
816 | } |
470 | |
817 | |
|
|
818 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
471 | my $bgmusic;#TODO#hack#d# |
819 | my $bgmusic;#TODO#hack#d# |
472 | |
820 | |
|
|
821 | sub audio_music_finished { |
|
|
822 | return unless $CFG->{bgm_enable}; |
|
|
823 | |
|
|
824 | # TODO: hack, do play loop and mood music |
|
|
825 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
826 | $bgmusic->play (0); |
|
|
827 | |
|
|
828 | push @bgmusic, shift @bgmusic; |
|
|
829 | } |
|
|
830 | |
473 | sub audio_init { |
831 | sub audio_init { |
474 | if ($CFG->{sound} || 1) { |
832 | if ($CFG->{audio_enable}) { |
475 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
833 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
476 | $SDL_MIXER = new SDL::Mixer; |
834 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
477 | $SDL_MIXER->allocate_channels (8); |
835 | CFClient::Mix_AllocateChannels 8; |
|
|
836 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
478 | |
837 | |
479 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
838 | audio_music_finished; |
480 | $SDL_MIXER->play_music ($bgmusic, 0); |
|
|
481 | |
839 | |
482 | while (<$fh>) { |
840 | while (<$fh>) { |
483 | next if /^\s*#/; |
841 | next if /^\s*#/; |
484 | next if /^\s*$/; |
842 | next if /^\s*$/; |
485 | |
843 | |
486 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
844 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
487 | |
845 | |
488 | push @SOUNDS, "$volume,$file"; |
846 | push @SOUNDS, "$volume,$file"; |
489 | |
847 | |
490 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
848 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
491 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
849 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
492 | $chunk->volume ($volume * 128 / 100); |
850 | $chunk->volume ($volume * 128 / 100); |
493 | $chunk |
851 | $chunk |
494 | }; |
852 | }; |
495 | } |
853 | } |
496 | } else { |
854 | } else { |
… | |
… | |
498 | } |
856 | } |
499 | } |
857 | } |
500 | } |
858 | } |
501 | |
859 | |
502 | sub audio_shutdown { |
860 | sub audio_shutdown { |
|
|
861 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
503 | undef $SDL_MIXER; |
862 | undef $SDL_MIXER; |
504 | @SOUNDS = (); |
863 | @SOUNDS = (); |
505 | %AUDIO_CHUNKS = (); |
864 | %AUDIO_CHUNKS = (); |
506 | } |
865 | } |
507 | |
866 | |
… | |
… | |
520 | $want_refresh = 0; |
879 | $want_refresh = 0; |
521 | $can_refresh = 0; |
880 | $can_refresh = 0; |
522 | |
881 | |
523 | $CFClient::UI::ROOT->draw; |
882 | $CFClient::UI::ROOT->draw; |
524 | |
883 | |
525 | SDL::GLSwapBuffers; |
884 | CFClient::SDL_GL_SwapBuffers; |
526 | |
885 | |
527 | $LAST_REFRESH = $NOW; |
886 | $LAST_REFRESH = $NOW; |
528 | } |
887 | } |
529 | |
888 | |
530 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
889 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
531 | $NOW = time; |
890 | $NOW = time; |
532 | |
891 | |
533 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
892 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
534 | while $SDL_EV->poll; |
893 | for CFClient::SDL_PollEvent; |
535 | |
894 | |
536 | if (%animate_object) { |
895 | if (%animate_object) { |
537 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
896 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
538 | $want_refresh++; |
897 | $want_refresh++; |
539 | } |
898 | } |
… | |
… | |
562 | @conn::ISA = Crossfire::Protocol::; |
921 | @conn::ISA = Crossfire::Protocol::; |
563 | |
922 | |
564 | sub conn::stats_update { |
923 | sub conn::stats_update { |
565 | my ($self, $stats) = @_; |
924 | my ($self, $stats) = @_; |
566 | |
925 | |
567 | # i love text protocols!!! |
926 | update_stats_window ($stats); |
568 | # FIXME: the stats are somehow weird |
|
|
569 | my $hp = $stats->{1}; |
|
|
570 | my $hp_m = $stats->{2}; |
|
|
571 | my $sp = $stats->{3}; |
|
|
572 | my $sp_m = $stats->{4}; |
|
|
573 | my $fo = $stats->{18}; |
|
|
574 | my $fo_m = 1000; |
|
|
575 | my $gr = $stats->{23}; |
|
|
576 | my $gr_m = $stats->{24}; |
|
|
577 | |
|
|
578 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
|
|
579 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
|
|
580 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
|
|
581 | $GAUGES->{food}->set_value ($fo, $fo_m); |
|
|
582 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
583 | } |
927 | } |
584 | |
928 | |
585 | sub conn::user_send { |
929 | sub conn::user_send { |
586 | my ($self, $command) = @_; |
930 | my ($self, $command) = @_; |
587 | |
931 | |
… | |
… | |
612 | |
956 | |
613 | my ($hash, $x, $y, $w, $h) = @$map_info; |
957 | my ($hash, $x, $y, $w, $h) = @$map_info; |
614 | |
958 | |
615 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
959 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
616 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
960 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
617 | |
|
|
618 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
961 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
619 | |
|
|
620 | } |
962 | } |
621 | |
963 | |
622 | sub conn::map_clear { |
964 | sub conn::map_clear { |
623 | my ($self) = @_; |
965 | my ($self) = @_; |
624 | |
966 | |
625 | $self->flush_map; |
967 | $self->flush_map; |
626 | delete $self->{neigh}; |
968 | delete $self->{neigh_map}; |
627 | |
969 | |
628 | $MAP->clear; |
970 | $MAP->clear; |
629 | } |
971 | } |
630 | |
972 | |
631 | |
973 | |
632 | sub conn::load_map($$$) { |
974 | sub conn::load_map($$$) { |
633 | my ($self, $hash, $x, $y) = @_; |
975 | my ($self, $hash, $x, $y) = @_; |
634 | |
976 | |
635 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
977 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
636 | $data = Compress::LZF::decompress $data; |
978 | $data = Compress::LZF::decompress $data; |
637 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
979 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
638 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
980 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
639 | my $data = $TILECACHE->get ($id) |
981 | my $data = $TILECACHE->get ($id) |
640 | or next; |
982 | or next; |
641 | |
983 | |
642 | $self->set_texture ($id => $data); |
984 | $self->set_texture ($id => $data); |
643 | } |
985 | } |
644 | } |
986 | } |
645 | } |
987 | } |
646 | |
988 | |
|
|
989 | # this method does a "flood fill" into every tile direction |
|
|
990 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
991 | # i.e. a map is the same as the left of the right map etc. |
|
|
992 | # failure to comply are harmless and result in display errors |
|
|
993 | # at worst. |
647 | sub conn::flood_fill { |
994 | sub conn::flood_fill { |
648 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
995 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
649 | |
996 | |
650 | # the server does not allow map paths > 6 |
997 | # the server does not allow map paths > 6 |
651 | return if 6 <= length $path; |
998 | return if 6 <= length $path; |
652 | |
999 | |
653 | for my $tile (1..4) { |
1000 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
654 | next if $self->{neigh}{$hash}[$tile]; |
1001 | |
|
|
1002 | for ( |
|
|
1003 | [1, 0, -1], |
|
|
1004 | [2, 1, 0], |
|
|
1005 | [3, 0, 1], |
|
|
1006 | [4, -1, 0], |
|
|
1007 | ) { |
|
|
1008 | my ($tile, $dx, $dy) = @$_; |
|
|
1009 | |
|
|
1010 | my $gx = $gx + $dx; |
|
|
1011 | my $gy = $gy + $dy; |
|
|
1012 | |
655 | next unless $flags & (1 << ($tile - 1)); |
1013 | next unless $flags & (1 << ($tile - 1)); |
|
|
1014 | next if $self->{neigh_grid}{$gx, $gy}++; |
656 | |
1015 | |
657 | my $neigh = $self->{neigh}{$hash} ||= []; |
1016 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
658 | |
1017 | if (my $info = $neigh->[$tile]) { |
659 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
660 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
1018 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
661 | |
1019 | |
662 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
663 | return if $mode ne "spatial"; |
|
|
664 | |
|
|
665 | $x += $MAP->ox; |
|
|
666 | $y += $MAP->oy; |
|
|
667 | |
|
|
668 | $self->load_map ($hash, $x, $y) |
|
|
669 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
670 | |
|
|
671 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
672 | |
|
|
673 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
1020 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
674 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
1021 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
1022 | |
|
|
1023 | } else { |
|
|
1024 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
1025 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
1026 | |
|
|
1027 | return if $mode ne "spatial"; |
|
|
1028 | |
|
|
1029 | $x += $MAP->ox; |
|
|
1030 | $y += $MAP->oy; |
|
|
1031 | |
|
|
1032 | $self->load_map ($hash, $x, $y) |
|
|
1033 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
1034 | |
|
|
1035 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
1036 | |
|
|
1037 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
1038 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
1039 | }); |
675 | }); |
1040 | } |
676 | } |
1041 | } |
677 | } |
1042 | } |
678 | |
1043 | |
679 | sub conn::map_change { |
1044 | sub conn::map_change { |
680 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
1045 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
683 | |
1048 | |
684 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
1049 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
685 | |
1050 | |
686 | my $mapmapw = 250; |
1051 | my $mapmapw = 250; |
687 | my $mapmaph = 250; |
1052 | my $mapmaph = 250; |
|
|
1053 | |
|
|
1054 | $self->{neigh_rect} = [ |
|
|
1055 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
1056 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
1057 | ]; |
688 | |
1058 | |
|
|
1059 | delete $self->{neigh_grid}; |
689 | $self->flood_fill ("", $hash, $flags, |
1060 | $self->flood_fill (0, 0, "", $hash, $flags); |
690 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
691 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
692 | |
1061 | |
693 | $x += $ox; |
1062 | $x += $ox; |
694 | $y += $oy; |
1063 | $y += $oy; |
695 | |
1064 | |
696 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
1065 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
1066 | |
|
|
1067 | my $map = $self->{map_info}[0]; |
|
|
1068 | $map =~ s/^.*?\/([^\/]+)$/\1/; |
|
|
1069 | $STATWIDS->{map}->set_text ("Map: " . $map); |
697 | |
1070 | |
698 | $self->load_map ($hash, $x, $y); |
1071 | $self->load_map ($hash, $x, $y); |
699 | } |
1072 | } |
700 | |
1073 | |
701 | sub conn::face_find { |
1074 | sub conn::face_find { |
… | |
… | |
727 | } |
1100 | } |
728 | |
1101 | |
729 | gotid: |
1102 | gotid: |
730 | $face->{id} = $id; |
1103 | $face->{id} = $id; |
731 | $MAP->set_face ($facenum => $id); |
1104 | $MAP->set_face ($facenum => $id); |
|
|
1105 | $self->{faceid}[$facenum] = $id;#d# |
732 | $TILECACHE->get ($id) |
1106 | $TILECACHE->get ($id) |
733 | } |
1107 | } |
734 | |
1108 | |
735 | sub conn::face_update { |
1109 | sub conn::face_update { |
736 | my ($self, $facenum, $face) = @_; |
1110 | my ($self, $facenum, $face) = @_; |
… | |
… | |
744 | my ($self, $id, $data) = @_; |
1118 | my ($self, $id, $data) = @_; |
745 | |
1119 | |
746 | $self->{texture}[$id] ||= do { |
1120 | $self->{texture}[$id] ||= do { |
747 | my $tex = |
1121 | my $tex = |
748 | new_from_image CFClient::Texture |
1122 | new_from_image CFClient::Texture |
749 | $data, minify => 1; |
1123 | $data, minify => 1, mipmap => 1; |
750 | |
1124 | |
751 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
1125 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
752 | $MAPWIDGET->update; |
1126 | $MAPWIDGET->update; |
753 | |
1127 | |
754 | $tex |
1128 | $tex |
… | |
… | |
756 | } |
1130 | } |
757 | |
1131 | |
758 | sub conn::sound_play { |
1132 | sub conn::sound_play { |
759 | my ($self, $x, $y, $soundnum, $type) = @_; |
1133 | my ($self, $x, $y, $soundnum, $type) = @_; |
760 | |
1134 | |
|
|
1135 | $SDL_MIXER |
|
|
1136 | or return; |
|
|
1137 | |
761 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
1138 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
762 | or return; |
1139 | or return; |
763 | |
1140 | |
764 | $SDL_MIXER->play_channel (-1, $chunk); |
1141 | $chunk->play; |
765 | warn "sound $x,$y,$soundnum,$type\n";#d# |
1142 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
766 | } |
1143 | } |
|
|
1144 | |
|
|
1145 | my $LAST_QUERY; # server is stupid, stupid, stupid |
767 | |
1146 | |
768 | sub conn::query { |
1147 | sub conn::query { |
769 | my ($self, $flags, $prompt) = @_; |
1148 | my ($self, $flags, $prompt) = @_; |
770 | |
1149 | |
771 | #TODO |
1150 | $prompt = $LAST_QUERY unless length $prompt; |
772 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
1151 | $LAST_QUERY = $prompt; |
|
|
1152 | |
|
|
1153 | my $dialog = new CFClient::UI::FancyFrame |
|
|
1154 | title => "Query", |
|
|
1155 | child => my $vbox = new CFClient::UI::VBox; |
|
|
1156 | |
|
|
1157 | $vbox->add (new CFClient::UI::Label |
|
|
1158 | max_w => $::WIDTH * 0.4, |
|
|
1159 | text => $prompt); |
|
|
1160 | |
|
|
1161 | if ($flags & Crossfire::Protocol::CS_QUERY_YESNO) { |
|
|
1162 | $vbox->add (my $hbox = new CFClient::HBox); |
|
|
1163 | $hbox->add (new CFClient::Button |
|
|
1164 | text => "No", |
|
|
1165 | connect_activate => sub { |
|
|
1166 | $self->send ("reply n"); |
|
|
1167 | $dialog->destroy; |
|
|
1168 | $MAPWIDGET->focus_in; |
|
|
1169 | } |
|
|
1170 | ); |
|
|
1171 | $hbox->add (new CFClient::Button |
|
|
1172 | text => "Yes", |
|
|
1173 | connect_activate => sub { |
|
|
1174 | $self->send ("reply y"); |
|
|
1175 | $dialog->destroy; |
|
|
1176 | $MAPWIDGET->focus_in; |
|
|
1177 | }, |
|
|
1178 | ); |
|
|
1179 | |
|
|
1180 | $dialog->focus_in; |
|
|
1181 | |
|
|
1182 | } elsif ($flags & Crossfire::Protocol::CS_QUERY_SINGLECHAR) { |
|
|
1183 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
|
|
1184 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
1185 | connect_changed => sub { |
|
|
1186 | $self->send ("reply $_[1]"); |
|
|
1187 | $dialog->destroy; |
|
|
1188 | $MAPWIDGET->focus_in; |
|
|
1189 | }, |
|
|
1190 | ); |
|
|
1191 | |
|
|
1192 | $entry->focus_in; |
|
|
1193 | |
|
|
1194 | } else { |
|
|
1195 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
|
|
1196 | |
|
|
1197 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
1198 | $flags & Crossfire::Protocol::CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
|
|
1199 | connect_activate => sub { |
|
|
1200 | $self->send ("reply $_[1]"); |
|
|
1201 | $dialog->destroy; |
|
|
1202 | $MAPWIDGET->focus_in; |
|
|
1203 | }, |
|
|
1204 | ); |
|
|
1205 | |
|
|
1206 | $entry->focus_in; |
|
|
1207 | } |
|
|
1208 | |
|
|
1209 | $dialog->show; |
773 | } |
1210 | } |
774 | |
1211 | |
775 | sub conn::drawinfo { |
1212 | sub conn::drawinfo { |
776 | my ($self, $color, $text) = @_; |
1213 | my ($self, $color, $text) = @_; |
777 | |
1214 | |
… | |
… | |
792 | ); |
1229 | ); |
793 | |
1230 | |
794 | $LOGVIEW->add_paragraph ($color[$color], $text); |
1231 | $LOGVIEW->add_paragraph ($color[$color], $text); |
795 | } |
1232 | } |
796 | |
1233 | |
|
|
1234 | sub conn::spell_add { |
|
|
1235 | my ($self, $spell) = @_; |
|
|
1236 | |
|
|
1237 | # TODO |
|
|
1238 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
|
|
1239 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}); |
|
|
1240 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}); |
|
|
1241 | } |
|
|
1242 | |
|
|
1243 | sub conn::spell_delete { |
|
|
1244 | my ($self, $spell) = @_; |
|
|
1245 | } |
|
|
1246 | |
|
|
1247 | sub conn::addme_success { |
|
|
1248 | my ($self) = @_; |
|
|
1249 | |
|
|
1250 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1251 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
|
|
1252 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
|
|
1253 | } |
|
|
1254 | } |
|
|
1255 | |
|
|
1256 | sub update_floorbox { |
|
|
1257 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
|
|
1258 | $FLOORBOX->clear; |
|
|
1259 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
|
|
1260 | |
|
|
1261 | my @items = values %{ $CONN->{container}{0} }; |
|
|
1262 | |
|
|
1263 | # we basically have to use the same sorting as everybody else |
|
|
1264 | @items = sort { $a->{type} <=> $b->{type} } @items; |
|
|
1265 | |
|
|
1266 | for my $item (reverse @items) { |
|
|
1267 | my $desc = $item->{nrof} < 2 |
|
|
1268 | ? $item->{name} |
|
|
1269 | : "$item->{nrof} $item->{name_pl}"; |
|
|
1270 | # todo: animation widget, face widget, weight(?) etc. |
|
|
1271 | $FLOORBOX->add (my $hbox = new CFClient::UI::HBox |
|
|
1272 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
1273 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
1274 | can_hover => 1, |
|
|
1275 | can_events => 1, |
|
|
1276 | ); |
|
|
1277 | |
|
|
1278 | $hbox->add (new CFClient::UI::Face |
|
|
1279 | face => $item->{face}, |
|
|
1280 | anim => $item->{anim}, |
|
|
1281 | animspeed => $item->{animspeed}, |
|
|
1282 | ); |
|
|
1283 | |
|
|
1284 | $hbox->add (new CFClient::UI::Label |
|
|
1285 | text => $desc, |
|
|
1286 | ); |
|
|
1287 | } |
|
|
1288 | }); |
|
|
1289 | refresh; |
|
|
1290 | } |
|
|
1291 | |
|
|
1292 | sub conn::container_add { |
|
|
1293 | my ($self, $id, $items) = @_; |
|
|
1294 | |
|
|
1295 | update_floorbox if $id == 0; |
|
|
1296 | # $self-<{player}{tag} => player inv |
|
|
1297 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
|
|
1298 | } |
|
|
1299 | |
|
|
1300 | sub conn::container_clear { |
|
|
1301 | my ($self, $id) = @_; |
|
|
1302 | |
|
|
1303 | update_floorbox if $id == 0; |
|
|
1304 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
|
|
1305 | } |
|
|
1306 | |
|
|
1307 | sub conn::item_delete { |
|
|
1308 | my ($self, @items) = @_; |
|
|
1309 | |
|
|
1310 | for (@items) { |
|
|
1311 | update_floorbox if $_->{container} == 0; |
|
|
1312 | } |
|
|
1313 | } |
|
|
1314 | |
|
|
1315 | sub conn::item_update { |
|
|
1316 | my ($self, $item) = @_; |
|
|
1317 | |
|
|
1318 | update_floorbox if $item->{container} == 0; |
|
|
1319 | } |
|
|
1320 | |
797 | %SDL_CB = ( |
1321 | %SDL_CB = ( |
798 | SDL_QUIT() => sub { |
1322 | CFClient::SDL_QUIT => sub { |
799 | Event::unloop -1; |
1323 | Event::unloop -1; |
800 | }, |
1324 | }, |
801 | SDL_VIDEORESIZE() => sub { |
1325 | CFClient::SDL_VIDEORESIZE => sub { |
802 | }, |
1326 | }, |
803 | SDL_VIDEOEXPOSE() => sub { |
1327 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
804 | refresh; |
1328 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
1329 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
805 | }, |
1330 | }, |
806 | SDL_KEYDOWN() => sub { |
1331 | CFClient::SDL_KEYDOWN => sub { |
807 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
1332 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
808 | # alt-enter |
1333 | # alt-enter |
809 | video_shutdown; |
1334 | video_shutdown; |
810 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
1335 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
811 | video_init; |
1336 | video_init; |
812 | } else { |
1337 | } else { |
813 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
1338 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
814 | } |
1339 | } |
815 | }, |
1340 | }, |
816 | SDL_KEYUP() => sub { |
1341 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
817 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
1342 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
818 | }, |
1343 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
819 | SDL_MOUSEMOTION() => sub { |
1344 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
820 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
1345 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
821 | }, |
|
|
822 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
823 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
824 | }, |
|
|
825 | SDL_MOUSEBUTTONUP() => sub { |
|
|
826 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
827 | }, |
|
|
828 | SDL_ACTIVEEVENT() => sub { |
|
|
829 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
830 | }, |
|
|
831 | ); |
1346 | ); |
832 | |
1347 | |
833 | ############################################################################# |
1348 | ############################################################################# |
834 | |
1349 | |
835 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
1350 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
… | |
… | |
843 | sdl_mode => 0, |
1358 | sdl_mode => 0, |
844 | width => 640, |
1359 | width => 640, |
845 | height => 480, |
1360 | height => 480, |
846 | fullscreen => 0, |
1361 | fullscreen => 0, |
847 | fast => 0, |
1362 | fast => 0, |
|
|
1363 | map_scale => 0.5, |
848 | fow_enable => 1, |
1364 | fow_enable => 1, |
849 | fow_intensity => 0.45, |
1365 | fow_intensity => 0.45, |
850 | fow_smooth => 0, |
1366 | fow_smooth => 0, |
|
|
1367 | gui_fontsize => 1, |
851 | log_fontsize => 14, |
1368 | log_fontsize => 1, |
|
|
1369 | gauge_fontsize => 1, |
|
|
1370 | gauge_size => 0.35, |
|
|
1371 | stat_fontsize => 1, |
852 | mapsize => 100, |
1372 | mapsize => 100, |
853 | host => "crossfire.schmorp.de", |
1373 | host => "crossfire.schmorp.de", |
854 | say_command => 'say', |
1374 | say_command => 'say', |
|
|
1375 | audio_enable => 1, |
|
|
1376 | bgm_enable => 1, |
|
|
1377 | bgm_volume => 0.25, |
855 | ); |
1378 | ); |
856 | |
1379 | |
857 | while (my ($k, $v) = each %DEF_CFG) { |
1380 | while (my ($k, $v) = each %DEF_CFG) { |
858 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
1381 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
859 | } |
1382 | } |
860 | |
1383 | |
861 | sdl_init; |
1384 | sdl_init; |
862 | |
1385 | |
863 | @SDL_MODES = reverse |
1386 | @SDL_MODES = reverse |
864 | grep $_->[0] >= 640 && $_->[1] >= 480, |
1387 | grep $_->[0] >= 640 && $_->[1] >= 480, |
865 | map [SDL::RectW ($_), SDL::RectH ($_)], |
1388 | CFClient::SDL_ListModes; |
866 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
867 | |
1389 | |
868 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
1390 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
869 | |
1391 | |
870 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
1392 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
871 | |
1393 | |
872 | { |
1394 | { |
873 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
1395 | my @fonts = map CFClient::find_rcfile "fonts/$_", qw( |
|
|
1396 | DejaVuSans.ttf |
|
|
1397 | DejaVuSansMono.ttf |
|
|
1398 | DejaVuSans-Bold.ttf |
|
|
1399 | DejaVuSansMono-Bold.ttf |
|
|
1400 | DejaVuSans-Oblique.ttf |
|
|
1401 | DejaVuSansMono-Oblique.ttf |
|
|
1402 | DejaVuSans-BoldOblique.ttf |
|
|
1403 | DejaVuSansMono-BoldOblique.ttf |
|
|
1404 | ); |
874 | |
1405 | |
875 | CFClient::add_font $_ for @fonts; |
1406 | CFClient::add_font $_ for @fonts; |
876 | CFClient::set_font $fonts[0]; |
1407 | |
|
|
1408 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
|
|
1409 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
|
|
1410 | |
|
|
1411 | $FONT_PROP->make_default; |
877 | } |
1412 | } |
878 | |
1413 | |
879 | video_init; |
1414 | video_init; |
880 | audio_init; |
1415 | audio_init; |
881 | |
1416 | |
882 | Event::loop; |
1417 | Event::loop; |
883 | |
1418 | |
884 | END { SDL::Quit } |
1419 | END { CFClient::SDL_Quit } |
885 | |
1420 | |
886 | |
1421 | |