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