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