… | |
… | |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Time::HiRes 'time'; |
6 | use Time::HiRes 'time'; |
7 | use Event; |
7 | use Event; |
8 | |
8 | |
9 | use SDL; |
|
|
10 | use SDL::App; |
|
|
11 | use SDL::Event; |
|
|
12 | use SDL::Surface; |
|
|
13 | use SDL::OpenGL; |
|
|
14 | |
|
|
15 | use Crossfire; |
9 | use Crossfire; |
16 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
17 | |
11 | |
|
|
12 | use Compress::LZF; |
|
|
13 | |
18 | use CFClient; |
14 | use CFClient; |
19 | use CFClient::UI; |
15 | use CFClient::UI; |
|
|
16 | use CFClient::MapWidget; |
20 | |
17 | |
21 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
22 | |
19 | |
23 | my $MAX_FPS = 60; |
20 | my $MAX_FPS = 60; |
24 | my $MIN_FPS = 5; # unused as of yet |
21 | my $MIN_FPS = 5; # unused as of yet |
25 | |
22 | |
|
|
23 | our $META_SERVER = "crossfire.real-time.com:13326"; |
|
|
24 | |
|
|
25 | our $FACEMAP; |
|
|
26 | our $TILECACHE; |
26 | our $FACECACHE; |
27 | our $MAPCACHE; |
27 | |
28 | |
28 | our $LAST_REFRESH; |
29 | our $LAST_REFRESH; |
29 | our $NOW; |
30 | our $NOW; |
30 | |
31 | |
31 | our $CFG; |
32 | our $CFG; |
… | |
… | |
36 | our $WIDTH; |
37 | our $WIDTH; |
37 | our $HEIGHT; |
38 | our $HEIGHT; |
38 | our $FULLSCREEN; |
39 | our $FULLSCREEN; |
39 | our $FONTSIZE; |
40 | our $FONTSIZE; |
40 | |
41 | |
|
|
42 | our $FONT_PROP; |
|
|
43 | our $FONT_FIXED; |
|
|
44 | |
41 | our $MAP; |
45 | our $MAP; |
42 | our $MAPWIDGET; |
46 | our $MAPWIDGET; |
|
|
47 | our $BUTTONBAR; |
|
|
48 | our $LOGVIEW; |
|
|
49 | our $CONSOLE; |
|
|
50 | our $METASERVER; |
|
|
51 | |
|
|
52 | our $GAUGES; |
|
|
53 | our $STATWIDS; |
43 | |
54 | |
44 | our $SDL_ACTIVE; |
55 | our $SDL_ACTIVE; |
45 | our $SDL_EV; |
|
|
46 | our %SDL_CB; |
56 | our %SDL_CB; |
|
|
57 | |
|
|
58 | our $SDL_MIXER; |
|
|
59 | our @SOUNDS; # event => file mapping |
|
|
60 | our %AUDIO_CHUNKS; # audio files |
47 | |
61 | |
48 | our $ALT_ENTER_MESSAGE; |
62 | our $ALT_ENTER_MESSAGE; |
49 | our $STATUS_LINE; |
63 | our $STATUS_LINE; |
50 | our $DEBUG_STATUS; |
64 | our $DEBUG_STATUS; |
51 | our $BUTTONBAR; |
|
|
52 | our $LOGVIEW; |
|
|
53 | |
65 | |
54 | sub status { |
66 | sub status { |
55 | $STATUS_LINE->set_text ($_[0]); |
67 | $STATUS_LINE->set_text ($_[0]); |
56 | my ($w, $h) = $STATUS_LINE->size_request; |
|
|
57 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
68 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
58 | } |
69 | } |
59 | |
70 | |
60 | sub debug { |
71 | sub debug { |
61 | $DEBUG_STATUS->set_text ($_[0]); |
72 | $DEBUG_STATUS->set_text ($_[0]); |
62 | my ($w, $h) = $DEBUG_STATUS->size_request; |
73 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
63 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
64 | } |
74 | } |
65 | |
75 | |
66 | sub start_game { |
76 | sub start_game { |
67 | status "logging in..."; |
77 | status "logging in..."; |
68 | |
78 | |
69 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
79 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
80 | |
|
|
81 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
70 | |
82 | |
71 | $MAP = new CFClient::Map $mapsize, $mapsize; |
83 | $MAP = new CFClient::Map $mapsize, $mapsize; |
|
|
84 | |
|
|
85 | my ($host, $port) = split /:/, $CFG->{host}; |
72 | |
86 | |
73 | $CONN = new conn |
87 | $CONN = new conn |
74 | host => $CFG->{host}, |
88 | host => $host, |
75 | port => $CFG->{port}, |
89 | port => $port || 13327, |
76 | user => $CFG->{user}, |
90 | user => $CFG->{user}, |
77 | pass => $CFG->{password}, |
91 | pass => $CFG->{password}, |
78 | mapw => $mapsize, |
92 | mapw => $mapsize, |
79 | maph => $mapsize, |
93 | maph => $mapsize, |
80 | ; |
94 | ; |
… | |
… | |
86 | |
100 | |
87 | sub stop_game { |
101 | sub stop_game { |
88 | undef $CONN; |
102 | undef $CONN; |
89 | } |
103 | } |
90 | |
104 | |
91 | sub config_dialog { |
105 | sub client_setup { |
92 | my $dialog = new CFClient::UI::FancyFrame |
106 | my $dialog = new CFClient::UI::FancyFrame |
|
|
107 | title => "Client Setup", |
93 | child => (my $vbox = new CFClient::UI::VBox); |
108 | child => (my $vbox = new CFClient::UI::VBox); |
94 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
|
|
95 | $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]); |
96 | |
110 | |
97 | $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"); |
98 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
112 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
99 | |
113 | |
100 | $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]); |
101 | $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"); |
102 | |
116 | |
103 | $mode_slider->connect (changed => sub { |
117 | $mode_slider->connect (changed => sub { |
104 | my ($self, $value) = @_; |
118 | my ($self, $value) = @_; |
105 | |
119 | |
106 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
120 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
107 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
121 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
108 | }); |
122 | }); |
109 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
123 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
110 | |
124 | |
|
|
125 | my $row = 1; |
|
|
126 | |
111 | $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"); |
112 | $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 { |
113 | my ($self, $value) = @_; |
132 | my ($self, $value) = @_; |
114 | $CFG->{fullscreen} = $value; |
133 | $CFG->{fullscreen} = $value; |
|
|
134 | } |
|
|
135 | ); |
|
|
136 | |
|
|
137 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
|
|
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 { |
|
|
142 | my ($self, $value) = @_; |
|
|
143 | $CFG->{fast} = $value; |
|
|
144 | } |
|
|
145 | ); |
|
|
146 | |
|
|
147 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale"); |
|
|
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 { |
|
|
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) = @_; |
|
|
163 | $CFG->{fow_enable} = $value; |
|
|
164 | } |
|
|
165 | ); |
|
|
166 | |
|
|
167 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
|
|
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 { |
|
|
172 | my ($self, $value) = @_; |
|
|
173 | $CFG->{fow_intensity} = $value; |
|
|
174 | } |
|
|
175 | ); |
|
|
176 | |
|
|
177 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
|
|
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 { |
|
|
182 | my ($self, $value) = @_; |
|
|
183 | $CFG->{fow_smooth} = $value; |
|
|
184 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
|
|
185 | } |
|
|
186 | ); |
|
|
187 | |
|
|
188 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
|
|
189 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
190 | range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1], |
|
|
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 | } |
|
|
196 | ); |
|
|
197 | |
|
|
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 { |
|
|
244 | video_shutdown (); |
|
|
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]; |
|
|
260 | # }); |
|
|
261 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
262 | $table->add (1, $row++, my $hbox = new CFClient::UI::HBox); |
|
|
263 | $hbox->add (new CFClient::UI::CheckBox |
|
|
264 | expand => 1, state => $CFG->{bgm_enable}, |
|
|
265 | tooltip => "Enable background music playing", |
|
|
266 | connect_changed => sub { |
|
|
267 | $CFG->{bgm_enable} = $_[1]; |
|
|
268 | } |
|
|
269 | ); |
|
|
270 | $hbox->add (new CFClient::UI::Slider |
|
|
271 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], |
|
|
272 | tooltip => "The volume of the background music", |
|
|
273 | connect_changed => sub { |
|
|
274 | $CFG->{bgm_volume} = $_[1]; |
|
|
275 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
276 | } |
|
|
277 | ); |
|
|
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 { |
|
|
283 | audio_shutdown (); |
|
|
284 | audio_init (); |
|
|
285 | } |
|
|
286 | ); |
|
|
287 | |
|
|
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 $hbg = new CFClient::UI::HBox expand => 1); |
|
|
316 | |
|
|
317 | $hbg->add (new CFClient::UI::Empty expand => 1); |
|
|
318 | $hbg->add (my $hb = new CFClient::UI::HBox); |
|
|
319 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', tooltip => "Health points"); |
|
|
320 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', tooltip => "Spellpoints"); |
|
|
321 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', tooltip => "Grace"); |
|
|
322 | $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', tooltip => "Food"); |
|
|
323 | |
|
|
324 | $vb->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, text => "XP: 0 LVL: 0"); |
|
|
325 | $vb->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, text => "Rng:"); |
|
|
326 | |
|
|
327 | $GAUGES = { |
|
|
328 | exp => $exp, win => $win, range => $rng, |
|
|
329 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
|
|
330 | }; |
|
|
331 | |
|
|
332 | &set_gauge_window_fontsize; |
|
|
333 | |
|
|
334 | $win |
|
|
335 | } |
|
|
336 | |
|
|
337 | sub make_stats_window { |
|
|
338 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
|
|
339 | |
|
|
340 | $tgw->add (my $vb = new CFClient::UI::VBox); |
|
|
341 | $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); |
|
|
342 | $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); |
|
|
343 | |
|
|
344 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
|
|
345 | |
|
|
346 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
|
|
347 | |
|
|
348 | $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
349 | $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
350 | $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
351 | $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
352 | $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
353 | $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
354 | $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
355 | |
|
|
356 | $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Str"); |
|
|
357 | $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dex"); |
|
|
358 | $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Con"); |
|
|
359 | $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Int"); |
|
|
360 | $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wis"); |
|
|
361 | $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Pow"); |
|
|
362 | $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Cha"); |
|
|
363 | |
|
|
364 | $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
365 | $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
366 | $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
367 | $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
368 | $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54"); |
|
|
369 | $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9"); |
|
|
370 | |
|
|
371 | $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc"); |
|
|
372 | $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac"); |
|
|
373 | $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam"); |
|
|
374 | $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm"); |
|
|
375 | $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp"); |
|
|
376 | $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp"); |
|
|
377 | |
|
|
378 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
|
|
379 | |
|
|
380 | my $row = 0; |
|
|
381 | my $col = 0; |
|
|
382 | |
|
|
383 | my %resist_names = ( |
|
|
384 | slow => "Slow", |
|
|
385 | holyw => "Holy Word", |
|
|
386 | conf => "Confusion", |
|
|
387 | fire => "Fire", |
|
|
388 | depl => "Depletion", |
|
|
389 | magic => "Magic", |
|
|
390 | drain => "Draining", |
|
|
391 | acid => "Acid", |
|
|
392 | pois => "Poison", |
|
|
393 | para => "Paralysation", |
|
|
394 | deat => "Death", |
|
|
395 | phys => "Physical", |
|
|
396 | blind => "Blind", |
|
|
397 | fear => "Fear", |
|
|
398 | tund => "Turn undead", |
|
|
399 | elec => "Electricity", |
|
|
400 | cold => "Cold", |
|
|
401 | ghit => "Ghost hit", |
|
|
402 | ); |
|
|
403 | for (qw/slow holyw conf fire depl magic |
|
|
404 | drain acid pois para deat phys |
|
|
405 | blind fear tund elec cold ghit/) |
|
|
406 | { |
|
|
407 | $tbl2->add ($col, $row, |
|
|
408 | $STATWIDS->{"res_$_"} = |
|
|
409 | new CFClient::UI::Label |
|
|
410 | template => "-100%", |
|
|
411 | align => +1, |
|
|
412 | valign => 0, |
|
|
413 | tooltip => $resist_names{$_} |
|
|
414 | ); |
|
|
415 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image |
|
|
416 | can_hover => 1, |
|
|
417 | can_events => 1, |
|
|
418 | image => "ui/resist/resist_$_.png", |
|
|
419 | tooltip => $resist_names{$_} |
|
|
420 | ); |
|
|
421 | |
|
|
422 | $row++; |
|
|
423 | if ($row % 6 == 0) { |
|
|
424 | $col += 2; |
|
|
425 | $row = 0; |
|
|
426 | } |
|
|
427 | } |
|
|
428 | |
|
|
429 | &set_stats_window_fontsize; |
|
|
430 | update_stats_window ({}); |
|
|
431 | |
|
|
432 | $tgw |
|
|
433 | } |
|
|
434 | |
|
|
435 | sub formsep { |
|
|
436 | reverse join ",", grep length, split /(...)/, reverse $_[0] * 1 |
|
|
437 | } |
|
|
438 | |
|
|
439 | sub update_stats_window { |
|
|
440 | my ($stats) = @_; |
|
|
441 | |
|
|
442 | # i love text protocols!!! |
|
|
443 | my $hp = $stats->{Crossfire::Protocol::CS_STAT_HP} * 1; |
|
|
444 | my $hp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXHP} * 1; |
|
|
445 | my $sp = $stats->{Crossfire::Protocol::CS_STAT_SP} * 1; |
|
|
446 | my $sp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXSP} * 1; |
|
|
447 | my $fo = $stats->{Crossfire::Protocol::CS_STAT_FOOD} * 1; |
|
|
448 | my $fo_m = 999; |
|
|
449 | my $gr = $stats->{Crossfire::Protocol::CS_STAT_GRACE} * 1; |
|
|
450 | my $gr_m = $stats->{Crossfire::Protocol::CS_STAT_MAXGRACE} * 1; |
|
|
451 | |
|
|
452 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
453 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
454 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
455 | $GAUGES->{grace} ->set_value ($gr, $gr_m); |
|
|
456 | $GAUGES->{exp} ->set_text ("Exp: " . (formsep $stats->{Crossfire::Protocol::CS_STAT_EXP64}) |
|
|
457 | . " (lvl " . ($stats->{Crossfire::Protocol::CS_STAT_LEVEL} * 1) . ")"); |
|
|
458 | my $rng = $stats->{Crossfire::Protocol::CS_STAT_RANGE}; |
|
|
459 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
460 | $GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
461 | my $title = $stats->{Crossfire::Protocol::CS_STAT_TITLE}; |
|
|
462 | $title =~ s/^Player: //; |
|
|
463 | $STATWIDS->{title} ->set_text ("Title: " . $title); |
|
|
464 | |
|
|
465 | $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5}); |
|
|
466 | $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8}); |
|
|
467 | $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9}); |
|
|
468 | $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6}); |
|
|
469 | $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7}); |
|
|
470 | $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22}); |
|
|
471 | $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10}); |
|
|
472 | $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13}); |
|
|
473 | $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14}); |
|
|
474 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
|
|
475 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
|
|
476 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_SPEED}); |
|
|
477 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_WEAP_SP}); |
|
|
478 | |
|
|
479 | my %tbl = ( |
|
|
480 | phys => 100, |
|
|
481 | magic => 101, |
|
|
482 | fire => 102, |
|
|
483 | elec => 103, |
|
|
484 | cold => 104, |
|
|
485 | conf => 105, |
|
|
486 | acid => 106, |
|
|
487 | drain => 107, |
|
|
488 | ghit => 108, |
|
|
489 | pois => 109, |
|
|
490 | slow => 110, |
|
|
491 | para => 111, |
|
|
492 | tund => 112, |
|
|
493 | fear => 113, |
|
|
494 | depl => 113, |
|
|
495 | deat => 115, |
|
|
496 | holyw => 116, |
|
|
497 | blind => 117 |
|
|
498 | ); |
|
|
499 | |
|
|
500 | for (keys %tbl) { |
|
|
501 | $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}}); |
|
|
502 | } |
|
|
503 | |
|
|
504 | } |
|
|
505 | |
|
|
506 | sub metaserver_dialog { |
|
|
507 | my $dialog = new CFClient::UI::FancyFrame |
|
|
508 | title => "Metaserver", |
|
|
509 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
510 | |
|
|
511 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
|
|
512 | |
|
|
513 | $dialog |
|
|
514 | } |
|
|
515 | |
|
|
516 | sub update_metaserver { |
|
|
517 | my ($HOST) = @_; |
|
|
518 | |
|
|
519 | status "fetching metaserver list..."; |
|
|
520 | |
|
|
521 | my $buf; |
|
|
522 | |
|
|
523 | my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; |
|
|
524 | |
|
|
525 | Event->io (fd => $fh, poll => 'r', cb => sub { |
|
|
526 | my $res = sysread $fh, $buf, 8192, length $buf; |
|
|
527 | |
|
|
528 | if (!defined $res) { |
|
|
529 | $_[0]->w->cancel; |
|
|
530 | status "metaserver: $!"; |
|
|
531 | } elsif ($res == 0) { |
|
|
532 | $_[0]->w->cancel; |
|
|
533 | status "server list retrieved"; |
|
|
534 | |
|
|
535 | my $table = $METASERVER->{table}; |
|
|
536 | |
|
|
537 | $table->clear; |
|
|
538 | |
|
|
539 | my @col = qw(Use #Users Host Uptime Version Description); |
|
|
540 | $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) |
|
|
541 | for 0 .. $#col; |
|
|
542 | |
|
|
543 | my @align = qw(1 0 1 1 -1); |
|
|
544 | |
|
|
545 | my $y = 0; |
|
|
546 | for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { |
|
|
547 | my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; |
|
|
548 | |
|
|
549 | for ($desc) { |
|
|
550 | s/<br>/\n/gi; |
|
|
551 | s/<li>/\n· /gi; |
|
|
552 | s/<.*?>//sgi; |
|
|
553 | s/&/&/g; |
|
|
554 | s/</</g; |
|
|
555 | s/>/>/g; |
|
|
556 | } |
|
|
557 | |
|
|
558 | $uptime = sprintf "%dd %02d:%02d:%02d", |
|
|
559 | (int $m->[8] / 86400), |
|
|
560 | (int $m->[8] / 3600) % 24, |
|
|
561 | (int $m->[8] / 60) % 60, |
|
|
562 | $m->[8] % 60; |
|
|
563 | |
|
|
564 | $m = [$users, $host, $uptime, $version, $desc]; |
|
|
565 | |
|
|
566 | $y++; |
|
|
567 | |
|
|
568 | $table->add (0, $y, new CFClient::UI::VBox children => [ |
|
|
569 | (new CFClient::UI::Button text => " ", connect_activate => sub { |
|
|
570 | $HOST->set_text ($CFG->{host} = $host); |
|
|
571 | }), |
|
|
572 | (new CFClient::UI::Empty expand => 1), |
|
|
573 | ]); |
|
|
574 | |
|
|
575 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
|
|
576 | for 0 .. $#$m; |
|
|
577 | } |
|
|
578 | } |
115 | }); |
579 | }); |
|
|
580 | } |
116 | |
581 | |
117 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); |
582 | sub server_setup { |
118 | $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
583 | my $dialog = new CFClient::UI::FancyFrame |
119 | my ($self, $value) = @_; |
584 | title => "Server Setup", |
120 | $CFG->{fast} = $value; |
585 | child => (my $vbox = new CFClient::UI::VBox); |
121 | }); |
|
|
122 | |
|
|
123 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); |
|
|
124 | $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
|
|
125 | my ($self, $value) = @_; |
|
|
126 | $CFG->{fow_enable} = $value; |
|
|
127 | }); |
|
|
128 | |
|
|
129 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); |
|
|
130 | $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
|
|
131 | my ($self, $value) = @_; |
|
|
132 | $CFG->{fow_intensity} = $value; |
|
|
133 | }); |
|
|
134 | |
|
|
135 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); |
|
|
136 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
|
|
137 | my ($self, $value) = @_; |
|
|
138 | $CFG->{fow_smooth} = $value; |
|
|
139 | }); |
|
|
140 | |
|
|
141 | $table->add (1, 6, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
142 | destroy_screen (); |
|
|
143 | init_screen (); |
|
|
144 | }); |
|
|
145 | |
586 | |
146 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
|
|
147 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
587 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
148 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); |
588 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
149 | $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}); |
589 | |
150 | |
590 | { |
151 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); |
591 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
152 | $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}); |
|
|
153 | |
592 | |
|
|
593 | $vbox->add ( |
|
|
594 | my $HOST = new CFClient::UI::Entry |
|
|
595 | expand => 1, |
|
|
596 | text => $CFG->{host}, |
|
|
597 | tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", |
|
|
598 | connect_changed => sub { |
|
|
599 | my ($self, $value) = @_; |
|
|
600 | $CFG->{host} = $value; |
|
|
601 | } |
|
|
602 | ); |
|
|
603 | |
|
|
604 | $METASERVER = metaserver_dialog; |
|
|
605 | |
|
|
606 | $vbox->add (new CFClient::UI::Flopper |
|
|
607 | expand => 1, |
|
|
608 | text => "Metaserver", |
|
|
609 | other => $METASERVER, |
|
|
610 | tooltip => "Show a list of avaible crossfire servers", |
|
|
611 | connect_open => sub { |
|
|
612 | update_metaserver $HOST; |
|
|
613 | } |
|
|
614 | ); |
|
|
615 | } |
|
|
616 | |
154 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
617 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
155 | $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}); |
618 | $table->add (1, 4, new CFClient::UI::Entry |
|
|
619 | text => $CFG->{user}, |
|
|
620 | tooltip => "The name of your character on the server", |
|
|
621 | connect_changed => sub { |
|
|
622 | my ($self, $value) = @_; |
|
|
623 | $CFG->{user} = $value; |
|
|
624 | } |
|
|
625 | ); |
156 | |
626 | |
157 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); |
627 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
158 | $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); |
628 | $table->add (1, 5, new CFClient::UI::Entry |
|
|
629 | text => $CFG->{password}, |
|
|
630 | hidden => 1, |
|
|
631 | tooltip => "The password for your character", |
|
|
632 | connect_changed => sub { |
|
|
633 | my ($self, $value) = @_; |
|
|
634 | $CFG->{password} = $value; |
|
|
635 | } |
|
|
636 | ); |
159 | |
637 | |
|
|
638 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
|
|
639 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry |
|
|
640 | text => $CFG->{say_command}, |
|
|
641 | tooltip => "This is the command that will be used if you write a line in the message window entry. " |
|
|
642 | ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " |
|
|
643 | ."But you could also set it to 'tell <playername>' to only chat with that user.", |
|
|
644 | connect_changed => sub { |
|
|
645 | my ($self, $value) = @_; |
|
|
646 | $CFG->{say_command} = $value; |
|
|
647 | } |
|
|
648 | ); |
|
|
649 | |
160 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size"); |
650 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
161 | $table->add (1, 6, new CFClient::UI::Slider |
651 | $table->add (1, 7, new CFClient::UI::Slider |
162 | req_w => 100, |
652 | req_w => 100, |
163 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
653 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
654 | tooltip => "This is the size of the portion of the map update the server sends you. " |
|
|
655 | ."If you set this to a high value you will be able to see further for example.", |
164 | connect_changed => sub { |
656 | connect_changed => sub { |
165 | my ($self, $value) = @_; |
657 | my ($self, $value) = @_; |
166 | |
658 | |
167 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
659 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
168 | }, |
660 | }, |
169 | ); |
661 | ); |
170 | |
662 | |
171 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
663 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
172 | start_game; |
664 | start_game; |
173 | }); |
665 | }); |
174 | |
666 | |
|
|
667 | $dialog |
|
|
668 | } |
|
|
669 | |
|
|
670 | sub message_window { |
|
|
671 | my $window = new CFClient::UI::FancyFrame |
|
|
672 | title => "Messages", |
|
|
673 | border_bg => [1, 1, 1, 0.5], |
|
|
674 | bg => [0.3, 0.3, 0.3, 0.8], |
|
|
675 | user_w => int $::WIDTH / 3, |
|
|
676 | user_h => int $::HEIGHT / 5, |
|
|
677 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
678 | |
|
|
679 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
|
|
680 | expand => 1, |
|
|
681 | font => $FONT_FIXED, |
|
|
682 | fontsize => $::CFG->{log_fontsize}, |
|
|
683 | ); |
|
|
684 | |
175 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
685 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
686 | connect_focus_in => sub { |
|
|
687 | my ($input, $prev_focus) = @_; |
176 | |
688 | |
|
|
689 | delete $input->{refocus_map}; |
|
|
690 | |
|
|
691 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
692 | $input->{refocus_map} = 1; |
|
|
693 | } |
|
|
694 | delete $input->{auto_activated}; |
|
|
695 | }, |
|
|
696 | connect_activate => sub { |
|
|
697 | my ($input, $text) = @_; |
|
|
698 | $input->set_text (''); |
|
|
699 | |
|
|
700 | if ($text =~ /^\/(.*)/) { |
|
|
701 | $::CONN->user_send ($1); |
|
|
702 | } else { |
|
|
703 | my $say_cmd = $::CFG->{say_command} || 'say'; |
|
|
704 | $::CONN->user_send ("$say_cmd $text"); |
|
|
705 | } |
|
|
706 | if ($input->{refocus_map}) { |
|
|
707 | delete $input->{refocus_map}; |
|
|
708 | $MAPWIDGET->focus_in |
|
|
709 | } |
|
|
710 | }, |
|
|
711 | connect_escape => sub { |
|
|
712 | $MAPWIDGET->focus_in |
|
|
713 | }, |
|
|
714 | ); |
|
|
715 | |
|
|
716 | $CONSOLE = { |
|
|
717 | window => $window, |
|
|
718 | input => $input |
|
|
719 | }; |
|
|
720 | |
|
|
721 | $window |
|
|
722 | } |
|
|
723 | |
|
|
724 | sub sdl_init { |
|
|
725 | CFClient::SDL_Init |
|
|
726 | and die "SDL::Init failed!\n"; |
|
|
727 | } |
|
|
728 | |
|
|
729 | sub video_init { |
|
|
730 | sdl_init; |
|
|
731 | |
|
|
732 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
733 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
734 | $FAST = $CFG->{fast}; |
|
|
735 | |
|
|
736 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
|
|
737 | or die "SDL_SetVideoMode failed!\n"; |
|
|
738 | |
|
|
739 | $SDL_ACTIVE = 1; |
|
|
740 | |
|
|
741 | $LAST_REFRESH = time - 0.01; |
|
|
742 | |
|
|
743 | CFClient::gl_init; |
|
|
744 | |
|
|
745 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
746 | |
|
|
747 | ############################################################################# |
|
|
748 | |
|
|
749 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
|
|
750 | $DEBUG_STATUS->show; |
|
|
751 | |
|
|
752 | $STATUS_LINE = new CFClient::UI::Label |
|
|
753 | padding => 0, |
|
|
754 | y => $HEIGHT - $FONTSIZE * 1.8; |
|
|
755 | $STATUS_LINE->show; |
|
|
756 | |
|
|
757 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
758 | padding => 0, |
|
|
759 | fontsize => 0.8, |
|
|
760 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
761 | $ALT_ENTER_MESSAGE->show; |
|
|
762 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
|
|
763 | |
|
|
764 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
|
|
765 | $MAPWIDGET->focus_in; |
|
|
766 | $MAPWIDGET->connect (activate_console => sub { |
|
|
767 | my ($mapwidget, $preset) = @_; |
|
|
768 | |
|
|
769 | if ($CONSOLE) { |
|
|
770 | $CONSOLE->{input}->{auto_activated} = 1; |
|
|
771 | $CONSOLE->{input}->focus_in; |
|
|
772 | |
|
|
773 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
|
|
774 | $CONSOLE->{input}->set_text ($preset); |
|
|
775 | } |
|
|
776 | } |
|
|
777 | }); |
|
|
778 | |
|
|
779 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
|
|
780 | |
|
|
781 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
|
|
782 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
|
|
783 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
|
|
784 | |
|
|
785 | $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 |
|
|
786 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
|
|
787 | |
177 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
788 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
178 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
789 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
179 | status "Configuration Saved"; |
790 | status "Configuration Saved"; |
180 | }); |
791 | }); |
181 | |
792 | |
182 | $dialog |
793 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
183 | } |
794 | } |
184 | |
795 | |
185 | sub console_window { |
796 | sub video_shutdown { |
186 | my $window = new CFClient::UI::FancyFrame |
|
|
187 | border_bg => [1, 1, 1, 0.5], |
|
|
188 | bg => [0.3, 0.3, 0.3, 0.8], |
|
|
189 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
190 | |
|
|
191 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView expand => 1); |
|
|
192 | $vbox->add (my $input = new CFClient::UI::Entry); |
|
|
193 | |
|
|
194 | $window |
|
|
195 | } |
|
|
196 | |
|
|
197 | sub sdl_init { |
|
|
198 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
199 | and die "SDL::Init failed!\n"; |
|
|
200 | } |
|
|
201 | |
|
|
202 | sub init_screen { |
|
|
203 | sdl_init; |
|
|
204 | |
|
|
205 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
206 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
207 | $FAST = $CFG->{fast}; |
|
|
208 | |
|
|
209 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
|
|
210 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
211 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
212 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 0; |
|
|
213 | |
|
|
214 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
215 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
216 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
217 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
218 | |
|
|
219 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
220 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
221 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
222 | |
|
|
223 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
224 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
225 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
226 | or die "SDL::SetVideoMode failed!\n"; |
|
|
227 | |
|
|
228 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
229 | |
|
|
230 | $SDL_EV = new SDL::Event; |
|
|
231 | $SDL_EV->set_unicode (1); |
|
|
232 | |
|
|
233 | $SDL_ACTIVE = 1; |
|
|
234 | |
|
|
235 | $LAST_REFRESH = time - 0.01; |
|
|
236 | |
|
|
237 | CFClient::gl_init; |
|
|
238 | |
|
|
239 | $FONTSIZE = int $HEIGHT / 40; |
|
|
240 | |
|
|
241 | ############################################################################# |
|
|
242 | |
|
|
243 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
|
|
244 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
245 | |
|
|
246 | $STATUS_LINE = new CFClient::UI::Label |
|
|
247 | padding => 0, |
|
|
248 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
|
|
249 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
|
|
250 | |
|
|
251 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
252 | padding => 0, |
|
|
253 | y => $HEIGHT * 44 / 45, |
|
|
254 | height => $HEIGHT / 45, |
|
|
255 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
256 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
257 | |
|
|
258 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
|
|
259 | $MAPWIDGET->focus_in; |
|
|
260 | |
|
|
261 | $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox); |
|
|
262 | |
|
|
263 | $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1); |
|
|
264 | $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Console", other => console_window); |
|
|
265 | } |
|
|
266 | |
|
|
267 | sub destroy_screen { |
|
|
268 | $CFClient::UI::TOPLEVEL->{children} = []; |
797 | $CFClient::UI::ROOT->{children} = []; |
269 | undef $SDL_ACTIVE; |
798 | undef $SDL_ACTIVE; |
|
|
799 | } |
|
|
800 | |
|
|
801 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
|
|
802 | my $bgmusic;#TODO#hack#d# |
|
|
803 | |
|
|
804 | sub audio_music_finished { |
|
|
805 | return unless $CFG->{bgm_enable}; |
|
|
806 | |
|
|
807 | # TODO: hack, do play loop and mood music |
|
|
808 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
809 | $bgmusic->play (0); |
|
|
810 | |
|
|
811 | push @bgmusic, shift @bgmusic; |
|
|
812 | } |
|
|
813 | |
|
|
814 | sub audio_init { |
|
|
815 | if ($CFG->{audio_enable}) { |
|
|
816 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
817 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
|
|
818 | CFClient::Mix_AllocateChannels 8; |
|
|
819 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
|
|
820 | |
|
|
821 | audio_music_finished; |
|
|
822 | |
|
|
823 | while (<$fh>) { |
|
|
824 | next if /^\s*#/; |
|
|
825 | next if /^\s*$/; |
|
|
826 | |
|
|
827 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
828 | |
|
|
829 | push @SOUNDS, "$volume,$file"; |
|
|
830 | |
|
|
831 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
832 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
|
|
833 | $chunk->volume ($volume * 128 / 100); |
|
|
834 | $chunk |
|
|
835 | }; |
|
|
836 | } |
|
|
837 | } else { |
|
|
838 | status "unable to open sound config: $!"; |
|
|
839 | } |
|
|
840 | } |
|
|
841 | } |
|
|
842 | |
|
|
843 | sub audio_shutdown { |
|
|
844 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
270 | undef $SDL_EV; |
845 | undef $SDL_MIXER; |
271 | SDL::Quit; |
846 | @SOUNDS = (); |
|
|
847 | %AUDIO_CHUNKS = (); |
272 | } |
848 | } |
273 | |
849 | |
274 | my %animate_object; |
850 | my %animate_object; |
275 | my $animate_timer; |
851 | my $animate_timer; |
276 | |
852 | |
… | |
… | |
284 | debug sprintf "%3.2f", $fps; |
860 | debug sprintf "%3.2f", $fps; |
285 | |
861 | |
286 | $want_refresh = 0; |
862 | $want_refresh = 0; |
287 | $can_refresh = 0; |
863 | $can_refresh = 0; |
288 | |
864 | |
289 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
290 | |
|
|
291 | glMatrixMode GL_PROJECTION; |
|
|
292 | glLoadIdentity; |
|
|
293 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
|
|
294 | glMatrixMode GL_MODELVIEW; |
|
|
295 | glLoadIdentity; |
|
|
296 | |
|
|
297 | glClearColor +($CFG->{fow_intensity}) x 3, 1; |
|
|
298 | glClear GL_COLOR_BUFFER_BIT; |
|
|
299 | |
|
|
300 | $CFClient::UI::TOPLEVEL->draw; |
865 | $CFClient::UI::ROOT->draw; |
301 | |
866 | |
302 | SDL::GLSwapBuffers; |
867 | CFClient::SDL_GL_SwapBuffers; |
303 | |
868 | |
304 | $LAST_REFRESH = $NOW; |
869 | $LAST_REFRESH = $NOW; |
305 | } |
870 | } |
306 | |
871 | |
307 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
872 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
308 | $NOW = time; |
873 | $NOW = time; |
309 | |
874 | |
310 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
875 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
311 | while $SDL_EV->poll; |
876 | for CFClient::SDL_PollEvent; |
312 | |
877 | |
313 | if (%animate_object) { |
878 | if (%animate_object) { |
314 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
879 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
315 | $want_refresh++; |
880 | $want_refresh++; |
316 | } |
881 | } |
… | |
… | |
336 | delete $animate_object{$widget}; |
901 | delete $animate_object{$widget}; |
337 | } |
902 | } |
338 | |
903 | |
339 | @conn::ISA = Crossfire::Protocol::; |
904 | @conn::ISA = Crossfire::Protocol::; |
340 | |
905 | |
|
|
906 | sub conn::stats_update { |
|
|
907 | my ($self, $stats) = @_; |
|
|
908 | |
|
|
909 | update_stats_window ($stats); |
|
|
910 | } |
|
|
911 | |
341 | sub conn::user_send { |
912 | sub conn::user_send { |
342 | my ($self, $command) = @_; |
913 | my ($self, $command) = @_; |
343 | |
914 | |
344 | $self->send ($command); |
915 | $self->send_command ($command); |
345 | status $command; |
916 | status $command; |
|
|
917 | } |
|
|
918 | |
|
|
919 | sub conn::map_scroll { |
|
|
920 | my ($self, $dx, $dy) = @_; |
|
|
921 | |
|
|
922 | $MAP->scroll ($dx, $dy); |
346 | } |
923 | } |
347 | |
924 | |
348 | sub conn::feed_map1a { |
925 | sub conn::feed_map1a { |
349 | my ($self, $data) = @_; |
926 | my ($self, $data) = @_; |
350 | |
927 | |
351 | # $self->Crossfire::Protocol::feed_map1a ($data); |
928 | # $self->Crossfire::Protocol::feed_map1a ($data); |
352 | |
929 | |
353 | $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y}); |
|
|
354 | $MAP->map1a_update ($data); |
930 | $MAP->map1a_update ($data); |
355 | $MAPWIDGET->update; |
931 | $MAPWIDGET->update; |
356 | } |
932 | } |
357 | |
933 | |
358 | #sub conn::map_update { |
934 | sub conn::flush_map { |
359 | # my ($self, $dirty) = @_; |
935 | my ($self) = @_; |
360 | # |
936 | |
361 | # $MAPWIDGET->update; |
937 | my $map_info = delete $self->{map_info} |
362 | #} |
938 | or return; |
|
|
939 | |
|
|
940 | my ($hash, $x, $y, $w, $h) = @$map_info; |
|
|
941 | |
|
|
942 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
|
|
943 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
|
|
944 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
945 | } |
363 | |
946 | |
364 | sub conn::map_clear { |
947 | sub conn::map_clear { |
365 | my ($self) = @_; |
948 | my ($self) = @_; |
366 | |
949 | |
|
|
950 | $self->flush_map; |
|
|
951 | delete $self->{neigh_map}; |
|
|
952 | |
367 | $MAP->clear; |
953 | $MAP->clear; |
|
|
954 | } |
368 | |
955 | |
369 | # refresh; |
956 | |
|
|
957 | sub conn::load_map($$$) { |
|
|
958 | my ($self, $hash, $x, $y) = @_; |
|
|
959 | |
|
|
960 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
|
|
961 | $data = Compress::LZF::decompress $data; |
|
|
962 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
963 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
|
|
964 | my $data = $TILECACHE->get ($id) |
|
|
965 | or next; |
|
|
966 | |
|
|
967 | $self->set_texture ($id => $data); |
|
|
968 | } |
|
|
969 | } |
|
|
970 | } |
|
|
971 | |
|
|
972 | # this method does a "flood fill" into every tile direction |
|
|
973 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
974 | # i.e. a map is the same as the left of the right map etc. |
|
|
975 | # failure to comply are harmless and result in display errors |
|
|
976 | # at worst. |
|
|
977 | sub conn::flood_fill { |
|
|
978 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
|
|
979 | |
|
|
980 | # the server does not allow map paths > 6 |
|
|
981 | return if 6 <= length $path; |
|
|
982 | |
|
|
983 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
|
|
984 | |
|
|
985 | for ( |
|
|
986 | [1, 0, -1], |
|
|
987 | [2, 1, 0], |
|
|
988 | [3, 0, 1], |
|
|
989 | [4, -1, 0], |
|
|
990 | ) { |
|
|
991 | my ($tile, $dx, $dy) = @$_; |
|
|
992 | |
|
|
993 | my $gx = $gx + $dx; |
|
|
994 | my $gy = $gy + $dy; |
|
|
995 | |
|
|
996 | next unless $flags & (1 << ($tile - 1)); |
|
|
997 | next if $self->{neigh_grid}{$gx, $gy}++; |
|
|
998 | |
|
|
999 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
|
|
1000 | if (my $info = $neigh->[$tile]) { |
|
|
1001 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
|
|
1002 | |
|
|
1003 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
1004 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
1005 | |
|
|
1006 | } else { |
|
|
1007 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
1008 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
1009 | |
|
|
1010 | return if $mode ne "spatial"; |
|
|
1011 | |
|
|
1012 | $x += $MAP->ox; |
|
|
1013 | $y += $MAP->oy; |
|
|
1014 | |
|
|
1015 | $self->load_map ($hash, $x, $y) |
|
|
1016 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
1017 | |
|
|
1018 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
1019 | |
|
|
1020 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
1021 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
1022 | }); |
|
|
1023 | } |
|
|
1024 | } |
|
|
1025 | } |
|
|
1026 | |
|
|
1027 | sub conn::map_change { |
|
|
1028 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
1029 | |
|
|
1030 | $self->flush_map; |
|
|
1031 | |
|
|
1032 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
1033 | |
|
|
1034 | my $mapmapw = 250; |
|
|
1035 | my $mapmaph = 250; |
|
|
1036 | |
|
|
1037 | $self->{neigh_rect} = [ |
|
|
1038 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
1039 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
1040 | ]; |
|
|
1041 | |
|
|
1042 | delete $self->{neigh_grid}; |
|
|
1043 | $self->flood_fill (0, 0, "", $hash, $flags); |
|
|
1044 | |
|
|
1045 | $x += $ox; |
|
|
1046 | $y += $oy; |
|
|
1047 | |
|
|
1048 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
1049 | |
|
|
1050 | my $map = $self->{map_info}[0]; |
|
|
1051 | $map =~ s/^.*?\/([^\/]+)$/\1/; |
|
|
1052 | $STATWIDS->{map}->set_text ("Map: " . $map); |
|
|
1053 | |
|
|
1054 | $self->load_map ($hash, $x, $y); |
370 | } |
1055 | } |
371 | |
1056 | |
372 | sub conn::face_find { |
1057 | sub conn::face_find { |
373 | my ($self, $face) = @_; |
1058 | my ($self, $facenum, $face) = @_; |
374 | |
1059 | |
375 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
1060 | my $hash = "$face->{chksum},$face->{name}"; |
|
|
1061 | |
|
|
1062 | my $id = $FACEMAP->get ($hash); |
|
|
1063 | |
|
|
1064 | unless ($id) { |
|
|
1065 | # create new id for face |
|
|
1066 | # i love transactions |
|
|
1067 | for (1..100) { |
|
|
1068 | my $txn = $CFClient::DB_ENV->txn_begin; |
|
|
1069 | my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW); |
|
|
1070 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
|
|
1071 | $id++; |
|
|
1072 | if ($FACEMAP->put (id => $id) == 0 |
|
|
1073 | && $FACEMAP->put ($hash => $id) == 0) { |
|
|
1074 | $txn->txn_commit; |
|
|
1075 | |
|
|
1076 | goto gotid; |
|
|
1077 | } |
|
|
1078 | } |
|
|
1079 | $txn->abort; |
|
|
1080 | } |
|
|
1081 | |
|
|
1082 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
|
|
1083 | } |
|
|
1084 | |
|
|
1085 | gotid: |
|
|
1086 | $face->{id} = $id; |
|
|
1087 | $MAP->set_face ($facenum => $id); |
|
|
1088 | $TILECACHE->get ($id) |
376 | } |
1089 | } |
377 | |
1090 | |
378 | sub conn::face_update { |
1091 | sub conn::face_update { |
379 | my ($self, $facenum, $face) = @_; |
1092 | my ($self, $facenum, $face) = @_; |
380 | |
1093 | |
381 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
1094 | $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
382 | |
1095 | |
383 | my $tex = $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
1096 | $self->set_texture ($face->{id} => delete $face->{image}); |
|
|
1097 | } |
384 | |
1098 | |
|
|
1099 | sub conn::set_texture { |
|
|
1100 | my ($self, $id, $data) = @_; |
|
|
1101 | |
|
|
1102 | $self->{texture}[$id] ||= do { |
|
|
1103 | my $tex = |
|
|
1104 | new_from_image CFClient::Texture |
|
|
1105 | $data, minify => 1; |
|
|
1106 | |
385 | $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}); |
1107 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
386 | $MAPWIDGET->update; |
1108 | $MAPWIDGET->update; |
|
|
1109 | |
|
|
1110 | $tex |
|
|
1111 | }; |
387 | } |
1112 | } |
|
|
1113 | |
|
|
1114 | sub conn::sound_play { |
|
|
1115 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
1116 | |
|
|
1117 | $SDL_MIXER |
|
|
1118 | or return; |
|
|
1119 | |
|
|
1120 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
1121 | or return; |
|
|
1122 | |
|
|
1123 | $chunk->play; |
|
|
1124 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
|
|
1125 | } |
|
|
1126 | |
|
|
1127 | my $LAST_QUERY; # server is stupid, stupid, stupid |
388 | |
1128 | |
389 | sub conn::query { |
1129 | sub conn::query { |
390 | my ($self, $flags, $prompt) = @_; |
1130 | my ($self, $flags, $prompt) = @_; |
391 | |
1131 | |
392 | #TODO |
1132 | $prompt = $LAST_QUERY unless length $prompt; |
393 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
1133 | $LAST_QUERY = $prompt; |
|
|
1134 | |
|
|
1135 | my $dialog = new CFClient::UI::FancyFrame |
|
|
1136 | title => "Query", |
|
|
1137 | child => my $vbox = new CFClient::UI::VBox; |
|
|
1138 | |
|
|
1139 | $vbox->add (new CFClient::UI::Label |
|
|
1140 | max_w => $::WIDTH * 0.4, |
|
|
1141 | text => $prompt); |
|
|
1142 | |
|
|
1143 | if ($flags & Crossfire::Protocol::CS_QUERY_YESNO) { |
|
|
1144 | $vbox->add (my $hbox = new CFClient::HBox); |
|
|
1145 | $hbox->add (new CFClient::Button |
|
|
1146 | text => "No", |
|
|
1147 | connect_activate => sub { |
|
|
1148 | $self->send ("reply n"); |
|
|
1149 | $dialog->destroy; |
|
|
1150 | $MAPWIDGET->focus_in; |
|
|
1151 | } |
|
|
1152 | ); |
|
|
1153 | $hbox->add (new CFClient::Button |
|
|
1154 | text => "Yes", |
|
|
1155 | connect_activate => sub { |
|
|
1156 | $self->send ("reply y"); |
|
|
1157 | $dialog->destroy; |
|
|
1158 | $MAPWIDGET->focus_in; |
|
|
1159 | }, |
|
|
1160 | ); |
|
|
1161 | |
|
|
1162 | $dialog->focus_in; |
|
|
1163 | |
|
|
1164 | } elsif ($flags & Crossfire::Protocol::CS_QUERY_SINGLECHAR) { |
|
|
1165 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
|
|
1166 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
1167 | connect_changed => sub { |
|
|
1168 | $self->send ("reply $_[1]"); |
|
|
1169 | $dialog->destroy; |
|
|
1170 | $MAPWIDGET->focus_in; |
|
|
1171 | }, |
|
|
1172 | ); |
|
|
1173 | |
|
|
1174 | $entry->focus_in; |
|
|
1175 | |
|
|
1176 | } else { |
|
|
1177 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
|
|
1178 | |
|
|
1179 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
1180 | $flags & Crossfire::Protocol::CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
|
|
1181 | connect_activate => sub { |
|
|
1182 | $self->send ("reply $_[1]"); |
|
|
1183 | $dialog->destroy; |
|
|
1184 | $MAPWIDGET->focus_in; |
|
|
1185 | }, |
|
|
1186 | ); |
|
|
1187 | |
|
|
1188 | $entry->focus_in; |
|
|
1189 | } |
|
|
1190 | |
|
|
1191 | $dialog->show; |
394 | } |
1192 | } |
395 | |
1193 | |
396 | sub conn::drawinfo { |
1194 | sub conn::drawinfo { |
397 | my ($self, $color, $text) = @_; |
1195 | my ($self, $color, $text) = @_; |
398 | |
1196 | |
399 | my @color = ( |
1197 | my @color = ( |
400 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
1198 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
401 | [1.00, 1.00, 1.00], |
1199 | [1.00, 1.00, 1.00], |
402 | [0.00, 0.00, 0.55], |
1200 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
403 | [1.00, 0.00, 0.00], |
1201 | [1.00, 0.00, 0.00], |
404 | [1.00, 0.54, 0.00], |
1202 | [1.00, 0.54, 0.00], |
405 | [0.11, 0.56, 1.00], |
1203 | [0.11, 0.56, 1.00], |
406 | [0.93, 0.46, 0.00], |
1204 | [0.93, 0.46, 0.00], |
407 | [0.18, 0.54, 0.34], |
1205 | [0.18, 0.54, 0.34], |
… | |
… | |
413 | ); |
1211 | ); |
414 | |
1212 | |
415 | $LOGVIEW->add_paragraph ($color[$color], $text); |
1213 | $LOGVIEW->add_paragraph ($color[$color], $text); |
416 | } |
1214 | } |
417 | |
1215 | |
|
|
1216 | sub conn::spell_add { |
|
|
1217 | my ($self, $spell) = @_; |
|
|
1218 | |
|
|
1219 | # TODO |
|
|
1220 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
|
|
1221 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}); |
|
|
1222 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}); |
|
|
1223 | } |
|
|
1224 | |
|
|
1225 | sub conn::spell_delete { |
|
|
1226 | my ($self, $spell) = @_; |
|
|
1227 | } |
|
|
1228 | |
|
|
1229 | sub conn::addme_success { |
|
|
1230 | my ($self) = @_; |
|
|
1231 | |
|
|
1232 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1233 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
|
|
1234 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
|
|
1235 | } |
|
|
1236 | } |
|
|
1237 | |
|
|
1238 | sub conn::container_add { |
|
|
1239 | my ($self, $id, $items) = @_; |
|
|
1240 | |
|
|
1241 | # 0 floor |
|
|
1242 | # $self-<{player}{tag} => player inv |
|
|
1243 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
|
|
1244 | } |
|
|
1245 | |
|
|
1246 | sub conn::container_clear { |
|
|
1247 | my ($self, $id) = @_; |
|
|
1248 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
|
|
1249 | } |
|
|
1250 | |
418 | %SDL_CB = ( |
1251 | %SDL_CB = ( |
419 | SDL_QUIT() => sub { |
1252 | CFClient::SDL_QUIT => sub { |
420 | Event::unloop -1; |
1253 | Event::unloop -1; |
421 | }, |
1254 | }, |
422 | SDL_VIDEORESIZE() => sub { |
1255 | CFClient::SDL_VIDEORESIZE => sub { |
423 | }, |
1256 | }, |
424 | SDL_VIDEOEXPOSE() => sub { |
1257 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
425 | refresh; |
|
|
426 | }, |
|
|
427 | SDL_KEYDOWN() => sub { |
|
|
428 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
|
|
429 | # alt-enter |
|
|
430 | destroy_screen; |
|
|
431 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
|
|
432 | init_screen; |
|
|
433 | } else { |
|
|
434 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
|
|
435 | } |
|
|
436 | }, |
|
|
437 | SDL_KEYUP() => sub { |
|
|
438 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
|
|
439 | }, |
|
|
440 | SDL_MOUSEMOTION() => sub { |
|
|
441 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
|
|
442 | }, |
|
|
443 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
444 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
445 | }, |
|
|
446 | SDL_MOUSEBUTTONUP() => sub { |
|
|
447 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
448 | }, |
|
|
449 | SDL_ACTIVEEVENT() => sub { |
1258 | CFClient::SDL_ACTIVEEVENT => sub { |
450 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
1259 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
451 | }, |
1260 | }, |
|
|
1261 | CFClient::SDL_KEYDOWN => sub { |
|
|
1262 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
|
|
1263 | # alt-enter |
|
|
1264 | video_shutdown; |
|
|
1265 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
|
|
1266 | video_init; |
|
|
1267 | } else { |
|
|
1268 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
|
|
1269 | } |
|
|
1270 | }, |
|
|
1271 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
|
|
1272 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
|
|
1273 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
|
|
1274 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
|
|
1275 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
452 | ); |
1276 | ); |
453 | |
1277 | |
454 | ############################################################################# |
1278 | ############################################################################# |
455 | |
1279 | |
|
|
1280 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
1281 | |
|
|
1282 | $TILECACHE = CFClient::db_table "tilecache"; |
|
|
1283 | $FACEMAP = CFClient::db_table "facemap"; |
|
|
1284 | |
456 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
1285 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
457 | |
1286 | |
458 | my %DEF_CFG = ( |
1287 | my %DEF_CFG = ( |
|
|
1288 | sdl_mode => 0, |
459 | width => 640, |
1289 | width => 640, |
460 | height => 480, |
1290 | height => 480, |
|
|
1291 | fullscreen => 0, |
461 | fast => 0, |
1292 | fast => 0, |
|
|
1293 | map_scale => 0.5, |
462 | fow_enable => 1, |
1294 | fow_enable => 1, |
463 | fow_intensity => 0.45, |
1295 | fow_intensity => 0.45, |
464 | fow_smooth => 0, |
1296 | fow_smooth => 0, |
465 | fullscreen => 0, |
1297 | gui_fontsize => 1, |
466 | sdl_mode => 0, |
1298 | log_fontsize => 1, |
|
|
1299 | gauge_fontsize => 1, |
|
|
1300 | gauge_size => 0.35, |
|
|
1301 | stat_fontsize => 1, |
467 | mapsize => 100, |
1302 | mapsize => 100, |
468 | host => "crossfire.schmorp.de", |
1303 | host => "crossfire.schmorp.de", |
469 | port => 13327, |
1304 | say_command => 'say', |
|
|
1305 | audio_enable => 1, |
|
|
1306 | bgm_enable => 1, |
|
|
1307 | bgm_volume => 0.25, |
470 | ); |
1308 | ); |
471 | |
1309 | |
472 | while (my ($k, $v) = each %DEF_CFG) { |
1310 | while (my ($k, $v) = each %DEF_CFG) { |
473 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
1311 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
474 | } |
1312 | } |
475 | |
1313 | |
476 | sdl_init; |
1314 | sdl_init; |
477 | |
1315 | |
478 | @SDL_MODES = reverse |
1316 | @SDL_MODES = reverse |
479 | grep $_->[0] >= 640 && $_->[1] >= 480, |
1317 | grep $_->[0] >= 640 && $_->[1] >= 480, |
480 | map [SDL::RectW ($_), SDL::RectH ($_)], |
1318 | CFClient::SDL_ListModes; |
481 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
482 | |
1319 | |
483 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
1320 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
484 | |
1321 | |
485 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
1322 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
486 | |
1323 | |
487 | init_screen; |
|
|
488 | |
|
|
489 | { |
1324 | { |
490 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
1325 | my @fonts = map CFClient::find_rcfile "fonts/$_", qw( |
|
|
1326 | DejaVuSans.ttf |
|
|
1327 | DejaVuSansMono.ttf |
|
|
1328 | DejaVuSans-Bold.ttf |
|
|
1329 | DejaVuSansMono-Bold.ttf |
|
|
1330 | DejaVuSans-Oblique.ttf |
|
|
1331 | DejaVuSansMono-Oblique.ttf |
|
|
1332 | DejaVuSans-BoldOblique.ttf |
|
|
1333 | DejaVuSansMono-BoldOblique.ttf |
|
|
1334 | ); |
491 | |
1335 | |
492 | CFClient::add_font $_ for @fonts; |
1336 | CFClient::add_font $_ for @fonts; |
493 | CFClient::set_font $fonts[0]; |
1337 | |
494 | } |
1338 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
|
|
1339 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
495 | |
1340 | |
496 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
1341 | $FONT_PROP->make_default; |
|
|
1342 | } |
|
|
1343 | |
|
|
1344 | video_init; |
|
|
1345 | audio_init; |
497 | |
1346 | |
498 | Event::loop; |
1347 | Event::loop; |
499 | |
1348 | |
500 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
1349 | END { CFClient::SDL_Quit } |
501 | |
1350 | |
|
|
1351 | |