1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
|
|
4 | use utf8; |
4 | |
5 | |
5 | use Glib; |
6 | use Glib; |
6 | use Gtk2 -init; |
7 | use Gtk2 -init; |
7 | |
8 | |
8 | use SDL; |
9 | use SDL; |
… | |
… | |
11 | use SDL::Surface; |
12 | use SDL::Surface; |
12 | use SDL::OpenGL; |
13 | use SDL::OpenGL; |
13 | use SDL::OpenGL::Constants; |
14 | use SDL::OpenGL::Constants; |
14 | |
15 | |
15 | use Crossfire; |
16 | use Crossfire; |
16 | use Crossfire::Client; |
|
|
17 | use Crossfire::Protocol; |
17 | use Crossfire::Protocol; |
18 | |
18 | |
19 | use Client::Util; |
19 | use CFClient; |
20 | use Client::Widget; |
20 | use CFClient::Widget; |
21 | |
21 | |
22 | our $VERSION = '0.1'; |
22 | our $VERSION = '0.1'; |
|
|
23 | |
|
|
24 | my $MAX_FPS = 30; |
|
|
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
|
|
26 | |
|
|
27 | our $FACECACHE; |
23 | |
28 | |
24 | our $CFG; |
29 | our $CFG; |
25 | our $CONN; |
30 | our $CONN; |
26 | |
31 | |
|
|
32 | our $WIDTH; |
|
|
33 | our $HEIGHT; |
|
|
34 | our $FULLSCREEN; |
|
|
35 | |
|
|
36 | our $FONTSIZE; |
|
|
37 | |
27 | our $SDL_TIMER; |
38 | our $SDL_TIMER; |
28 | our $SDL_APP; |
39 | our $SDL_APP; |
29 | our $SDL_EV = new SDL::Event; |
40 | our $SDL_EV; |
30 | our %SDL_CB; |
41 | our %SDL_CB; |
31 | |
42 | |
|
|
43 | our $ALT_ENTER_MESSAGE; |
|
|
44 | our $STATUS_LINE; |
|
|
45 | our $DEBUG_STATUS; |
|
|
46 | |
|
|
47 | my $last_refresh; |
|
|
48 | my %ANIMATE; |
|
|
49 | my $refresh_handler; |
|
|
50 | |
|
|
51 | our ($tw, $te); # Test widget #d# |
|
|
52 | |
32 | sub init_screen { |
53 | sub init_screen { |
33 | # nuke all gl context data |
|
|
34 | |
|
|
35 | $SDL_APP = new SDL::App |
54 | $SDL_APP = new SDL::App |
36 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
55 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
37 | -title => "Crossfire+ Client", |
56 | -title => "Crossfire+ Client", |
38 | -width => $CFG->{width}, |
57 | -width => $WIDTH, |
39 | -height => $CFG->{height}, |
58 | -height => $HEIGHT, |
40 | -opengl => 1, |
59 | -opengl => 1, |
41 | -red_size => 8, |
60 | -red_size => 5, |
42 | -green_size => 8, |
61 | -green_size => 5, |
43 | -blue_size => 8, |
62 | -blue_size => 5, |
|
|
63 | -alpha_size => 0, |
44 | -double_buffer => 1, |
64 | -double_buffer => 1, |
45 | -fullscreen => $CFG->{fullscreen}, |
65 | -fullscreen => $FULLSCREEN, |
46 | -resizeable => 0; |
66 | -resizeable => 0; |
47 | |
67 | |
|
|
68 | $SDL_EV = new SDL::Event; |
|
|
69 | $SDL_EV->set_unicode (1); |
|
|
70 | |
|
|
71 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
|
|
72 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
73 | while $SDL_EV->poll; |
|
|
74 | |
|
|
75 | 1 |
|
|
76 | }; |
|
|
77 | |
|
|
78 | $last_refresh = SDL::GetTicks; |
|
|
79 | |
|
|
80 | CFClient::gl_init; |
|
|
81 | |
|
|
82 | $FONTSIZE = int $HEIGHT / 50; |
|
|
83 | |
|
|
84 | ############################################################################# |
|
|
85 | |
|
|
86 | glClearColor 0.45, 0.45, 0.45, 1; |
|
|
87 | |
48 | glEnable GL_TEXTURE_2D; |
88 | glEnable GL_TEXTURE_2D; |
49 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
89 | glEnable GL_COLOR_MATERIAL; |
50 | glShadeModel GL_FLAT; |
90 | glShadeModel GL_FLAT; |
51 | glDisable GL_DEPTH_TEST; |
91 | glDisable GL_DEPTH_TEST; |
52 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
92 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
53 | glEnable GL_BLEND; |
93 | |
|
|
94 | ############################################################################# |
|
|
95 | |
|
|
96 | $DEBUG_STATUS = new CFClient::Widget::Label; |
|
|
97 | $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
98 | |
|
|
99 | $STATUS_LINE = new CFClient::Widget::Label |
|
|
100 | y => $HEIGHT * 59 / 60 - $FONTSIZE; |
|
|
101 | $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); |
|
|
102 | |
|
|
103 | $ALT_ENTER_MESSAGE = new CFClient::Widget::Label |
|
|
104 | y => $HEIGHT * 59 / 60, |
|
|
105 | height => $HEIGHT / 60, |
|
|
106 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
107 | $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
108 | |
|
|
109 | # Test code #d# |
|
|
110 | unless ($tw) { # haha... |
|
|
111 | $te = new CFClient::Widget::FancyFrame x => 300, z => 1; |
|
|
112 | $te->add (new CFClient::Widget::Entry); |
|
|
113 | $CFClient::Widget::TOPLEVEL->add ($te); |
|
|
114 | |
|
|
115 | $tw = new CFClient::Widget::Animator x => $WIDTH - 200, w => 400, h => 300; |
|
|
116 | my $lbl1 = new CFClient::Widget::Label text => "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
117 | my $lbl2 = new CFClient::Widget::Label text => "LBL2"; |
|
|
118 | my $vb = new CFClient::Widget::VBox; |
|
|
119 | my $f = new CFClient::Widget::FancyFrame; |
|
|
120 | my $f2 = new CFClient::Widget::FancyFrame; |
|
|
121 | $f->add ($lbl1); |
|
|
122 | $f2->add ($lbl2); |
|
|
123 | $vb->add ($f); |
|
|
124 | $vb->add ($f2, 1); |
|
|
125 | |
|
|
126 | $tw->add ($vb); |
|
|
127 | $tw->moveto (0, 0); |
|
|
128 | $CFClient::Widget::TOPLEVEL->add ($tw); |
|
|
129 | |
|
|
130 | # $f->move ($WIDTH - 200, 0); |
|
|
131 | # $CFClient::Widget::TOPLEVEL->add ($f); |
|
|
132 | } |
|
|
133 | } |
|
|
134 | |
|
|
135 | sub destroy_screen { |
|
|
136 | remove Glib::Source $SDL_TIMER; |
|
|
137 | undef $SDL_APP; |
|
|
138 | undef $SDL_EV; |
|
|
139 | SDL::Quit; |
|
|
140 | } |
|
|
141 | |
|
|
142 | sub start_game { |
|
|
143 | $WIDTH = $CFG->{width}; |
|
|
144 | $HEIGHT = $CFG->{height}; |
|
|
145 | $FULLSCREEN = 0; |
|
|
146 | |
|
|
147 | init_screen; |
|
|
148 | |
|
|
149 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
150 | |
|
|
151 | $CONN = new conn |
|
|
152 | host => $CFG->{host}, |
|
|
153 | port => $CFG->{port}, |
|
|
154 | user => $CFG->{user}, |
|
|
155 | pass => $CFG->{password}, |
|
|
156 | mapw => $mapsize, |
|
|
157 | maph => $mapsize, |
|
|
158 | ; |
|
|
159 | |
|
|
160 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
161 | } |
|
|
162 | |
|
|
163 | sub stop_game { |
|
|
164 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
165 | undef $refresh_handler; |
|
|
166 | |
|
|
167 | undef $CONN; |
|
|
168 | destroy_screen; |
|
|
169 | } |
|
|
170 | |
|
|
171 | sub force_refresh { |
|
|
172 | glViewport 0, 0, $WIDTH, $HEIGHT; |
54 | |
173 | |
55 | glMatrixMode GL_PROJECTION; |
174 | glMatrixMode GL_PROJECTION; |
56 | glLoadIdentity; |
175 | glLoadIdentity; |
57 | glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -1 , 1; |
176 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
|
|
177 | glMatrixMode GL_MODELVIEW; |
58 | |
178 | |
59 | # re-bind all textures |
179 | glClear GL_COLOR_BUFFER_BIT; |
60 | } |
|
|
61 | |
180 | |
62 | sub start_game { |
181 | $CFClient::Widget::TOPLEVEL->draw; |
63 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
182 | |
64 | while ($SDL_EV->poll) { |
183 | SDL::GLSwapBuffers; |
65 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
184 | } |
|
|
185 | |
|
|
186 | sub debug { |
|
|
187 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
188 | $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request); |
|
|
189 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0); |
|
|
190 | } |
|
|
191 | |
|
|
192 | my $FPS; |
|
|
193 | |
|
|
194 | sub refresh { |
|
|
195 | $refresh_handler ||= add Glib::Idle sub { |
|
|
196 | if ($SDL_APP) { |
|
|
197 | my $next_refresh = SDL::GetTicks; |
|
|
198 | |
|
|
199 | if ($next_refresh - $last_refresh < $TICKS_PER_FRAME) { |
|
|
200 | SDL::Delay $TICKS_PER_FRAME - ($next_refresh - $last_refresh); |
|
|
201 | $next_refresh = SDL::GetTicks; |
|
|
202 | } |
|
|
203 | |
|
|
204 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
|
|
205 | $last_refresh = $next_refresh; |
|
|
206 | |
|
|
207 | if ($interval) { |
|
|
208 | $FPS ||= 1 / $interval; |
|
|
209 | $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; |
|
|
210 | debug sprintf "%5.02f", $FPS; |
|
|
211 | } |
|
|
212 | |
|
|
213 | force_refresh; |
|
|
214 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
215 | |
|
|
216 | if (%ANIMATE) { |
|
|
217 | 1 |
|
|
218 | } else { |
|
|
219 | undef $refresh_handler; |
|
|
220 | 0 |
|
|
221 | } |
|
|
222 | } else { |
|
|
223 | undef $refresh_handler; |
|
|
224 | 0 |
66 | } |
225 | } |
67 | |
|
|
68 | 1 |
|
|
69 | }; |
226 | }; |
70 | |
|
|
71 | init_screen; |
|
|
72 | |
|
|
73 | $CONN = new conn |
|
|
74 | host => $CFG->{host}, |
|
|
75 | port => $CFG->{port}; |
|
|
76 | } |
227 | } |
77 | |
228 | |
78 | sub stop_game { |
229 | sub animation_start { |
79 | remove Glib::Source $SDL_TIMER; |
230 | my ($widget) = @_; |
|
|
231 | $ANIMATE{$widget} = $widget; |
|
|
232 | Scalar::Util::weaken $ANIMATE{$widget}; |
80 | |
233 | |
81 | undef $SDL_APP; |
234 | refresh; |
82 | SDL::Quit; |
|
|
83 | } |
235 | } |
84 | |
236 | |
85 | sub refresh { |
237 | sub animation_stop { |
86 | glClearColor 0, 0, 0, 0; |
238 | my ($widget) = @_; |
87 | glClear GL_COLOR_BUFFER_BIT; |
239 | delete $ANIMATE{$widget}; |
88 | |
|
|
89 | my $map = $CONN->{map}; |
|
|
90 | |
|
|
91 | for my $x (0 .. $CONN->{mapw} - 1) { |
|
|
92 | for my $y (0 .. $CONN->{maph} - 1) { |
|
|
93 | |
|
|
94 | my $cell = $map->[$x][$y] |
|
|
95 | or next; |
|
|
96 | |
|
|
97 | my $darkness = $cell->[3] * (1 / 255); |
|
|
98 | glColor $darkness, $darkness, $darkness; |
|
|
99 | |
|
|
100 | for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
|
|
101 | my $tex = $CONN->{face}[$num]{texture} || 0; |
|
|
102 | |
|
|
103 | glBindTexture GL_TEXTURE_2D, $tex; |
|
|
104 | |
|
|
105 | glBegin GL_QUADS; |
|
|
106 | glTexCoord 0, 0; glVertex $x, $y; |
|
|
107 | glTexCoord 0, 1; glVertex $x, $y + 1; |
|
|
108 | glTexCoord 1, 1; glVertex $x + 1, $y + 1; |
|
|
109 | glTexCoord 1, 0; glVertex $x + 1, $y; |
|
|
110 | glEnd; |
|
|
111 | } |
|
|
112 | } |
|
|
113 | } |
|
|
114 | |
|
|
115 | SDL::GLSwapBuffers; |
|
|
116 | } |
240 | } |
117 | |
241 | |
118 | %SDL_CB = ( |
242 | %SDL_CB = ( |
119 | SDL_QUIT() => sub { |
243 | SDL_QUIT() => sub { |
120 | warn "sdl quit\n";#d# |
244 | main_quit Gtk2; |
121 | exit; |
|
|
122 | }, |
245 | }, |
123 | SDL_VIDEORESIZE() => sub { |
246 | SDL_VIDEORESIZE() => sub { |
124 | }, |
247 | }, |
125 | SDL_VIDEOEXPOSE() => sub { |
248 | SDL_VIDEOEXPOSE() => sub { |
126 | refresh; |
249 | refresh; |
127 | }, |
250 | }, |
128 | SDL_KEYDOWN() => sub { |
251 | SDL_KEYDOWN() => sub { |
|
|
252 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
|
|
253 | # alt-enter |
|
|
254 | $FULLSCREEN = !$FULLSCREEN; |
|
|
255 | init_screen; |
|
|
256 | } else { |
129 | # Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
257 | CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); |
|
|
258 | } |
130 | }, |
259 | }, |
131 | SDL_KEYUP() => sub { |
260 | SDL_KEYUP() => sub { |
132 | # Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
261 | CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); |
133 | }, |
262 | }, |
134 | SDL_MOUSEMOTION() => sub { |
263 | SDL_MOUSEMOTION() => sub { |
135 | warn "sdl motion\n";#d# |
264 | CFClient::Widget::feed_sdl_motion_event ($SDL_EV); |
136 | }, |
265 | }, |
137 | SDL_MOUSEBUTTONDOWN() => sub { |
266 | SDL_MOUSEBUTTONDOWN() => sub { |
138 | # Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
267 | CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); |
139 | }, |
268 | }, |
140 | SDL_MOUSEBUTTONUP() => sub { |
269 | SDL_MOUSEBUTTONUP() => sub { |
141 | # Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
270 | CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); |
142 | }, |
271 | }, |
143 | SDL_ACTIVEEVENT() => sub { |
272 | SDL_ACTIVEEVENT() => sub { |
144 | warn "active\n";#d# |
273 | printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
145 | }, |
274 | }, |
146 | ); |
275 | ); |
147 | |
276 | |
148 | @conn::ISA = Crossfire::Protocol::; |
277 | @conn::ISA = Crossfire::Protocol::; |
149 | |
278 | |
… | |
… | |
154 | } |
283 | } |
155 | |
284 | |
156 | sub conn::map_scroll { |
285 | sub conn::map_scroll { |
157 | my ($self, $dx, $dy) = @_; |
286 | my ($self, $dx, $dy) = @_; |
158 | |
287 | |
159 | refresh; |
288 | # refresh; |
160 | } |
289 | } |
161 | |
290 | |
162 | sub conn::map_clear { |
291 | sub conn::map_clear { |
163 | my ($self) = @_; |
292 | my ($self) = @_; |
164 | |
293 | |
165 | refresh; |
294 | # refresh; |
|
|
295 | } |
|
|
296 | |
|
|
297 | sub conn::face_find { |
|
|
298 | my ($self, $face) = @_; |
|
|
299 | |
|
|
300 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
166 | } |
301 | } |
167 | |
302 | |
168 | sub conn::face_update { |
303 | sub conn::face_update { |
169 | my ($self, $num, $face) = @_; |
304 | my ($self, $face) = @_; |
170 | |
305 | |
171 | my $pb = new Gtk2::Gdk::PixbufLoader; |
306 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
172 | $pb->write ($face->{image}); |
|
|
173 | $pb->close; |
|
|
174 | |
307 | |
175 | $pb = $pb->get_pixbuf; |
308 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
176 | $pb = $pb->add_alpha (0, 0, 0, 0); |
309 | } |
177 | |
310 | |
178 | glGetError(); |
311 | sub conn::query { |
179 | my ($tex) = @{glGenTextures 1}; |
312 | my ($self, $flags, $prompt) = @_; |
180 | |
313 | |
181 | $face->{texture} = $tex; |
314 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
|
|
315 | } |
|
|
316 | |
|
|
317 | sub gtk_add_cfg_field { |
|
|
318 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
|
|
319 | my $i = $cfg->{_i}++; |
|
|
320 | $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); |
|
|
321 | $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1); |
|
|
322 | if ($key eq 'password') { |
|
|
323 | $ent->set_invisible_char ("*"); |
|
|
324 | $ent->set (visibility => 0) |
|
|
325 | } |
|
|
326 | $ent->set_text ($value); |
|
|
327 | $ent->signal_connect (changed => sub { |
|
|
328 | my ($ent) = @_; |
|
|
329 | $cfg->{$key} = $ent->get_text; |
|
|
330 | # TODO: Mapsize should be a slider in the game gui |
|
|
331 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
|
|
332 | $cfg->{$key} = 100; |
|
|
333 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
334 | $cfg->{$key} = 50; |
|
|
335 | } |
|
|
336 | }); |
|
|
337 | } |
|
|
338 | |
|
|
339 | sub run_config_dialog { |
|
|
340 | my (%events) = @_; |
|
|
341 | |
|
|
342 | my $w = Gtk2::Window->new; |
|
|
343 | |
|
|
344 | my @cfg = ( |
|
|
345 | [qw/Host host/], |
|
|
346 | [qw/Port port/], |
|
|
347 | [qw/Mapsize% mapsize/], |
|
|
348 | [qw/Username user/], |
|
|
349 | [qw/Password password/], |
182 | |
350 | ); |
183 | glBindTexture GL_TEXTURE_2D, $tex; |
351 | |
184 | my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr; |
352 | my $cfg = {}; |
|
|
353 | |
|
|
354 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
355 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
356 | |
|
|
357 | $w->add (my $vb = Gtk2::VBox->new); |
|
|
358 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
|
|
359 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
|
|
360 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
|
|
361 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
|
|
362 | my $i = 0; |
|
|
363 | my $act = 0; |
|
|
364 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
|
|
365 | if ($_ eq $selmode) { $act = $i } |
|
|
366 | $cb->append_text ($_); |
|
|
367 | $i++; |
|
|
368 | } |
|
|
369 | $cb->set_active ($act); |
|
|
370 | $cb->signal_connect (changed => sub { |
|
|
371 | my ($cb) = @_; |
|
|
372 | my $txt = $cb->get_active_text; |
|
|
373 | if ($txt =~ m/(\d+)x(\d+)/) { |
|
|
374 | $::CFG->{width} = $1; |
|
|
375 | $::CFG->{height} = $2; |
185 | |
376 | } |
186 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
377 | }); |
187 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
378 | |
188 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
379 | $cfg->{_i} = 1; |
189 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
380 | for (@cfg) { |
190 | |
381 | gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]}); |
191 | glTexImage2D GL_TEXTURE_2D, 0, |
382 | } |
192 | GL_RGBA8, |
383 | |
193 | $pb->get_width, $pb->get_height, |
384 | $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
|
|
385 | $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5); |
|
|
386 | $cb->signal_connect (clicked => sub { |
|
|
387 | for (keys %$cfg) { |
|
|
388 | $::CFG->{$_} = $cfg->{$_} |
|
|
389 | if $_ ne '_i'; |
194 | 0, |
390 | } |
|
|
391 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
|
|
392 | }); |
|
|
393 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
|
|
394 | $cb->signal_connect (clicked => sub { |
|
|
395 | for (keys %$cfg) { |
|
|
396 | $::CFG->{$_} = $cfg->{$_} |
|
|
397 | if $_ ne '_i'; |
195 | GL_RGBA, |
398 | } |
196 | GL_UNSIGNED_BYTE, |
399 | my $cb = $events{login} || sub {}; |
197 | $pb->get_pixels; |
400 | $cb->($::CFG->{user}, $::CFG->{password}); |
198 | my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr; |
401 | }); |
|
|
402 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
|
|
403 | $cb->signal_connect (clicked => sub { |
|
|
404 | my $cb = $events{logout} || sub {}; |
|
|
405 | $cb->(); |
|
|
406 | }); |
|
|
407 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
|
|
408 | $cb->signal_connect (clicked => sub { $w->destroy }); |
|
|
409 | |
|
|
410 | $w->show_all; |
|
|
411 | |
|
|
412 | $w->signal_connect (destroy => sub { Gtk2->main_quit }); |
199 | } |
413 | } |
|
|
414 | |
200 | |
415 | |
201 | ############################################################################# |
416 | ############################################################################# |
202 | |
417 | |
|
|
418 | SDL::Init SDL_INIT_EVERYTHING; |
|
|
419 | |
|
|
420 | my $mapwidget = CFClient::Widget::MapWidget->new; |
|
|
421 | |
|
|
422 | $CFClient::Widget::TOPLEVEL->add ($mapwidget); |
|
|
423 | $mapwidget->focus_in; |
|
|
424 | |
203 | Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc"; |
425 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
204 | |
426 | |
205 | $CFG ||= { |
427 | $CFG ||= { |
206 | width => 640, |
428 | width => 640, |
207 | height => 480, |
429 | height => 480, |
|
|
430 | mapsize => 100, |
208 | fullscreen => 0, |
431 | fullscreen => 0, |
209 | host => "crossfire.schmorp.de", |
432 | host => "crossfire.schmorp.de", |
210 | port => 13327, |
433 | port => 13327, |
211 | }; |
434 | }; |
212 | |
435 | |
213 | Client::Util::run_config_dialog |
436 | { |
|
|
437 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
|
|
438 | |
|
|
439 | CFClient::add_font $_ for @fonts; |
|
|
440 | CFClient::set_font $fonts[0]; |
|
|
441 | } |
|
|
442 | |
|
|
443 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
|
|
444 | |
|
|
445 | run_config_dialog |
214 | login => sub { start_game }, |
446 | login => sub { start_game }, |
215 | logout => sub { stop_game }, |
447 | logout => sub { stop_game }; |
216 | |
448 | |
217 | main Gtk2; |
449 | main Gtk2; |
|
|
450 | |
|
|
451 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |