1 |
root |
1.1 |
#!/opt/bin/perl |
2 |
root |
1.25 |
|
3 |
root |
1.2 |
use strict; |
4 |
root |
1.25 |
use utf8; |
5 |
root |
1.2 |
|
6 |
root |
1.87 |
use Time::HiRes 'time'; |
7 |
|
|
use Event; |
8 |
root |
1.13 |
|
9 |
elmex |
1.11 |
use Crossfire; |
10 |
root |
1.2 |
use Crossfire::Protocol; |
11 |
|
|
|
12 |
root |
1.116 |
use Compress::LZF; |
13 |
|
|
|
14 |
root |
1.67 |
use CFClient; |
15 |
root |
1.72 |
use CFClient::UI; |
16 |
root |
1.141 |
use CFClient::MapWidget; |
17 |
elmex |
1.10 |
|
18 |
root |
1.63 |
our $VERSION = '0.1'; |
19 |
|
|
|
20 |
root |
1.96 |
my $MAX_FPS = 60; |
21 |
root |
1.90 |
my $MIN_FPS = 5; # unused as of yet |
22 |
root |
1.63 |
|
23 |
root |
1.112 |
our $META_SERVER = "crossfire.real-time.com:13326"; |
24 |
|
|
|
25 |
root |
1.116 |
our $FACEMAP; |
26 |
|
|
our $TILECACHE; |
27 |
|
|
our $MAPCACHE; |
28 |
root |
1.19 |
|
29 |
root |
1.87 |
our $LAST_REFRESH; |
30 |
|
|
our $NOW; |
31 |
|
|
|
32 |
elmex |
1.10 |
our $CFG; |
33 |
root |
1.13 |
our $CONN; |
34 |
root |
1.85 |
our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
35 |
root |
1.2 |
|
36 |
root |
1.75 |
our @SDL_MODES; |
37 |
root |
1.30 |
our $WIDTH; |
38 |
|
|
our $HEIGHT; |
39 |
|
|
our $FULLSCREEN; |
40 |
root |
1.99 |
our $FONTSIZE; |
41 |
root |
1.30 |
|
42 |
root |
1.95 |
our $MAP; |
43 |
root |
1.69 |
our $MAPWIDGET; |
44 |
root |
1.112 |
our $BUTTONBAR; |
45 |
|
|
our $LOGVIEW; |
46 |
|
|
our $CONSOLE; |
47 |
|
|
our $METASERVER; |
48 |
root |
1.57 |
|
49 |
elmex |
1.125 |
our $GAUGES; |
50 |
elmex |
1.154 |
our $STATWIDS; |
51 |
elmex |
1.125 |
|
52 |
root |
1.86 |
our $SDL_ACTIVE; |
53 |
root |
1.13 |
our %SDL_CB; |
54 |
root |
1.18 |
|
55 |
root |
1.134 |
our $SDL_MIXER; |
56 |
|
|
our @SOUNDS; # event => file mapping |
57 |
|
|
our %AUDIO_CHUNKS; # audio files |
58 |
|
|
|
59 |
root |
1.30 |
our $ALT_ENTER_MESSAGE; |
60 |
root |
1.51 |
our $STATUS_LINE; |
61 |
root |
1.64 |
our $DEBUG_STATUS; |
62 |
root |
1.30 |
|
63 |
root |
1.82 |
sub status { |
64 |
|
|
$STATUS_LINE->set_text ($_[0]); |
65 |
root |
1.128 |
$STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
66 |
root |
1.82 |
} |
67 |
|
|
|
68 |
|
|
sub debug { |
69 |
|
|
$DEBUG_STATUS->set_text ($_[0]); |
70 |
root |
1.128 |
$DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
71 |
root |
1.82 |
} |
72 |
|
|
|
73 |
root |
1.84 |
sub start_game { |
74 |
root |
1.85 |
status "logging in..."; |
75 |
|
|
|
76 |
root |
1.106 |
my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
77 |
root |
1.84 |
|
78 |
root |
1.116 |
$MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
79 |
|
|
|
80 |
root |
1.95 |
$MAP = new CFClient::Map $mapsize, $mapsize; |
81 |
root |
1.112 |
|
82 |
|
|
my ($host, $port) = split /:/, $CFG->{host}; |
83 |
root |
1.95 |
|
84 |
root |
1.84 |
$CONN = new conn |
85 |
root |
1.112 |
host => $host, |
86 |
|
|
port => $port || 13327, |
87 |
root |
1.84 |
user => $CFG->{user}, |
88 |
|
|
pass => $CFG->{password}, |
89 |
|
|
mapw => $mapsize, |
90 |
|
|
maph => $mapsize, |
91 |
|
|
; |
92 |
|
|
|
93 |
root |
1.85 |
status "login successful"; |
94 |
|
|
|
95 |
root |
1.84 |
CFClient::lowdelay fileno $CONN->{fh}; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
sub stop_game { |
99 |
|
|
undef $CONN; |
100 |
|
|
} |
101 |
|
|
|
102 |
root |
1.111 |
sub client_setup { |
103 |
root |
1.99 |
my $dialog = new CFClient::UI::FancyFrame |
104 |
root |
1.150 |
title => "Client Setup", |
105 |
root |
1.81 |
child => (my $vbox = new CFClient::UI::VBox); |
106 |
|
|
$vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
107 |
|
|
|
108 |
root |
1.140 |
$table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
109 |
root |
1.81 |
$table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
110 |
|
|
|
111 |
|
|
$hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
112 |
root |
1.150 |
$hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
113 |
root |
1.81 |
|
114 |
|
|
$mode_slider->connect (changed => sub { |
115 |
|
|
my ($self, $value) = @_; |
116 |
|
|
|
117 |
|
|
$CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
118 |
|
|
$mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
119 |
|
|
}); |
120 |
|
|
$mode_slider->emit (changed => $mode_slider->{range}[0]); |
121 |
root |
1.82 |
|
122 |
root |
1.140 |
$table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
123 |
root |
1.85 |
$table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
124 |
|
|
my ($self, $value) = @_; |
125 |
|
|
$CFG->{fullscreen} = $value; |
126 |
|
|
}); |
127 |
|
|
|
128 |
root |
1.140 |
$table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
129 |
root |
1.89 |
$table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { |
130 |
|
|
my ($self, $value) = @_; |
131 |
|
|
$CFG->{fast} = $value; |
132 |
|
|
}); |
133 |
|
|
|
134 |
root |
1.140 |
$table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
135 |
root |
1.97 |
$table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { |
136 |
|
|
my ($self, $value) = @_; |
137 |
|
|
$CFG->{fow_enable} = $value; |
138 |
|
|
}); |
139 |
|
|
|
140 |
root |
1.140 |
$table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
141 |
root |
1.97 |
$table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { |
142 |
root |
1.90 |
my ($self, $value) = @_; |
143 |
|
|
$CFG->{fow_intensity} = $value; |
144 |
|
|
}); |
145 |
|
|
|
146 |
root |
1.140 |
$table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
147 |
root |
1.97 |
$table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { |
148 |
root |
1.91 |
my ($self, $value) = @_; |
149 |
|
|
$CFG->{fow_smooth} = $value; |
150 |
root |
1.132 |
status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
151 |
root |
1.91 |
}); |
152 |
|
|
|
153 |
root |
1.141 |
$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 |
root |
1.140 |
# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
157 |
|
|
}); |
158 |
|
|
|
159 |
root |
1.141 |
$table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
160 |
|
|
$table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
161 |
|
|
$LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
162 |
root |
1.105 |
}); |
163 |
|
|
|
164 |
root |
1.140 |
$table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
165 |
root |
1.134 |
video_shutdown (); |
166 |
|
|
video_init (); |
167 |
root |
1.82 |
}); |
168 |
root |
1.111 |
|
169 |
root |
1.140 |
$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]; |
176 |
|
|
# }); |
177 |
root |
1.141 |
$table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
178 |
root |
1.140 |
$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 |
root |
1.146 |
$hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
183 |
root |
1.140 |
$CFG->{bgm_volume} = $_[1]; |
184 |
root |
1.149 |
CFClient::MixMusic::volume $_[1] * 128; |
185 |
elmex |
1.137 |
}); |
186 |
root |
1.140 |
|
187 |
|
|
$table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
188 |
elmex |
1.137 |
audio_shutdown (); |
189 |
|
|
audio_init (); |
190 |
|
|
}); |
191 |
|
|
|
192 |
root |
1.111 |
$dialog |
193 |
|
|
} |
194 |
|
|
|
195 |
elmex |
1.154 |
sub make_stats_window { |
196 |
elmex |
1.156 |
my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
197 |
root |
1.155 |
|
198 |
|
|
$tgw->add (my $vb = new CFClient::UI::VBox); |
199 |
elmex |
1.156 |
$vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:"); |
200 |
|
|
$vb->add (my $lhb = new CFClient::UI::HBox); |
201 |
|
|
$lhb->add ($STATWIDS->{exp} = new CFClient::UI::Label valign => 0, align => -1, text => "Exp:", expand => 1); |
202 |
|
|
$lhb->add ($STATWIDS->{lvl} = new CFClient::UI::Label valign => 0, align => -1, text => "Level:", expand => 1); |
203 |
|
|
|
204 |
|
|
$vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
205 |
|
|
$hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', expand => 1); |
206 |
|
|
$hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', expand => 1); |
207 |
|
|
$hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', expand => 1); |
208 |
|
|
$hb->add (my $fg = new CFClient::UI::Gauge type => 'food', expand => 1); |
209 |
|
|
$GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
210 |
|
|
|
211 |
|
|
$hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
212 |
|
|
|
213 |
|
|
if (0) { # this code can vanish, just wanted to preserver it for a checkin |
214 |
|
|
$tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => -1, text => "S"); |
215 |
|
|
$tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => -1, text => "D"); |
216 |
|
|
$tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => -1, text => "Co"); |
217 |
|
|
$tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => -1, text => "I"); |
218 |
|
|
$tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => -1, text => "W"); |
219 |
|
|
$tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => -1, text => "P"); |
220 |
|
|
$tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => -1, text => "Ch"); |
221 |
|
|
|
222 |
|
|
$tbl->add (1, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc"); |
223 |
|
|
$tbl->add (1, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac"); |
224 |
|
|
$tbl->add (1, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam"); |
225 |
|
|
$tbl->add (1, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm"); |
226 |
|
|
$tbl->add (1, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp"); |
227 |
|
|
$tbl->add (1, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp"); |
228 |
|
|
} else { |
229 |
|
|
$tbl->add (0, 0, new CFClient::UI::Label valign => 0, align => +1, text => "S"); |
230 |
|
|
$tbl->add (0, 1, new CFClient::UI::Label valign => 0, align => +1, text => "D"); |
231 |
|
|
$tbl->add (0, 2, new CFClient::UI::Label valign => 0, align => +1, text => "Co"); |
232 |
|
|
$tbl->add (0, 3, new CFClient::UI::Label valign => 0, align => +1, text => "I"); |
233 |
|
|
$tbl->add (0, 4, new CFClient::UI::Label valign => 0, align => +1, text => "W"); |
234 |
|
|
$tbl->add (0, 5, new CFClient::UI::Label valign => 0, align => +1, text => "P"); |
235 |
|
|
$tbl->add (0, 6, new CFClient::UI::Label valign => 0, align => +1, text => "Ch"); |
236 |
|
|
|
237 |
|
|
$tbl->add (1, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
238 |
|
|
$tbl->add (1, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
239 |
|
|
$tbl->add (1, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
240 |
|
|
$tbl->add (1, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
241 |
|
|
$tbl->add (1, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
242 |
|
|
$tbl->add (1, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
243 |
|
|
$tbl->add (1, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
244 |
|
|
|
245 |
|
|
$tbl->add (2, 0, new CFClient::UI::Label valign => 0, align => +1, text => "Wc"); |
246 |
|
|
$tbl->add (2, 1, new CFClient::UI::Label valign => 0, align => +1, text => "Ac"); |
247 |
|
|
$tbl->add (2, 2, new CFClient::UI::Label valign => 0, align => +1, text => "Dam"); |
248 |
|
|
$tbl->add (2, 3, new CFClient::UI::Label valign => 0, align => +1, text => "Arm"); |
249 |
|
|
$tbl->add (2, 4, new CFClient::UI::Label valign => 0, align => +1, text => "Sp"); |
250 |
|
|
$tbl->add (2, 5, new CFClient::UI::Label valign => 0, align => +1, text => "WSp"); |
251 |
|
|
|
252 |
|
|
$tbl->add (3, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
253 |
|
|
$tbl->add (3, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
254 |
|
|
$tbl->add (3, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
255 |
|
|
$tbl->add (3, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
256 |
|
|
$tbl->add (3, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
257 |
|
|
$tbl->add (3, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => -1, text => ""); |
258 |
|
|
} |
259 |
root |
1.155 |
|
260 |
elmex |
1.156 |
$hb->add (my $tbl2 = new CFClient::UI::Table); |
261 |
root |
1.155 |
|
262 |
elmex |
1.156 |
my $row = 0; |
263 |
|
|
my $col = 0; |
264 |
root |
1.155 |
|
265 |
elmex |
1.156 |
for (qw/slow holyw conf fire depl magic |
266 |
|
|
drain acid pois para deat phys |
267 |
|
|
blind fear tund elec cold ghit/) |
268 |
|
|
{ |
269 |
|
|
$tbl2->add ($col, $row, new CFClient::UI::Image image => "ui/resist/resist_$_.png"); |
270 |
|
|
$tbl2->add ($col + 1, $row, |
271 |
|
|
$STATWIDS->{"res_$_"} = |
272 |
|
|
new CFClient::UI::Label text => "0", align => -1, valign => 0 |
273 |
|
|
); |
274 |
|
|
|
275 |
|
|
$row++; |
276 |
|
|
if ($row % 6 == 0) { |
277 |
|
|
$col += 2; |
278 |
|
|
$row = 0; |
279 |
|
|
} |
280 |
|
|
} |
281 |
|
|
|
282 |
|
|
update_stats_window ({}); |
283 |
root |
1.155 |
|
284 |
elmex |
1.154 |
$tgw |
285 |
|
|
} |
286 |
|
|
|
287 |
|
|
sub update_stats_window { |
288 |
|
|
my ($stats) = @_; |
289 |
|
|
|
290 |
elmex |
1.156 |
# i love text protocols!!! |
291 |
|
|
my $hp = $stats->{1}; |
292 |
|
|
my $hp_m = $stats->{2}; |
293 |
|
|
my $sp = $stats->{3}; |
294 |
|
|
my $sp_m = $stats->{4}; |
295 |
|
|
my $fo = $stats->{18}; |
296 |
|
|
my $fo_m = 999; |
297 |
|
|
my $gr = $stats->{23}; |
298 |
|
|
my $gr_m = $stats->{24}; |
299 |
|
|
|
300 |
|
|
$GAUGES->{hp} ->set_value ($hp, $hp_m); |
301 |
|
|
$GAUGES->{mana} ->set_value ($sp, $sp_m); |
302 |
|
|
$GAUGES->{food} ->set_value ($fo, $fo_m); |
303 |
|
|
$GAUGES->{grace} ->set_value ($gr, $gr_m); |
304 |
|
|
$STATWIDS->{title} ->set_text ("Title: " . $stats->{21}); |
305 |
|
|
$STATWIDS->{exp} ->set_text ("Exp.: " . ($stats->{11} || $stats->{28})); |
306 |
|
|
$STATWIDS->{lvl} ->set_text ("Level: " . $stats->{12}); |
307 |
|
|
|
308 |
|
|
if (0) { # this code can vanish, just wanted to preserver it for a checkin |
309 |
|
|
$STATWIDS->{st_str} ->set_text (sprintf "S%d", $stats->{5}); |
310 |
|
|
$STATWIDS->{st_dex} ->set_text (sprintf "D%d", $stats->{8}); |
311 |
|
|
$STATWIDS->{st_con} ->set_text (sprintf "Co%d", $stats->{9}); |
312 |
|
|
$STATWIDS->{st_int} ->set_text (sprintf "I%d", $stats->{6}); |
313 |
|
|
$STATWIDS->{st_wis} ->set_text (sprintf "W%d", $stats->{7}); |
314 |
|
|
$STATWIDS->{st_pow} ->set_text (sprintf "P%d", $stats->{22}); |
315 |
|
|
$STATWIDS->{st_cha} ->set_text (sprintf "Ch%d", $stats->{10}); |
316 |
|
|
$STATWIDS->{st_wc} ->set_text (sprintf "Wc%d", $stats->{13}); |
317 |
|
|
$STATWIDS->{st_ac} ->set_text (sprintf "Ac%d", $stats->{14}); |
318 |
|
|
$STATWIDS->{st_dam} ->set_text (sprintf "Dam%d", $stats->{15}); |
319 |
|
|
$STATWIDS->{st_arm} ->set_text (sprintf "Arm%d", $stats->{16}); |
320 |
|
|
$STATWIDS->{st_spd} ->set_text (sprintf "Sp%.1f", $stats->{17}); |
321 |
|
|
$STATWIDS->{st_wspd}->set_text (sprintf "WSp%.1f", $stats->{19}); |
322 |
|
|
} else { |
323 |
|
|
$STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5}); |
324 |
|
|
$STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8}); |
325 |
|
|
$STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9}); |
326 |
|
|
$STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6}); |
327 |
|
|
$STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7}); |
328 |
|
|
$STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22}); |
329 |
|
|
$STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10}); |
330 |
|
|
$STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13}); |
331 |
|
|
$STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14}); |
332 |
|
|
$STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
333 |
|
|
$STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
334 |
|
|
$STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17}); |
335 |
|
|
$STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19}); |
336 |
|
|
} |
337 |
|
|
|
338 |
|
|
my %tbl = ( |
339 |
|
|
phys => 100, |
340 |
|
|
magic => 101, |
341 |
|
|
fire => 102, |
342 |
|
|
elec => 103, |
343 |
|
|
cold => 104, |
344 |
|
|
conf => 105, |
345 |
|
|
acid => 106, |
346 |
|
|
drain => 107, |
347 |
|
|
ghit => 108, |
348 |
|
|
pois => 109, |
349 |
|
|
slow => 110, |
350 |
|
|
para => 111, |
351 |
|
|
tund => 112, |
352 |
|
|
fear => 113, |
353 |
|
|
deat => 115, |
354 |
|
|
holyw => 116, |
355 |
|
|
blind => 117 |
356 |
elmex |
1.154 |
); |
357 |
elmex |
1.156 |
|
358 |
|
|
for (keys %tbl) { |
359 |
|
|
$STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}}); |
360 |
|
|
} |
361 |
|
|
|
362 |
elmex |
1.154 |
} |
363 |
|
|
|
364 |
root |
1.112 |
sub metaserver_dialog { |
365 |
|
|
my $dialog = new CFClient::UI::FancyFrame |
366 |
root |
1.150 |
title => "Metaserver", |
367 |
root |
1.112 |
child => (my $vbox = new CFClient::UI::VBox); |
368 |
|
|
|
369 |
|
|
$vbox->add ($dialog->{table} = new CFClient::UI::Table); |
370 |
|
|
|
371 |
|
|
$dialog |
372 |
|
|
} |
373 |
|
|
|
374 |
|
|
sub update_metaserver { |
375 |
root |
1.114 |
my ($HOST) = @_; |
376 |
|
|
|
377 |
root |
1.112 |
status "fetching metaserver list..."; |
378 |
|
|
|
379 |
|
|
my $buf; |
380 |
|
|
|
381 |
|
|
my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; |
382 |
|
|
|
383 |
|
|
Event->io (fd => $fh, poll => 'r', cb => sub { |
384 |
|
|
my $res = sysread $fh, $buf, 8192, length $buf; |
385 |
|
|
|
386 |
|
|
if (!defined $res) { |
387 |
|
|
$_[0]->w->cancel; |
388 |
|
|
status "metaserver: $!"; |
389 |
|
|
} elsif ($res == 0) { |
390 |
|
|
$_[0]->w->cancel; |
391 |
|
|
status "server list retrieved"; |
392 |
root |
1.113 |
|
393 |
|
|
my $table = $METASERVER->{table}; |
394 |
|
|
|
395 |
|
|
$table->clear; |
396 |
|
|
|
397 |
root |
1.114 |
my @col = qw(Use #Users Host Uptime Version Description); |
398 |
root |
1.113 |
$table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) |
399 |
|
|
for 0 .. $#col; |
400 |
|
|
|
401 |
|
|
my @align = qw(1 0 1 1 -1); |
402 |
|
|
|
403 |
|
|
my $y = 0; |
404 |
root |
1.114 |
for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { |
405 |
root |
1.113 |
my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; |
406 |
|
|
|
407 |
|
|
for ($desc) { |
408 |
|
|
s/<br>/\n/gi; |
409 |
|
|
s/<li>/\n· /gi; |
410 |
|
|
s/<.*?>//sgi; |
411 |
|
|
s/&/&/g; |
412 |
|
|
s/</</g; |
413 |
|
|
s/>/>/g; |
414 |
|
|
} |
415 |
|
|
|
416 |
|
|
$uptime = sprintf "%dd %02d:%02d:%02d", |
417 |
|
|
(int $m->[8] / 86400), |
418 |
|
|
(int $m->[8] / 3600) % 24, |
419 |
|
|
(int $m->[8] / 60) % 60, |
420 |
|
|
$m->[8] % 60; |
421 |
|
|
|
422 |
|
|
$m = [$users, $host, $uptime, $version, $desc]; |
423 |
|
|
|
424 |
|
|
$y++; |
425 |
root |
1.114 |
|
426 |
|
|
$table->add (0, $y, new CFClient::UI::VBox children => [ |
427 |
|
|
(new CFClient::UI::Button text => " ", connect_activate => sub { |
428 |
|
|
$HOST->set_text ($CFG->{host} = $host); |
429 |
|
|
}), |
430 |
|
|
(new CFClient::UI::Empty expand => 1), |
431 |
|
|
]); |
432 |
|
|
|
433 |
root |
1.140 |
$table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
434 |
root |
1.113 |
for 0 .. $#$m; |
435 |
|
|
} |
436 |
root |
1.112 |
} |
437 |
|
|
}); |
438 |
|
|
} |
439 |
|
|
|
440 |
root |
1.111 |
sub server_setup { |
441 |
|
|
my $dialog = new CFClient::UI::FancyFrame |
442 |
root |
1.150 |
title => "Server Setup", |
443 |
root |
1.111 |
child => (my $vbox = new CFClient::UI::VBox); |
444 |
root |
1.81 |
|
445 |
root |
1.82 |
$vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
446 |
root |
1.141 |
$table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
447 |
root |
1.112 |
|
448 |
|
|
{ |
449 |
|
|
$table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
450 |
|
|
|
451 |
root |
1.141 |
$vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub { |
452 |
root |
1.112 |
my ($self, $value) = @_; |
453 |
|
|
$CFG->{host} = $value; |
454 |
|
|
}); |
455 |
|
|
|
456 |
|
|
$METASERVER = metaserver_dialog; |
457 |
elmex |
1.101 |
|
458 |
root |
1.141 |
$vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub { |
459 |
root |
1.114 |
update_metaserver $HOST; |
460 |
root |
1.112 |
}); |
461 |
|
|
} |
462 |
root |
1.81 |
|
463 |
root |
1.141 |
$table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
464 |
root |
1.114 |
$table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { |
465 |
elmex |
1.101 |
my ($self, $value) = @_; |
466 |
|
|
$CFG->{user} = $value; |
467 |
|
|
}); |
468 |
root |
1.81 |
|
469 |
root |
1.141 |
$table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
470 |
root |
1.114 |
$table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { |
471 |
elmex |
1.101 |
my ($self, $value) = @_; |
472 |
|
|
$CFG->{password} = $value; |
473 |
|
|
}); |
474 |
|
|
|
475 |
root |
1.141 |
$table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
476 |
elmex |
1.101 |
$table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { |
477 |
|
|
my ($self, $value) = @_; |
478 |
|
|
$CFG->{say_command} = $value; |
479 |
|
|
}); |
480 |
root |
1.81 |
|
481 |
root |
1.141 |
$table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
482 |
elmex |
1.101 |
$table->add (1, 7, new CFClient::UI::Slider |
483 |
root |
1.81 |
req_w => 100, |
484 |
|
|
range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
485 |
|
|
connect_changed => sub { |
486 |
|
|
my ($self, $value) = @_; |
487 |
|
|
|
488 |
|
|
$CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
489 |
|
|
}, |
490 |
|
|
); |
491 |
|
|
|
492 |
elmex |
1.101 |
$table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
493 |
root |
1.84 |
start_game; |
494 |
root |
1.82 |
}); |
495 |
|
|
|
496 |
root |
1.98 |
$dialog |
497 |
root |
1.81 |
} |
498 |
root |
1.58 |
|
499 |
root |
1.111 |
sub message_window { |
500 |
root |
1.99 |
my $window = new CFClient::UI::FancyFrame |
501 |
root |
1.150 |
title => "Messages", |
502 |
root |
1.99 |
border_bg => [1, 1, 1, 0.5], |
503 |
|
|
bg => [0.3, 0.3, 0.3, 0.8], |
504 |
root |
1.124 |
user_w => int $::WIDTH / 3, |
505 |
|
|
user_h => int $::HEIGHT / 5, |
506 |
root |
1.99 |
child => (my $vbox = new CFClient::UI::VBox); |
507 |
|
|
|
508 |
root |
1.105 |
$vbox->add ($LOGVIEW = new CFClient::UI::TextView |
509 |
|
|
expand => 1, |
510 |
|
|
fontsize => $::CFG->{log_fontsize}, |
511 |
|
|
); |
512 |
|
|
|
513 |
root |
1.122 |
$vbox->add (my $input = new CFClient::UI::Entry |
514 |
elmex |
1.118 |
connect_focus_in => sub { |
515 |
|
|
my ($input, $prev_focus) = @_; |
516 |
|
|
|
517 |
|
|
delete $input->{refocus_map}; |
518 |
|
|
|
519 |
|
|
if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
520 |
|
|
$input->{refocus_map} = 1; |
521 |
|
|
} |
522 |
|
|
delete $input->{auto_activated}; |
523 |
|
|
}, |
524 |
root |
1.116 |
connect_activate => sub { |
525 |
elmex |
1.100 |
my ($input, $text) = @_; |
526 |
|
|
$input->set_text (''); |
527 |
|
|
|
528 |
|
|
if ($text =~ /^\/(.*)/) { |
529 |
root |
1.123 |
$::CONN->user_send ($1); |
530 |
elmex |
1.100 |
} else { |
531 |
elmex |
1.101 |
my $say_cmd = $::CFG->{say_command} || 'say'; |
532 |
root |
1.123 |
$::CONN->user_send ("$say_cmd $text"); |
533 |
elmex |
1.100 |
} |
534 |
elmex |
1.118 |
if ($input->{refocus_map}) { |
535 |
|
|
delete $input->{refocus_map}; |
536 |
|
|
$MAPWIDGET->focus_in |
537 |
|
|
} |
538 |
root |
1.116 |
}, |
539 |
|
|
connect_escape => sub { |
540 |
elmex |
1.102 |
$MAPWIDGET->focus_in |
541 |
root |
1.116 |
}, |
542 |
|
|
); |
543 |
elmex |
1.102 |
|
544 |
|
|
$CONSOLE = { |
545 |
|
|
window => $window, |
546 |
|
|
input => $input |
547 |
|
|
}; |
548 |
root |
1.99 |
|
549 |
|
|
$window |
550 |
|
|
} |
551 |
|
|
|
552 |
root |
1.89 |
sub sdl_init { |
553 |
root |
1.145 |
CFClient::SDL_Init |
554 |
root |
1.89 |
and die "SDL::Init failed!\n"; |
555 |
|
|
} |
556 |
|
|
|
557 |
root |
1.134 |
sub video_init { |
558 |
root |
1.89 |
sdl_init; |
559 |
|
|
|
560 |
root |
1.84 |
($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
561 |
|
|
$FULLSCREEN = $CFG->{fullscreen}; |
562 |
root |
1.89 |
$FAST = $CFG->{fast}; |
563 |
root |
1.84 |
|
564 |
root |
1.145 |
CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
565 |
|
|
or die "SDL_SetVideoMode failed!\n"; |
566 |
root |
1.2 |
|
567 |
root |
1.86 |
$SDL_ACTIVE = 1; |
568 |
|
|
|
569 |
root |
1.87 |
$LAST_REFRESH = time - 0.01; |
570 |
root |
1.45 |
|
571 |
root |
1.67 |
CFClient::gl_init; |
572 |
root |
1.30 |
|
573 |
root |
1.140 |
$FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
574 |
root |
1.39 |
|
575 |
root |
1.52 |
############################################################################# |
576 |
|
|
|
577 |
root |
1.99 |
$DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
578 |
root |
1.140 |
$DEBUG_STATUS->show; |
579 |
root |
1.52 |
|
580 |
root |
1.72 |
$STATUS_LINE = new CFClient::UI::Label |
581 |
root |
1.77 |
padding => 0, |
582 |
root |
1.140 |
y => $HEIGHT - $FONTSIZE * 1.8; |
583 |
|
|
$STATUS_LINE->show; |
584 |
root |
1.51 |
|
585 |
root |
1.72 |
$ALT_ENTER_MESSAGE = new CFClient::UI::Label |
586 |
root |
1.123 |
padding => 0, |
587 |
root |
1.140 |
fontsize => 0.8, |
588 |
root |
1.123 |
markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
589 |
root |
1.140 |
$ALT_ENTER_MESSAGE->show; |
590 |
|
|
$ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
591 |
root |
1.30 |
|
592 |
root |
1.141 |
$CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
593 |
root |
1.69 |
$MAPWIDGET->focus_in; |
594 |
elmex |
1.102 |
$MAPWIDGET->connect (activate_console => sub { |
595 |
elmex |
1.103 |
my ($mapwidget, $preset) = @_; |
596 |
|
|
|
597 |
elmex |
1.102 |
if ($CONSOLE) { |
598 |
elmex |
1.118 |
$CONSOLE->{input}->{auto_activated} = 1; |
599 |
elmex |
1.102 |
$CONSOLE->{input}->focus_in; |
600 |
elmex |
1.103 |
|
601 |
|
|
if ($preset && $CONSOLE->{input}->get_text eq '') { |
602 |
|
|
$CONSOLE->{input}->set_text ($preset); |
603 |
|
|
} |
604 |
elmex |
1.102 |
} |
605 |
|
|
}); |
606 |
root |
1.81 |
|
607 |
root |
1.111 |
$CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
608 |
|
|
|
609 |
|
|
$BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
610 |
|
|
$BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
611 |
|
|
$BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
612 |
|
|
|
613 |
|
|
$BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
614 |
|
|
CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
615 |
|
|
status "Configuration Saved"; |
616 |
|
|
}); |
617 |
root |
1.98 |
|
618 |
root |
1.119 |
$BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
619 |
elmex |
1.125 |
|
620 |
root |
1.126 |
|
621 |
elmex |
1.154 |
$CFClient::UI::ROOT->add (make_stats_window); |
622 |
root |
1.2 |
} |
623 |
|
|
|
624 |
root |
1.134 |
sub video_shutdown { |
625 |
root |
1.111 |
$CFClient::UI::ROOT->{children} = []; |
626 |
root |
1.86 |
undef $SDL_ACTIVE; |
627 |
root |
1.134 |
} |
628 |
|
|
|
629 |
root |
1.153 |
my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
630 |
root |
1.135 |
my $bgmusic;#TODO#hack#d# |
631 |
|
|
|
632 |
root |
1.153 |
sub audio_music_finished { |
633 |
|
|
return unless $CFG->{bgm_enable}; |
634 |
|
|
|
635 |
|
|
# TODO: hack, do play loop and mood music |
636 |
|
|
$bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
637 |
|
|
$bgmusic->play (0); |
638 |
|
|
|
639 |
|
|
push @bgmusic, shift @bgmusic; |
640 |
|
|
} |
641 |
|
|
|
642 |
root |
1.134 |
sub audio_init { |
643 |
root |
1.139 |
if ($CFG->{audio_enable}) { |
644 |
root |
1.134 |
if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
645 |
root |
1.146 |
$SDL_MIXER = !CFClient::Mix_OpenAudio; |
646 |
|
|
CFClient::Mix_AllocateChannels 8; |
647 |
root |
1.149 |
CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
648 |
root |
1.134 |
|
649 |
root |
1.153 |
audio_music_finished; |
650 |
root |
1.135 |
|
651 |
root |
1.134 |
while (<$fh>) { |
652 |
|
|
next if /^\s*#/; |
653 |
|
|
next if /^\s*$/; |
654 |
|
|
|
655 |
|
|
my ($file, $volume, $event) = split /\s+/, $_, 3; |
656 |
|
|
|
657 |
|
|
push @SOUNDS, "$volume,$file"; |
658 |
|
|
|
659 |
|
|
$AUDIO_CHUNKS{"$volume,$file"} ||= do { |
660 |
root |
1.146 |
my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
661 |
root |
1.134 |
$chunk->volume ($volume * 128 / 100); |
662 |
|
|
$chunk |
663 |
|
|
}; |
664 |
|
|
} |
665 |
|
|
} else { |
666 |
|
|
status "unable to open sound config: $!"; |
667 |
|
|
} |
668 |
|
|
} |
669 |
|
|
} |
670 |
|
|
|
671 |
|
|
sub audio_shutdown { |
672 |
root |
1.146 |
CFClient::Mix_CloseAudio if $SDL_MIXER; |
673 |
root |
1.134 |
undef $SDL_MIXER; |
674 |
|
|
@SOUNDS = (); |
675 |
|
|
%AUDIO_CHUNKS = (); |
676 |
root |
1.62 |
} |
677 |
|
|
|
678 |
root |
1.87 |
my %animate_object; |
679 |
|
|
my $animate_timer; |
680 |
|
|
|
681 |
|
|
my $want_refresh; |
682 |
|
|
my $can_refresh; |
683 |
|
|
|
684 |
|
|
my $fps = 9; |
685 |
|
|
|
686 |
root |
1.30 |
sub force_refresh { |
687 |
root |
1.87 |
$fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; |
688 |
|
|
debug sprintf "%3.2f", $fps; |
689 |
|
|
|
690 |
root |
1.96 |
$want_refresh = 0; |
691 |
root |
1.87 |
$can_refresh = 0; |
692 |
|
|
|
693 |
root |
1.111 |
$CFClient::UI::ROOT->draw; |
694 |
root |
1.1 |
|
695 |
root |
1.148 |
CFClient::SDL_GL_SwapBuffers; |
696 |
root |
1.87 |
|
697 |
|
|
$LAST_REFRESH = $NOW; |
698 |
root |
1.1 |
} |
699 |
|
|
|
700 |
root |
1.87 |
my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
701 |
|
|
$NOW = time; |
702 |
|
|
|
703 |
root |
1.147 |
($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
704 |
|
|
for CFClient::SDL_PollEvent; |
705 |
root |
1.87 |
|
706 |
|
|
if (%animate_object) { |
707 |
|
|
$_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
708 |
|
|
$want_refresh++; |
709 |
|
|
} |
710 |
|
|
|
711 |
|
|
if ($want_refresh) { |
712 |
|
|
force_refresh; |
713 |
|
|
} else { |
714 |
|
|
$can_refresh = 1; |
715 |
|
|
} |
716 |
|
|
}); |
717 |
root |
1.64 |
|
718 |
root |
1.30 |
sub refresh { |
719 |
root |
1.87 |
$want_refresh++; |
720 |
root |
1.30 |
} |
721 |
|
|
|
722 |
root |
1.45 |
sub animation_start { |
723 |
|
|
my ($widget) = @_; |
724 |
root |
1.87 |
$animate_object{$widget} = $widget; |
725 |
root |
1.45 |
} |
726 |
|
|
|
727 |
|
|
sub animation_stop { |
728 |
|
|
my ($widget) = @_; |
729 |
root |
1.87 |
delete $animate_object{$widget}; |
730 |
root |
1.45 |
} |
731 |
|
|
|
732 |
root |
1.2 |
@conn::ISA = Crossfire::Protocol::; |
733 |
root |
1.1 |
|
734 |
elmex |
1.125 |
sub conn::stats_update { |
735 |
|
|
my ($self, $stats) = @_; |
736 |
|
|
|
737 |
elmex |
1.154 |
update_stats_window ($stats); |
738 |
elmex |
1.125 |
} |
739 |
|
|
|
740 |
root |
1.89 |
sub conn::user_send { |
741 |
root |
1.88 |
my ($self, $command) = @_; |
742 |
|
|
|
743 |
root |
1.123 |
$self->send_command ($command); |
744 |
root |
1.88 |
status $command; |
745 |
|
|
} |
746 |
|
|
|
747 |
root |
1.119 |
sub conn::map_scroll { |
748 |
|
|
my ($self, $dx, $dy) = @_; |
749 |
|
|
|
750 |
|
|
$MAP->scroll ($dx, $dy); |
751 |
|
|
} |
752 |
|
|
|
753 |
root |
1.94 |
sub conn::feed_map1a { |
754 |
|
|
my ($self, $data) = @_; |
755 |
|
|
|
756 |
root |
1.95 |
# $self->Crossfire::Protocol::feed_map1a ($data); |
757 |
root |
1.1 |
|
758 |
root |
1.95 |
$MAP->map1a_update ($data); |
759 |
root |
1.69 |
$MAPWIDGET->update; |
760 |
root |
1.1 |
} |
761 |
|
|
|
762 |
root |
1.116 |
sub conn::flush_map { |
763 |
|
|
my ($self) = @_; |
764 |
|
|
|
765 |
|
|
my $map_info = delete $self->{map_info} |
766 |
|
|
or return; |
767 |
|
|
|
768 |
|
|
my ($hash, $x, $y, $w, $h) = @$map_info; |
769 |
|
|
|
770 |
|
|
my $data = $MAP->get_rect ($x, $y, $w, $h); |
771 |
|
|
$MAPCACHE->put ($hash => Compress::LZF::compress $data); |
772 |
root |
1.152 |
#warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
773 |
root |
1.116 |
} |
774 |
root |
1.1 |
|
775 |
root |
1.2 |
sub conn::map_clear { |
776 |
root |
1.1 |
my ($self) = @_; |
777 |
|
|
|
778 |
root |
1.116 |
$self->flush_map; |
779 |
root |
1.150 |
delete $self->{neigh_map}; |
780 |
root |
1.116 |
|
781 |
root |
1.95 |
$MAP->clear; |
782 |
root |
1.1 |
} |
783 |
|
|
|
784 |
root |
1.116 |
|
785 |
root |
1.119 |
sub conn::load_map($$$) { |
786 |
|
|
my ($self, $hash, $x, $y) = @_; |
787 |
root |
1.115 |
|
788 |
root |
1.116 |
if (defined (my $data = $MAPCACHE->get ($hash))) { |
789 |
|
|
$data = Compress::LZF::decompress $data; |
790 |
root |
1.152 |
#warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
791 |
root |
1.116 |
for my $id ($MAP->set_rect ($x, $y, $data)) { |
792 |
|
|
my $data = $TILECACHE->get ($id) |
793 |
|
|
or next; |
794 |
|
|
|
795 |
|
|
$self->set_texture ($id => $data); |
796 |
|
|
} |
797 |
|
|
} |
798 |
root |
1.115 |
} |
799 |
|
|
|
800 |
root |
1.152 |
# this method does a "flood fill" into every tile direction |
801 |
|
|
# it assumes that tiles are arranged in a rectangular grid, |
802 |
|
|
# i.e. a map is the same as the left of the right map etc. |
803 |
|
|
# failure to comply are harmless and result in display errors |
804 |
|
|
# at worst. |
805 |
root |
1.119 |
sub conn::flood_fill { |
806 |
root |
1.150 |
my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
807 |
root |
1.119 |
|
808 |
root |
1.121 |
# the server does not allow map paths > 6 |
809 |
root |
1.120 |
return if 6 <= length $path; |
810 |
|
|
|
811 |
root |
1.150 |
my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
812 |
|
|
|
813 |
|
|
for ( |
814 |
|
|
[1, 0, -1], |
815 |
|
|
[2, 1, 0], |
816 |
|
|
[3, 0, 1], |
817 |
|
|
[4, -1, 0], |
818 |
|
|
) { |
819 |
|
|
my ($tile, $dx, $dy) = @$_; |
820 |
|
|
|
821 |
|
|
my $gx = $gx + $dx; |
822 |
|
|
my $gy = $gy + $dy; |
823 |
|
|
|
824 |
root |
1.119 |
next unless $flags & (1 << ($tile - 1)); |
825 |
root |
1.150 |
next if $self->{neigh_grid}{$gx, $gy}++; |
826 |
root |
1.119 |
|
827 |
root |
1.150 |
my $neigh = $self->{neigh_map}{$hash} ||= []; |
828 |
|
|
if (my $info = $neigh->[$tile]) { |
829 |
|
|
my ($flags, $x, $y, $w, $h, $hash) = @$info; |
830 |
root |
1.119 |
|
831 |
root |
1.150 |
$self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
832 |
|
|
if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
833 |
|
|
|
834 |
|
|
} else { |
835 |
|
|
$self->send_mapinfo ("spatial $path$tile", sub { |
836 |
|
|
my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
837 |
root |
1.119 |
|
838 |
root |
1.150 |
return if $mode ne "spatial"; |
839 |
root |
1.119 |
|
840 |
root |
1.150 |
$x += $MAP->ox; |
841 |
|
|
$y += $MAP->oy; |
842 |
|
|
|
843 |
|
|
$self->load_map ($hash, $x, $y) |
844 |
|
|
unless $self->{neigh_map}{$hash}[5]++;#d# |
845 |
root |
1.119 |
|
846 |
root |
1.150 |
$neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
847 |
root |
1.119 |
|
848 |
root |
1.150 |
$self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
849 |
|
|
if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
850 |
|
|
}); |
851 |
|
|
} |
852 |
root |
1.119 |
} |
853 |
|
|
} |
854 |
|
|
|
855 |
|
|
sub conn::map_change { |
856 |
|
|
my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
857 |
|
|
|
858 |
|
|
$self->flush_map; |
859 |
|
|
|
860 |
|
|
my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
861 |
|
|
|
862 |
|
|
my $mapmapw = 250; |
863 |
|
|
my $mapmaph = 250; |
864 |
root |
1.150 |
|
865 |
|
|
$self->{neigh_rect} = [ |
866 |
root |
1.152 |
$ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
867 |
|
|
$ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
868 |
root |
1.150 |
]; |
869 |
root |
1.119 |
|
870 |
root |
1.150 |
delete $self->{neigh_grid}; |
871 |
|
|
$self->flood_fill (0, 0, "", $hash, $flags); |
872 |
root |
1.119 |
|
873 |
|
|
$x += $ox; |
874 |
|
|
$y += $oy; |
875 |
|
|
|
876 |
|
|
$self->{map_info} = [$hash, $x, $y, $w, $h]; |
877 |
|
|
|
878 |
|
|
$self->load_map ($hash, $x, $y); |
879 |
|
|
} |
880 |
|
|
|
881 |
root |
1.19 |
sub conn::face_find { |
882 |
root |
1.116 |
my ($self, $facenum, $face) = @_; |
883 |
|
|
|
884 |
|
|
my $hash = "$face->{chksum},$face->{name}"; |
885 |
|
|
|
886 |
|
|
my $id = $FACEMAP->get ($hash); |
887 |
|
|
|
888 |
|
|
unless ($id) { |
889 |
|
|
# create new id for face |
890 |
|
|
# i love transactions |
891 |
|
|
for (1..100) { |
892 |
|
|
my $txn = $CFClient::DB_ENV->txn_begin; |
893 |
|
|
my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW); |
894 |
|
|
if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
895 |
|
|
$id++; |
896 |
|
|
if ($FACEMAP->put (id => $id) == 0 |
897 |
|
|
&& $FACEMAP->put ($hash => $id) == 0) { |
898 |
|
|
$txn->txn_commit; |
899 |
|
|
|
900 |
|
|
goto gotid; |
901 |
|
|
} |
902 |
|
|
} |
903 |
|
|
$txn->abort; |
904 |
|
|
} |
905 |
root |
1.19 |
|
906 |
root |
1.116 |
CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
907 |
|
|
} |
908 |
root |
1.114 |
|
909 |
root |
1.116 |
gotid: |
910 |
|
|
$face->{id} = $id; |
911 |
|
|
$MAP->set_face ($facenum => $id); |
912 |
|
|
$TILECACHE->get ($id) |
913 |
root |
1.19 |
} |
914 |
|
|
|
915 |
root |
1.2 |
sub conn::face_update { |
916 |
root |
1.95 |
my ($self, $facenum, $face) = @_; |
917 |
root |
1.19 |
|
918 |
root |
1.116 |
$TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
919 |
|
|
|
920 |
|
|
$self->set_texture ($face->{id} => delete $face->{image}); |
921 |
|
|
} |
922 |
root |
1.1 |
|
923 |
root |
1.116 |
sub conn::set_texture { |
924 |
|
|
my ($self, $id, $data) = @_; |
925 |
root |
1.95 |
|
926 |
root |
1.116 |
$self->{texture}[$id] ||= do { |
927 |
|
|
my $tex = |
928 |
|
|
new_from_image CFClient::Texture |
929 |
|
|
$data, minify => 1; |
930 |
|
|
|
931 |
|
|
$MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
932 |
|
|
$MAPWIDGET->update; |
933 |
|
|
|
934 |
|
|
$tex |
935 |
|
|
}; |
936 |
root |
1.1 |
} |
937 |
|
|
|
938 |
root |
1.134 |
sub conn::sound_play { |
939 |
|
|
my ($self, $x, $y, $soundnum, $type) = @_; |
940 |
|
|
|
941 |
root |
1.139 |
$SDL_MIXER |
942 |
|
|
or return; |
943 |
|
|
|
944 |
root |
1.134 |
my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
945 |
|
|
or return; |
946 |
|
|
|
947 |
root |
1.146 |
$chunk->play; |
948 |
root |
1.143 |
# warn "sound $x,$y,$soundnum,$type\n";#d# |
949 |
root |
1.134 |
} |
950 |
|
|
|
951 |
root |
1.33 |
sub conn::query { |
952 |
|
|
my ($self, $flags, $prompt) = @_; |
953 |
|
|
|
954 |
root |
1.143 |
#TODO, display dialog with relevant information |
955 |
root |
1.33 |
warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
956 |
|
|
} |
957 |
|
|
|
958 |
root |
1.99 |
sub conn::drawinfo { |
959 |
|
|
my ($self, $color, $text) = @_; |
960 |
|
|
|
961 |
|
|
my @color = ( |
962 |
|
|
[1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
963 |
|
|
[1.00, 1.00, 1.00], |
964 |
root |
1.117 |
[0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
965 |
root |
1.99 |
[1.00, 0.00, 0.00], |
966 |
|
|
[1.00, 0.54, 0.00], |
967 |
|
|
[0.11, 0.56, 1.00], |
968 |
|
|
[0.93, 0.46, 0.00], |
969 |
|
|
[0.18, 0.54, 0.34], |
970 |
|
|
[0.56, 0.73, 0.56], |
971 |
|
|
[0.80, 0.80, 0.80], |
972 |
|
|
[0.55, 0.41, 0.13], |
973 |
|
|
[0.99, 0.77, 0.26], |
974 |
|
|
[0.74, 0.65, 0.41], |
975 |
|
|
); |
976 |
|
|
|
977 |
|
|
$LOGVIEW->add_paragraph ($color[$color], $text); |
978 |
|
|
} |
979 |
|
|
|
980 |
root |
1.144 |
sub conn::spell_add { |
981 |
root |
1.143 |
my ($self, $spell) = @_; |
982 |
|
|
|
983 |
root |
1.144 |
$MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub { |
984 |
|
|
}); |
985 |
|
|
$MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub { |
986 |
|
|
}); |
987 |
|
|
} |
988 |
|
|
|
989 |
|
|
sub conn::spell_delete { |
990 |
|
|
my ($self, $spell) = @_; |
991 |
|
|
} |
992 |
|
|
|
993 |
|
|
sub conn::addme_success { |
994 |
|
|
my ($self) = @_; |
995 |
|
|
|
996 |
|
|
for my $skill (values %{$self->{skill_info}}) { |
997 |
|
|
$MAPWIDGET->add_command ("ready_skill $skill", "", sub { |
998 |
|
|
}); |
999 |
|
|
$MAPWIDGET->add_command ("use_skill $skill", "", sub { |
1000 |
|
|
}); |
1001 |
|
|
} |
1002 |
root |
1.143 |
} |
1003 |
|
|
|
1004 |
root |
1.87 |
%SDL_CB = ( |
1005 |
root |
1.145 |
CFClient::SDL_QUIT => sub { |
1006 |
root |
1.87 |
Event::unloop -1; |
1007 |
|
|
}, |
1008 |
root |
1.145 |
CFClient::SDL_VIDEORESIZE => sub { |
1009 |
root |
1.87 |
}, |
1010 |
root |
1.153 |
CFClient::SDL_VIDEOEXPOSE => \&refresh, |
1011 |
|
|
CFClient::SDL_ACTIVEEVENT => sub { |
1012 |
|
|
# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
1013 |
root |
1.87 |
}, |
1014 |
root |
1.145 |
CFClient::SDL_KEYDOWN => sub { |
1015 |
root |
1.147 |
if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
1016 |
root |
1.87 |
# alt-enter |
1017 |
root |
1.134 |
video_shutdown; |
1018 |
root |
1.99 |
$CFG->{fullscreen} = !$CFG->{fullscreen}; |
1019 |
root |
1.134 |
video_init; |
1020 |
root |
1.87 |
} else { |
1021 |
root |
1.147 |
CFClient::UI::feed_sdl_key_down_event ($_[0]); |
1022 |
elmex |
1.23 |
} |
1023 |
root |
1.87 |
}, |
1024 |
root |
1.153 |
CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
1025 |
|
|
CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
1026 |
|
|
CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
1027 |
|
|
CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
1028 |
|
|
CFClient::SDL_USEREVENT => \&audio_music_finished, |
1029 |
root |
1.87 |
); |
1030 |
elmex |
1.23 |
|
1031 |
root |
1.1 |
############################################################################# |
1032 |
|
|
|
1033 |
root |
1.131 |
$SIG{INT} = $SIG{TERM} = sub { exit }; |
1034 |
|
|
|
1035 |
root |
1.116 |
$TILECACHE = CFClient::db_table "tilecache"; |
1036 |
|
|
$FACEMAP = CFClient::db_table "facemap"; |
1037 |
root |
1.114 |
|
1038 |
root |
1.67 |
CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
1039 |
elmex |
1.10 |
|
1040 |
root |
1.90 |
my %DEF_CFG = ( |
1041 |
root |
1.105 |
sdl_mode => 0, |
1042 |
root |
1.90 |
width => 640, |
1043 |
|
|
height => 480, |
1044 |
root |
1.105 |
fullscreen => 0, |
1045 |
root |
1.90 |
fast => 0, |
1046 |
root |
1.97 |
fow_enable => 1, |
1047 |
root |
1.90 |
fow_intensity => 0.45, |
1048 |
root |
1.92 |
fow_smooth => 0, |
1049 |
root |
1.140 |
gui_fontsize => 1, |
1050 |
root |
1.105 |
log_fontsize => 14, |
1051 |
root |
1.90 |
mapsize => 100, |
1052 |
|
|
host => "crossfire.schmorp.de", |
1053 |
elmex |
1.101 |
say_command => 'say', |
1054 |
root |
1.139 |
audio_enable => 1, |
1055 |
|
|
bgm_enable => 1, |
1056 |
root |
1.149 |
bgm_volume => 0.25, |
1057 |
root |
1.90 |
); |
1058 |
|
|
|
1059 |
|
|
while (my ($k, $v) = each %DEF_CFG) { |
1060 |
|
|
$CFG->{$k} = $v unless exists $CFG->{$k}; |
1061 |
|
|
} |
1062 |
elmex |
1.12 |
|
1063 |
root |
1.89 |
sdl_init; |
1064 |
root |
1.87 |
|
1065 |
root |
1.93 |
@SDL_MODES = reverse |
1066 |
|
|
grep $_->[0] >= 640 && $_->[1] >= 480, |
1067 |
root |
1.145 |
CFClient::SDL_ListModes; |
1068 |
root |
1.87 |
|
1069 |
root |
1.89 |
@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
1070 |
|
|
|
1071 |
|
|
$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
1072 |
|
|
|
1073 |
root |
1.65 |
{ |
1074 |
root |
1.67 |
my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
1075 |
root |
1.65 |
|
1076 |
root |
1.67 |
CFClient::add_font $_ for @fonts; |
1077 |
|
|
CFClient::set_font $fonts[0]; |
1078 |
root |
1.65 |
} |
1079 |
root |
1.40 |
|
1080 |
root |
1.134 |
video_init; |
1081 |
|
|
audio_init; |
1082 |
root |
1.122 |
|
1083 |
root |
1.87 |
Event::loop; |
1084 |
root |
1.19 |
|
1085 |
root |
1.148 |
END { CFClient::SDL_Quit } |
1086 |
root |
1.131 |
|
1087 |
root |
1.82 |
|