… | |
… | |
40 | our %SDL_CB; |
40 | our %SDL_CB; |
41 | |
41 | |
42 | our @GL_INIT; # hooks called on every gl init |
42 | our @GL_INIT; # hooks called on every gl init |
43 | |
43 | |
44 | our $ALT_ENTER_MESSAGE; |
44 | our $ALT_ENTER_MESSAGE; |
|
|
45 | our $STATUS_LINE; |
45 | |
46 | |
46 | our $TOPLEVEL; |
47 | our $TOPLEVEL; |
47 | |
48 | |
48 | our $tw; # Test widget #d# |
49 | our $tw; # Test widget #d# |
|
|
50 | |
|
|
51 | my $last_refresh; |
|
|
52 | my %ANIMATE; |
|
|
53 | my $refresh_handler; |
49 | |
54 | |
50 | sub init_screen { |
55 | sub init_screen { |
51 | $SDL_APP = new SDL::App |
56 | $SDL_APP = new SDL::App |
52 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
57 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
53 | -title => "Crossfire+ Client", |
58 | -title => "Crossfire+ Client", |
54 | -width => $WIDTH, |
59 | -width => $WIDTH, |
55 | -height => $HEIGHT, |
60 | -height => $HEIGHT, |
56 | -opengl => 1, |
61 | -opengl => 1, |
57 | -red_size => 8, |
62 | -red_size => 5, |
58 | -green_size => 8, |
63 | -green_size => 5, |
59 | -blue_size => 8, |
64 | -blue_size => 5, |
|
|
65 | -alpha_size => 0, |
60 | -double_buffer => 1, |
66 | -double_buffer => 1, |
61 | -fullscreen => $FULLSCREEN, |
67 | -fullscreen => $FULLSCREEN, |
62 | -resizeable => 0; |
68 | -resizeable => 0; |
63 | |
69 | |
|
|
70 | $last_refresh = SDL::GetTicks; |
|
|
71 | |
64 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
72 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
65 | |
73 | |
66 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
74 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
67 | or warn "WARNING: non-power-of-two opengl extension required"; |
75 | or warn "WARNING: non-power-of-two opengl extension required"; |
68 | |
76 | |
69 | $FONTSIZE = int $HEIGHT / 50; |
77 | $FONTSIZE = int $HEIGHT / 50; |
70 | |
78 | |
71 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
79 | ############################################################################# |
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 | |
|
|
77 | # Test code #d# |
|
|
78 | { |
|
|
79 | my $frm = new Crossfire::Client::Widget::Frame; |
|
|
80 | $tw = new Crossfire::Client::Widget::Window; |
|
|
81 | $frm->add (my $te = new Crossfire::Client::Widget::TextEntry 0, 0, 10, $FONTSIZE, "Foo in the garden!"); |
|
|
82 | $tw->add ($frm); |
|
|
83 | |
|
|
84 | $tw->move (0, $HEIGHT - 120); |
|
|
85 | $TOPLEVEL->add ($tw); |
|
|
86 | # $te->focus_in; |
|
|
87 | } |
|
|
88 | |
80 | |
89 | glClearColor 0, 0, 0, 0; |
81 | glClearColor 0, 0, 0, 0; |
90 | |
82 | |
91 | glEnable GL_TEXTURE_2D; |
83 | glEnable GL_TEXTURE_2D; |
92 | glEnable GL_COLOR_MATERIAL; |
84 | glEnable GL_COLOR_MATERIAL; |
93 | glShadeModel GL_FLAT; |
85 | glShadeModel GL_FLAT; |
94 | glDisable GL_DEPTH_TEST; |
86 | glDisable GL_DEPTH_TEST; |
95 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
87 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
96 | |
88 | |
97 | $_->() for @GL_INIT; |
89 | $_->() for @GL_INIT; |
|
|
90 | |
|
|
91 | ############################################################################# |
|
|
92 | |
|
|
93 | $STATUS_LINE = new Crossfire::Client::Widget::Label |
|
|
94 | 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, |
|
|
95 | ""; |
|
|
96 | $TOPLEVEL->add ($STATUS_LINE); |
|
|
97 | |
|
|
98 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
|
|
99 | 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, |
|
|
100 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
101 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
102 | |
|
|
103 | # Test code #d# |
|
|
104 | unless ($tw) { # haha... |
|
|
105 | $tw = new Crossfire::Client::Widget::Animator; |
|
|
106 | my $lbl1 = new Crossfire::Client::Widget::Label |
|
|
107 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
108 | my $lbl2 = new Crossfire::Client::Widget::Label |
|
|
109 | 0, 0, 10, $FONTSIZE, "LBL2"; |
|
|
110 | |
|
|
111 | my $vb = new Crossfire::Client::Widget::VBox; |
|
|
112 | my $f = new Crossfire::Client::Widget::FancyFrame; |
|
|
113 | my $f2 = new Crossfire::Client::Widget::FancyFrame; |
|
|
114 | $f->add ($lbl1); |
|
|
115 | $f2->add ($lbl2); |
|
|
116 | $vb->add ($f); |
|
|
117 | $vb->add ($f2, 1); |
|
|
118 | |
|
|
119 | $tw->add ($vb); |
|
|
120 | $tw->w (400); |
|
|
121 | $tw->h (300); |
|
|
122 | $tw->move ($WIDTH - 200, 0); |
|
|
123 | $tw->moveto (0, 0); |
|
|
124 | $TOPLEVEL->add ($tw); |
|
|
125 | |
|
|
126 | # $f->move ($WIDTH - 200, 0); |
|
|
127 | # $TOPLEVEL->add ($f); |
|
|
128 | } |
98 | } |
129 | } |
99 | |
130 | |
100 | sub start_game { |
131 | sub start_game { |
101 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
132 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
102 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
133 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
103 | while $SDL_EV->poll; |
134 | while $SDL_EV->poll; |
104 | |
135 | |
105 | 1 |
136 | 1 |
106 | }; |
137 | }; |
… | |
… | |
108 | $WIDTH = $CFG->{width}; |
139 | $WIDTH = $CFG->{width}; |
109 | $HEIGHT = $CFG->{height}; |
140 | $HEIGHT = $CFG->{height}; |
110 | $FULLSCREEN = 0; |
141 | $FULLSCREEN = 0; |
111 | |
142 | |
112 | init_screen; |
143 | init_screen; |
|
|
144 | |
|
|
145 | my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
113 | |
146 | |
114 | $CONN = new conn |
147 | $CONN = new conn |
115 | host => $CFG->{host}, |
148 | host => $CFG->{host}, |
116 | port => $CFG->{port}, |
149 | port => $CFG->{port}, |
117 | user => $CFG->{user}, |
150 | user => $CFG->{user}, |
118 | pass => $CFG->{password}, |
151 | pass => $CFG->{password}, |
119 | mapw => 50, |
152 | mapw => $mapsize, |
120 | maph => 37, |
153 | maph => $mapsize, |
121 | ; |
154 | ; |
|
|
155 | |
|
|
156 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
122 | } |
157 | } |
123 | |
158 | |
124 | sub stop_game { |
159 | sub stop_game { |
125 | remove Glib::Source $SDL_TIMER; |
160 | remove Glib::Source $SDL_TIMER; |
|
|
161 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
162 | undef $refresh_handler; |
126 | |
163 | |
127 | undef $SDL_APP; |
164 | undef $SDL_APP; |
|
|
165 | undef $CONN; |
128 | SDL::Quit; |
166 | SDL::Quit; |
129 | } |
167 | } |
130 | |
168 | |
131 | |
169 | |
132 | sub force_refresh { |
170 | sub force_refresh { |
133 | glViewport 0, 0, $WIDTH, $HEIGHT; |
171 | glViewport 0, 0, $WIDTH, $HEIGHT; |
134 | |
172 | |
135 | glMatrixMode GL_PROJECTION; |
173 | glMatrixMode GL_PROJECTION; |
136 | glLoadIdentity; |
174 | glLoadIdentity; |
137 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
175 | glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; |
138 | glMatrixMode GL_MODELVIEW; |
176 | glMatrixMode GL_MODELVIEW; |
139 | |
177 | |
140 | glClear GL_COLOR_BUFFER_BIT; |
178 | glClear GL_COLOR_BUFFER_BIT; |
141 | |
179 | |
142 | $TOPLEVEL->draw; |
180 | $TOPLEVEL->draw; |
143 | |
181 | |
144 | SDL::GLSwapBuffers; |
182 | SDL::GLSwapBuffers; |
145 | } |
183 | } |
146 | |
|
|
147 | my $refresh_handler; |
|
|
148 | |
184 | |
149 | sub refresh { |
185 | sub refresh { |
150 | $refresh_handler ||= add Glib::Idle sub { |
186 | $refresh_handler ||= add Glib::Idle sub { |
|
|
187 | return unless $SDL_APP; |
|
|
188 | |
|
|
189 | my $next_refresh = SDL::GetTicks; |
|
|
190 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
|
|
191 | $last_refresh = $next_refresh; |
|
|
192 | |
151 | force_refresh; |
193 | force_refresh; |
|
|
194 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
195 | |
|
|
196 | if (%ANIMATE) { |
|
|
197 | 1 |
|
|
198 | } else { |
152 | undef $refresh_handler; |
199 | undef $refresh_handler; |
|
|
200 | 0 |
153 | 0 |
201 | } |
154 | }; |
202 | }; |
|
|
203 | } |
|
|
204 | |
|
|
205 | sub animation_start { |
|
|
206 | my ($widget) = @_; |
|
|
207 | $ANIMATE{$widget} = $widget; |
|
|
208 | Scalar::Util::weaken $ANIMATE{$widget}; |
|
|
209 | |
|
|
210 | refresh; |
|
|
211 | } |
|
|
212 | |
|
|
213 | sub animation_stop { |
|
|
214 | my ($widget) = @_; |
|
|
215 | delete $ANIMATE{$widget}; |
155 | } |
216 | } |
156 | |
217 | |
157 | %SDL_CB = ( |
218 | %SDL_CB = ( |
158 | SDL_QUIT() => sub { |
219 | SDL_QUIT() => sub { |
159 | main_quit Gtk2; |
220 | main_quit Gtk2; |
… | |
… | |
198 | } |
259 | } |
199 | |
260 | |
200 | sub conn::map_scroll { |
261 | sub conn::map_scroll { |
201 | my ($self, $dx, $dy) = @_; |
262 | my ($self, $dx, $dy) = @_; |
202 | |
263 | |
203 | refresh; |
264 | # refresh; |
204 | } |
265 | } |
205 | |
266 | |
206 | sub conn::map_clear { |
267 | sub conn::map_clear { |
207 | my ($self) = @_; |
268 | my ($self) = @_; |
208 | |
269 | |
209 | refresh; |
270 | # refresh; |
210 | } |
271 | } |
211 | |
272 | |
212 | sub conn::face_find { |
273 | sub conn::face_find { |
213 | my ($self, $face) = @_; |
274 | my ($self, $face) = @_; |
214 | |
275 | |
… | |
… | |
240 | } |
301 | } |
241 | $ent->set_text ($value); |
302 | $ent->set_text ($value); |
242 | $ent->signal_connect (changed => sub { |
303 | $ent->signal_connect (changed => sub { |
243 | my ($ent) = @_; |
304 | my ($ent) = @_; |
244 | $cfg->{$key} = $ent->get_text; |
305 | $cfg->{$key} = $ent->get_text; |
|
|
306 | # TODO: Mapsize should be a slider in the game gui |
|
|
307 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
|
|
308 | $cfg->{$key} = 100; |
|
|
309 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
310 | $cfg->{$key} = 50; |
|
|
311 | } |
245 | }); |
312 | }); |
246 | } |
313 | } |
247 | |
314 | |
248 | sub run_config_dialog { |
315 | sub run_config_dialog { |
249 | my (%events) = @_; |
316 | my (%events) = @_; |
… | |
… | |
251 | my $w = Gtk2::Window->new; |
318 | my $w = Gtk2::Window->new; |
252 | |
319 | |
253 | my @cfg = ( |
320 | my @cfg = ( |
254 | [qw/Host host/], |
321 | [qw/Host host/], |
255 | [qw/Port port/], |
322 | [qw/Port port/], |
|
|
323 | [qw/Mapsize% mapsize/], |
256 | [qw/Username user/], |
324 | [qw/Username user/], |
257 | [qw/Password password/], |
325 | [qw/Password password/], |
258 | ); |
326 | ); |
259 | |
327 | |
260 | my $cfg = {}; |
328 | my $cfg = {}; |
… | |
… | |
307 | my $cb = $events{login} || sub {}; |
375 | my $cb = $events{login} || sub {}; |
308 | $cb->($::CFG->{user}, $::CFG->{password}); |
376 | $cb->($::CFG->{user}, $::CFG->{password}); |
309 | }); |
377 | }); |
310 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
378 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
311 | $cb->signal_connect (clicked => sub { |
379 | $cb->signal_connect (clicked => sub { |
312 | my $cb = $events{login} || sub {}; |
380 | my $cb = $events{logout} || sub {}; |
313 | $cb->(); |
381 | $cb->(); |
314 | }); |
382 | }); |
315 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
383 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
316 | $cb->signal_connect (clicked => sub { $w->destroy }); |
384 | $cb->signal_connect (clicked => sub { $w->destroy }); |
317 | |
385 | |
… | |
… | |
335 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
403 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
336 | |
404 | |
337 | $CFG ||= { |
405 | $CFG ||= { |
338 | width => 640, |
406 | width => 640, |
339 | height => 480, |
407 | height => 480, |
|
|
408 | mapsize => 100, |
340 | fullscreen => 0, |
409 | fullscreen => 0, |
341 | host => "crossfire.schmorp.de", |
410 | host => "crossfire.schmorp.de", |
342 | port => 13327, |
411 | port => 13327, |
343 | }; |
412 | }; |
344 | |
413 | |