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 $MIN_FPS = 5; # unused |
|
|
26 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
|
|
27 | |
|
|
28 | our $FACECACHE; |
|
|
29 | |
|
|
30 | our $CFG; |
|
|
31 | our $CONN; |
|
|
32 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
|
|
33 | |
|
|
34 | our @SDL_MODES; |
|
|
35 | our $WIDTH; |
|
|
36 | our $HEIGHT; |
|
|
37 | our $FULLSCREEN; |
|
|
38 | |
|
|
39 | our $NOW; |
|
|
40 | |
|
|
41 | our $MAPWIDGET; |
|
|
42 | our $FONTSIZE; |
|
|
43 | |
|
|
44 | our $SDL_TIMER; |
|
|
45 | our $SDL_APP; |
|
|
46 | our $SDL_EV; |
|
|
47 | our %SDL_CB; |
|
|
48 | |
|
|
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 | }); |
27 | |
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 | } |
|
|
160 | |
|
|
161 | sub init_screen { |
|
|
162 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
163 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
164 | |
28 | $app = new SDL::App |
165 | $SDL_APP = new SDL::App |
29 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
166 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
30 | -title => "Crossfire+ Client", |
167 | -title => "Crossfire+ Client", |
31 | -width => $WIDTH, |
168 | -width => $WIDTH, |
32 | -height => $HEIGHT, |
169 | -height => $HEIGHT, |
33 | -opengl => 1, |
170 | -opengl => 1, |
34 | -red_size => 8, |
171 | -red_size => 5, |
35 | -green_size => 8, |
172 | -green_size => 5, |
36 | -blue_size => 8, |
173 | -blue_size => 5, |
|
|
174 | -alpha_size => 0, |
37 | -double_buffer => 1, |
175 | -double_buffer => 1, |
|
|
176 | -fullscreen => $FULLSCREEN, |
38 | -resizeable => 0; |
177 | -resizeable => 0; |
39 | |
178 | |
40 | glEnable GL_TEXTURE_2D; |
179 | $SDL_EV = new SDL::Event; |
41 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL; |
180 | $SDL_EV->set_unicode (1); |
42 | glShadeModel GL_FLAT; |
181 | |
43 | glDisable GL_DEPTH_TEST; |
182 | $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { |
|
|
183 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
184 | while $SDL_EV->poll; |
|
|
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; |
|
|
231 | |
44 | glMatrixMode GL_PROJECTION; |
232 | glMatrixMode GL_PROJECTION; |
45 | |
|
|
46 | glLoadIdentity; |
233 | glLoadIdentity; |
47 | glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1; |
234 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
|
|
235 | glMatrixMode GL_MODELVIEW; |
|
|
236 | glLoadIdentity; |
48 | |
237 | |
49 | # re-bind all textures |
238 | glClear GL_COLOR_BUFFER_BIT; |
|
|
239 | |
|
|
240 | $CFClient::UI::TOPLEVEL->draw; |
|
|
241 | |
|
|
242 | SDL::GLSwapBuffers; |
50 | } |
243 | } |
|
|
244 | |
|
|
245 | my $FPS; |
51 | |
246 | |
52 | sub refresh { |
247 | sub refresh { |
53 | glClearColor 0.5, 0.5, 0.7, 0; |
248 | $refresh_handler ||= add Glib::Idle sub { |
54 | glClear GL_COLOR_BUFFER_BIT; |
249 | if ($SDL_APP) { |
|
|
250 | $NOW = SDL::GetTicks; |
55 | |
251 | |
56 | my $map = $conn->{map}; |
252 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
57 | |
253 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
58 | for my $x (0 .. $conn->{mapw} - 1) { |
254 | $NOW = SDL::GetTicks; |
59 | for my $y (0 .. $conn->{maph} - 1) { |
|
|
60 | |
|
|
61 | my $cell = $map->[$x][$y] |
|
|
62 | or next; |
|
|
63 | |
|
|
64 | for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
|
|
65 | my $tex = $conn->{face}[$num]{texture} || 0; |
|
|
66 | |
|
|
67 | glBindTexture GL_TEXTURE_2D, $tex; |
|
|
68 | |
|
|
69 | glColor 1,0.2,0.7; |
|
|
70 | glBegin GL_QUADS; |
|
|
71 | glTexCoord 0, 0; glVertex $x, $y; |
|
|
72 | glTexCoord 0, 1; glVertex $x, $y + 0.9; |
|
|
73 | glTexCoord 1, 1; glVertex $x + 0.9, $y + 0.9; |
|
|
74 | glTexCoord 1, 0; glVertex $x + 0.9, $y; |
|
|
75 | glEnd; |
|
|
76 | } |
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 |
77 | } |
278 | } |
78 | } |
279 | }; |
79 | |
|
|
80 | SDL::GLSwapBuffers; |
|
|
81 | } |
280 | } |
82 | |
281 | |
83 | my $ev = new SDL::Event; |
282 | sub animation_start { |
84 | my %ev_cb; |
283 | my ($widget) = @_; |
|
|
284 | $ANIMATE{$widget} = $widget; |
|
|
285 | Scalar::Util::weaken $ANIMATE{$widget}; |
85 | |
286 | |
86 | sub event(&$) { |
|
|
87 | $ev_cb{$_[0]->()} = $_[1]; |
|
|
88 | } |
|
|
89 | |
|
|
90 | sub does(&) { shift } |
|
|
91 | |
|
|
92 | event {SDL_QUIT} does { |
|
|
93 | exit; |
|
|
94 | }; |
|
|
95 | |
|
|
96 | event {SDL_VIDEORESIZE} does { |
|
|
97 | print "resize\n"; |
|
|
98 | }; |
|
|
99 | |
|
|
100 | event {SDL_VIDEOEXPOSE} does { |
|
|
101 | refresh; |
287 | refresh; |
102 | }; |
288 | } |
103 | |
289 | |
104 | event {SDL_KEYDOWN} does { |
290 | sub animation_stop { |
105 | print "keypress\n"; |
291 | my ($widget) = @_; |
106 | }; |
292 | delete $ANIMATE{$widget}; |
|
|
293 | } |
107 | |
294 | |
108 | event {SDL_KEYUP} does { |
295 | %SDL_CB = ( |
109 | print "keyup\n";#d# |
296 | SDL_QUIT() => sub { |
110 | }; |
297 | main_quit Gtk2; |
111 | |
298 | }, |
112 | event {SDL_MOUSEMOTION} does { |
299 | SDL_VIDEORESIZE() => sub { |
113 | print "motion\n"; |
300 | }, |
114 | }; |
301 | SDL_VIDEOEXPOSE() => sub { |
115 | |
302 | refresh; |
116 | event {SDL_MOUSEBUTTONDOWN} does { |
303 | }, |
117 | print "button\n"; |
304 | SDL_KEYDOWN() => sub { |
118 | }; |
305 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
119 | |
306 | # alt-enter |
120 | event {SDL_MOUSEBUTTONUP} does { |
307 | $FULLSCREEN = !$FULLSCREEN; |
121 | print "buttup\n"; |
308 | destroy_screen; |
122 | }; |
309 | init_screen; |
123 | |
310 | } else { |
124 | event {SDL_ACTIVEEVENT} does { |
311 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
125 | print "active\n"; |
312 | } |
126 | }; |
313 | }, |
127 | |
314 | SDL_KEYUP() => sub { |
128 | package Crossfire::Client; |
315 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
|
|
316 | }, |
|
|
317 | SDL_MOUSEMOTION() => sub { |
|
|
318 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
|
|
319 | }, |
|
|
320 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
321 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
322 | }, |
|
|
323 | SDL_MOUSEBUTTONUP() => sub { |
|
|
324 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
325 | }, |
|
|
326 | SDL_ACTIVEEVENT() => sub { |
|
|
327 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
328 | }, |
|
|
329 | ); |
129 | |
330 | |
130 | @conn::ISA = Crossfire::Protocol::; |
331 | @conn::ISA = Crossfire::Protocol::; |
131 | |
332 | |
132 | sub conn::map_update { |
333 | sub conn::map_update { |
133 | my ($self, $dirty) = @_; |
334 | my ($self, $dirty) = @_; |
134 | |
335 | |
135 | refresh; |
336 | $MAPWIDGET->update; |
136 | } |
337 | } |
137 | |
338 | |
138 | sub conn::map_scroll { |
339 | sub conn::map_scroll { |
139 | my ($self, $dx, $dy) = @_; |
340 | my ($self, $dx, $dy) = @_; |
140 | |
341 | |
141 | refresh; |
342 | # refresh; |
142 | } |
343 | } |
143 | |
344 | |
144 | sub conn::map_clear { |
345 | sub conn::map_clear { |
145 | my ($self) = @_; |
346 | my ($self) = @_; |
146 | |
347 | |
147 | refresh; |
348 | # refresh; |
|
|
349 | } |
|
|
350 | |
|
|
351 | sub conn::face_find { |
|
|
352 | my ($self, $face) = @_; |
|
|
353 | |
|
|
354 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
148 | } |
355 | } |
149 | |
356 | |
150 | sub conn::face_update { |
357 | sub conn::face_update { |
151 | my ($self, $num, $face) = @_; |
358 | my ($self, $face) = @_; |
152 | |
359 | |
153 | warn "up face $self,$num,$face\n";#d# |
360 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
154 | #TODO |
|
|
155 | open my $fh, ">:raw", "/tmp/x~"; |
|
|
156 | syswrite $fh, $face->{image}; |
|
|
157 | close $fh; |
|
|
158 | |
361 | |
159 | my $surface = new SDL::Surface -name => "/tmp/x~"; |
362 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
|
|
363 | } |
160 | |
364 | |
161 | unlink "/tmp/x~"; |
365 | sub conn::query { |
|
|
366 | my ($self, $flags, $prompt) = @_; |
162 | |
367 | |
163 | my ($tex) = @{glGenTextures 1}; |
368 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
164 | glGetError(); |
369 | } |
165 | |
370 | |
166 | $face->{texture} = $tex; |
371 | sub gtk_add_cfg_field { |
|
|
372 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
|
|
373 | my $i = $cfg->{_i}++; |
|
|
374 | $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); |
|
|
375 | $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1); |
|
|
376 | if ($key eq 'password') { |
|
|
377 | $ent->set_invisible_char ("*"); |
|
|
378 | $ent->set (visibility => 0) |
|
|
379 | } |
|
|
380 | $ent->set_text ($value); |
|
|
381 | $ent->signal_connect (changed => sub { |
|
|
382 | my ($ent) = @_; |
|
|
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 | } |
|
|
390 | }); |
|
|
391 | } |
|
|
392 | |
|
|
393 | sub run_config_dialog { |
|
|
394 | my (%events) = @_; |
|
|
395 | |
|
|
396 | my $w = Gtk2::Window->new; |
|
|
397 | |
|
|
398 | my @cfg = ( |
|
|
399 | [qw/Host host/], |
|
|
400 | [qw/Port port/], |
|
|
401 | [qw/Mapsize% mapsize/], |
|
|
402 | [qw/Username user/], |
|
|
403 | [qw/Password password/], |
167 | |
404 | ); |
168 | glBindTexture GL_TEXTURE_2D, $tex; |
405 | |
169 | my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr; |
406 | my $cfg = {}; |
|
|
407 | |
|
|
408 | $w->add (my $vb = Gtk2::VBox->new); |
|
|
409 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
|
|
410 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
|
|
411 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
|
|
412 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
|
|
413 | my $i = 0; |
|
|
414 | my $act = 0; |
|
|
415 | for (map { "$_->[0]x$_->[1]" } @SDL_MODES) { |
|
|
416 | if ($_ eq $selmode) { $act = $i } |
|
|
417 | $cb->append_text ($_); |
|
|
418 | $i++; |
|
|
419 | } |
|
|
420 | $cb->set_active ($act); |
|
|
421 | $cb->signal_connect (changed => sub { |
|
|
422 | my ($cb) = @_; |
|
|
423 | my $txt = $cb->get_active_text; |
|
|
424 | if ($txt =~ m/(\d+)x(\d+)/) { |
|
|
425 | $::CFG->{width} = $1; |
|
|
426 | $::CFG->{height} = $2; |
170 | |
427 | } |
171 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
428 | }); |
172 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR; |
|
|
173 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
|
|
174 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
|
|
175 | |
|
|
176 | $surface->rgba; |
|
|
177 | |
429 | |
178 | glTexImage2D GL_TEXTURE_2D, 0, |
430 | $cfg->{_i} = 1; |
179 | 4, # components |
431 | for (@cfg) { |
180 | $surface->width, $surface->height, |
432 | gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]}); |
|
|
433 | } |
|
|
434 | |
|
|
435 | $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
|
|
436 | $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5); |
|
|
437 | $cb->signal_connect (clicked => sub { |
|
|
438 | for (keys %$cfg) { |
|
|
439 | $::CFG->{$_} = $cfg->{$_} |
|
|
440 | if $_ ne '_i'; |
181 | 0, |
441 | } |
|
|
442 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
|
|
443 | }); |
|
|
444 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
|
|
445 | $cb->signal_connect (clicked => sub { |
|
|
446 | for (keys %$cfg) { |
|
|
447 | $::CFG->{$_} = $cfg->{$_} |
|
|
448 | if $_ ne '_i'; |
182 | GL_RGBA, |
449 | } |
183 | GL_UNSIGNED_BYTE, |
450 | my $cb = $events{login} || sub {}; |
184 | $surface->pixels; |
451 | $cb->($::CFG->{user}, $::CFG->{password}); |
185 | my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr; |
452 | }); |
|
|
453 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
|
|
454 | $cb->signal_connect (clicked => sub { |
|
|
455 | my $cb = $events{logout} || sub {}; |
|
|
456 | $cb->(); |
|
|
457 | }); |
|
|
458 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
|
|
459 | $cb->signal_connect (clicked => sub { $w->destroy }); |
|
|
460 | |
|
|
461 | $w->show_all; |
|
|
462 | |
|
|
463 | $w->signal_connect (destroy => sub { Gtk2->main_quit }); |
186 | } |
464 | } |
|
|
465 | |
187 | |
466 | |
188 | ############################################################################# |
467 | ############################################################################# |
189 | |
468 | |
190 | use Event; |
469 | SDL::Init SDL_INIT_EVERYTHING; |
191 | |
470 | |
192 | glinit; |
471 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
|
|
472 | @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; |
193 | |
473 | |
194 | $conn = new conn |
474 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
475 | |
|
|
476 | $CFG ||= { |
|
|
477 | width => 640, |
|
|
478 | height => 480, |
|
|
479 | fullscreen => 0, |
|
|
480 | sdl_mode => 0, |
|
|
481 | mapsize => 100, |
195 | host => "cf.schmorp.de", |
482 | host => "crossfire.schmorp.de", |
196 | port => 13327; |
483 | port => 13327, |
197 | |
|
|
198 | Event->timer (after => 0, interval => 1/20, hard => 1, cb => sub { |
|
|
199 | while ($ev->poll) { |
|
|
200 | ($ev_cb{$ev->type} || sub { warn "unhandled event ", $ev->type })->(); |
|
|
201 | } |
|
|
202 | }); |
484 | }; |
203 | |
485 | |
204 | Event::loop; |
486 | { |
|
|
487 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
205 | |
488 | |
|
|
489 | CFClient::add_font $_ for @fonts; |
|
|
490 | CFClient::set_font $fonts[0]; |
|
|
491 | } |
206 | |
492 | |
|
|
493 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
|
|
494 | |
|
|
495 | init_screen; |
|
|
496 | |
|
|
497 | main Gtk2; |
|
|
498 | |
|
|
499 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
|
|
500 | |