ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.169
Committed: Mon Apr 24 02:41:48 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.168: +59 -28 lines
Log Message:
implmenet map scale - now fully playability at 640x480

File Contents

# User Rev Content
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.168 our $FONT_PROP;
43     our $FONT_FIXED;
44    
45 root 1.95 our $MAP;
46 root 1.69 our $MAPWIDGET;
47 root 1.112 our $BUTTONBAR;
48     our $LOGVIEW;
49     our $CONSOLE;
50     our $METASERVER;
51 root 1.57
52 elmex 1.125 our $GAUGES;
53 elmex 1.154 our $STATWIDS;
54 elmex 1.125
55 root 1.86 our $SDL_ACTIVE;
56 root 1.13 our %SDL_CB;
57 root 1.18
58 root 1.134 our $SDL_MIXER;
59     our @SOUNDS; # event => file mapping
60     our %AUDIO_CHUNKS; # audio files
61    
62 root 1.30 our $ALT_ENTER_MESSAGE;
63 root 1.51 our $STATUS_LINE;
64 root 1.64 our $DEBUG_STATUS;
65 root 1.30
66 root 1.82 sub status {
67     $STATUS_LINE->set_text ($_[0]);
68 root 1.128 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
69 root 1.82 }
70    
71     sub debug {
72     $DEBUG_STATUS->set_text ($_[0]);
73 root 1.128 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
74 root 1.82 }
75    
76 root 1.84 sub start_game {
77 root 1.85 status "logging in...";
78    
79 root 1.106 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
80 root 1.84
81 root 1.116 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
82    
83 root 1.95 $MAP = new CFClient::Map $mapsize, $mapsize;
84 root 1.112
85     my ($host, $port) = split /:/, $CFG->{host};
86 root 1.95
87 root 1.84 $CONN = new conn
88 root 1.112 host => $host,
89     port => $port || 13327,
90 root 1.84 user => $CFG->{user},
91     pass => $CFG->{password},
92     mapw => $mapsize,
93     maph => $mapsize,
94     ;
95    
96 root 1.85 status "login successful";
97    
98 root 1.84 CFClient::lowdelay fileno $CONN->{fh};
99     }
100    
101     sub stop_game {
102     undef $CONN;
103     }
104    
105 root 1.111 sub client_setup {
106 root 1.99 my $dialog = new CFClient::UI::FancyFrame
107 root 1.150 title => "Client Setup",
108 root 1.81 child => (my $vbox = new CFClient::UI::VBox);
109     $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
110    
111 root 1.140 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
112 root 1.81 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
113    
114     $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
115 root 1.150 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
116 root 1.81
117     $mode_slider->connect (changed => sub {
118     my ($self, $value) = @_;
119    
120     $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
121     $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
122     });
123     $mode_slider->emit (changed => $mode_slider->{range}[0]);
124 root 1.82
125 elmex 1.158 my $row = 1;
126    
127     $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
128 elmex 1.166 $table->add (1, $row++, new CFClient::UI::CheckBox
129     state => $CFG->{fullscreen},
130     tooltip => "Bring the client into fullscreen mode",
131     connect_changed => sub {
132     my ($self, $value) = @_;
133     $CFG->{fullscreen} = $value;
134     }
135     );
136 root 1.85
137 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
138 root 1.163 $table->add (1, $row++, new CFClient::UI::CheckBox
139     state => $CFG->{fast},
140     tooltip => "Lower the visual quality considerably to speed up rendering.",
141     connect_changed => sub {
142     my ($self, $value) = @_;
143     $CFG->{fast} = $value;
144     }
145     );
146 root 1.89
147 root 1.169 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale");
148     $table->add (1, $row++, new CFClient::UI::Slider
149     range => [$CFG->{map_scale}, 0.25, 2, 0.05],
150     tooltip => "Enlarge or shrink the displayed map",
151     connect_changed => sub {
152     my ($self, $value) = @_;
153     $CFG->{map_scale} = 0.05 * int $value / 0.05;
154     }
155     );
156    
157 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
158 root 1.163 $table->add (1, $row++, new CFClient::UI::CheckBox
159     state => $CFG->{fow_enable},
160     tooltip => "Fog-of-War marks areas that cannot be seen by the player",
161     connect_changed => sub {
162     my ($self, $value) = @_;
163     $CFG->{fow_enable} = $value;
164     }
165     );
166 root 1.97
167 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
168 root 1.163 $table->add (1, $row++, new CFClient::UI::Slider
169     range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001],
170     tooltip => "The higher the intensity, the lighter the Fog-of-War color",
171     connect_changed => sub {
172     my ($self, $value) = @_;
173     $CFG->{fow_intensity} = $value;
174     }
175     );
176 root 1.90
177 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
178 root 1.163 $table->add (1, $row++, new CFClient::UI::CheckBox
179     state => $CFG->{fow_smooth},
180     tooltip => "Smooth the Fog-of-War a bit to make it more realistic",
181     connect_changed => sub {
182     my ($self, $value) = @_;
183     $CFG->{fow_smooth} = $value;
184     status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
185     }
186     );
187 root 1.91
188 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
189 root 1.163 $table->add (1, $row++, new CFClient::UI::Slider
190     range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1],
191     tooltip => "The font size used by most GUI elements",
192     connect_changed => sub {
193     $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
194 root 1.140 # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
195 root 1.163 }
196     );
197 root 1.140
198 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
199 root 1.163 $table->add (1, $row++, new CFClient::UI::Slider
200     range => [$CFG->{log_fontsize}, 0.5, 2, 0.1],
201     tooltip => "The font size used by the server log window only",
202     connect_changed => sub {
203     $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
204     }
205     );
206 root 1.105
207 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize");
208 root 1.163
209     $table->add (1, $row++, new CFClient::UI::Slider
210     range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1],
211     tooltip => "The font size used by the statistics window only",
212     connect_changed => sub {
213     $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10;
214     &set_stats_window_fontsize;
215     }
216     );
217 elmex 1.157
218 root 1.163 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size");
219     $table->add (1, $row++, new CFClient::UI::Slider
220     range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02],
221     tooltip => "Adjust the size of the stats gauges at the bottom right",
222     connect_changed => sub {
223     $CFG->{gauge_size} = $_[1];
224 root 1.164 my $h = int $HEIGHT * $CFG->{gauge_size};
225 root 1.163 $GAUGES->{win}->set_size ($WIDTH, $h);
226 root 1.164 $GAUGES->{win}->move (0, $HEIGHT - $h);
227 root 1.163 }
228     );
229 elmex 1.158
230     $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize");
231 root 1.163 $table->add (1, $row++, new CFClient::UI::Slider
232     range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1],
233 elmex 1.166 tooltip => "Adjusts the fontsize of the gauges at the bottom right",
234 root 1.163 connect_changed => sub {
235     $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10;
236     &set_gauge_window_fontsize;
237     }
238     );
239 elmex 1.158
240 root 1.163 $table->add (1, $row++, new CFClient::UI::Button
241     expand => 1, align => 0, text => "Apply",
242 root 1.168 tooltip => "Apply the video settings",
243 root 1.163 connect_activate => sub {
244     video_shutdown ();
245     video_init ();
246     }
247     );
248 root 1.111
249 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
250 root 1.163 $table->add (1, $row++, new CFClient::UI::CheckBox
251     state => $CFG->{audio_enable},
252     tooltip => "If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.",
253     connect_changed => sub {
254     $CFG->{audio_enable} = $_[1];
255     }
256     );
257 root 1.140 # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
258     # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
259     # $CFG->{effects_volume} = $_[1];
260     # });
261 elmex 1.158 $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
262     $table->add (1, $row++, my $hbox = new CFClient::UI::HBox);
263 root 1.163 $hbox->add (new CFClient::UI::CheckBox
264     expand => 1, state => $CFG->{bgm_enable},
265     tooltip => "Enable background music playing",
266     connect_changed => sub {
267     $CFG->{bgm_enable} = $_[1];
268     }
269     );
270     $hbox->add (new CFClient::UI::Slider
271     expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1],
272     tooltip => "The volume of the background music",
273     connect_changed => sub {
274     $CFG->{bgm_volume} = $_[1];
275     CFClient::MixMusic::volume $_[1] * 128;
276     }
277     );
278 root 1.140
279 root 1.163 $table->add (1, $row++, new CFClient::UI::Button
280     expand => 1, align => 0, text => "Apply",
281 root 1.168 tooltip => "Apply the audio settings",
282 root 1.163 connect_activate => sub {
283     audio_shutdown ();
284     audio_init ();
285     }
286     );
287 elmex 1.137
288 root 1.111 $dialog
289     }
290    
291 elmex 1.157 sub set_stats_window_fontsize {
292 elmex 1.158 for (values %{$STATWIDS}) {
293 elmex 1.157 $_->set_fontsize ($::CFG->{stat_fontsize});
294     }
295     }
296    
297 elmex 1.158 sub set_gauge_window_fontsize {
298     for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) {
299     $_->set_fontsize ($::CFG->{gauge_fontsize});
300     }
301 root 1.169
302     # local $GAUGES->{win}{parent};#d#
303     # use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D;
304 elmex 1.158 }
305    
306     sub make_gauge_window {
307     my $gh = int ($HEIGHT * $CFG->{gauge_size});
308 elmex 1.161 # my $gw = int ($WIDTH * $CFG->{gauge_w_size});
309 elmex 1.158
310     my $win = new CFClient::UI::Frame (
311 root 1.169 y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh
312 elmex 1.158 );
313     $win->add (my $vb = new CFClient::UI::VBox);
314    
315 elmex 1.161 $vb->add (my $hbg = new CFClient::UI::HBox expand => 1);
316    
317     $hbg->add (new CFClient::UI::Empty expand => 1);
318     $hbg->add (my $hb = new CFClient::UI::HBox);
319 elmex 1.166 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', tooltip => "Health points");
320     $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', tooltip => "Spellpoints");
321     $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', tooltip => "Grace");
322     $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', tooltip => "Food");
323 elmex 1.161
324 elmex 1.166 $vb->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, text => "XP: 0 LVL: 0");
325 elmex 1.161 $vb->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, text => "Rng:");
326 elmex 1.158
327     $GAUGES = {
328 elmex 1.166 exp => $exp, win => $win, range => $rng,
329 elmex 1.158 food => $fg, mana => $mg, hp => $hg, grace => $gg
330     };
331 root 1.169
332     &set_gauge_window_fontsize;
333    
334 elmex 1.158 $win
335     }
336    
337 elmex 1.154 sub make_stats_window {
338 elmex 1.156 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats");
339 root 1.155
340     $tgw->add (my $vb = new CFClient::UI::VBox);
341 root 1.168 $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1);
342     $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
343 elmex 1.156
344     $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
345    
346     $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
347    
348 root 1.168 $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
349     $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
350     $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
351     $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
352     $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
353     $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
354     $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30");
355    
356     $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Str");
357     $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dex");
358     $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Con");
359     $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Int");
360     $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wis");
361     $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Pow");
362     $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Cha");
363    
364     $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120");
365     $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120");
366     $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120");
367     $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120");
368     $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54");
369     $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9");
370    
371     $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc");
372     $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac");
373     $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam");
374     $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm");
375     $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp");
376     $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp");
377 root 1.155
378 elmex 1.158 $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1);
379 root 1.155
380 elmex 1.156 my $row = 0;
381     my $col = 0;
382 root 1.155
383 elmex 1.166 my %resist_names = (
384     slow => "Slow",
385     holyw => "Holy Word",
386     conf => "Confusion",
387     fire => "Fire",
388     depl => "Depletion",
389     magic => "Magic",
390     drain => "Draining",
391     acid => "Acid",
392     pois => "Poison",
393     para => "Paralysation",
394     deat => "Death",
395     phys => "Physical",
396     blind => "Blind",
397     fear => "Fear",
398     tund => "Turn undead",
399     elec => "Electricity",
400     cold => "Cold",
401     ghit => "Ghost hit",
402     );
403 elmex 1.156 for (qw/slow holyw conf fire depl magic
404     drain acid pois para deat phys
405     blind fear tund elec cold ghit/)
406     {
407 root 1.164 $tbl2->add ($col, $row,
408 elmex 1.156 $STATWIDS->{"res_$_"} =
409 root 1.168 new CFClient::UI::Label
410     template => "-100%",
411     align => +1,
412     valign => 0,
413     tooltip => $resist_names{$_}
414     );
415     $tbl2->add ($col + 1, $row, new CFClient::UI::Image
416     can_hover => 1,
417     can_events => 1,
418     image => "ui/resist/resist_$_.png",
419     tooltip => $resist_names{$_}
420 elmex 1.156 );
421    
422     $row++;
423     if ($row % 6 == 0) {
424     $col += 2;
425     $row = 0;
426     }
427     }
428    
429 elmex 1.157 &set_stats_window_fontsize;
430 elmex 1.156 update_stats_window ({});
431 root 1.155
432 elmex 1.154 $tgw
433     }
434    
435 root 1.169 sub formsep {
436     reverse join ",", grep length, split /(...)/, reverse $_[0] * 1
437     }
438    
439 elmex 1.154 sub update_stats_window {
440     my ($stats) = @_;
441    
442 elmex 1.156 # i love text protocols!!!
443 root 1.169 my $hp = $stats->{Crossfire::Protocol::CS_STAT_HP} * 1;
444     my $hp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXHP} * 1;
445     my $sp = $stats->{Crossfire::Protocol::CS_STAT_SP} * 1;
446     my $sp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXSP} * 1;
447     my $fo = $stats->{Crossfire::Protocol::CS_STAT_FOOD} * 1;
448 elmex 1.156 my $fo_m = 999;
449 root 1.169 my $gr = $stats->{Crossfire::Protocol::CS_STAT_GRACE} * 1;
450     my $gr_m = $stats->{Crossfire::Protocol::CS_STAT_MAXGRACE} * 1;
451 elmex 1.156
452     $GAUGES->{hp} ->set_value ($hp, $hp_m);
453     $GAUGES->{mana} ->set_value ($sp, $sp_m);
454     $GAUGES->{food} ->set_value ($fo, $fo_m);
455     $GAUGES->{grace} ->set_value ($gr, $gr_m);
456 root 1.169 $GAUGES->{exp} ->set_text ("Exp: " . (formsep $stats->{Crossfire::Protocol::CS_STAT_EXP64})
457     . " (lvl " . ($stats->{Crossfire::Protocol::CS_STAT_LEVEL} * 1) . ")");
458     my $rng = $stats->{Crossfire::Protocol::CS_STAT_RANGE};
459 elmex 1.159 $rng =~ s/^Range: //; # thank you so much dear server
460     $GAUGES->{range} ->set_text ("Rng: " . $rng);
461 root 1.169 my $title = $stats->{Crossfire::Protocol::CS_STAT_TITLE};
462 elmex 1.165 $title =~ s/^Player: //;
463     $STATWIDS->{title} ->set_text ("Title: " . $title);
464 elmex 1.156
465 root 1.169 $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5});
466     $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8});
467     $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9});
468     $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6});
469     $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7});
470     $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22});
471     $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10});
472     $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13});
473     $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14});
474     $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15});
475     $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16});
476     $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_SPEED});
477     $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_WEAP_SP});
478 elmex 1.156
479     my %tbl = (
480     phys => 100,
481     magic => 101,
482     fire => 102,
483     elec => 103,
484     cold => 104,
485     conf => 105,
486     acid => 106,
487     drain => 107,
488     ghit => 108,
489     pois => 109,
490     slow => 110,
491     para => 111,
492     tund => 112,
493     fear => 113,
494 elmex 1.165 depl => 113,
495 elmex 1.156 deat => 115,
496     holyw => 116,
497     blind => 117
498 elmex 1.154 );
499 elmex 1.156
500     for (keys %tbl) {
501     $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}});
502     }
503    
504 elmex 1.154 }
505    
506 root 1.112 sub metaserver_dialog {
507     my $dialog = new CFClient::UI::FancyFrame
508 root 1.150 title => "Metaserver",
509 root 1.112 child => (my $vbox = new CFClient::UI::VBox);
510    
511     $vbox->add ($dialog->{table} = new CFClient::UI::Table);
512    
513     $dialog
514     }
515    
516     sub update_metaserver {
517 root 1.114 my ($HOST) = @_;
518    
519 root 1.112 status "fetching metaserver list...";
520    
521     my $buf;
522    
523     my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
524    
525     Event->io (fd => $fh, poll => 'r', cb => sub {
526     my $res = sysread $fh, $buf, 8192, length $buf;
527    
528     if (!defined $res) {
529     $_[0]->w->cancel;
530     status "metaserver: $!";
531     } elsif ($res == 0) {
532     $_[0]->w->cancel;
533     status "server list retrieved";
534 root 1.113
535     my $table = $METASERVER->{table};
536    
537     $table->clear;
538    
539 root 1.114 my @col = qw(Use #Users Host Uptime Version Description);
540 root 1.113 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_])
541     for 0 .. $#col;
542    
543     my @align = qw(1 0 1 1 -1);
544    
545     my $y = 0;
546 root 1.114 for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) {
547 root 1.113 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m;
548    
549     for ($desc) {
550     s/<br>/\n/gi;
551     s/<li>/\n· /gi;
552     s/<.*?>//sgi;
553     s/&/&amp;/g;
554     s/</&lt;/g;
555     s/>/&gt;/g;
556     }
557    
558     $uptime = sprintf "%dd %02d:%02d:%02d",
559     (int $m->[8] / 86400),
560     (int $m->[8] / 3600) % 24,
561     (int $m->[8] / 60) % 60,
562     $m->[8] % 60;
563    
564     $m = [$users, $host, $uptime, $version, $desc];
565    
566     $y++;
567 root 1.114
568     $table->add (0, $y, new CFClient::UI::VBox children => [
569     (new CFClient::UI::Button text => " ", connect_activate => sub {
570     $HOST->set_text ($CFG->{host} = $host);
571     }),
572     (new CFClient::UI::Empty expand => 1),
573     ]);
574    
575 root 1.140 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
576 root 1.113 for 0 .. $#$m;
577     }
578 root 1.112 }
579     });
580     }
581    
582 root 1.111 sub server_setup {
583     my $dialog = new CFClient::UI::FancyFrame
584 root 1.150 title => "Server Setup",
585 root 1.111 child => (my $vbox = new CFClient::UI::VBox);
586 root 1.81
587 root 1.82 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
588 root 1.141 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
589 root 1.112
590     {
591     $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
592    
593 elmex 1.166 $vbox->add (
594     my $HOST = new CFClient::UI::Entry
595     expand => 1,
596     text => $CFG->{host},
597     tooltip => "The hostname or ip address of the Crossfire(+) server to connect to",
598     connect_changed => sub {
599     my ($self, $value) = @_;
600     $CFG->{host} = $value;
601     }
602     );
603 root 1.112
604     $METASERVER = metaserver_dialog;
605 elmex 1.101
606 elmex 1.166 $vbox->add (new CFClient::UI::Flopper
607     expand => 1,
608     text => "Metaserver",
609     other => $METASERVER,
610 root 1.167 tooltip => "Show a list of avaible crossfire servers",
611 elmex 1.166 connect_open => sub {
612     update_metaserver $HOST;
613     }
614     );
615 root 1.112 }
616 root 1.81
617 root 1.141 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
618 elmex 1.166 $table->add (1, 4, new CFClient::UI::Entry
619     text => $CFG->{user},
620     tooltip => "The name of your character on the server",
621     connect_changed => sub {
622     my ($self, $value) = @_;
623     $CFG->{user} = $value;
624     }
625     );
626 root 1.81
627 root 1.141 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
628 elmex 1.166 $table->add (1, 5, new CFClient::UI::Entry
629     text => $CFG->{password},
630     hidden => 1,
631     tooltip => "The password for your character",
632     connect_changed => sub {
633     my ($self, $value) = @_;
634     $CFG->{password} = $value;
635     }
636     );
637 elmex 1.101
638 root 1.141 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
639 elmex 1.166 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry
640     text => $CFG->{say_command},
641     tooltip => "This is the command that will be used if you write a line in the message window entry. "
642     ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. "
643     ."But you could also set it to 'tell <playername>' to only chat with that user.",
644     connect_changed => sub {
645     my ($self, $value) = @_;
646     $CFG->{say_command} = $value;
647     }
648     );
649 root 1.81
650 root 1.141 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
651 elmex 1.101 $table->add (1, 7, new CFClient::UI::Slider
652 root 1.81 req_w => 100,
653     range => [$CFG->{mapsize}, 10, 100 + 1, 1],
654 elmex 1.166 tooltip => "This is the size of the portion of the map update the server sends you. "
655     ."If you set this to a high value you will be able to see further for example.",
656 root 1.81 connect_changed => sub {
657     my ($self, $value) = @_;
658    
659     $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
660     },
661     );
662    
663 elmex 1.101 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
664 root 1.84 start_game;
665 root 1.82 });
666    
667 root 1.98 $dialog
668 root 1.81 }
669 root 1.58
670 root 1.111 sub message_window {
671 root 1.99 my $window = new CFClient::UI::FancyFrame
672 root 1.150 title => "Messages",
673 root 1.99 border_bg => [1, 1, 1, 0.5],
674     bg => [0.3, 0.3, 0.3, 0.8],
675 root 1.124 user_w => int $::WIDTH / 3,
676     user_h => int $::HEIGHT / 5,
677 root 1.99 child => (my $vbox = new CFClient::UI::VBox);
678    
679 root 1.105 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
680     expand => 1,
681 root 1.168 font => $FONT_FIXED,
682 root 1.105 fontsize => $::CFG->{log_fontsize},
683     );
684    
685 root 1.122 $vbox->add (my $input = new CFClient::UI::Entry
686 elmex 1.118 connect_focus_in => sub {
687     my ($input, $prev_focus) = @_;
688    
689     delete $input->{refocus_map};
690    
691     if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
692     $input->{refocus_map} = 1;
693     }
694     delete $input->{auto_activated};
695     },
696 root 1.116 connect_activate => sub {
697 elmex 1.100 my ($input, $text) = @_;
698     $input->set_text ('');
699    
700     if ($text =~ /^\/(.*)/) {
701 root 1.123 $::CONN->user_send ($1);
702 elmex 1.100 } else {
703 elmex 1.101 my $say_cmd = $::CFG->{say_command} || 'say';
704 root 1.123 $::CONN->user_send ("$say_cmd $text");
705 elmex 1.100 }
706 elmex 1.118 if ($input->{refocus_map}) {
707     delete $input->{refocus_map};
708     $MAPWIDGET->focus_in
709     }
710 root 1.116 },
711     connect_escape => sub {
712 elmex 1.102 $MAPWIDGET->focus_in
713 root 1.116 },
714     );
715 elmex 1.102
716     $CONSOLE = {
717     window => $window,
718     input => $input
719     };
720 root 1.99
721     $window
722     }
723    
724 root 1.89 sub sdl_init {
725 root 1.145 CFClient::SDL_Init
726 root 1.89 and die "SDL::Init failed!\n";
727     }
728    
729 root 1.134 sub video_init {
730 root 1.89 sdl_init;
731    
732 root 1.84 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
733     $FULLSCREEN = $CFG->{fullscreen};
734 root 1.89 $FAST = $CFG->{fast};
735 root 1.84
736 root 1.145 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
737     or die "SDL_SetVideoMode failed!\n";
738 root 1.2
739 root 1.86 $SDL_ACTIVE = 1;
740    
741 root 1.87 $LAST_REFRESH = time - 0.01;
742 root 1.45
743 root 1.67 CFClient::gl_init;
744 root 1.30
745 root 1.140 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
746 root 1.39
747 root 1.52 #############################################################################
748    
749 root 1.99 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
750 root 1.140 $DEBUG_STATUS->show;
751 root 1.52
752 root 1.72 $STATUS_LINE = new CFClient::UI::Label
753 root 1.77 padding => 0,
754 root 1.140 y => $HEIGHT - $FONTSIZE * 1.8;
755     $STATUS_LINE->show;
756 root 1.51
757 root 1.72 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
758 root 1.123 padding => 0,
759 root 1.140 fontsize => 0.8,
760 root 1.123 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
761 root 1.140 $ALT_ENTER_MESSAGE->show;
762     $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
763 root 1.30
764 root 1.141 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
765 root 1.69 $MAPWIDGET->focus_in;
766 elmex 1.102 $MAPWIDGET->connect (activate_console => sub {
767 elmex 1.103 my ($mapwidget, $preset) = @_;
768    
769 elmex 1.102 if ($CONSOLE) {
770 elmex 1.118 $CONSOLE->{input}->{auto_activated} = 1;
771 elmex 1.102 $CONSOLE->{input}->focus_in;
772 elmex 1.103
773     if ($preset && $CONSOLE->{input}->get_text eq '') {
774     $CONSOLE->{input}->set_text ($preset);
775     }
776 elmex 1.102 }
777     });
778 root 1.81
779 root 1.111 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
780    
781     $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
782     $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
783     $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
784    
785 root 1.167 $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
786     $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
787    
788 root 1.111 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
789     CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
790     status "Configuration Saved";
791     });
792 root 1.98
793 root 1.119 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
794 root 1.2 }
795    
796 root 1.134 sub video_shutdown {
797 root 1.111 $CFClient::UI::ROOT->{children} = [];
798 root 1.86 undef $SDL_ACTIVE;
799 root 1.134 }
800    
801 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#
802 root 1.135 my $bgmusic;#TODO#hack#d#
803    
804 root 1.153 sub audio_music_finished {
805     return unless $CFG->{bgm_enable};
806    
807     # TODO: hack, do play loop and mood music
808     $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
809     $bgmusic->play (0);
810    
811     push @bgmusic, shift @bgmusic;
812     }
813    
814 root 1.134 sub audio_init {
815 root 1.139 if ($CFG->{audio_enable}) {
816 root 1.134 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
817 root 1.146 $SDL_MIXER = !CFClient::Mix_OpenAudio;
818     CFClient::Mix_AllocateChannels 8;
819 root 1.149 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
820 root 1.134
821 root 1.153 audio_music_finished;
822 root 1.135
823 root 1.134 while (<$fh>) {
824     next if /^\s*#/;
825     next if /^\s*$/;
826    
827     my ($file, $volume, $event) = split /\s+/, $_, 3;
828    
829     push @SOUNDS, "$volume,$file";
830    
831     $AUDIO_CHUNKS{"$volume,$file"} ||= do {
832 root 1.146 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
833 root 1.134 $chunk->volume ($volume * 128 / 100);
834     $chunk
835     };
836     }
837     } else {
838     status "unable to open sound config: $!";
839     }
840     }
841     }
842    
843     sub audio_shutdown {
844 root 1.146 CFClient::Mix_CloseAudio if $SDL_MIXER;
845 root 1.134 undef $SDL_MIXER;
846     @SOUNDS = ();
847     %AUDIO_CHUNKS = ();
848 root 1.62 }
849    
850 root 1.87 my %animate_object;
851     my $animate_timer;
852    
853     my $want_refresh;
854     my $can_refresh;
855    
856     my $fps = 9;
857    
858 root 1.30 sub force_refresh {
859 root 1.87 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
860     debug sprintf "%3.2f", $fps;
861    
862 root 1.96 $want_refresh = 0;
863 root 1.87 $can_refresh = 0;
864    
865 root 1.111 $CFClient::UI::ROOT->draw;
866 root 1.1
867 root 1.148 CFClient::SDL_GL_SwapBuffers;
868 root 1.87
869     $LAST_REFRESH = $NOW;
870 root 1.1 }
871    
872 root 1.87 my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
873     $NOW = time;
874    
875 root 1.147 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
876     for CFClient::SDL_PollEvent;
877 root 1.87
878     if (%animate_object) {
879     $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
880     $want_refresh++;
881     }
882    
883     if ($want_refresh) {
884     force_refresh;
885     } else {
886     $can_refresh = 1;
887     }
888     });
889 root 1.64
890 root 1.30 sub refresh {
891 root 1.87 $want_refresh++;
892 root 1.30 }
893    
894 root 1.45 sub animation_start {
895     my ($widget) = @_;
896 root 1.87 $animate_object{$widget} = $widget;
897 root 1.45 }
898    
899     sub animation_stop {
900     my ($widget) = @_;
901 root 1.87 delete $animate_object{$widget};
902 root 1.45 }
903    
904 root 1.2 @conn::ISA = Crossfire::Protocol::;
905 root 1.1
906 elmex 1.125 sub conn::stats_update {
907     my ($self, $stats) = @_;
908    
909 elmex 1.154 update_stats_window ($stats);
910 elmex 1.125 }
911    
912 root 1.89 sub conn::user_send {
913 root 1.88 my ($self, $command) = @_;
914    
915 root 1.123 $self->send_command ($command);
916 root 1.88 status $command;
917     }
918    
919 root 1.119 sub conn::map_scroll {
920     my ($self, $dx, $dy) = @_;
921    
922     $MAP->scroll ($dx, $dy);
923     }
924    
925 root 1.94 sub conn::feed_map1a {
926     my ($self, $data) = @_;
927    
928 root 1.95 # $self->Crossfire::Protocol::feed_map1a ($data);
929 root 1.1
930 root 1.95 $MAP->map1a_update ($data);
931 root 1.69 $MAPWIDGET->update;
932 root 1.1 }
933    
934 root 1.116 sub conn::flush_map {
935     my ($self) = @_;
936    
937     my $map_info = delete $self->{map_info}
938     or return;
939    
940     my ($hash, $x, $y, $w, $h) = @$map_info;
941    
942     my $data = $MAP->get_rect ($x, $y, $w, $h);
943     $MAPCACHE->put ($hash => Compress::LZF::compress $data);
944 root 1.152 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
945 root 1.116 }
946 root 1.1
947 root 1.2 sub conn::map_clear {
948 root 1.1 my ($self) = @_;
949    
950 root 1.116 $self->flush_map;
951 root 1.150 delete $self->{neigh_map};
952 root 1.116
953 root 1.95 $MAP->clear;
954 root 1.1 }
955    
956 root 1.116
957 root 1.119 sub conn::load_map($$$) {
958     my ($self, $hash, $x, $y) = @_;
959 root 1.115
960 root 1.116 if (defined (my $data = $MAPCACHE->get ($hash))) {
961     $data = Compress::LZF::decompress $data;
962 root 1.152 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
963 root 1.116 for my $id ($MAP->set_rect ($x, $y, $data)) {
964     my $data = $TILECACHE->get ($id)
965     or next;
966    
967     $self->set_texture ($id => $data);
968     }
969     }
970 root 1.115 }
971    
972 root 1.152 # this method does a "flood fill" into every tile direction
973     # it assumes that tiles are arranged in a rectangular grid,
974     # i.e. a map is the same as the left of the right map etc.
975     # failure to comply are harmless and result in display errors
976     # at worst.
977 root 1.119 sub conn::flood_fill {
978 root 1.150 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
979 root 1.119
980 root 1.121 # the server does not allow map paths > 6
981 root 1.120 return if 6 <= length $path;
982    
983 root 1.150 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
984    
985     for (
986     [1, 0, -1],
987     [2, 1, 0],
988     [3, 0, 1],
989     [4, -1, 0],
990     ) {
991     my ($tile, $dx, $dy) = @$_;
992    
993     my $gx = $gx + $dx;
994     my $gy = $gy + $dy;
995    
996 root 1.119 next unless $flags & (1 << ($tile - 1));
997 root 1.150 next if $self->{neigh_grid}{$gx, $gy}++;
998 root 1.119
999 root 1.150 my $neigh = $self->{neigh_map}{$hash} ||= [];
1000     if (my $info = $neigh->[$tile]) {
1001     my ($flags, $x, $y, $w, $h, $hash) = @$info;
1002 root 1.119
1003 root 1.150 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
1004     if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
1005    
1006     } else {
1007     $self->send_mapinfo ("spatial $path$tile", sub {
1008     my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
1009 root 1.119
1010 root 1.150 return if $mode ne "spatial";
1011 root 1.119
1012 root 1.150 $x += $MAP->ox;
1013     $y += $MAP->oy;
1014    
1015     $self->load_map ($hash, $x, $y)
1016     unless $self->{neigh_map}{$hash}[5]++;#d#
1017 root 1.119
1018 root 1.150 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
1019 root 1.119
1020 root 1.150 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
1021     if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
1022     });
1023     }
1024 root 1.119 }
1025     }
1026    
1027     sub conn::map_change {
1028     my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
1029    
1030     $self->flush_map;
1031    
1032     my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
1033    
1034     my $mapmapw = 250;
1035     my $mapmaph = 250;
1036 root 1.150
1037     $self->{neigh_rect} = [
1038 root 1.152 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
1039     $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
1040 root 1.150 ];
1041 root 1.119
1042 root 1.150 delete $self->{neigh_grid};
1043     $self->flood_fill (0, 0, "", $hash, $flags);
1044 root 1.119
1045     $x += $ox;
1046     $y += $oy;
1047    
1048     $self->{map_info} = [$hash, $x, $y, $w, $h];
1049    
1050 elmex 1.158 my $map = $self->{map_info}[0];
1051     $map =~ s/^.*?\/([^\/]+)$/\1/;
1052     $STATWIDS->{map}->set_text ("Map: " . $map);
1053 elmex 1.157
1054 root 1.119 $self->load_map ($hash, $x, $y);
1055     }
1056    
1057 root 1.19 sub conn::face_find {
1058 root 1.116 my ($self, $facenum, $face) = @_;
1059    
1060     my $hash = "$face->{chksum},$face->{name}";
1061    
1062     my $id = $FACEMAP->get ($hash);
1063    
1064     unless ($id) {
1065     # create new id for face
1066     # i love transactions
1067     for (1..100) {
1068     my $txn = $CFClient::DB_ENV->txn_begin;
1069     my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW);
1070     if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
1071     $id++;
1072     if ($FACEMAP->put (id => $id) == 0
1073     && $FACEMAP->put ($hash => $id) == 0) {
1074     $txn->txn_commit;
1075    
1076     goto gotid;
1077     }
1078     }
1079     $txn->abort;
1080     }
1081 root 1.19
1082 root 1.116 CFClient::fatal "maximum number of transaction retries reached - database problems?";
1083     }
1084 root 1.114
1085 root 1.116 gotid:
1086     $face->{id} = $id;
1087     $MAP->set_face ($facenum => $id);
1088     $TILECACHE->get ($id)
1089 root 1.19 }
1090    
1091 root 1.2 sub conn::face_update {
1092 root 1.95 my ($self, $facenum, $face) = @_;
1093 root 1.19
1094 root 1.116 $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes
1095    
1096     $self->set_texture ($face->{id} => delete $face->{image});
1097     }
1098 root 1.1
1099 root 1.116 sub conn::set_texture {
1100     my ($self, $id, $data) = @_;
1101 root 1.95
1102 root 1.116 $self->{texture}[$id] ||= do {
1103     my $tex =
1104     new_from_image CFClient::Texture
1105     $data, minify => 1;
1106    
1107     $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
1108     $MAPWIDGET->update;
1109    
1110     $tex
1111     };
1112 root 1.1 }
1113    
1114 root 1.134 sub conn::sound_play {
1115     my ($self, $x, $y, $soundnum, $type) = @_;
1116    
1117 root 1.139 $SDL_MIXER
1118     or return;
1119    
1120 root 1.134 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
1121     or return;
1122    
1123 root 1.146 $chunk->play;
1124 root 1.143 # warn "sound $x,$y,$soundnum,$type\n";#d#
1125 root 1.134 }
1126    
1127 root 1.33 sub conn::query {
1128     my ($self, $flags, $prompt) = @_;
1129    
1130 root 1.143 #TODO, display dialog with relevant information
1131 root 1.33 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
1132     }
1133    
1134 root 1.99 sub conn::drawinfo {
1135     my ($self, $color, $text) = @_;
1136    
1137     my @color = (
1138     [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
1139     [1.00, 1.00, 1.00],
1140 root 1.117 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
1141 root 1.99 [1.00, 0.00, 0.00],
1142     [1.00, 0.54, 0.00],
1143     [0.11, 0.56, 1.00],
1144     [0.93, 0.46, 0.00],
1145     [0.18, 0.54, 0.34],
1146     [0.56, 0.73, 0.56],
1147     [0.80, 0.80, 0.80],
1148     [0.55, 0.41, 0.13],
1149     [0.99, 0.77, 0.26],
1150     [0.74, 0.65, 0.41],
1151     );
1152    
1153     $LOGVIEW->add_paragraph ($color[$color], $text);
1154     }
1155    
1156 root 1.144 sub conn::spell_add {
1157 root 1.143 my ($self, $spell) = @_;
1158    
1159 root 1.144 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
1160     });
1161     $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
1162     });
1163     }
1164    
1165     sub conn::spell_delete {
1166     my ($self, $spell) = @_;
1167     }
1168    
1169     sub conn::addme_success {
1170     my ($self) = @_;
1171    
1172     for my $skill (values %{$self->{skill_info}}) {
1173     $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
1174     });
1175     $MAPWIDGET->add_command ("use_skill $skill", "", sub {
1176     });
1177     }
1178 root 1.143 }
1179    
1180 root 1.169 sub conn::container_add {
1181     my ($self, $id, $items) = @_;
1182    
1183     # 0 floor
1184     # $self-<{player}{tag} => player inv
1185     #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1186     }
1187    
1188     sub conn::container_clear {
1189     my ($self, $id) = @_;
1190     # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1191     }
1192    
1193 root 1.87 %SDL_CB = (
1194 root 1.145 CFClient::SDL_QUIT => sub {
1195 root 1.87 Event::unloop -1;
1196     },
1197 root 1.145 CFClient::SDL_VIDEORESIZE => sub {
1198 root 1.87 },
1199 root 1.153 CFClient::SDL_VIDEOEXPOSE => \&refresh,
1200     CFClient::SDL_ACTIVEEVENT => sub {
1201     # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1202 root 1.87 },
1203 root 1.145 CFClient::SDL_KEYDOWN => sub {
1204 root 1.147 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1205 root 1.87 # alt-enter
1206 root 1.134 video_shutdown;
1207 root 1.99 $CFG->{fullscreen} = !$CFG->{fullscreen};
1208 root 1.134 video_init;
1209 root 1.87 } else {
1210 root 1.147 CFClient::UI::feed_sdl_key_down_event ($_[0]);
1211 elmex 1.23 }
1212 root 1.87 },
1213 root 1.153 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
1214     CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
1215     CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
1216     CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
1217     CFClient::SDL_USEREVENT => \&audio_music_finished,
1218 root 1.87 );
1219 elmex 1.23
1220 root 1.1 #############################################################################
1221    
1222 root 1.131 $SIG{INT} = $SIG{TERM} = sub { exit };
1223    
1224 root 1.116 $TILECACHE = CFClient::db_table "tilecache";
1225     $FACEMAP = CFClient::db_table "facemap";
1226 root 1.114
1227 root 1.67 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1228 elmex 1.10
1229 root 1.90 my %DEF_CFG = (
1230 root 1.105 sdl_mode => 0,
1231 root 1.90 width => 640,
1232     height => 480,
1233 root 1.105 fullscreen => 0,
1234 root 1.90 fast => 0,
1235 root 1.169 map_scale => 0.5,
1236 root 1.97 fow_enable => 1,
1237 root 1.90 fow_intensity => 0.45,
1238 root 1.92 fow_smooth => 0,
1239 root 1.140 gui_fontsize => 1,
1240 elmex 1.157 log_fontsize => 1,
1241 elmex 1.158 gauge_fontsize => 1,
1242     gauge_size => 0.35,
1243 elmex 1.157 stat_fontsize => 1,
1244 root 1.90 mapsize => 100,
1245     host => "crossfire.schmorp.de",
1246 elmex 1.101 say_command => 'say',
1247 root 1.139 audio_enable => 1,
1248     bgm_enable => 1,
1249 root 1.149 bgm_volume => 0.25,
1250 root 1.90 );
1251    
1252     while (my ($k, $v) = each %DEF_CFG) {
1253     $CFG->{$k} = $v unless exists $CFG->{$k};
1254     }
1255 elmex 1.12
1256 root 1.89 sdl_init;
1257 root 1.87
1258 root 1.93 @SDL_MODES = reverse
1259     grep $_->[0] >= 640 && $_->[1] >= 480,
1260 root 1.145 CFClient::SDL_ListModes;
1261 root 1.87
1262 root 1.89 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1263    
1264     $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1265    
1266 root 1.65 {
1267 root 1.168 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1268     DejaVuSans.ttf
1269     DejaVuSansMono.ttf
1270     DejaVuSans-Bold.ttf
1271     DejaVuSansMono-Bold.ttf
1272     DejaVuSans-Oblique.ttf
1273     DejaVuSansMono-Oblique.ttf
1274     DejaVuSans-BoldOblique.ttf
1275     DejaVuSansMono-BoldOblique.ttf
1276     );
1277 root 1.65
1278 root 1.67 CFClient::add_font $_ for @fonts;
1279 root 1.168
1280     $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1281     $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1282    
1283     $FONT_PROP->make_default;
1284 root 1.65 }
1285 root 1.40
1286 root 1.134 video_init;
1287     audio_init;
1288 root 1.122
1289 root 1.87 Event::loop;
1290 root 1.19
1291 root 1.148 END { CFClient::SDL_Quit }
1292 root 1.131
1293 root 1.82