… | |
… | |
12 | use SDL::Surface; |
12 | use SDL::Surface; |
13 | use SDL::OpenGL; |
13 | use SDL::OpenGL; |
14 | use SDL::OpenGL::Constants; |
14 | use SDL::OpenGL::Constants; |
15 | |
15 | |
16 | use Crossfire; |
16 | use Crossfire; |
17 | use Crossfire::Client; |
|
|
18 | use Crossfire::Protocol; |
17 | use Crossfire::Protocol; |
19 | |
18 | |
20 | use Crossfire::Client::Util; |
19 | use CFClient; |
21 | use Crossfire::Client::Widget; |
20 | use CFClient::UI; |
|
|
21 | |
|
|
22 | our $VERSION = '0.1'; |
|
|
23 | |
|
|
24 | my $MAX_FPS = 60; |
|
|
25 | my $MIN_FPS = 5; # unused |
|
|
26 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
22 | |
27 | |
23 | our $FACECACHE; |
28 | our $FACECACHE; |
24 | |
|
|
25 | our $VERSION = '0.1'; |
|
|
26 | |
29 | |
27 | our $CFG; |
30 | our $CFG; |
28 | our $CONN; |
31 | our $CONN; |
|
|
32 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
29 | |
33 | |
|
|
34 | our @SDL_MODES; |
|
|
35 | our $WIDTH; |
|
|
36 | our $HEIGHT; |
|
|
37 | our $FULLSCREEN; |
|
|
38 | |
|
|
39 | our $NOW; |
|
|
40 | |
|
|
41 | our $MAPWIDGET; |
30 | our $UIFONT; |
42 | our $FONTSIZE; |
31 | |
43 | |
32 | our $SDL_TIMER; |
44 | our $SDL_TIMER; |
33 | our $SDL_APP; |
45 | our $SDL_APP; |
34 | our $SDL_EV = new SDL::Event; |
46 | our $SDL_EV; |
35 | our %SDL_CB; |
47 | our %SDL_CB; |
36 | |
48 | |
37 | our @GL_INIT; # hooks called on every gl init |
49 | our $ALT_ENTER_MESSAGE; |
|
|
50 | our $STATUS_LINE; |
|
|
51 | our $DEBUG_STATUS; |
|
|
52 | |
|
|
53 | my $last_refresh; |
|
|
54 | my %ANIMATE; |
|
|
55 | my $refresh_handler; |
|
|
56 | |
|
|
57 | sub status { |
|
|
58 | $STATUS_LINE->set_text ($_[0]); |
|
|
59 | my ($w, $h) = $STATUS_LINE->size_request; |
|
|
60 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
|
|
61 | } |
|
|
62 | |
|
|
63 | sub debug { |
|
|
64 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
65 | my ($w, $h) = $DEBUG_STATUS->size_request; |
|
|
66 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
67 | } |
|
|
68 | |
|
|
69 | sub start_game { |
|
|
70 | status "logging in..."; |
|
|
71 | |
|
|
72 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
73 | |
|
|
74 | $CONN = new conn |
|
|
75 | host => $CFG->{host}, |
|
|
76 | port => $CFG->{port}, |
|
|
77 | user => $CFG->{user}, |
|
|
78 | pass => $CFG->{password}, |
|
|
79 | mapw => $mapsize, |
|
|
80 | maph => $mapsize, |
|
|
81 | ; |
|
|
82 | |
|
|
83 | status "login successful"; |
|
|
84 | |
|
|
85 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
86 | } |
|
|
87 | |
|
|
88 | sub stop_game { |
|
|
89 | undef $CONN; |
|
|
90 | } |
|
|
91 | |
|
|
92 | sub config_dialog { |
|
|
93 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
|
|
94 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
95 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
|
|
96 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
97 | |
|
|
98 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
|
|
99 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
|
|
100 | |
|
|
101 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
102 | $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); |
|
|
103 | |
|
|
104 | $mode_slider->connect (changed => sub { |
|
|
105 | my ($self, $value) = @_; |
|
|
106 | |
|
|
107 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
|
|
108 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
109 | }); |
|
|
110 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
|
|
111 | |
|
|
112 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); |
|
|
113 | $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
|
|
114 | my ($self, $value) = @_; |
|
|
115 | $CFG->{fullscreen} = $value; |
|
|
116 | }); |
|
|
117 | |
|
|
118 | $table->add (1, 2, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
119 | destroy_screen (); |
|
|
120 | init_screen (); |
|
|
121 | }); |
|
|
122 | |
|
|
123 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server"); |
|
|
124 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
125 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); |
|
|
126 | $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}); |
|
|
127 | |
|
|
128 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); |
|
|
129 | $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}); |
|
|
130 | |
|
|
131 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
|
|
132 | $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}); |
|
|
133 | |
|
|
134 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); |
|
|
135 | $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); |
|
|
136 | |
|
|
137 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size"); |
|
|
138 | $table->add (1, 6, new CFClient::UI::Slider |
|
|
139 | req_w => 100, |
|
|
140 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
141 | connect_changed => sub { |
|
|
142 | my ($self, $value) = @_; |
|
|
143 | |
|
|
144 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
|
|
145 | }, |
|
|
146 | ); |
|
|
147 | |
|
|
148 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
|
|
149 | start_game; |
|
|
150 | }); |
|
|
151 | |
|
|
152 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
153 | |
|
|
154 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
|
|
155 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
156 | status "Configuration Saved"; |
|
|
157 | }); |
|
|
158 | $CFClient::UI::TOPLEVEL->add ($dialog); |
|
|
159 | } |
38 | |
160 | |
39 | sub init_screen { |
161 | sub init_screen { |
|
|
162 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
163 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
164 | |
40 | $SDL_APP = new SDL::App |
165 | $SDL_APP = new SDL::App |
41 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
166 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
42 | -title => "Crossfire+ Client", |
167 | -title => "Crossfire+ Client", |
43 | -width => $CFG->{width}, |
168 | -width => $WIDTH, |
44 | -height => $CFG->{height}, |
169 | -height => $HEIGHT, |
45 | -opengl => 1, |
170 | -opengl => 1, |
46 | -red_size => 8, |
171 | -red_size => 5, |
47 | -green_size => 8, |
172 | -green_size => 5, |
48 | -blue_size => 8, |
173 | -blue_size => 5, |
|
|
174 | -alpha_size => 0, |
49 | -double_buffer => 1, |
175 | -double_buffer => 1, |
50 | -fullscreen => $CFG->{fullscreen}, |
176 | -fullscreen => $FULLSCREEN, |
51 | -resizeable => 0; |
177 | -resizeable => 0; |
52 | |
178 | |
53 | glClearColor 0, 0, 0, 0; |
179 | $SDL_EV = new SDL::Event; |
|
|
180 | $SDL_EV->set_unicode (1); |
54 | |
181 | |
55 | glEnable GL_TEXTURE_2D; |
182 | $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { |
56 | glShadeModel GL_FLAT; |
183 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
57 | glDisable GL_DEPTH_TEST; |
184 | while $SDL_EV->poll; |
58 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
185 | |
|
|
186 | 1 |
|
|
187 | }; |
|
|
188 | |
|
|
189 | $last_refresh = SDL::GetTicks; |
|
|
190 | |
|
|
191 | CFClient::gl_init; |
|
|
192 | |
|
|
193 | $FONTSIZE = int $HEIGHT / 40; |
|
|
194 | |
|
|
195 | ############################################################################# |
|
|
196 | |
|
|
197 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
|
|
198 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
199 | |
|
|
200 | $STATUS_LINE = new CFClient::UI::Label |
|
|
201 | padding => 0, |
|
|
202 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
|
|
203 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
|
|
204 | |
|
|
205 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
206 | padding => 0, |
|
|
207 | y => $HEIGHT * 49 / 50, |
|
|
208 | height => $HEIGHT / 50, |
|
|
209 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
210 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
211 | |
|
|
212 | $MAPWIDGET = new CFClient::UI::MapWidget; |
|
|
213 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
|
|
214 | $MAPWIDGET->focus_in; |
|
|
215 | |
|
|
216 | config_dialog; |
|
|
217 | } |
|
|
218 | |
|
|
219 | sub destroy_screen { |
|
|
220 | $CFClient::UI::TOPLEVEL->{children} = []; |
|
|
221 | remove Glib::Source $SDL_TIMER; |
|
|
222 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
223 | undef $refresh_handler; |
|
|
224 | undef $SDL_APP; |
|
|
225 | undef $SDL_EV; |
|
|
226 | SDL::Quit; |
|
|
227 | } |
|
|
228 | |
|
|
229 | sub force_refresh { |
|
|
230 | glViewport 0, 0, $WIDTH, $HEIGHT; |
59 | |
231 | |
60 | glMatrixMode GL_PROJECTION; |
232 | glMatrixMode GL_PROJECTION; |
61 | glLoadIdentity; |
233 | glLoadIdentity; |
62 | glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; |
234 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
63 | |
|
|
64 | glMatrixMode GL_MODELVIEW; |
235 | glMatrixMode GL_MODELVIEW; |
|
|
236 | glLoadIdentity; |
65 | |
237 | |
66 | $_->() for @GL_INIT; |
238 | glClear GL_COLOR_BUFFER_BIT; |
67 | } |
|
|
68 | |
239 | |
69 | my $label;#d# |
240 | $CFClient::UI::TOPLEVEL->draw; |
70 | |
241 | |
71 | sub start_game { |
242 | SDL::GLSwapBuffers; |
72 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
243 | } |
73 | while ($SDL_EV->poll) { |
244 | |
74 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
245 | my $FPS; |
|
|
246 | |
|
|
247 | sub refresh { |
|
|
248 | $refresh_handler ||= add Glib::Idle sub { |
|
|
249 | if ($SDL_APP) { |
|
|
250 | $NOW = SDL::GetTicks; |
|
|
251 | |
|
|
252 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
|
|
253 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
|
|
254 | $NOW = SDL::GetTicks; |
|
|
255 | } |
|
|
256 | |
|
|
257 | my $interval = ($NOW - $last_refresh) * 0.001; |
|
|
258 | $last_refresh = $NOW; |
|
|
259 | |
|
|
260 | if ($interval) { |
|
|
261 | $FPS ||= 1 / $interval; |
|
|
262 | $FPS = $FPS * 0.9 + (1 / $interval) * 0.1; |
|
|
263 | debug sprintf "%5.02f", $FPS; |
|
|
264 | } |
|
|
265 | |
|
|
266 | force_refresh; |
|
|
267 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
268 | |
|
|
269 | if (%ANIMATE) { |
|
|
270 | 1 |
|
|
271 | } else { |
|
|
272 | undef $refresh_handler; |
|
|
273 | 0 |
|
|
274 | } |
|
|
275 | } else { |
|
|
276 | undef $refresh_handler; |
|
|
277 | 0 |
75 | } |
278 | } |
76 | |
|
|
77 | 1 |
|
|
78 | }; |
279 | }; |
79 | |
|
|
80 | init_screen; |
|
|
81 | |
|
|
82 | $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]"; |
|
|
83 | $label->activate; |
|
|
84 | |
|
|
85 | $CONN = new conn |
|
|
86 | host => $CFG->{host}, |
|
|
87 | port => $CFG->{port}; |
|
|
88 | } |
280 | } |
89 | |
281 | |
90 | sub stop_game { |
282 | sub animation_start { |
91 | remove Glib::Source $SDL_TIMER; |
283 | my ($widget) = @_; |
|
|
284 | $ANIMATE{$widget} = $widget; |
|
|
285 | Scalar::Util::weaken $ANIMATE{$widget}; |
92 | |
286 | |
93 | undef $SDL_APP; |
287 | refresh; |
94 | SDL::Quit; |
|
|
95 | } |
288 | } |
96 | |
289 | |
97 | sub refresh { |
290 | sub animation_stop { |
98 | glClear GL_COLOR_BUFFER_BIT; |
291 | my ($widget) = @_; |
99 | |
292 | delete $ANIMATE{$widget}; |
100 | $_->draw for values %Crossfire::Client::Widget::ACTIVE_WIDGETS; |
|
|
101 | |
|
|
102 | SDL::GLSwapBuffers; |
|
|
103 | } |
293 | } |
104 | |
294 | |
105 | %SDL_CB = ( |
295 | %SDL_CB = ( |
106 | SDL_QUIT() => sub { |
296 | SDL_QUIT() => sub { |
107 | main_quit Gtk2; |
297 | main_quit Gtk2; |
… | |
… | |
112 | refresh; |
302 | refresh; |
113 | }, |
303 | }, |
114 | SDL_KEYDOWN() => sub { |
304 | SDL_KEYDOWN() => sub { |
115 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
305 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
116 | # alt-enter |
306 | # alt-enter |
117 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
307 | $FULLSCREEN = !$FULLSCREEN; |
|
|
308 | destroy_screen; |
118 | init_screen; |
309 | init_screen; |
119 | } else { |
310 | } else { |
120 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
311 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
121 | } |
312 | } |
122 | }, |
313 | }, |
123 | SDL_KEYUP() => sub { |
314 | SDL_KEYUP() => sub { |
124 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
315 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
125 | }, |
316 | }, |
126 | SDL_MOUSEMOTION() => sub { |
317 | SDL_MOUSEMOTION() => sub { |
127 | warn "sdl motion\n";#d# |
318 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
128 | }, |
319 | }, |
129 | SDL_MOUSEBUTTONDOWN() => sub { |
320 | SDL_MOUSEBUTTONDOWN() => sub { |
130 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
321 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
131 | }, |
322 | }, |
132 | SDL_MOUSEBUTTONUP() => sub { |
323 | SDL_MOUSEBUTTONUP() => sub { |
133 | Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
324 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
134 | }, |
325 | }, |
135 | SDL_ACTIVEEVENT() => sub { |
326 | SDL_ACTIVEEVENT() => sub { |
136 | warn "active\n";#d# |
327 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
137 | }, |
328 | }, |
138 | ); |
329 | ); |
139 | |
330 | |
140 | @conn::ISA = Crossfire::Protocol::; |
331 | @conn::ISA = Crossfire::Protocol::; |
141 | |
332 | |
142 | sub conn::map_update { |
333 | sub conn::map_update { |
143 | my ($self, $dirty) = @_; |
334 | my ($self, $dirty) = @_; |
144 | |
335 | |
145 | refresh; |
336 | $MAPWIDGET->update; |
146 | } |
337 | } |
147 | |
338 | |
148 | sub conn::map_scroll { |
339 | sub conn::map_scroll { |
149 | my ($self, $dx, $dy) = @_; |
340 | my ($self, $dx, $dy) = @_; |
150 | |
341 | |
151 | refresh; |
342 | # refresh; |
152 | } |
343 | } |
153 | |
344 | |
154 | sub conn::map_clear { |
345 | sub conn::map_clear { |
155 | my ($self) = @_; |
346 | my ($self) = @_; |
156 | |
347 | |
157 | refresh; |
348 | # refresh; |
158 | } |
349 | } |
159 | |
350 | |
160 | sub conn::face_find { |
351 | sub conn::face_find { |
161 | my ($self, $face) = @_; |
352 | my ($self, $face) = @_; |
162 | |
353 | |
… | |
… | |
166 | sub conn::face_update { |
357 | sub conn::face_update { |
167 | my ($self, $face) = @_; |
358 | my ($self, $face) = @_; |
168 | |
359 | |
169 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
360 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
170 | |
361 | |
171 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
362 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
|
|
363 | } |
|
|
364 | |
|
|
365 | sub conn::query { |
|
|
366 | my ($self, $flags, $prompt) = @_; |
|
|
367 | |
|
|
368 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
172 | } |
369 | } |
173 | |
370 | |
174 | sub gtk_add_cfg_field { |
371 | sub gtk_add_cfg_field { |
175 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
372 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
176 | my $i = $cfg->{_i}++; |
373 | my $i = $cfg->{_i}++; |
… | |
… | |
182 | } |
379 | } |
183 | $ent->set_text ($value); |
380 | $ent->set_text ($value); |
184 | $ent->signal_connect (changed => sub { |
381 | $ent->signal_connect (changed => sub { |
185 | my ($ent) = @_; |
382 | my ($ent) = @_; |
186 | $cfg->{$key} = $ent->get_text; |
383 | $cfg->{$key} = $ent->get_text; |
|
|
384 | # TODO: Mapsize should be a slider in the game gui |
|
|
385 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
|
|
386 | $cfg->{$key} = 100; |
|
|
387 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
388 | $cfg->{$key} = 50; |
|
|
389 | } |
187 | }); |
390 | }); |
188 | } |
391 | } |
189 | |
392 | |
190 | sub run_config_dialog { |
393 | sub run_config_dialog { |
191 | my (%events) = @_; |
394 | my (%events) = @_; |
… | |
… | |
193 | my $w = Gtk2::Window->new; |
396 | my $w = Gtk2::Window->new; |
194 | |
397 | |
195 | my @cfg = ( |
398 | my @cfg = ( |
196 | [qw/Host host/], |
399 | [qw/Host host/], |
197 | [qw/Port port/], |
400 | [qw/Port port/], |
|
|
401 | [qw/Mapsize% mapsize/], |
198 | [qw/Username user/], |
402 | [qw/Username user/], |
199 | [qw/Password password/], |
403 | [qw/Password password/], |
200 | ); |
404 | ); |
201 | |
405 | |
202 | my $cfg = {}; |
406 | my $cfg = {}; |
203 | |
|
|
204 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
205 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
206 | |
407 | |
207 | $w->add (my $vb = Gtk2::VBox->new); |
408 | $w->add (my $vb = Gtk2::VBox->new); |
208 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
409 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
209 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
410 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
210 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
411 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
211 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
412 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
212 | my $i = 0; |
413 | my $i = 0; |
213 | my $act = 0; |
414 | my $act = 0; |
214 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
415 | for (map { "$_->[0]x$_->[1]" } @SDL_MODES) { |
215 | if ($_ eq $selmode) { $act = $i } |
416 | if ($_ eq $selmode) { $act = $i } |
216 | $cb->append_text ($_); |
417 | $cb->append_text ($_); |
217 | $i++; |
418 | $i++; |
218 | } |
419 | } |
219 | $cb->set_active ($act); |
420 | $cb->set_active ($act); |
… | |
… | |
236 | $cb->signal_connect (clicked => sub { |
437 | $cb->signal_connect (clicked => sub { |
237 | for (keys %$cfg) { |
438 | for (keys %$cfg) { |
238 | $::CFG->{$_} = $cfg->{$_} |
439 | $::CFG->{$_} = $cfg->{$_} |
239 | if $_ ne '_i'; |
440 | if $_ ne '_i'; |
240 | } |
441 | } |
241 | Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc"; |
442 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
242 | }); |
443 | }); |
243 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
444 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
244 | $cb->signal_connect (clicked => sub { |
445 | $cb->signal_connect (clicked => sub { |
245 | for (keys %$cfg) { |
446 | for (keys %$cfg) { |
246 | $::CFG->{$_} = $cfg->{$_} |
447 | $::CFG->{$_} = $cfg->{$_} |
… | |
… | |
249 | my $cb = $events{login} || sub {}; |
450 | my $cb = $events{login} || sub {}; |
250 | $cb->($::CFG->{user}, $::CFG->{password}); |
451 | $cb->($::CFG->{user}, $::CFG->{password}); |
251 | }); |
452 | }); |
252 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
453 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
253 | $cb->signal_connect (clicked => sub { |
454 | $cb->signal_connect (clicked => sub { |
254 | my $cb = $events{login} || sub {}; |
455 | my $cb = $events{logout} || sub {}; |
255 | $cb->(); |
456 | $cb->(); |
256 | }); |
457 | }); |
257 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
458 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
258 | $cb->signal_connect (clicked => sub { $w->destroy }); |
459 | $cb->signal_connect (clicked => sub { $w->destroy }); |
259 | |
460 | |
… | |
… | |
265 | |
466 | |
266 | ############################################################################# |
467 | ############################################################################# |
267 | |
468 | |
268 | SDL::Init SDL_INIT_EVERYTHING; |
469 | SDL::Init SDL_INIT_EVERYTHING; |
269 | |
470 | |
270 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
471 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
|
|
472 | @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; |
271 | |
473 | |
272 | $mapwidget->activate; |
|
|
273 | $mapwidget->focus_in; |
|
|
274 | |
|
|
275 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
474 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
276 | |
475 | |
277 | $CFG ||= { |
476 | $CFG ||= { |
278 | width => 640, |
477 | width => 640, |
279 | height => 480, |
478 | height => 480, |
280 | fullscreen => 0, |
479 | fullscreen => 0, |
|
|
480 | sdl_mode => 0, |
|
|
481 | mapsize => 100, |
281 | host => "crossfire.schmorp.de", |
482 | host => "crossfire.schmorp.de", |
282 | port => 13327, |
483 | port => 13327, |
283 | }; |
484 | }; |
284 | |
485 | |
|
|
486 | { |
|
|
487 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
|
|
488 | |
|
|
489 | CFClient::add_font $_ for @fonts; |
|
|
490 | CFClient::set_font $fonts[0]; |
|
|
491 | } |
|
|
492 | |
285 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
493 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
286 | |
494 | |
287 | SDL::TTFInit; |
495 | init_screen; |
288 | |
|
|
289 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", 24 |
|
|
290 | or die "TTFOpenFont: $!"; |
|
|
291 | |
|
|
292 | run_config_dialog |
|
|
293 | login => sub { start_game }, |
|
|
294 | logout => sub { stop_game }; |
|
|
295 | |
496 | |
296 | main Gtk2; |
497 | main Gtk2; |
297 | |
498 | |
298 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
499 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
|
|
500 | |