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