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