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