ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.158
Committed: Sat Apr 22 12:14:45 2006 UTC (18 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.157: +129 -82 lines
Log Message:
Moved gauges to the main window to a fixed position. Made their size configurable
Put the stats window into a Flopper.

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