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