1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Glib; |
6 | BEGIN { |
7 | use Gtk2 -init; |
7 | if (%PAR::LibCache) { |
|
|
8 | @INC = grep ref, @INC; # weed out all paths except pars loader refs |
8 | |
9 | |
9 | use SDL; |
10 | while (my ($filename, $zip) = each %PAR::LibCache) { |
10 | use SDL::App; |
11 | for ($zip->memberNames) { |
|
|
12 | next unless /^\/root\/(.*)/; |
|
|
13 | $zip->extractMember ($_, "$ENV{PAR_TEMP}/$1") |
|
|
14 | unless -e "$ENV{PAR_TEMP}/$1"; |
|
|
15 | } |
|
|
16 | } |
|
|
17 | |
|
|
18 | unshift @INC, $ENV{PAR_TEMP}; |
|
|
19 | |
|
|
20 | if ($^O eq "MSWin32") { |
|
|
21 | $ENV{GTK_RC_FILES} = "$ENV{PAR_TEMP}/share/themes/MS-Windows/gtk-2.0/gtkrc"; |
|
|
22 | } |
|
|
23 | } |
|
|
24 | } |
|
|
25 | |
|
|
26 | # need to do it again because that pile of garbage called PAR nukes it before main |
|
|
27 | unshift @INC, $ENV{PAR_TEMP}; |
|
|
28 | |
|
|
29 | use Time::HiRes 'time'; |
11 | use SDL::Event; |
30 | use Event; |
12 | use SDL::Surface; |
|
|
13 | use SDL::OpenGL; |
|
|
14 | use SDL::OpenGL::Constants; |
|
|
15 | |
31 | |
16 | use Crossfire; |
32 | use Crossfire; |
17 | use Crossfire::Client; |
|
|
18 | use Crossfire::Protocol; |
33 | use Crossfire::Protocol; |
19 | |
34 | |
20 | use Crossfire::Client::Widget; |
35 | use Compress::LZF; |
21 | |
36 | |
22 | our $FACECACHE; |
37 | use CFClient; |
|
|
38 | use CFClient::UI; |
|
|
39 | use CFClient::MapWidget; |
|
|
40 | |
|
|
41 | $Event::DIED = sub { |
|
|
42 | CFClient::error $_[1]; |
|
|
43 | }; |
23 | |
44 | |
24 | our $VERSION = '0.1'; |
45 | our $VERSION = '0.1'; |
25 | |
46 | |
26 | our %GL_EXT; |
47 | my $MAX_FPS = 60; |
|
|
48 | my $MIN_FPS = 5; # unused as of yet |
|
|
49 | |
|
|
50 | our $META_SERVER = "crossfire.real-time.com:13326"; |
|
|
51 | |
|
|
52 | our $FACEMAP; |
|
|
53 | our $TILECACHE; |
|
|
54 | our $MAPCACHE; |
|
|
55 | |
|
|
56 | our $LAST_REFRESH; |
|
|
57 | our $NOW; |
27 | |
58 | |
28 | our $CFG; |
59 | our $CFG; |
29 | our $CONN; |
60 | our $CONN; |
|
|
61 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
30 | |
62 | |
|
|
63 | our @SDL_MODES; |
31 | our $WIDTH; |
64 | our $WIDTH; |
32 | our $HEIGHT; |
65 | our $HEIGHT; |
33 | our $FULLSCREEN; |
66 | our $FULLSCREEN; |
34 | |
|
|
35 | our $FONTSIZE; |
67 | our $FONTSIZE; |
36 | our $FOCUS; |
68 | |
|
|
69 | our $FONT_PROP; |
|
|
70 | our $FONT_FIXED; |
|
|
71 | |
|
|
72 | our $MAP; |
|
|
73 | our $MAPWIDGET; |
|
|
74 | our $BUTTONBAR; |
37 | our $HOVER; |
75 | our $LOGVIEW; |
|
|
76 | our $CONSOLE; |
|
|
77 | our $METASERVER; |
38 | |
78 | |
|
|
79 | our $FLOORBOX; |
|
|
80 | our $GAUGES; |
|
|
81 | our $STATWIDS; |
|
|
82 | |
39 | our $SDL_TIMER; |
83 | our $SDL_ACTIVE; |
40 | our $SDL_APP; |
|
|
41 | our $SDL_EV = new SDL::Event; |
|
|
42 | our %SDL_CB; |
84 | our %SDL_CB; |
43 | |
85 | |
44 | our @GL_INIT; # hooks called on every gl init |
86 | our $SDL_MIXER; |
|
|
87 | our @SOUNDS; # event => file mapping |
|
|
88 | our %AUDIO_CHUNKS; # audio files |
45 | |
89 | |
46 | our $ALT_ENTER_MESSAGE; |
90 | our $ALT_ENTER_MESSAGE; |
47 | our $STATUS_LINE; |
91 | our $STATUS_LINE; |
|
|
92 | our $DEBUG_STATUS; |
48 | |
93 | |
49 | our $TOPLEVEL; |
94 | sub status { |
|
|
95 | $STATUS_LINE->set_text ($_[0]); |
|
|
96 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
|
|
97 | } |
50 | |
98 | |
51 | our $tw; # Test widget #d# |
99 | sub debug { |
|
|
100 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
101 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
|
|
102 | } |
52 | |
103 | |
53 | my $last_refresh; |
104 | sub start_game { |
54 | my %ANIMATE; |
105 | status "logging in..."; |
55 | my $refresh_handler; |
|
|
56 | |
106 | |
57 | sub init_screen { |
107 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
58 | $SDL_APP = new SDL::App |
|
|
59 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
|
|
60 | -title => "Crossfire+ Client", |
|
|
61 | -width => $WIDTH, |
|
|
62 | -height => $HEIGHT, |
|
|
63 | -opengl => 1, |
|
|
64 | -red_size => 5, |
|
|
65 | -green_size => 5, |
|
|
66 | -blue_size => 5, |
|
|
67 | -alpha_size => 0, |
|
|
68 | -double_buffer => 1, |
|
|
69 | -fullscreen => $FULLSCREEN, |
|
|
70 | -resizeable => 0; |
|
|
71 | |
108 | |
72 | $last_refresh = SDL::GetTicks; |
109 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
73 | |
110 | |
74 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
111 | $MAP = new CFClient::Map $mapsize, $mapsize; |
75 | |
112 | |
76 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
113 | my ($host, $port) = split /:/, $CFG->{host}; |
77 | or warn "WARNING: non-power-of-two opengl extension required"; |
|
|
78 | |
|
|
79 | $FONTSIZE = int $HEIGHT / 50; |
|
|
80 | |
|
|
81 | ############################################################################# |
|
|
82 | |
|
|
83 | glClearColor 0, 0, 0, 0; |
|
|
84 | |
|
|
85 | glEnable GL_TEXTURE_2D; |
|
|
86 | glEnable GL_COLOR_MATERIAL; |
|
|
87 | glShadeModel GL_FLAT; |
|
|
88 | glDisable GL_DEPTH_TEST; |
|
|
89 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
90 | |
|
|
91 | $_->() for @GL_INIT; |
|
|
92 | |
|
|
93 | ############################################################################# |
|
|
94 | |
114 | |
95 | $STATUS_LINE = new Crossfire::Client::Widget::Label |
|
|
96 | 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, |
|
|
97 | ""; |
|
|
98 | $TOPLEVEL->add ($STATUS_LINE); |
|
|
99 | |
|
|
100 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
|
|
101 | 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, |
|
|
102 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
103 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
104 | |
|
|
105 | # Test code #d# |
|
|
106 | unless ($tw) { # haha... |
|
|
107 | $tw = new Crossfire::Client::Widget::Animator; |
|
|
108 | my $lbl1 = new Crossfire::Client::Widget::Label |
|
|
109 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
110 | my $lbl2 = new Crossfire::Client::Widget::Label |
|
|
111 | 0, 0, 10, $FONTSIZE, "LBL2"; |
|
|
112 | |
|
|
113 | my $vb = new Crossfire::Client::Widget::VBox; |
|
|
114 | my $f = new Crossfire::Client::Widget::FancyFrame; |
|
|
115 | my $f2 = new Crossfire::Client::Widget::FancyFrame; |
|
|
116 | $f->add ($lbl1); |
|
|
117 | $f2->add ($lbl2); |
|
|
118 | $vb->add ($f); |
|
|
119 | $vb->add ($f2, 1); |
|
|
120 | |
|
|
121 | $tw->add ($vb); |
|
|
122 | $tw->w (400); |
|
|
123 | $tw->h (300); |
|
|
124 | $tw->move ($WIDTH - 200, 0); |
|
|
125 | $tw->moveto (0, 0); |
|
|
126 | $TOPLEVEL->add ($tw); |
|
|
127 | |
|
|
128 | # $f->move ($WIDTH - 200, 0); |
|
|
129 | # $TOPLEVEL->add ($f); |
|
|
130 | } |
|
|
131 | } |
|
|
132 | |
|
|
133 | sub start_game { |
|
|
134 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
|
|
135 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
136 | while $SDL_EV->poll; |
|
|
137 | |
|
|
138 | 1 |
|
|
139 | }; |
|
|
140 | |
|
|
141 | $WIDTH = $CFG->{width}; |
|
|
142 | $HEIGHT = $CFG->{height}; |
|
|
143 | $FULLSCREEN = 0; |
|
|
144 | |
|
|
145 | init_screen; |
|
|
146 | |
|
|
147 | my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
|
|
148 | |
|
|
149 | $CONN = new conn |
115 | $CONN = new conn |
150 | host => $CFG->{host}, |
116 | host => $host, |
151 | port => $CFG->{port}, |
117 | port => $port || 13327, |
152 | user => $CFG->{user}, |
118 | user => $CFG->{user}, |
153 | pass => $CFG->{password}, |
119 | pass => $CFG->{password}, |
154 | mapw => $mapsize, |
120 | mapw => $mapsize, |
155 | maph => $mapsize, |
121 | maph => $mapsize, |
156 | ; |
122 | ; |
157 | |
123 | |
|
|
124 | status "login successful"; |
|
|
125 | |
158 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
126 | CFClient::lowdelay fileno $CONN->{fh}; |
159 | } |
127 | } |
160 | |
128 | |
161 | sub stop_game { |
129 | sub stop_game { |
162 | remove Glib::Source $SDL_TIMER; |
|
|
163 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
164 | undef $refresh_handler; |
|
|
165 | |
|
|
166 | undef $SDL_APP; |
|
|
167 | undef $CONN; |
130 | undef $CONN; |
168 | SDL::Quit; |
|
|
169 | } |
131 | } |
170 | |
132 | |
|
|
133 | sub client_setup { |
|
|
134 | my $dialog = new CFClient::UI::FancyFrame |
|
|
135 | title => "Client Setup", |
|
|
136 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
137 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
138 | |
|
|
139 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
|
|
140 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
|
|
141 | |
|
|
142 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
143 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
|
|
144 | |
|
|
145 | $mode_slider->connect (changed => sub { |
|
|
146 | my ($self, $value) = @_; |
|
|
147 | |
|
|
148 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
|
|
149 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
150 | }); |
|
|
151 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
|
|
152 | |
|
|
153 | my $row = 1; |
|
|
154 | |
|
|
155 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
|
|
156 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
157 | state => $CFG->{fullscreen}, |
|
|
158 | tooltip => "Bring the client into fullscreen mode", |
|
|
159 | connect_changed => sub { |
|
|
160 | my ($self, $value) = @_; |
|
|
161 | $CFG->{fullscreen} = $value; |
|
|
162 | } |
|
|
163 | ); |
|
|
164 | |
|
|
165 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
|
|
166 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
167 | state => $CFG->{fast}, |
|
|
168 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
|
|
169 | connect_changed => sub { |
|
|
170 | my ($self, $value) = @_; |
|
|
171 | $CFG->{fast} = $value; |
|
|
172 | } |
|
|
173 | ); |
|
|
174 | |
|
|
175 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Map Scale"); |
|
|
176 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
177 | range => [$CFG->{map_scale}, 0.25, 2, 0.05], |
|
|
178 | tooltip => "Enlarge or shrink the displayed map", |
|
|
179 | connect_changed => sub { |
|
|
180 | my ($self, $value) = @_; |
|
|
181 | $CFG->{map_scale} = 0.05 * int $value / 0.05; |
|
|
182 | } |
|
|
183 | ); |
|
|
184 | |
|
|
185 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
|
|
186 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
187 | state => $CFG->{fow_enable}, |
|
|
188 | tooltip => "Fog-of-War marks areas that cannot be seen by the player", |
|
|
189 | connect_changed => sub { |
|
|
190 | my ($self, $value) = @_; |
|
|
191 | $CFG->{fow_enable} = $value; |
|
|
192 | } |
|
|
193 | ); |
|
|
194 | |
|
|
195 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
|
|
196 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
197 | range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], |
|
|
198 | tooltip => "The higher the intensity, the lighter the Fog-of-War color", |
|
|
199 | connect_changed => sub { |
|
|
200 | my ($self, $value) = @_; |
|
|
201 | $CFG->{fow_intensity} = $value; |
|
|
202 | } |
|
|
203 | ); |
|
|
204 | |
|
|
205 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
|
|
206 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
207 | state => $CFG->{fow_smooth}, |
|
|
208 | tooltip => "Smooth the Fog-of-War a bit to make it more realistic", |
|
|
209 | connect_changed => sub { |
|
|
210 | my ($self, $value) = @_; |
|
|
211 | $CFG->{fow_smooth} = $value; |
|
|
212 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
|
|
213 | } |
|
|
214 | ); |
|
|
215 | |
|
|
216 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
|
|
217 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
218 | range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1], |
|
|
219 | tooltip => "The font size used by most GUI elements", |
|
|
220 | connect_changed => sub { |
|
|
221 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
222 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
223 | } |
|
|
224 | ); |
|
|
225 | |
|
|
226 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
|
|
227 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
228 | range => [$CFG->{log_fontsize}, 0.5, 2, 0.1], |
|
|
229 | tooltip => "The font size used by the server log window only", |
|
|
230 | connect_changed => sub { |
|
|
231 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
|
|
232 | } |
|
|
233 | ); |
|
|
234 | |
|
|
235 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize"); |
|
|
236 | |
|
|
237 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
238 | range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1], |
|
|
239 | tooltip => "The font size used by the statistics window only", |
|
|
240 | connect_changed => sub { |
|
|
241 | $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10; |
|
|
242 | &set_stats_window_fontsize; |
|
|
243 | } |
|
|
244 | ); |
|
|
245 | |
|
|
246 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size"); |
|
|
247 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
248 | range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], |
|
|
249 | tooltip => "Adjust the size of the stats gauges at the bottom right", |
|
|
250 | connect_changed => sub { |
|
|
251 | $CFG->{gauge_size} = $_[1]; |
|
|
252 | my $h = int $HEIGHT * $CFG->{gauge_size}; |
|
|
253 | $GAUGES->{win}->set_size ($WIDTH, $h); |
|
|
254 | $GAUGES->{win}->move (0, $HEIGHT - $h); |
|
|
255 | } |
|
|
256 | ); |
|
|
257 | |
|
|
258 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
|
|
259 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
260 | range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1], |
|
|
261 | tooltip => "Adjusts the fontsize of the gauges at the bottom right", |
|
|
262 | connect_changed => sub { |
|
|
263 | $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10; |
|
|
264 | &set_gauge_window_fontsize; |
|
|
265 | } |
|
|
266 | ); |
|
|
267 | |
|
|
268 | $table->add (1, $row++, new CFClient::UI::Button |
|
|
269 | expand => 1, align => 0, text => "Apply", |
|
|
270 | tooltip => "Apply the video settings", |
|
|
271 | connect_activate => sub { |
|
|
272 | video_shutdown (); |
|
|
273 | video_init (); |
|
|
274 | } |
|
|
275 | ); |
|
|
276 | |
|
|
277 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
|
|
278 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
279 | state => $CFG->{audio_enable}, |
|
|
280 | tooltip => "If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.", |
|
|
281 | connect_changed => sub { |
|
|
282 | $CFG->{audio_enable} = $_[1]; |
|
|
283 | } |
|
|
284 | ); |
|
|
285 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
286 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
287 | # $CFG->{effects_volume} = $_[1]; |
|
|
288 | # }); |
|
|
289 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
290 | $table->add (1, $row++, my $hbox = new CFClient::UI::HBox); |
|
|
291 | $hbox->add (new CFClient::UI::CheckBox |
|
|
292 | expand => 1, state => $CFG->{bgm_enable}, |
|
|
293 | tooltip => "Enable background music playing", |
|
|
294 | connect_changed => sub { |
|
|
295 | $CFG->{bgm_enable} = $_[1]; |
|
|
296 | } |
|
|
297 | ); |
|
|
298 | $hbox->add (new CFClient::UI::Slider |
|
|
299 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], |
|
|
300 | tooltip => "The volume of the background music", |
|
|
301 | connect_changed => sub { |
|
|
302 | $CFG->{bgm_volume} = $_[1]; |
|
|
303 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
304 | } |
|
|
305 | ); |
|
|
306 | |
|
|
307 | $table->add (1, $row++, new CFClient::UI::Button |
|
|
308 | expand => 1, align => 0, text => "Apply", |
|
|
309 | tooltip => "Apply the audio settings", |
|
|
310 | connect_activate => sub { |
|
|
311 | audio_shutdown (); |
|
|
312 | audio_init (); |
|
|
313 | } |
|
|
314 | ); |
|
|
315 | |
|
|
316 | $dialog |
|
|
317 | } |
|
|
318 | |
|
|
319 | sub set_stats_window_fontsize { |
|
|
320 | for (values %{$STATWIDS}) { |
|
|
321 | $_->set_fontsize ($::CFG->{stat_fontsize}); |
|
|
322 | } |
|
|
323 | } |
|
|
324 | |
|
|
325 | sub set_gauge_window_fontsize { |
|
|
326 | for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) { |
|
|
327 | $_->set_fontsize ($::CFG->{gauge_fontsize}); |
|
|
328 | } |
|
|
329 | |
|
|
330 | # local $GAUGES->{win}{parent};#d# |
|
|
331 | # use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D; |
|
|
332 | } |
|
|
333 | |
|
|
334 | sub make_gauge_window { |
|
|
335 | my $gh = int ($HEIGHT * $CFG->{gauge_size}); |
|
|
336 | # my $gw = int ($WIDTH * $CFG->{gauge_w_size}); |
|
|
337 | |
|
|
338 | my $win = new CFClient::UI::Frame ( |
|
|
339 | y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh |
|
|
340 | ); |
|
|
341 | $win->add (my $hbox = new CFClient::UI::HBox |
|
|
342 | children => [ |
|
|
343 | (new CFClient::UI::HBox expand => 1), |
|
|
344 | ($FLOORBOX = new CFClient::UI::VBox), |
|
|
345 | (my $vbox = new CFClient::UI::VBox), |
|
|
346 | ], |
|
|
347 | ); |
|
|
348 | |
|
|
349 | $vbox->add (new CFClient::UI::HBox |
|
|
350 | expand => 1, |
|
|
351 | children => [ |
|
|
352 | (new CFClient::UI::Empty expand => 1), |
|
|
353 | (my $hb = new CFClient::UI::HBox), |
|
|
354 | ], |
|
|
355 | ); |
|
|
356 | |
|
|
357 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', |
|
|
358 | tooltip => "Health points - depletes when you get wounded, refills when you heal or idle"); |
|
|
359 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', |
|
|
360 | tooltip => "Spell points - deplete when you cast wizard spells, refills when you idle"); |
|
|
361 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', |
|
|
362 | tooltip => "Grace points - deplete when you cast priest spells, refills when you pray"); |
|
|
363 | $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', |
|
|
364 | tooltip => "Food - depletes with time, faster when you heal or build mana, refills when you eat healthy food"); |
|
|
365 | |
|
|
366 | $vbox->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, |
|
|
367 | tooltip => "Experience points and level - increases when you kill monsters or successfully use skills"); |
|
|
368 | $vbox->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, |
|
|
369 | tooltip => "Ranged attack - how you attack when you press shift-cursor (spell, skill, weapon etc.)"); |
|
|
370 | |
|
|
371 | $GAUGES = { |
|
|
372 | exp => $exp, win => $win, range => $rng, |
|
|
373 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
|
|
374 | }; |
|
|
375 | |
|
|
376 | &set_gauge_window_fontsize; |
|
|
377 | |
|
|
378 | $win |
|
|
379 | } |
|
|
380 | |
|
|
381 | sub make_stats_window { |
|
|
382 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
|
|
383 | |
|
|
384 | $tgw->add (my $vb = new CFClient::UI::VBox); |
|
|
385 | $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); |
|
|
386 | $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); |
|
|
387 | |
|
|
388 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
|
|
389 | |
|
|
390 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
|
|
391 | |
|
|
392 | my $black = [0, 0, 0]; |
|
|
393 | |
|
|
394 | $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
395 | $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
396 | $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
397 | $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
398 | $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
399 | $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
400 | $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
401 | |
|
|
402 | $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Str"); |
|
|
403 | $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Dex"); |
|
|
404 | $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Con"); |
|
|
405 | $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Int"); |
|
|
406 | $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Wis"); |
|
|
407 | $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Pow"); |
|
|
408 | $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Cha"); |
|
|
409 | |
|
|
410 | $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
411 | $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
412 | $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
413 | $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
414 | $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54"); |
|
|
415 | $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9"); |
|
|
416 | |
|
|
417 | $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Wc"); |
|
|
418 | $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Ac"); |
|
|
419 | $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Dam"); |
|
|
420 | $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Arm"); |
|
|
421 | $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "Sp"); |
|
|
422 | $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label fg => $black, valign => 0, align => -1, text => "WSp"); |
|
|
423 | |
|
|
424 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
|
|
425 | |
|
|
426 | my $row = 0; |
|
|
427 | my $col = 0; |
|
|
428 | |
|
|
429 | my %resist_names = ( |
|
|
430 | slow => "Slow", |
|
|
431 | holyw => "Holy Word", |
|
|
432 | conf => "Confusion", |
|
|
433 | fire => "Fire", |
|
|
434 | depl => "Depletion", |
|
|
435 | magic => "Magic", |
|
|
436 | drain => "Draining", |
|
|
437 | acid => "Acid", |
|
|
438 | pois => "Poison", |
|
|
439 | para => "Paralysation", |
|
|
440 | deat => "Death", |
|
|
441 | phys => "Physical", |
|
|
442 | blind => "Blind", |
|
|
443 | fear => "Fear", |
|
|
444 | tund => "Turn undead", |
|
|
445 | elec => "Electricity", |
|
|
446 | cold => "Cold", |
|
|
447 | ghit => "Ghost hit", |
|
|
448 | ); |
|
|
449 | for (qw/slow holyw conf fire depl magic |
|
|
450 | drain acid pois para deat phys |
|
|
451 | blind fear tund elec cold ghit/) |
|
|
452 | { |
|
|
453 | $tbl2->add ($col, $row, |
|
|
454 | $STATWIDS->{"res_$_"} = |
|
|
455 | new CFClient::UI::Label |
|
|
456 | template => "-100%", |
|
|
457 | align => +1, |
|
|
458 | valign => 0, |
|
|
459 | tooltip => $resist_names{$_} |
|
|
460 | ); |
|
|
461 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image |
|
|
462 | can_hover => 1, |
|
|
463 | can_events => 1, |
|
|
464 | image => "ui/resist/resist_$_.png", |
|
|
465 | tooltip => $resist_names{$_} |
|
|
466 | ); |
|
|
467 | |
|
|
468 | $row++; |
|
|
469 | if ($row % 6 == 0) { |
|
|
470 | $col += 2; |
|
|
471 | $row = 0; |
|
|
472 | } |
|
|
473 | } |
|
|
474 | |
|
|
475 | &set_stats_window_fontsize; |
|
|
476 | update_stats_window ({}); |
|
|
477 | |
|
|
478 | $tgw |
|
|
479 | } |
|
|
480 | |
|
|
481 | sub formsep { |
|
|
482 | reverse join ",", grep length, split /(...)/, reverse $_[0] * 1 |
|
|
483 | } |
|
|
484 | |
|
|
485 | sub update_stats_window { |
|
|
486 | my ($stats) = @_; |
|
|
487 | |
|
|
488 | # i love text protocols!!! |
|
|
489 | my $hp = $stats->{Crossfire::Protocol::CS_STAT_HP} * 1; |
|
|
490 | my $hp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXHP} * 1; |
|
|
491 | my $sp = $stats->{Crossfire::Protocol::CS_STAT_SP} * 1; |
|
|
492 | my $sp_m = $stats->{Crossfire::Protocol::CS_STAT_MAXSP} * 1; |
|
|
493 | my $fo = $stats->{Crossfire::Protocol::CS_STAT_FOOD} * 1; |
|
|
494 | my $fo_m = 999; |
|
|
495 | my $gr = $stats->{Crossfire::Protocol::CS_STAT_GRACE} * 1; |
|
|
496 | my $gr_m = $stats->{Crossfire::Protocol::CS_STAT_MAXGRACE} * 1; |
|
|
497 | |
|
|
498 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
499 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
500 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
501 | $GAUGES->{grace} ->set_value ($gr, $gr_m); |
|
|
502 | $GAUGES->{exp} ->set_text ("Exp: " . (formsep $stats->{Crossfire::Protocol::CS_STAT_EXP64}) |
|
|
503 | . " (lvl " . ($stats->{Crossfire::Protocol::CS_STAT_LEVEL} * 1) . ")"); |
|
|
504 | my $rng = $stats->{Crossfire::Protocol::CS_STAT_RANGE}; |
|
|
505 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
506 | $GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
507 | my $title = $stats->{Crossfire::Protocol::CS_STAT_TITLE}; |
|
|
508 | $title =~ s/^Player: //; |
|
|
509 | $STATWIDS->{title} ->set_text ("Title: " . $title); |
|
|
510 | |
|
|
511 | $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5}); |
|
|
512 | $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8}); |
|
|
513 | $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9}); |
|
|
514 | $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6}); |
|
|
515 | $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7}); |
|
|
516 | $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22}); |
|
|
517 | $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10}); |
|
|
518 | $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13}); |
|
|
519 | $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14}); |
|
|
520 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
|
|
521 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
|
|
522 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_SPEED}); |
|
|
523 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{Crossfire::Protocol::CS_STAT_WEAP_SP}); |
|
|
524 | |
|
|
525 | my %tbl = ( |
|
|
526 | phys => 100, |
|
|
527 | magic => 101, |
|
|
528 | fire => 102, |
|
|
529 | elec => 103, |
|
|
530 | cold => 104, |
|
|
531 | conf => 105, |
|
|
532 | acid => 106, |
|
|
533 | drain => 107, |
|
|
534 | ghit => 108, |
|
|
535 | pois => 109, |
|
|
536 | slow => 110, |
|
|
537 | para => 111, |
|
|
538 | tund => 112, |
|
|
539 | fear => 113, |
|
|
540 | depl => 113, |
|
|
541 | deat => 115, |
|
|
542 | holyw => 116, |
|
|
543 | blind => 117 |
|
|
544 | ); |
|
|
545 | |
|
|
546 | for (keys %tbl) { |
|
|
547 | $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}}); |
|
|
548 | } |
|
|
549 | |
|
|
550 | } |
|
|
551 | |
|
|
552 | sub metaserver_dialog { |
|
|
553 | my $dialog = new CFClient::UI::FancyFrame |
|
|
554 | title => "Metaserver", |
|
|
555 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
556 | |
|
|
557 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
|
|
558 | |
|
|
559 | $dialog |
|
|
560 | } |
|
|
561 | |
|
|
562 | sub update_metaserver { |
|
|
563 | my ($HOST) = @_; |
|
|
564 | |
|
|
565 | status "fetching metaserver list..."; |
|
|
566 | |
|
|
567 | my $buf; |
|
|
568 | |
|
|
569 | my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; |
|
|
570 | |
|
|
571 | Event->io (fd => $fh, poll => 'r', cb => sub { |
|
|
572 | my $res = sysread $fh, $buf, 8192, length $buf; |
|
|
573 | |
|
|
574 | if (!defined $res) { |
|
|
575 | $_[0]->w->cancel; |
|
|
576 | status "metaserver: $!"; |
|
|
577 | } elsif ($res == 0) { |
|
|
578 | $_[0]->w->cancel; |
|
|
579 | status "server list retrieved"; |
|
|
580 | |
|
|
581 | my $table = $METASERVER->{table}; |
|
|
582 | |
|
|
583 | $table->clear; |
|
|
584 | |
|
|
585 | my @col = qw(Use #Users Host Uptime Version Description); |
|
|
586 | $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) |
|
|
587 | for 0 .. $#col; |
|
|
588 | |
|
|
589 | my @align = qw(1 0 1 1 -1); |
|
|
590 | |
|
|
591 | my $y = 0; |
|
|
592 | for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { |
|
|
593 | my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; |
|
|
594 | |
|
|
595 | for ($desc) { |
|
|
596 | s/<br>/\n/gi; |
|
|
597 | s/<li>/\n· /gi; |
|
|
598 | s/<.*?>//sgi; |
|
|
599 | s/&/&/g; |
|
|
600 | s/</</g; |
|
|
601 | s/>/>/g; |
|
|
602 | } |
|
|
603 | |
|
|
604 | $uptime = sprintf "%dd %02d:%02d:%02d", |
|
|
605 | (int $m->[8] / 86400), |
|
|
606 | (int $m->[8] / 3600) % 24, |
|
|
607 | (int $m->[8] / 60) % 60, |
|
|
608 | $m->[8] % 60; |
|
|
609 | |
|
|
610 | $m = [$users, $host, $uptime, $version, $desc]; |
|
|
611 | |
|
|
612 | $y++; |
|
|
613 | |
|
|
614 | $table->add (0, $y, new CFClient::UI::VBox children => [ |
|
|
615 | (new CFClient::UI::Button text => " ", connect_activate => sub { |
|
|
616 | $HOST->set_text ($CFG->{host} = $host); |
|
|
617 | }), |
|
|
618 | (new CFClient::UI::Empty expand => 1), |
|
|
619 | ]); |
|
|
620 | |
|
|
621 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
|
|
622 | for 0 .. $#$m; |
|
|
623 | } |
|
|
624 | } |
|
|
625 | }); |
|
|
626 | } |
|
|
627 | |
|
|
628 | sub server_setup { |
|
|
629 | my $dialog = new CFClient::UI::FancyFrame |
|
|
630 | title => "Server Setup", |
|
|
631 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
632 | |
|
|
633 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
634 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
|
|
635 | |
|
|
636 | { |
|
|
637 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
|
|
638 | |
|
|
639 | $vbox->add ( |
|
|
640 | my $HOST = new CFClient::UI::Entry |
|
|
641 | expand => 1, |
|
|
642 | text => $CFG->{host}, |
|
|
643 | tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", |
|
|
644 | connect_changed => sub { |
|
|
645 | my ($self, $value) = @_; |
|
|
646 | $CFG->{host} = $value; |
|
|
647 | } |
|
|
648 | ); |
|
|
649 | |
|
|
650 | $METASERVER = metaserver_dialog; |
|
|
651 | |
|
|
652 | $vbox->add (new CFClient::UI::Flopper |
|
|
653 | expand => 1, |
|
|
654 | text => "Metaserver", |
|
|
655 | other => $METASERVER, |
|
|
656 | tooltip => "Show a list of avaible crossfire servers", |
|
|
657 | connect_open => sub { |
|
|
658 | update_metaserver $HOST; |
|
|
659 | } |
|
|
660 | ); |
|
|
661 | } |
|
|
662 | |
|
|
663 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
|
|
664 | $table->add (1, 4, new CFClient::UI::Entry |
|
|
665 | text => $CFG->{user}, |
|
|
666 | tooltip => "The name of your character on the server", |
|
|
667 | connect_changed => sub { |
|
|
668 | my ($self, $value) = @_; |
|
|
669 | $CFG->{user} = $value; |
|
|
670 | } |
|
|
671 | ); |
|
|
672 | |
|
|
673 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
|
|
674 | $table->add (1, 5, new CFClient::UI::Entry |
|
|
675 | text => $CFG->{password}, |
|
|
676 | hidden => 1, |
|
|
677 | tooltip => "The password for your character", |
|
|
678 | connect_changed => sub { |
|
|
679 | my ($self, $value) = @_; |
|
|
680 | $CFG->{password} = $value; |
|
|
681 | } |
|
|
682 | ); |
|
|
683 | |
|
|
684 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
|
|
685 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry |
|
|
686 | text => $CFG->{say_command}, |
|
|
687 | tooltip => "This is the command that will be used if you write a line in the message window entry. " |
|
|
688 | ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " |
|
|
689 | ."But you could also set it to 'tell <playername>' to only chat with that user.", |
|
|
690 | connect_changed => sub { |
|
|
691 | my ($self, $value) = @_; |
|
|
692 | $CFG->{say_command} = $value; |
|
|
693 | } |
|
|
694 | ); |
|
|
695 | |
|
|
696 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
|
|
697 | $table->add (1, 7, new CFClient::UI::Slider |
|
|
698 | req_w => 100, |
|
|
699 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
700 | tooltip => "This is the size of the portion of the map update the server sends you. " |
|
|
701 | ."If you set this to a high value you will be able to see further for example.", |
|
|
702 | connect_changed => sub { |
|
|
703 | my ($self, $value) = @_; |
|
|
704 | |
|
|
705 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
|
|
706 | }, |
|
|
707 | ); |
|
|
708 | |
|
|
709 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
|
|
710 | start_game; |
|
|
711 | }); |
|
|
712 | |
|
|
713 | $dialog |
|
|
714 | } |
|
|
715 | |
|
|
716 | sub message_window { |
|
|
717 | my $window = new CFClient::UI::FancyFrame |
|
|
718 | title => "Messages", |
|
|
719 | border_bg => [1, 1, 1, 0.5], |
|
|
720 | bg => [0.3, 0.3, 0.3, 0.8], |
|
|
721 | user_w => int $::WIDTH / 3, |
|
|
722 | user_h => int $::HEIGHT / 5, |
|
|
723 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
724 | |
|
|
725 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
|
|
726 | expand => 1, |
|
|
727 | font => $FONT_FIXED, |
|
|
728 | fontsize => $::CFG->{log_fontsize}, |
|
|
729 | ); |
|
|
730 | |
|
|
731 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
732 | connect_focus_in => sub { |
|
|
733 | my ($input, $prev_focus) = @_; |
|
|
734 | |
|
|
735 | delete $input->{refocus_map}; |
|
|
736 | |
|
|
737 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
738 | $input->{refocus_map} = 1; |
|
|
739 | } |
|
|
740 | delete $input->{auto_activated}; |
|
|
741 | }, |
|
|
742 | connect_activate => sub { |
|
|
743 | my ($input, $text) = @_; |
|
|
744 | $input->set_text (''); |
|
|
745 | |
|
|
746 | if ($text =~ /^\/(.*)/) { |
|
|
747 | $::CONN->user_send ($1); |
|
|
748 | } else { |
|
|
749 | my $say_cmd = $::CFG->{say_command} || 'say'; |
|
|
750 | $::CONN->user_send ("$say_cmd $text"); |
|
|
751 | } |
|
|
752 | if ($input->{refocus_map}) { |
|
|
753 | delete $input->{refocus_map}; |
|
|
754 | $MAPWIDGET->focus_in |
|
|
755 | } |
|
|
756 | }, |
|
|
757 | connect_escape => sub { |
|
|
758 | $MAPWIDGET->focus_in |
|
|
759 | }, |
|
|
760 | ); |
|
|
761 | |
|
|
762 | $CONSOLE = { |
|
|
763 | window => $window, |
|
|
764 | input => $input |
|
|
765 | }; |
|
|
766 | |
|
|
767 | $window |
|
|
768 | } |
|
|
769 | |
|
|
770 | sub sdl_init { |
|
|
771 | CFClient::SDL_Init |
|
|
772 | and die "SDL::Init failed!\n"; |
|
|
773 | } |
|
|
774 | |
|
|
775 | sub video_init { |
|
|
776 | sdl_init; |
|
|
777 | |
|
|
778 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
779 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
780 | $FAST = $CFG->{fast}; |
|
|
781 | |
|
|
782 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
|
|
783 | or die "SDL_SetVideoMode failed!\n"; |
|
|
784 | |
|
|
785 | $SDL_ACTIVE = 1; |
|
|
786 | |
|
|
787 | $LAST_REFRESH = time - 0.01; |
|
|
788 | |
|
|
789 | CFClient::gl_init; |
|
|
790 | |
|
|
791 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
792 | |
|
|
793 | ############################################################################# |
|
|
794 | |
|
|
795 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
|
|
796 | $DEBUG_STATUS->show; |
|
|
797 | |
|
|
798 | $STATUS_LINE = new CFClient::UI::Label |
|
|
799 | padding => 0, |
|
|
800 | y => $HEIGHT - $FONTSIZE * 1.8; |
|
|
801 | $STATUS_LINE->show; |
|
|
802 | |
|
|
803 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
804 | padding => 0, |
|
|
805 | fontsize => 0.8, |
|
|
806 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
807 | $ALT_ENTER_MESSAGE->show; |
|
|
808 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
|
|
809 | |
|
|
810 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
|
|
811 | $MAPWIDGET->focus_in; |
|
|
812 | $MAPWIDGET->connect (activate_console => sub { |
|
|
813 | my ($mapwidget, $preset) = @_; |
|
|
814 | |
|
|
815 | if ($CONSOLE) { |
|
|
816 | $CONSOLE->{input}->{auto_activated} = 1; |
|
|
817 | $CONSOLE->{input}->focus_in; |
|
|
818 | |
|
|
819 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
|
|
820 | $CONSOLE->{input}->set_text ($preset); |
|
|
821 | } |
|
|
822 | } |
|
|
823 | }); |
|
|
824 | |
|
|
825 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
|
|
826 | |
|
|
827 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
|
|
828 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
|
|
829 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
|
|
830 | |
|
|
831 | $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 |
|
|
832 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
|
|
833 | |
|
|
834 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
|
|
835 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
836 | status "Configuration Saved"; |
|
|
837 | }); |
|
|
838 | |
|
|
839 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
840 | } |
|
|
841 | |
|
|
842 | sub video_shutdown { |
|
|
843 | $CFClient::UI::ROOT->{children} = []; |
|
|
844 | undef $CFClient::UI::GRAB; |
|
|
845 | undef $CFClient::UI::HOVER; |
|
|
846 | undef $SDL_ACTIVE; |
|
|
847 | } |
|
|
848 | |
|
|
849 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
|
|
850 | my $bgmusic;#TODO#hack#d# |
|
|
851 | |
|
|
852 | sub audio_music_finished { |
|
|
853 | return unless $CFG->{bgm_enable}; |
|
|
854 | |
|
|
855 | # TODO: hack, do play loop and mood music |
|
|
856 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
857 | $bgmusic->play (0); |
|
|
858 | |
|
|
859 | push @bgmusic, shift @bgmusic; |
|
|
860 | } |
|
|
861 | |
|
|
862 | sub audio_init { |
|
|
863 | if ($CFG->{audio_enable}) { |
|
|
864 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
865 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
|
|
866 | CFClient::Mix_AllocateChannels 8; |
|
|
867 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
|
|
868 | |
|
|
869 | audio_music_finished; |
|
|
870 | |
|
|
871 | while (<$fh>) { |
|
|
872 | next if /^\s*#/; |
|
|
873 | next if /^\s*$/; |
|
|
874 | |
|
|
875 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
876 | |
|
|
877 | push @SOUNDS, "$volume,$file"; |
|
|
878 | |
|
|
879 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
880 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
|
|
881 | $chunk->volume ($volume * 128 / 100); |
|
|
882 | $chunk |
|
|
883 | }; |
|
|
884 | } |
|
|
885 | } else { |
|
|
886 | status "unable to open sound config: $!"; |
|
|
887 | } |
|
|
888 | } |
|
|
889 | } |
|
|
890 | |
|
|
891 | sub audio_shutdown { |
|
|
892 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
|
|
893 | undef $SDL_MIXER; |
|
|
894 | @SOUNDS = (); |
|
|
895 | %AUDIO_CHUNKS = (); |
|
|
896 | } |
|
|
897 | |
|
|
898 | my %animate_object; |
|
|
899 | my $animate_timer; |
|
|
900 | |
|
|
901 | my $want_refresh; |
|
|
902 | my $can_refresh; |
|
|
903 | |
|
|
904 | my $fps = 9; |
171 | |
905 | |
172 | sub force_refresh { |
906 | sub force_refresh { |
173 | glViewport 0, 0, $WIDTH, $HEIGHT; |
907 | $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; |
|
|
908 | debug sprintf "%3.2f", $fps; |
174 | |
909 | |
175 | glMatrixMode GL_PROJECTION; |
910 | $want_refresh = 0; |
176 | glLoadIdentity; |
911 | $can_refresh = 0; |
177 | glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; |
|
|
178 | glMatrixMode GL_MODELVIEW; |
|
|
179 | |
912 | |
180 | glClear GL_COLOR_BUFFER_BIT; |
913 | $CFClient::UI::ROOT->draw; |
181 | |
914 | |
182 | $TOPLEVEL->draw; |
915 | CFClient::SDL_GL_SwapBuffers; |
183 | |
916 | |
184 | SDL::GLSwapBuffers; |
917 | $LAST_REFRESH = $NOW; |
185 | } |
918 | } |
|
|
919 | |
|
|
920 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
|
|
921 | $NOW = time; |
|
|
922 | |
|
|
923 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
|
|
924 | for CFClient::SDL_PollEvent; |
|
|
925 | |
|
|
926 | if (%animate_object) { |
|
|
927 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
|
|
928 | $want_refresh++; |
|
|
929 | } |
|
|
930 | |
|
|
931 | if ($want_refresh) { |
|
|
932 | force_refresh; |
|
|
933 | } else { |
|
|
934 | $can_refresh = 1; |
|
|
935 | } |
|
|
936 | }); |
186 | |
937 | |
187 | sub refresh { |
938 | sub refresh { |
188 | $refresh_handler ||= add Glib::Idle sub { |
939 | $want_refresh++; |
189 | return unless $SDL_APP; |
|
|
190 | |
|
|
191 | my $next_refresh = SDL::GetTicks; |
|
|
192 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
|
|
193 | $last_refresh = $next_refresh; |
|
|
194 | |
|
|
195 | force_refresh; |
|
|
196 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
197 | |
|
|
198 | if (%ANIMATE) { |
|
|
199 | 1 |
|
|
200 | } else { |
|
|
201 | undef $refresh_handler; |
|
|
202 | 0 |
|
|
203 | } |
|
|
204 | }; |
|
|
205 | } |
940 | } |
206 | |
941 | |
207 | sub animation_start { |
942 | sub animation_start { |
208 | my ($widget) = @_; |
943 | my ($widget) = @_; |
209 | $ANIMATE{$widget} = $widget; |
944 | $animate_object{$widget} = $widget; |
210 | Scalar::Util::weaken $ANIMATE{$widget}; |
|
|
211 | |
|
|
212 | refresh; |
|
|
213 | } |
945 | } |
214 | |
946 | |
215 | sub animation_stop { |
947 | sub animation_stop { |
216 | my ($widget) = @_; |
948 | my ($widget) = @_; |
217 | delete $ANIMATE{$widget}; |
949 | delete $animate_object{$widget}; |
218 | } |
950 | } |
219 | |
|
|
220 | %SDL_CB = ( |
|
|
221 | SDL_QUIT() => sub { |
|
|
222 | main_quit Gtk2; |
|
|
223 | }, |
|
|
224 | SDL_VIDEORESIZE() => sub { |
|
|
225 | }, |
|
|
226 | SDL_VIDEOEXPOSE() => sub { |
|
|
227 | refresh; |
|
|
228 | }, |
|
|
229 | SDL_KEYDOWN() => sub { |
|
|
230 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
|
|
231 | # alt-enter |
|
|
232 | $FULLSCREEN = !$FULLSCREEN; |
|
|
233 | init_screen; |
|
|
234 | } else { |
|
|
235 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
|
|
236 | } |
|
|
237 | }, |
|
|
238 | SDL_KEYUP() => sub { |
|
|
239 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
|
|
240 | }, |
|
|
241 | SDL_MOUSEMOTION() => sub { |
|
|
242 | my ($x, $y) = ($SDL_EV->motion_x, $SDL_EV->motion_y); |
|
|
243 | $HOVER = $TOPLEVEL->find_widget ($x, $y); |
|
|
244 | $self->refresh; |
|
|
245 | |
|
|
246 | warn "mouse $x, $y = $HOVER\n"; |
|
|
247 | }, |
|
|
248 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
249 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
|
|
250 | }, |
|
|
251 | SDL_MOUSEBUTTONUP() => sub { |
|
|
252 | Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
|
|
253 | }, |
|
|
254 | SDL_ACTIVEEVENT() => sub { |
|
|
255 | warn "active\n";#d# |
|
|
256 | }, |
|
|
257 | ); |
|
|
258 | |
951 | |
259 | @conn::ISA = Crossfire::Protocol::; |
952 | @conn::ISA = Crossfire::Protocol::; |
260 | |
953 | |
261 | sub conn::map_update { |
954 | sub conn::stats_update { |
262 | my ($self, $dirty) = @_; |
955 | my ($self, $stats) = @_; |
263 | |
956 | |
264 | refresh; |
957 | update_stats_window ($stats); |
|
|
958 | } |
|
|
959 | |
|
|
960 | sub conn::user_send { |
|
|
961 | my ($self, $command) = @_; |
|
|
962 | |
|
|
963 | $self->send_command ($command); |
|
|
964 | status $command; |
265 | } |
965 | } |
266 | |
966 | |
267 | sub conn::map_scroll { |
967 | sub conn::map_scroll { |
268 | my ($self, $dx, $dy) = @_; |
968 | my ($self, $dx, $dy) = @_; |
269 | |
969 | |
270 | # refresh; |
970 | $MAP->scroll ($dx, $dy); |
|
|
971 | } |
|
|
972 | |
|
|
973 | sub conn::feed_map1a { |
|
|
974 | my ($self, $data) = @_; |
|
|
975 | |
|
|
976 | # $self->Crossfire::Protocol::feed_map1a ($data); |
|
|
977 | |
|
|
978 | $MAP->map1a_update ($data); |
|
|
979 | $MAPWIDGET->update; |
|
|
980 | } |
|
|
981 | |
|
|
982 | sub conn::flush_map { |
|
|
983 | my ($self) = @_; |
|
|
984 | |
|
|
985 | my $map_info = delete $self->{map_info} |
|
|
986 | or return; |
|
|
987 | |
|
|
988 | my ($hash, $x, $y, $w, $h) = @$map_info; |
|
|
989 | |
|
|
990 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
|
|
991 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
|
|
992 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
271 | } |
993 | } |
272 | |
994 | |
273 | sub conn::map_clear { |
995 | sub conn::map_clear { |
274 | my ($self) = @_; |
996 | my ($self) = @_; |
275 | |
997 | |
276 | # refresh; |
998 | $self->flush_map; |
|
|
999 | delete $self->{neigh_map}; |
|
|
1000 | |
|
|
1001 | $MAP->clear; |
|
|
1002 | } |
|
|
1003 | |
|
|
1004 | |
|
|
1005 | sub conn::load_map($$$) { |
|
|
1006 | my ($self, $hash, $x, $y) = @_; |
|
|
1007 | |
|
|
1008 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
|
|
1009 | $data = Compress::LZF::decompress $data; |
|
|
1010 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
1011 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
|
|
1012 | my $data = $TILECACHE->get ($id) |
|
|
1013 | or next; |
|
|
1014 | |
|
|
1015 | $self->set_texture ($id => $data); |
|
|
1016 | } |
|
|
1017 | } |
|
|
1018 | } |
|
|
1019 | |
|
|
1020 | # this method does a "flood fill" into every tile direction |
|
|
1021 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
1022 | # i.e. a map is the same as the left of the right map etc. |
|
|
1023 | # failure to comply are harmless and result in display errors |
|
|
1024 | # at worst. |
|
|
1025 | sub conn::flood_fill { |
|
|
1026 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
|
|
1027 | |
|
|
1028 | # the server does not allow map paths > 6 |
|
|
1029 | return if 6 <= length $path; |
|
|
1030 | |
|
|
1031 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
|
|
1032 | |
|
|
1033 | for ( |
|
|
1034 | [1, 0, -1], |
|
|
1035 | [2, 1, 0], |
|
|
1036 | [3, 0, 1], |
|
|
1037 | [4, -1, 0], |
|
|
1038 | ) { |
|
|
1039 | my ($tile, $dx, $dy) = @$_; |
|
|
1040 | |
|
|
1041 | my $gx = $gx + $dx; |
|
|
1042 | my $gy = $gy + $dy; |
|
|
1043 | |
|
|
1044 | next unless $flags & (1 << ($tile - 1)); |
|
|
1045 | next if $self->{neigh_grid}{$gx, $gy}++; |
|
|
1046 | |
|
|
1047 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
|
|
1048 | if (my $info = $neigh->[$tile]) { |
|
|
1049 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
|
|
1050 | |
|
|
1051 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
1052 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
1053 | |
|
|
1054 | } else { |
|
|
1055 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
1056 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
1057 | |
|
|
1058 | return if $mode ne "spatial"; |
|
|
1059 | |
|
|
1060 | $x += $MAP->ox; |
|
|
1061 | $y += $MAP->oy; |
|
|
1062 | |
|
|
1063 | $self->load_map ($hash, $x, $y) |
|
|
1064 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
1065 | |
|
|
1066 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
1067 | |
|
|
1068 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
1069 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
1070 | }); |
|
|
1071 | } |
|
|
1072 | } |
|
|
1073 | } |
|
|
1074 | |
|
|
1075 | sub conn::map_change { |
|
|
1076 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
1077 | |
|
|
1078 | $self->flush_map; |
|
|
1079 | |
|
|
1080 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
1081 | |
|
|
1082 | my $mapmapw = 250; |
|
|
1083 | my $mapmaph = 250; |
|
|
1084 | |
|
|
1085 | $self->{neigh_rect} = [ |
|
|
1086 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
1087 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
1088 | ]; |
|
|
1089 | |
|
|
1090 | delete $self->{neigh_grid}; |
|
|
1091 | $self->flood_fill (0, 0, "", $hash, $flags); |
|
|
1092 | |
|
|
1093 | $x += $ox; |
|
|
1094 | $y += $oy; |
|
|
1095 | |
|
|
1096 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
1097 | |
|
|
1098 | my $map = $self->{map_info}[0]; |
|
|
1099 | $map =~ s/^.*?\/([^\/]+)$/\1/; |
|
|
1100 | $STATWIDS->{map}->set_text ("Map: " . $map); |
|
|
1101 | |
|
|
1102 | $self->load_map ($hash, $x, $y); |
277 | } |
1103 | } |
278 | |
1104 | |
279 | sub conn::face_find { |
1105 | sub conn::face_find { |
280 | my ($self, $face) = @_; |
1106 | my ($self, $facenum, $face) = @_; |
281 | |
1107 | |
282 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
1108 | my $hash = "$face->{chksum},$face->{name}"; |
|
|
1109 | |
|
|
1110 | my $id = $FACEMAP->get ($hash); |
|
|
1111 | |
|
|
1112 | unless ($id) { |
|
|
1113 | # create new id for face |
|
|
1114 | # i love transactions |
|
|
1115 | for (1..100) { |
|
|
1116 | my $txn = $CFClient::DB_ENV->txn_begin; |
|
|
1117 | my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW); |
|
|
1118 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
|
|
1119 | $id++; |
|
|
1120 | if ($FACEMAP->put (id => $id) == 0 |
|
|
1121 | && $FACEMAP->put ($hash => $id) == 0) { |
|
|
1122 | $txn->txn_commit; |
|
|
1123 | |
|
|
1124 | goto gotid; |
|
|
1125 | } |
|
|
1126 | } |
|
|
1127 | $txn->abort; |
|
|
1128 | } |
|
|
1129 | |
|
|
1130 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
|
|
1131 | } |
|
|
1132 | |
|
|
1133 | gotid: |
|
|
1134 | $face->{id} = $id; |
|
|
1135 | $MAP->set_face ($facenum => $id); |
|
|
1136 | $self->{faceid}[$facenum] = $id;#d# |
|
|
1137 | $TILECACHE->get ($id) |
283 | } |
1138 | } |
284 | |
1139 | |
285 | sub conn::face_update { |
1140 | sub conn::face_update { |
286 | my ($self, $face) = @_; |
1141 | my ($self, $facenum, $face) = @_; |
287 | |
1142 | |
288 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
1143 | $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
289 | |
1144 | |
290 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
1145 | $self->set_texture ($face->{id} => delete $face->{image}); |
291 | } |
1146 | } |
|
|
1147 | |
|
|
1148 | sub conn::set_texture { |
|
|
1149 | my ($self, $id, $data) = @_; |
|
|
1150 | |
|
|
1151 | $self->{texture}[$id] ||= do { |
|
|
1152 | my $tex = |
|
|
1153 | new_from_image CFClient::Texture |
|
|
1154 | $data, minify => 1, mipmap => 1; |
|
|
1155 | |
|
|
1156 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
1157 | $MAPWIDGET->update; |
|
|
1158 | |
|
|
1159 | $tex |
|
|
1160 | }; |
|
|
1161 | } |
|
|
1162 | |
|
|
1163 | sub conn::sound_play { |
|
|
1164 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
1165 | |
|
|
1166 | $SDL_MIXER |
|
|
1167 | or return; |
|
|
1168 | |
|
|
1169 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
1170 | or return; |
|
|
1171 | |
|
|
1172 | $chunk->play; |
|
|
1173 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
|
|
1174 | } |
|
|
1175 | |
|
|
1176 | my $LAST_QUERY; # server is stupid, stupid, stupid |
292 | |
1177 | |
293 | sub conn::query { |
1178 | sub conn::query { |
294 | my ($self, $flags, $prompt) = @_; |
1179 | my ($self, $flags, $prompt) = @_; |
295 | |
1180 | |
296 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
1181 | $prompt = $LAST_QUERY unless length $prompt; |
297 | } |
1182 | $LAST_QUERY = $prompt; |
298 | |
1183 | |
299 | sub gtk_add_cfg_field { |
1184 | my $dialog = new CFClient::UI::FancyFrame |
300 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
1185 | title => "Query", |
301 | my $i = $cfg->{_i}++; |
1186 | child => my $vbox = new CFClient::UI::VBox; |
302 | $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); |
1187 | |
303 | $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1); |
1188 | $vbox->add (new CFClient::UI::Label |
304 | if ($key eq 'password') { |
1189 | max_w => $::WIDTH * 0.4, |
305 | $ent->set_invisible_char ("*"); |
1190 | text => $prompt); |
306 | $ent->set (visibility => 0) |
1191 | |
307 | } |
1192 | if ($flags & Crossfire::Protocol::CS_QUERY_YESNO) { |
308 | $ent->set_text ($value); |
1193 | $vbox->add (my $hbox = new CFClient::HBox); |
309 | $ent->signal_connect (changed => sub { |
1194 | $hbox->add (new CFClient::Button |
310 | my ($ent) = @_; |
1195 | text => "No", |
311 | $cfg->{$key} = $ent->get_text; |
1196 | connect_activate => sub { |
312 | # TODO: Mapsize should be a slider in the game gui |
1197 | $self->send ("reply n"); |
313 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
1198 | $dialog->destroy; |
314 | $cfg->{$key} = 100; |
1199 | $MAPWIDGET->focus_in; |
315 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
316 | $cfg->{$key} = 50; |
|
|
317 | } |
1200 | } |
318 | }); |
1201 | ); |
319 | } |
1202 | $hbox->add (new CFClient::Button |
320 | |
1203 | text => "Yes", |
321 | sub run_config_dialog { |
1204 | connect_activate => sub { |
322 | my (%events) = @_; |
1205 | $self->send ("reply y"); |
323 | |
1206 | $dialog->destroy; |
324 | my $w = Gtk2::Window->new; |
1207 | $MAPWIDGET->focus_in; |
325 | |
|
|
326 | my @cfg = ( |
|
|
327 | [qw/Host host/], |
|
|
328 | [qw/Port port/], |
|
|
329 | [qw/Mapsize% mapsize/], |
|
|
330 | [qw/Username user/], |
|
|
331 | [qw/Password password/], |
|
|
332 | ); |
|
|
333 | |
|
|
334 | my $cfg = {}; |
|
|
335 | |
|
|
336 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
337 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
338 | |
|
|
339 | $w->add (my $vb = Gtk2::VBox->new); |
|
|
340 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
|
|
341 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
|
|
342 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
|
|
343 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
|
|
344 | my $i = 0; |
|
|
345 | my $act = 0; |
|
|
346 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
|
|
347 | if ($_ eq $selmode) { $act = $i } |
|
|
348 | $cb->append_text ($_); |
|
|
349 | $i++; |
|
|
350 | } |
1208 | }, |
351 | $cb->set_active ($act); |
1209 | ); |
|
|
1210 | |
|
|
1211 | $dialog->focus_in; |
|
|
1212 | |
|
|
1213 | } elsif ($flags & Crossfire::Protocol::CS_QUERY_SINGLECHAR) { |
|
|
1214 | $dialog->{tooltip} = "Press a key (click on the entry to make sure it has keyboard focus)"; |
|
|
1215 | $vbox->add (my $entry = new CFClient::UI::Entry |
352 | $cb->signal_connect (changed => sub { |
1216 | connect_changed => sub { |
353 | my ($cb) = @_; |
1217 | $self->send ("reply $_[1]"); |
354 | my $txt = $cb->get_active_text; |
1218 | $dialog->destroy; |
355 | if ($txt =~ m/(\d+)x(\d+)/) { |
1219 | $MAPWIDGET->focus_in; |
356 | $::CFG->{width} = $1; |
1220 | }, |
357 | $::CFG->{height} = $2; |
1221 | ); |
|
|
1222 | |
|
|
1223 | $entry->focus_in; |
|
|
1224 | |
|
|
1225 | } else { |
|
|
1226 | $dialog->{tooltip} = "Enter the reply and press return (click on the entry to make sure it has keyboard focus)"; |
|
|
1227 | |
|
|
1228 | $vbox->add (my $entry = new CFClient::UI::Entry |
|
|
1229 | $flags & Crossfire::Protocol::CS_QUERY_HIDEINPUT ? (hiddenchar => "*") : (), |
|
|
1230 | connect_activate => sub { |
|
|
1231 | $self->send ("reply $_[1]"); |
|
|
1232 | $dialog->destroy; |
|
|
1233 | $MAPWIDGET->focus_in; |
|
|
1234 | }, |
|
|
1235 | ); |
|
|
1236 | |
|
|
1237 | $entry->focus_in; |
|
|
1238 | } |
|
|
1239 | |
|
|
1240 | $dialog->show; |
|
|
1241 | } |
|
|
1242 | |
|
|
1243 | sub conn::drawinfo { |
|
|
1244 | my ($self, $color, $text) = @_; |
|
|
1245 | |
|
|
1246 | my @color = ( |
|
|
1247 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
|
|
1248 | [1.00, 1.00, 1.00], |
|
|
1249 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
|
|
1250 | [1.00, 0.00, 0.00], |
|
|
1251 | [1.00, 0.54, 0.00], |
|
|
1252 | [0.11, 0.56, 1.00], |
|
|
1253 | [0.93, 0.46, 0.00], |
|
|
1254 | [0.18, 0.54, 0.34], |
|
|
1255 | [0.56, 0.73, 0.56], |
|
|
1256 | [0.80, 0.80, 0.80], |
|
|
1257 | [0.55, 0.41, 0.13], |
|
|
1258 | [0.99, 0.77, 0.26], |
|
|
1259 | [0.74, 0.65, 0.41], |
|
|
1260 | ); |
|
|
1261 | |
|
|
1262 | $LOGVIEW->add_paragraph ($color[$color], $text); |
|
|
1263 | } |
|
|
1264 | |
|
|
1265 | sub conn::spell_add { |
|
|
1266 | my ($self, $spell) = @_; |
|
|
1267 | |
|
|
1268 | # TODO |
|
|
1269 | # create a widget dynamically, using spell face (CF::Protocol downloads them) |
|
|
1270 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}); |
|
|
1271 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}); |
|
|
1272 | } |
|
|
1273 | |
|
|
1274 | sub conn::spell_delete { |
|
|
1275 | my ($self, $spell) = @_; |
|
|
1276 | } |
|
|
1277 | |
|
|
1278 | sub conn::addme_success { |
|
|
1279 | my ($self) = @_; |
|
|
1280 | |
|
|
1281 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1282 | $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); |
|
|
1283 | $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); |
|
|
1284 | } |
|
|
1285 | } |
|
|
1286 | |
|
|
1287 | sub update_floorbox { |
|
|
1288 | $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { |
|
|
1289 | $FLOORBOX->clear; |
|
|
1290 | $FLOORBOX->add (new CFClient::UI::Empty expand => 1); |
|
|
1291 | |
|
|
1292 | my @items = values %{ $CONN->{container}{0} }; |
|
|
1293 | |
|
|
1294 | # we basically have to use the same sorting as everybody else |
|
|
1295 | @items = sort { $a->{type} <=> $b->{type} } @items; |
|
|
1296 | |
|
|
1297 | for my $item (reverse @items) { |
|
|
1298 | my $desc = $item->{nrof} < 2 |
|
|
1299 | ? $item->{name} |
|
|
1300 | : "$item->{nrof} $item->{name_pl}"; |
|
|
1301 | # todo: animation widget, face widget, weight(?) etc. |
|
|
1302 | $FLOORBOX->add (my $hbox = new CFClient::UI::HBox |
|
|
1303 | tooltip => (CFClient::UI::Label->escape ($desc) |
|
|
1304 | . "\n<small>leftclick - pick up\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
1305 | can_hover => 1, |
|
|
1306 | can_events => 1, |
|
|
1307 | connect_button_down => sub { |
|
|
1308 | my ($self, $ev, $x, $y) = @_; |
|
|
1309 | |
|
|
1310 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
1311 | if ($ev->{button} == 1) { |
|
|
1312 | $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0"); |
|
|
1313 | } elsif ($ev->{button} == 2) { |
|
|
1314 | $CONN->send ("apply $item->{tag}"); |
|
|
1315 | } elsif ($ev->{button} == 3) { |
|
|
1316 | # examine, lock, mark, maybe other things |
|
|
1317 | warn "MENU not implemented yet\n"; |
358 | } |
1318 | } |
|
|
1319 | |
|
|
1320 | 1 |
359 | }); |
1321 | }, |
|
|
1322 | ); |
360 | |
1323 | |
361 | $cfg->{_i} = 1; |
1324 | $hbox->add (new CFClient::UI::Face |
362 | for (@cfg) { |
1325 | can_events => 0, |
363 | gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]}); |
1326 | face => $item->{face}, |
|
|
1327 | anim => $item->{anim}, |
|
|
1328 | animspeed => $item->{animspeed}, |
|
|
1329 | ); |
364 | } |
1330 | |
365 | |
1331 | $hbox->add (new CFClient::UI::Label |
366 | $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
1332 | can_events => 0, |
367 | $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5); |
1333 | text => $desc, |
368 | $cb->signal_connect (clicked => sub { |
|
|
369 | for (keys %$cfg) { |
|
|
370 | $::CFG->{$_} = $cfg->{$_} |
|
|
371 | if $_ ne '_i'; |
|
|
372 | } |
|
|
373 | Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
374 | }); |
1334 | ); |
375 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
1335 | } |
376 | $cb->signal_connect (clicked => sub { |
1336 | }); |
377 | for (keys %$cfg) { |
1337 | refresh; |
378 | $::CFG->{$_} = $cfg->{$_} |
|
|
379 | if $_ ne '_i'; |
|
|
380 | } |
|
|
381 | my $cb = $events{login} || sub {}; |
|
|
382 | $cb->($::CFG->{user}, $::CFG->{password}); |
|
|
383 | }); |
|
|
384 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
|
|
385 | $cb->signal_connect (clicked => sub { |
|
|
386 | my $cb = $events{logout} || sub {}; |
|
|
387 | $cb->(); |
|
|
388 | }); |
|
|
389 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
|
|
390 | $cb->signal_connect (clicked => sub { $w->destroy }); |
|
|
391 | |
|
|
392 | $w->show_all; |
|
|
393 | |
|
|
394 | $w->signal_connect (destroy => sub { Gtk2->main_quit }); |
|
|
395 | } |
1338 | } |
396 | |
1339 | |
|
|
1340 | sub conn::container_add { |
|
|
1341 | my ($self, $id, $items) = @_; |
|
|
1342 | |
|
|
1343 | update_floorbox if $id == 0; |
|
|
1344 | # $self-<{player}{tag} => player inv |
|
|
1345 | #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; |
|
|
1346 | } |
|
|
1347 | |
|
|
1348 | sub conn::container_clear { |
|
|
1349 | my ($self, $id) = @_; |
|
|
1350 | |
|
|
1351 | update_floorbox if $id == 0; |
|
|
1352 | # use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; |
|
|
1353 | } |
|
|
1354 | |
|
|
1355 | sub conn::item_delete { |
|
|
1356 | my ($self, @items) = @_; |
|
|
1357 | |
|
|
1358 | for (@items) { |
|
|
1359 | update_floorbox if $_->{container} == 0; |
|
|
1360 | } |
|
|
1361 | } |
|
|
1362 | |
|
|
1363 | sub conn::item_update { |
|
|
1364 | my ($self, $item) = @_; |
|
|
1365 | |
|
|
1366 | update_floorbox if $item->{container} == 0; |
|
|
1367 | } |
|
|
1368 | |
|
|
1369 | %SDL_CB = ( |
|
|
1370 | CFClient::SDL_QUIT => sub { |
|
|
1371 | Event::unloop -1; |
|
|
1372 | }, |
|
|
1373 | CFClient::SDL_VIDEORESIZE => sub { |
|
|
1374 | }, |
|
|
1375 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
|
|
1376 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
1377 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
1378 | }, |
|
|
1379 | CFClient::SDL_KEYDOWN => sub { |
|
|
1380 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
|
|
1381 | # alt-enter |
|
|
1382 | video_shutdown; |
|
|
1383 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
|
|
1384 | video_init; |
|
|
1385 | } else { |
|
|
1386 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
|
|
1387 | } |
|
|
1388 | }, |
|
|
1389 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
|
|
1390 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
|
|
1391 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
|
|
1392 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
|
|
1393 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
|
|
1394 | ); |
397 | |
1395 | |
398 | ############################################################################# |
1396 | ############################################################################# |
399 | |
1397 | |
400 | SDL::Init SDL_INIT_EVERYTHING; |
1398 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
401 | |
1399 | |
402 | $TOPLEVEL = Crossfire::Client::Widget::Toplevel->new; |
1400 | $TILECACHE = CFClient::db_table "tilecache"; |
|
|
1401 | $FACEMAP = CFClient::db_table "facemap"; |
403 | |
1402 | |
404 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
|
|
405 | |
|
|
406 | $TOPLEVEL->add ($mapwidget); |
|
|
407 | $mapwidget->focus_in; |
|
|
408 | |
|
|
409 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
1403 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
410 | |
1404 | |
411 | $CFG ||= { |
1405 | my %DEF_CFG = ( |
|
|
1406 | sdl_mode => 0, |
412 | width => 640, |
1407 | width => 640, |
413 | height => 480, |
1408 | height => 480, |
|
|
1409 | fullscreen => 0, |
|
|
1410 | fast => 0, |
|
|
1411 | map_scale => 0.5, |
|
|
1412 | fow_enable => 1, |
|
|
1413 | fow_intensity => 0.45, |
|
|
1414 | fow_smooth => 0, |
|
|
1415 | gui_fontsize => 1, |
|
|
1416 | log_fontsize => 1, |
|
|
1417 | gauge_fontsize => 1, |
|
|
1418 | gauge_size => 0.35, |
|
|
1419 | stat_fontsize => 1, |
414 | mapsize => 100, |
1420 | mapsize => 100, |
415 | fullscreen => 0, |
|
|
416 | host => "crossfire.schmorp.de", |
1421 | host => "crossfire.schmorp.de", |
417 | port => 13327, |
1422 | say_command => 'say', |
418 | }; |
1423 | audio_enable => 1, |
|
|
1424 | bgm_enable => 1, |
|
|
1425 | bgm_volume => 0.25, |
|
|
1426 | ); |
419 | |
1427 | |
420 | Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf"; |
1428 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
1429 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
1430 | } |
421 | |
1431 | |
422 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
1432 | sdl_init; |
423 | |
1433 | |
424 | run_config_dialog |
1434 | @SDL_MODES = reverse |
425 | login => sub { start_game }, |
1435 | grep $_->[0] >= 640 && $_->[1] >= 480, |
426 | logout => sub { stop_game }; |
1436 | CFClient::SDL_ListModes; |
427 | |
1437 | |
428 | main Gtk2; |
1438 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
429 | |
1439 | |
430 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
1440 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
|
|
1441 | |
|
|
1442 | { |
|
|
1443 | my @fonts = map CFClient::find_rcfile "fonts/$_", qw( |
|
|
1444 | DejaVuSans.ttf |
|
|
1445 | DejaVuSansMono.ttf |
|
|
1446 | DejaVuSans-Bold.ttf |
|
|
1447 | DejaVuSansMono-Bold.ttf |
|
|
1448 | DejaVuSans-Oblique.ttf |
|
|
1449 | DejaVuSansMono-Oblique.ttf |
|
|
1450 | DejaVuSans-BoldOblique.ttf |
|
|
1451 | DejaVuSansMono-BoldOblique.ttf |
|
|
1452 | ); |
|
|
1453 | |
|
|
1454 | CFClient::add_font $_ for @fonts; |
|
|
1455 | |
|
|
1456 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
|
|
1457 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
|
|
1458 | |
|
|
1459 | $FONT_PROP->make_default; |
|
|
1460 | } |
|
|
1461 | |
|
|
1462 | video_init; |
|
|
1463 | audio_init; |
|
|
1464 | |
|
|
1465 | Event::loop; |
|
|
1466 | |
|
|
1467 | END { CFClient::SDL_Quit } |
|
|
1468 | |
|
|
1469 | |