… | |
… | |
8 | |
8 | |
9 | use SDL; |
9 | use SDL; |
10 | use SDL::App; |
10 | use SDL::App; |
11 | use SDL::Event; |
11 | use SDL::Event; |
12 | use SDL::Surface; |
12 | use SDL::Surface; |
|
|
13 | |
|
|
14 | use SDL::Mixer; |
|
|
15 | use SDL::Sound; |
|
|
16 | use SDL::Music; |
|
|
17 | |
13 | use SDL::OpenGL; |
18 | use SDL::OpenGL; |
14 | |
19 | |
15 | use Crossfire; |
20 | use Crossfire; |
16 | use Crossfire::Protocol; |
21 | use Crossfire::Protocol; |
17 | |
22 | |
|
|
23 | use Compress::LZF; |
|
|
24 | |
18 | use CFClient; |
25 | use CFClient; |
19 | use CFClient::UI; |
26 | use CFClient::UI; |
|
|
27 | use CFClient::MapWidget; |
20 | |
28 | |
21 | our $VERSION = '0.1'; |
29 | our $VERSION = '0.1'; |
22 | |
30 | |
23 | my $MAX_FPS = 60; |
31 | my $MAX_FPS = 60; |
24 | my $MIN_FPS = 5; # unused |
32 | my $MIN_FPS = 5; # unused as of yet |
25 | |
33 | |
|
|
34 | our $META_SERVER = "crossfire.real-time.com:13326"; |
|
|
35 | |
|
|
36 | our $FACEMAP; |
|
|
37 | our $TILECACHE; |
26 | our $FACECACHE; |
38 | our $MAPCACHE; |
27 | |
39 | |
28 | our $LAST_REFRESH; |
40 | our $LAST_REFRESH; |
29 | our $NOW; |
41 | our $NOW; |
30 | |
42 | |
31 | our $CFG; |
43 | our $CFG; |
… | |
… | |
34 | |
46 | |
35 | our @SDL_MODES; |
47 | our @SDL_MODES; |
36 | our $WIDTH; |
48 | our $WIDTH; |
37 | our $HEIGHT; |
49 | our $HEIGHT; |
38 | our $FULLSCREEN; |
50 | our $FULLSCREEN; |
|
|
51 | our $FONTSIZE; |
39 | |
52 | |
|
|
53 | our $MAP; |
40 | our $MAPWIDGET; |
54 | our $MAPWIDGET; |
41 | our $FONTSIZE; |
55 | our $BUTTONBAR; |
|
|
56 | our $LOGVIEW; |
|
|
57 | our $CONSOLE; |
|
|
58 | our $METASERVER; |
|
|
59 | |
|
|
60 | our $GAUGES; |
42 | |
61 | |
43 | our $SDL_ACTIVE; |
62 | our $SDL_ACTIVE; |
44 | our $SDL_EV; |
63 | our $SDL_EV; |
45 | our %SDL_CB; |
64 | our %SDL_CB; |
46 | |
65 | |
|
|
66 | our $SDL_MIXER; |
|
|
67 | our @SOUNDS; # event => file mapping |
|
|
68 | our %AUDIO_CHUNKS; # audio files |
|
|
69 | |
47 | our $ALT_ENTER_MESSAGE; |
70 | our $ALT_ENTER_MESSAGE; |
48 | our $STATUS_LINE; |
71 | our $STATUS_LINE; |
49 | our $DEBUG_STATUS; |
72 | our $DEBUG_STATUS; |
50 | |
73 | |
51 | sub status { |
74 | sub status { |
52 | $STATUS_LINE->set_text ($_[0]); |
75 | $STATUS_LINE->set_text ($_[0]); |
53 | my ($w, $h) = $STATUS_LINE->size_request; |
|
|
54 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
76 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
55 | } |
77 | } |
56 | |
78 | |
57 | sub debug { |
79 | sub debug { |
58 | $DEBUG_STATUS->set_text ($_[0]); |
80 | $DEBUG_STATUS->set_text ($_[0]); |
59 | my ($w, $h) = $DEBUG_STATUS->size_request; |
81 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
60 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
61 | } |
82 | } |
62 | |
83 | |
63 | sub start_game { |
84 | sub start_game { |
64 | status "logging in..."; |
85 | status "logging in..."; |
65 | |
86 | |
66 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
87 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
67 | |
88 | |
|
|
89 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
|
|
90 | |
|
|
91 | $MAP = new CFClient::Map $mapsize, $mapsize; |
|
|
92 | |
|
|
93 | my ($host, $port) = split /:/, $CFG->{host}; |
|
|
94 | |
68 | $CONN = new conn |
95 | $CONN = new conn |
69 | host => $CFG->{host}, |
96 | host => $host, |
70 | port => $CFG->{port}, |
97 | port => $port || 13327, |
71 | user => $CFG->{user}, |
98 | user => $CFG->{user}, |
72 | pass => $CFG->{password}, |
99 | pass => $CFG->{password}, |
73 | mapw => $mapsize, |
100 | mapw => $mapsize, |
74 | maph => $mapsize, |
101 | maph => $mapsize, |
75 | ; |
102 | ; |
… | |
… | |
81 | |
108 | |
82 | sub stop_game { |
109 | sub stop_game { |
83 | undef $CONN; |
110 | undef $CONN; |
84 | } |
111 | } |
85 | |
112 | |
86 | sub config_dialog { |
113 | sub client_setup { |
87 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
114 | my $dialog = new CFClient::UI::FancyFrame |
88 | child => (my $vbox = new CFClient::UI::VBox); |
115 | child => (my $vbox = new CFClient::UI::VBox); |
89 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
116 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup"); |
90 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
117 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
91 | |
118 | |
92 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
119 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
93 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
120 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
94 | |
121 | |
95 | $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_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
96 | $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); |
123 | $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); |
97 | |
124 | |
98 | $mode_slider->connect (changed => sub { |
125 | $mode_slider->connect (changed => sub { |
99 | my ($self, $value) = @_; |
126 | my ($self, $value) = @_; |
100 | |
127 | |
101 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
128 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
102 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
129 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
103 | }); |
130 | }); |
104 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
131 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
105 | |
132 | |
106 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); |
133 | $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
107 | $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
134 | $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
108 | my ($self, $value) = @_; |
135 | my ($self, $value) = @_; |
109 | $CFG->{fullscreen} = $value; |
136 | $CFG->{fullscreen} = $value; |
110 | }); |
137 | }); |
111 | |
138 | |
|
|
139 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
|
|
140 | $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
|
|
141 | my ($self, $value) = @_; |
|
|
142 | $CFG->{fast} = $value; |
|
|
143 | }); |
|
|
144 | |
|
|
145 | $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
|
|
146 | $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
|
|
147 | my ($self, $value) = @_; |
|
|
148 | $CFG->{fow_enable} = $value; |
|
|
149 | }); |
|
|
150 | |
|
|
151 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
|
|
152 | $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
|
|
153 | my ($self, $value) = @_; |
|
|
154 | $CFG->{fow_intensity} = $value; |
|
|
155 | }); |
|
|
156 | |
|
|
157 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
|
|
158 | $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
|
|
159 | my ($self, $value) = @_; |
|
|
160 | $CFG->{fow_smooth} = $value; |
|
|
161 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
|
|
162 | }); |
|
|
163 | |
|
|
164 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
|
|
165 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
166 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
167 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
168 | }); |
|
|
169 | |
|
|
170 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
|
|
171 | $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
172 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
|
|
173 | }); |
|
|
174 | |
112 | $table->add (1, 2, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
175 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
113 | destroy_screen (); |
176 | video_shutdown (); |
114 | init_screen (); |
177 | video_init (); |
|
|
178 | }); |
|
|
179 | |
|
|
180 | $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
|
|
181 | $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
|
|
182 | $CFG->{audio_enable} = $_[1]; |
|
|
183 | }); |
|
|
184 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
185 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
186 | # $CFG->{effects_volume} = $_[1]; |
115 | }); |
187 | # }); |
|
|
188 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
189 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
|
|
190 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
|
|
191 | $CFG->{bgm_enable} = $_[1]; |
|
|
192 | }); |
|
|
193 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { |
|
|
194 | $CFG->{bgm_volume} = $_[1]; |
|
|
195 | $SDL_MIXER->music_volume ($_[1]); |
|
|
196 | }); |
|
|
197 | |
|
|
198 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
199 | audio_shutdown (); |
|
|
200 | audio_init (); |
|
|
201 | }); |
|
|
202 | |
|
|
203 | $dialog |
|
|
204 | } |
|
|
205 | |
|
|
206 | sub metaserver_dialog { |
|
|
207 | my $dialog = new CFClient::UI::FancyFrame |
|
|
208 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
209 | |
|
|
210 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
|
|
211 | |
|
|
212 | $dialog |
|
|
213 | } |
|
|
214 | |
|
|
215 | sub update_metaserver { |
|
|
216 | my ($HOST) = @_; |
|
|
217 | |
|
|
218 | status "fetching metaserver list..."; |
|
|
219 | |
|
|
220 | my $buf; |
|
|
221 | |
|
|
222 | my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; |
|
|
223 | |
|
|
224 | Event->io (fd => $fh, poll => 'r', cb => sub { |
|
|
225 | my $res = sysread $fh, $buf, 8192, length $buf; |
|
|
226 | |
|
|
227 | if (!defined $res) { |
|
|
228 | $_[0]->w->cancel; |
|
|
229 | status "metaserver: $!"; |
|
|
230 | } elsif ($res == 0) { |
|
|
231 | $_[0]->w->cancel; |
|
|
232 | status "server list retrieved"; |
|
|
233 | |
|
|
234 | my $table = $METASERVER->{table}; |
|
|
235 | |
|
|
236 | $table->clear; |
|
|
237 | |
|
|
238 | my @col = qw(Use #Users Host Uptime Version Description); |
|
|
239 | $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) |
|
|
240 | for 0 .. $#col; |
|
|
241 | |
|
|
242 | my @align = qw(1 0 1 1 -1); |
|
|
243 | |
|
|
244 | my $y = 0; |
|
|
245 | for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { |
|
|
246 | my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; |
|
|
247 | |
|
|
248 | for ($desc) { |
|
|
249 | s/<br>/\n/gi; |
|
|
250 | s/<li>/\n· /gi; |
|
|
251 | s/<.*?>//sgi; |
|
|
252 | s/&/&/g; |
|
|
253 | s/</</g; |
|
|
254 | s/>/>/g; |
|
|
255 | } |
|
|
256 | |
|
|
257 | $uptime = sprintf "%dd %02d:%02d:%02d", |
|
|
258 | (int $m->[8] / 86400), |
|
|
259 | (int $m->[8] / 3600) % 24, |
|
|
260 | (int $m->[8] / 60) % 60, |
|
|
261 | $m->[8] % 60; |
|
|
262 | |
|
|
263 | $m = [$users, $host, $uptime, $version, $desc]; |
|
|
264 | |
|
|
265 | $y++; |
|
|
266 | |
|
|
267 | $table->add (0, $y, new CFClient::UI::VBox children => [ |
|
|
268 | (new CFClient::UI::Button text => " ", connect_activate => sub { |
|
|
269 | $HOST->set_text ($CFG->{host} = $host); |
|
|
270 | }), |
|
|
271 | (new CFClient::UI::Empty expand => 1), |
|
|
272 | ]); |
|
|
273 | |
|
|
274 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
|
|
275 | for 0 .. $#$m; |
|
|
276 | } |
|
|
277 | } |
|
|
278 | }); |
|
|
279 | } |
|
|
280 | |
|
|
281 | sub server_setup { |
|
|
282 | my $dialog = new CFClient::UI::FancyFrame |
|
|
283 | child => (my $vbox = new CFClient::UI::VBox); |
116 | |
284 | |
117 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server"); |
285 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup"); |
118 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
286 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
119 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); |
287 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
120 | $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}); |
288 | |
121 | |
289 | { |
122 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); |
290 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
123 | $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}); |
|
|
124 | |
291 | |
|
|
292 | $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub { |
|
|
293 | my ($self, $value) = @_; |
|
|
294 | $CFG->{host} = $value; |
|
|
295 | }); |
|
|
296 | |
|
|
297 | $METASERVER = metaserver_dialog; |
|
|
298 | |
|
|
299 | $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub { |
|
|
300 | update_metaserver $HOST; |
|
|
301 | }); |
|
|
302 | } |
|
|
303 | |
125 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
304 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
126 | $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}); |
305 | $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
|
|
306 | my ($self, $value) = @_; |
|
|
307 | $CFG->{user} = $value; |
|
|
308 | }); |
127 | |
309 | |
128 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); |
310 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
129 | $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); |
311 | $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
|
|
312 | my ($self, $value) = @_; |
|
|
313 | $CFG->{password} = $value; |
|
|
314 | }); |
130 | |
315 | |
|
|
316 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
|
|
317 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
|
|
318 | my ($self, $value) = @_; |
|
|
319 | $CFG->{say_command} = $value; |
|
|
320 | }); |
|
|
321 | |
131 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size"); |
322 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
132 | $table->add (1, 6, new CFClient::UI::Slider |
323 | $table->add (1, 7, new CFClient::UI::Slider |
133 | req_w => 100, |
324 | req_w => 100, |
134 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
325 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
135 | connect_changed => sub { |
326 | connect_changed => sub { |
136 | my ($self, $value) = @_; |
327 | my ($self, $value) = @_; |
137 | |
328 | |
138 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
329 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
139 | }, |
330 | }, |
140 | ); |
331 | ); |
141 | |
332 | |
142 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
333 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
143 | start_game; |
334 | start_game; |
144 | }); |
335 | }); |
145 | |
336 | |
146 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
337 | $dialog |
|
|
338 | } |
147 | |
339 | |
148 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
340 | sub message_window { |
149 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
341 | my $window = new CFClient::UI::FancyFrame |
150 | status "Configuration Saved"; |
342 | border_bg => [1, 1, 1, 0.5], |
|
|
343 | bg => [0.3, 0.3, 0.3, 0.8], |
|
|
344 | user_w => int $::WIDTH / 3, |
|
|
345 | user_h => int $::HEIGHT / 5, |
|
|
346 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
347 | |
|
|
348 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
|
|
349 | expand => 1, |
|
|
350 | fontsize => $::CFG->{log_fontsize}, |
151 | }); |
351 | ); |
152 | $CFClient::UI::TOPLEVEL->add ($dialog); |
|
|
153 | } |
|
|
154 | |
352 | |
155 | sub init_screen { |
353 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
354 | connect_focus_in => sub { |
|
|
355 | my ($input, $prev_focus) = @_; |
|
|
356 | |
|
|
357 | delete $input->{refocus_map}; |
|
|
358 | |
|
|
359 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
360 | $input->{refocus_map} = 1; |
|
|
361 | } |
|
|
362 | delete $input->{auto_activated}; |
|
|
363 | }, |
|
|
364 | connect_activate => sub { |
|
|
365 | my ($input, $text) = @_; |
|
|
366 | $input->set_text (''); |
|
|
367 | |
|
|
368 | if ($text =~ /^\/(.*)/) { |
|
|
369 | $::CONN->user_send ($1); |
|
|
370 | } else { |
|
|
371 | my $say_cmd = $::CFG->{say_command} || 'say'; |
|
|
372 | $::CONN->user_send ("$say_cmd $text"); |
|
|
373 | } |
|
|
374 | if ($input->{refocus_map}) { |
|
|
375 | delete $input->{refocus_map}; |
|
|
376 | $MAPWIDGET->focus_in |
|
|
377 | } |
|
|
378 | }, |
|
|
379 | connect_escape => sub { |
|
|
380 | $MAPWIDGET->focus_in |
|
|
381 | }, |
|
|
382 | ); |
|
|
383 | |
|
|
384 | $CONSOLE = { |
|
|
385 | window => $window, |
|
|
386 | input => $input |
|
|
387 | }; |
|
|
388 | |
|
|
389 | $window |
|
|
390 | } |
|
|
391 | |
|
|
392 | sub sdl_init { |
|
|
393 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
|
|
394 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
395 | and die "SDL::Init failed!\n"; |
|
|
396 | } |
|
|
397 | |
|
|
398 | sub video_init { |
|
|
399 | sdl_init; |
|
|
400 | |
156 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
401 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
157 | $FULLSCREEN = $CFG->{fullscreen}; |
402 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
403 | $FAST = $CFG->{fast}; |
158 | |
404 | |
159 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
405 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
160 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
406 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
161 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
407 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
162 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 0; |
408 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
163 | |
409 | |
164 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
410 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
165 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
411 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
166 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
412 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
167 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
413 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
… | |
… | |
184 | |
430 | |
185 | $LAST_REFRESH = time - 0.01; |
431 | $LAST_REFRESH = time - 0.01; |
186 | |
432 | |
187 | CFClient::gl_init; |
433 | CFClient::gl_init; |
188 | |
434 | |
189 | $FONTSIZE = int $HEIGHT / 40; |
435 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
190 | |
436 | |
191 | ############################################################################# |
437 | ############################################################################# |
192 | |
438 | |
193 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
439 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
194 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
440 | $DEBUG_STATUS->show; |
195 | |
441 | |
196 | $STATUS_LINE = new CFClient::UI::Label |
442 | $STATUS_LINE = new CFClient::UI::Label |
197 | padding => 0, |
443 | padding => 0, |
198 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
444 | y => $HEIGHT - $FONTSIZE * 1.8; |
199 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
445 | $STATUS_LINE->show; |
200 | |
446 | |
201 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
447 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
202 | padding => 0, |
448 | padding => 0, |
203 | y => $HEIGHT * 49 / 50, |
449 | fontsize => 0.8, |
204 | height => $HEIGHT / 50, |
|
|
205 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
450 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
206 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
451 | $ALT_ENTER_MESSAGE->show; |
|
|
452 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
207 | |
453 | |
208 | $MAPWIDGET = new CFClient::UI::MapWidget; |
454 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
209 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
|
|
210 | $MAPWIDGET->focus_in; |
455 | $MAPWIDGET->focus_in; |
|
|
456 | $MAPWIDGET->connect (activate_console => sub { |
|
|
457 | my ($mapwidget, $preset) = @_; |
211 | |
458 | |
212 | config_dialog; |
459 | if ($CONSOLE) { |
213 | } |
460 | $CONSOLE->{input}->{auto_activated} = 1; |
|
|
461 | $CONSOLE->{input}->focus_in; |
214 | |
462 | |
215 | sub destroy_screen { |
463 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
|
|
464 | $CONSOLE->{input}->set_text ($preset); |
|
|
465 | } |
|
|
466 | } |
|
|
467 | }); |
|
|
468 | |
|
|
469 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
|
|
470 | |
|
|
471 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
|
|
472 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
|
|
473 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
|
|
474 | |
|
|
475 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
|
|
476 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
477 | status "Configuration Saved"; |
|
|
478 | }); |
|
|
479 | |
|
|
480 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
481 | |
|
|
482 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
483 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
484 | |
|
|
485 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
486 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
487 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
488 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
489 | |
|
|
490 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
491 | $CFClient::UI::ROOT->add ($tgw); |
|
|
492 | } |
|
|
493 | |
|
|
494 | sub video_shutdown { |
216 | $CFClient::UI::TOPLEVEL->{children} = []; |
495 | $CFClient::UI::ROOT->{children} = []; |
217 | undef $SDL_ACTIVE; |
496 | undef $SDL_ACTIVE; |
218 | undef $SDL_EV; |
497 | undef $SDL_EV; |
219 | SDL::Quit; |
498 | } |
|
|
499 | |
|
|
500 | my $bgmusic;#TODO#hack#d# |
|
|
501 | |
|
|
502 | sub audio_init { |
|
|
503 | if ($CFG->{audio_enable}) { |
|
|
504 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
505 | |
|
|
506 | $SDL_MIXER = new SDL::Mixer |
|
|
507 | -rate => 22050, |
|
|
508 | -channels => 1, # mono |
|
|
509 | -size => 512; |
|
|
510 | |
|
|
511 | $SDL_MIXER->allocate_channels (8); |
|
|
512 | |
|
|
513 | # TODO: hack, do play loop and mood music |
|
|
514 | if ($CFG->{bgm_enable}) { |
|
|
515 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
|
|
516 | $SDL_MIXER->play_music ($bgmusic, -1); |
|
|
517 | $SDL_MIXER->music_volume ($CFG->{bgm_volume}); |
|
|
518 | } |
|
|
519 | |
|
|
520 | while (<$fh>) { |
|
|
521 | next if /^\s*#/; |
|
|
522 | next if /^\s*$/; |
|
|
523 | |
|
|
524 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
525 | |
|
|
526 | push @SOUNDS, "$volume,$file"; |
|
|
527 | |
|
|
528 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
529 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
|
|
530 | $chunk->volume ($volume * 128 / 100); |
|
|
531 | $chunk |
|
|
532 | }; |
|
|
533 | } |
|
|
534 | } else { |
|
|
535 | status "unable to open sound config: $!"; |
|
|
536 | } |
|
|
537 | } |
|
|
538 | } |
|
|
539 | |
|
|
540 | sub audio_shutdown { |
|
|
541 | undef $SDL_MIXER; |
|
|
542 | @SOUNDS = (); |
|
|
543 | %AUDIO_CHUNKS = (); |
220 | } |
544 | } |
221 | |
545 | |
222 | my %animate_object; |
546 | my %animate_object; |
223 | my $animate_timer; |
547 | my $animate_timer; |
224 | |
548 | |
… | |
… | |
232 | debug sprintf "%3.2f", $fps; |
556 | debug sprintf "%3.2f", $fps; |
233 | |
557 | |
234 | $want_refresh = 0; |
558 | $want_refresh = 0; |
235 | $can_refresh = 0; |
559 | $can_refresh = 0; |
236 | |
560 | |
237 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
238 | |
|
|
239 | glMatrixMode GL_PROJECTION; |
|
|
240 | glLoadIdentity; |
|
|
241 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
|
|
242 | glMatrixMode GL_MODELVIEW; |
|
|
243 | glLoadIdentity; |
|
|
244 | |
|
|
245 | glClear GL_COLOR_BUFFER_BIT; |
|
|
246 | |
|
|
247 | $CFClient::UI::TOPLEVEL->draw; |
561 | $CFClient::UI::ROOT->draw; |
248 | |
562 | |
249 | SDL::GLSwapBuffers; |
563 | SDL::GLSwapBuffers; |
250 | |
564 | |
251 | $LAST_REFRESH = $NOW; |
565 | $LAST_REFRESH = $NOW; |
252 | } |
566 | } |
… | |
… | |
283 | delete $animate_object{$widget}; |
597 | delete $animate_object{$widget}; |
284 | } |
598 | } |
285 | |
599 | |
286 | @conn::ISA = Crossfire::Protocol::; |
600 | @conn::ISA = Crossfire::Protocol::; |
287 | |
601 | |
288 | sub conn::map_update { |
602 | sub conn::stats_update { |
289 | my ($self, $dirty) = @_; |
603 | my ($self, $stats) = @_; |
290 | |
604 | |
291 | $MAPWIDGET->update; |
605 | # i love text protocols!!! |
|
|
606 | # FIXME: the stats are somehow weird |
|
|
607 | my $hp = $stats->{1}; |
|
|
608 | my $hp_m = $stats->{2}; |
|
|
609 | my $sp = $stats->{3}; |
|
|
610 | my $sp_m = $stats->{4}; |
|
|
611 | my $fo = $stats->{18}; |
|
|
612 | my $fo_m = 1000; |
|
|
613 | my $gr = $stats->{23}; |
|
|
614 | my $gr_m = $stats->{24}; |
|
|
615 | |
|
|
616 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
|
|
617 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
|
|
618 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
|
|
619 | $GAUGES->{food}->set_value ($fo, $fo_m); |
|
|
620 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
621 | } |
|
|
622 | |
|
|
623 | sub conn::user_send { |
|
|
624 | my ($self, $command) = @_; |
|
|
625 | |
|
|
626 | $self->send_command ($command); |
|
|
627 | status $command; |
292 | } |
628 | } |
293 | |
629 | |
294 | sub conn::map_scroll { |
630 | sub conn::map_scroll { |
295 | my ($self, $dx, $dy) = @_; |
631 | my ($self, $dx, $dy) = @_; |
296 | |
632 | |
297 | # refresh; |
633 | $MAP->scroll ($dx, $dy); |
|
|
634 | } |
|
|
635 | |
|
|
636 | sub conn::feed_map1a { |
|
|
637 | my ($self, $data) = @_; |
|
|
638 | |
|
|
639 | # $self->Crossfire::Protocol::feed_map1a ($data); |
|
|
640 | |
|
|
641 | $MAP->map1a_update ($data); |
|
|
642 | $MAPWIDGET->update; |
|
|
643 | } |
|
|
644 | |
|
|
645 | sub conn::flush_map { |
|
|
646 | my ($self) = @_; |
|
|
647 | |
|
|
648 | my $map_info = delete $self->{map_info} |
|
|
649 | or return; |
|
|
650 | |
|
|
651 | my ($hash, $x, $y, $w, $h) = @$map_info; |
|
|
652 | |
|
|
653 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
|
|
654 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
|
|
655 | |
|
|
656 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
657 | |
298 | } |
658 | } |
299 | |
659 | |
300 | sub conn::map_clear { |
660 | sub conn::map_clear { |
301 | my ($self) = @_; |
661 | my ($self) = @_; |
302 | |
662 | |
303 | # refresh; |
663 | $self->flush_map; |
|
|
664 | delete $self->{neigh}; |
|
|
665 | |
|
|
666 | $MAP->clear; |
|
|
667 | } |
|
|
668 | |
|
|
669 | |
|
|
670 | sub conn::load_map($$$) { |
|
|
671 | my ($self, $hash, $x, $y) = @_; |
|
|
672 | |
|
|
673 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
|
|
674 | $data = Compress::LZF::decompress $data; |
|
|
675 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
676 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
|
|
677 | my $data = $TILECACHE->get ($id) |
|
|
678 | or next; |
|
|
679 | |
|
|
680 | $self->set_texture ($id => $data); |
|
|
681 | } |
|
|
682 | } |
|
|
683 | } |
|
|
684 | |
|
|
685 | sub conn::flood_fill { |
|
|
686 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
|
|
687 | |
|
|
688 | # the server does not allow map paths > 6 |
|
|
689 | return if 6 <= length $path; |
|
|
690 | |
|
|
691 | for my $tile (1..4) { |
|
|
692 | next if $self->{neigh}{$hash}[$tile]; |
|
|
693 | next unless $flags & (1 << ($tile - 1)); |
|
|
694 | |
|
|
695 | my $neigh = $self->{neigh}{$hash} ||= []; |
|
|
696 | |
|
|
697 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
698 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
699 | |
|
|
700 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
701 | return if $mode ne "spatial"; |
|
|
702 | |
|
|
703 | $x += $MAP->ox; |
|
|
704 | $y += $MAP->oy; |
|
|
705 | |
|
|
706 | $self->load_map ($hash, $x, $y) |
|
|
707 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
708 | |
|
|
709 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
710 | |
|
|
711 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
|
|
712 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
713 | }); |
|
|
714 | } |
|
|
715 | } |
|
|
716 | |
|
|
717 | sub conn::map_change { |
|
|
718 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
719 | |
|
|
720 | $self->flush_map; |
|
|
721 | |
|
|
722 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
723 | |
|
|
724 | my $mapmapw = 250; |
|
|
725 | my $mapmaph = 250; |
|
|
726 | |
|
|
727 | $self->flood_fill ("", $hash, $flags, |
|
|
728 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
729 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
730 | |
|
|
731 | $x += $ox; |
|
|
732 | $y += $oy; |
|
|
733 | |
|
|
734 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
735 | |
|
|
736 | $self->load_map ($hash, $x, $y); |
304 | } |
737 | } |
305 | |
738 | |
306 | sub conn::face_find { |
739 | sub conn::face_find { |
307 | my ($self, $face) = @_; |
740 | my ($self, $facenum, $face) = @_; |
308 | |
741 | |
309 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
742 | my $hash = "$face->{chksum},$face->{name}"; |
|
|
743 | |
|
|
744 | my $id = $FACEMAP->get ($hash); |
|
|
745 | |
|
|
746 | unless ($id) { |
|
|
747 | # create new id for face |
|
|
748 | # i love transactions |
|
|
749 | for (1..100) { |
|
|
750 | my $txn = $CFClient::DB_ENV->txn_begin; |
|
|
751 | my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW); |
|
|
752 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
|
|
753 | $id++; |
|
|
754 | if ($FACEMAP->put (id => $id) == 0 |
|
|
755 | && $FACEMAP->put ($hash => $id) == 0) { |
|
|
756 | $txn->txn_commit; |
|
|
757 | |
|
|
758 | goto gotid; |
|
|
759 | } |
|
|
760 | } |
|
|
761 | $txn->abort; |
|
|
762 | } |
|
|
763 | |
|
|
764 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
|
|
765 | } |
|
|
766 | |
|
|
767 | gotid: |
|
|
768 | $face->{id} = $id; |
|
|
769 | $MAP->set_face ($facenum => $id); |
|
|
770 | $TILECACHE->get ($id) |
310 | } |
771 | } |
311 | |
772 | |
312 | sub conn::face_update { |
773 | sub conn::face_update { |
313 | my ($self, $face) = @_; |
774 | my ($self, $facenum, $face) = @_; |
314 | |
775 | |
315 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
776 | $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
316 | |
777 | |
317 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
778 | $self->set_texture ($face->{id} => delete $face->{image}); |
|
|
779 | } |
|
|
780 | |
|
|
781 | sub conn::set_texture { |
|
|
782 | my ($self, $id, $data) = @_; |
|
|
783 | |
|
|
784 | $self->{texture}[$id] ||= do { |
|
|
785 | my $tex = |
|
|
786 | new_from_image CFClient::Texture |
|
|
787 | $data, minify => 1; |
|
|
788 | |
|
|
789 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
790 | $MAPWIDGET->update; |
|
|
791 | |
|
|
792 | $tex |
|
|
793 | }; |
|
|
794 | } |
|
|
795 | |
|
|
796 | sub conn::sound_play { |
|
|
797 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
798 | |
|
|
799 | $SDL_MIXER |
|
|
800 | or return; |
|
|
801 | |
|
|
802 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
803 | or return; |
|
|
804 | |
|
|
805 | $SDL_MIXER->play_channel (-1, $chunk, 0, -1); |
|
|
806 | warn "sound $x,$y,$soundnum,$type\n";#d# |
318 | } |
807 | } |
319 | |
808 | |
320 | sub conn::query { |
809 | sub conn::query { |
321 | my ($self, $flags, $prompt) = @_; |
810 | my ($self, $flags, $prompt) = @_; |
322 | |
811 | |
|
|
812 | #TODO |
323 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
813 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
|
|
814 | } |
|
|
815 | |
|
|
816 | sub conn::drawinfo { |
|
|
817 | my ($self, $color, $text) = @_; |
|
|
818 | |
|
|
819 | my @color = ( |
|
|
820 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
|
|
821 | [1.00, 1.00, 1.00], |
|
|
822 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
|
|
823 | [1.00, 0.00, 0.00], |
|
|
824 | [1.00, 0.54, 0.00], |
|
|
825 | [0.11, 0.56, 1.00], |
|
|
826 | [0.93, 0.46, 0.00], |
|
|
827 | [0.18, 0.54, 0.34], |
|
|
828 | [0.56, 0.73, 0.56], |
|
|
829 | [0.80, 0.80, 0.80], |
|
|
830 | [0.55, 0.41, 0.13], |
|
|
831 | [0.99, 0.77, 0.26], |
|
|
832 | [0.74, 0.65, 0.41], |
|
|
833 | ); |
|
|
834 | |
|
|
835 | $LOGVIEW->add_paragraph ($color[$color], $text); |
324 | } |
836 | } |
325 | |
837 | |
326 | %SDL_CB = ( |
838 | %SDL_CB = ( |
327 | SDL_QUIT() => sub { |
839 | SDL_QUIT() => sub { |
328 | Event::unloop -1; |
840 | Event::unloop -1; |
… | |
… | |
333 | refresh; |
845 | refresh; |
334 | }, |
846 | }, |
335 | SDL_KEYDOWN() => sub { |
847 | SDL_KEYDOWN() => sub { |
336 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
848 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
337 | # alt-enter |
849 | # alt-enter |
338 | $FULLSCREEN = !$FULLSCREEN; |
850 | video_shutdown; |
339 | destroy_screen; |
851 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
340 | init_screen; |
852 | video_init; |
341 | } else { |
853 | } else { |
342 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
854 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
343 | } |
855 | } |
344 | }, |
856 | }, |
345 | SDL_KEYUP() => sub { |
857 | SDL_KEYUP() => sub { |
… | |
… | |
359 | }, |
871 | }, |
360 | ); |
872 | ); |
361 | |
873 | |
362 | ############################################################################# |
874 | ############################################################################# |
363 | |
875 | |
|
|
876 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
877 | |
|
|
878 | $TILECACHE = CFClient::db_table "tilecache"; |
|
|
879 | $FACEMAP = CFClient::db_table "facemap"; |
|
|
880 | |
364 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
881 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
365 | |
882 | |
366 | $CFG ||= { |
883 | my %DEF_CFG = ( |
|
|
884 | sdl_mode => 0, |
367 | width => 640, |
885 | width => 640, |
368 | height => 480, |
886 | height => 480, |
369 | fullscreen => 0, |
887 | fullscreen => 0, |
370 | sdl_mode => 0, |
888 | fast => 0, |
|
|
889 | fow_enable => 1, |
|
|
890 | fow_intensity => 0.45, |
|
|
891 | fow_smooth => 0, |
|
|
892 | gui_fontsize => 1, |
|
|
893 | log_fontsize => 14, |
371 | mapsize => 100, |
894 | mapsize => 100, |
372 | host => "crossfire.schmorp.de", |
895 | host => "crossfire.schmorp.de", |
373 | port => 13327, |
896 | say_command => 'say', |
374 | }; |
897 | audio_enable => 1, |
|
|
898 | bgm_enable => 1, |
|
|
899 | bgm_volume => 64, |
|
|
900 | ); |
375 | |
901 | |
376 | SDL::Init SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO |
902 | while (my ($k, $v) = each %DEF_CFG) { |
377 | and die "SDL::Init failed!\n"; |
903 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
904 | } |
378 | |
905 | |
379 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
906 | sdl_init; |
|
|
907 | |
|
|
908 | @SDL_MODES = reverse |
|
|
909 | grep $_->[0] >= 640 && $_->[1] >= 480, |
|
|
910 | map [SDL::RectW ($_), SDL::RectH ($_)], |
380 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
911 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
381 | |
912 | |
382 | init_screen; |
913 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
|
|
914 | |
|
|
915 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
383 | |
916 | |
384 | { |
917 | { |
385 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
918 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
386 | |
919 | |
387 | CFClient::add_font $_ for @fonts; |
920 | CFClient::add_font $_ for @fonts; |
388 | CFClient::set_font $fonts[0]; |
921 | CFClient::set_font $fonts[0]; |
389 | } |
922 | } |
390 | |
923 | |
391 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
924 | video_init; |
|
|
925 | audio_init; |
392 | |
926 | |
393 | Event::loop; |
927 | Event::loop; |
394 | |
928 | |
395 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
929 | END { SDL::Quit } |
396 | |
930 | |
|
|
931 | |