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