… | |
… | |
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# |
49 | |
50 | |
50 | my $last_refresh; |
51 | my $last_refresh; |
|
|
52 | my %ANIMATE; |
|
|
53 | my $refresh_handler; |
51 | |
54 | |
52 | sub init_screen { |
55 | sub init_screen { |
53 | $SDL_APP = new SDL::App |
56 | $SDL_APP = new SDL::App |
54 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
57 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
55 | -title => "Crossfire+ Client", |
58 | -title => "Crossfire+ Client", |
56 | -width => $WIDTH, |
59 | -width => $WIDTH, |
57 | -height => $HEIGHT, |
60 | -height => $HEIGHT, |
58 | -opengl => 1, |
61 | -opengl => 1, |
59 | -red_size => 8, |
62 | -red_size => 5, |
60 | -green_size => 8, |
63 | -green_size => 5, |
61 | -blue_size => 8, |
64 | -blue_size => 5, |
|
|
65 | -alpha_size => 0, |
62 | -double_buffer => 1, |
66 | -double_buffer => 1, |
63 | -fullscreen => $FULLSCREEN, |
67 | -fullscreen => $FULLSCREEN, |
64 | -resizeable => 0; |
68 | -resizeable => 0; |
65 | |
69 | |
66 | $last_refresh = SDL::GetTicks; |
70 | $last_refresh = SDL::GetTicks; |
… | |
… | |
70 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
74 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
71 | or warn "WARNING: non-power-of-two opengl extension required"; |
75 | or warn "WARNING: non-power-of-two opengl extension required"; |
72 | |
76 | |
73 | $FONTSIZE = int $HEIGHT / 50; |
77 | $FONTSIZE = int $HEIGHT / 50; |
74 | |
78 | |
|
|
79 | $STATUS_LINE = new Crossfire::Client::Widget::Label |
|
|
80 | 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, |
|
|
81 | ""; |
|
|
82 | $TOPLEVEL->add ($STATUS_LINE); |
|
|
83 | |
75 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
84 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
76 | 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, |
85 | 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, |
77 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
86 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
78 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
|
|
79 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
87 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
80 | |
88 | |
81 | # Test code #d# |
89 | # Test code #d# |
82 | unless ($tw) { # haha... |
90 | unless ($tw) { # haha... |
83 | $tw = new Crossfire::Client::Widget::Animator; |
91 | $tw = new Crossfire::Client::Widget::Animator; |
… | |
… | |
115 | |
123 | |
116 | $_->() for @GL_INIT; |
124 | $_->() for @GL_INIT; |
117 | } |
125 | } |
118 | |
126 | |
119 | sub start_game { |
127 | sub start_game { |
120 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
128 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
121 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
129 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
122 | while $SDL_EV->poll; |
130 | while $SDL_EV->poll; |
123 | |
131 | |
124 | 1 |
132 | 1 |
125 | }; |
133 | }; |
… | |
… | |
127 | $WIDTH = $CFG->{width}; |
135 | $WIDTH = $CFG->{width}; |
128 | $HEIGHT = $CFG->{height}; |
136 | $HEIGHT = $CFG->{height}; |
129 | $FULLSCREEN = 0; |
137 | $FULLSCREEN = 0; |
130 | |
138 | |
131 | init_screen; |
139 | init_screen; |
|
|
140 | |
|
|
141 | my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
132 | |
142 | |
133 | $CONN = new conn |
143 | $CONN = new conn |
134 | host => $CFG->{host}, |
144 | host => $CFG->{host}, |
135 | port => $CFG->{port}, |
145 | port => $CFG->{port}, |
136 | user => $CFG->{user}, |
146 | user => $CFG->{user}, |
137 | pass => $CFG->{password}, |
147 | pass => $CFG->{password}, |
138 | mapw => 50, |
148 | mapw => $mapsize, |
139 | maph => 37, |
149 | maph => $mapsize, |
140 | ; |
150 | ; |
141 | |
151 | |
142 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
152 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
143 | } |
153 | } |
144 | |
154 | |
145 | sub stop_game { |
155 | sub stop_game { |
146 | remove Glib::Source $SDL_TIMER; |
156 | remove Glib::Source $SDL_TIMER; |
|
|
157 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
158 | undef $refresh_handler; |
147 | |
159 | |
148 | undef $SDL_APP; |
160 | undef $SDL_APP; |
|
|
161 | undef $CONN; |
149 | SDL::Quit; |
162 | SDL::Quit; |
150 | } |
163 | } |
151 | |
164 | |
152 | |
165 | |
153 | sub force_refresh { |
166 | sub force_refresh { |
… | |
… | |
163 | $TOPLEVEL->draw; |
176 | $TOPLEVEL->draw; |
164 | |
177 | |
165 | SDL::GLSwapBuffers; |
178 | SDL::GLSwapBuffers; |
166 | } |
179 | } |
167 | |
180 | |
168 | my %ANIMATE; |
|
|
169 | |
|
|
170 | my $refresh_handler; |
|
|
171 | |
|
|
172 | sub refresh { |
181 | sub refresh { |
173 | $refresh_handler ||= add Glib::Idle sub { |
182 | $refresh_handler ||= add Glib::Idle sub { |
|
|
183 | return unless $SDL_APP; |
|
|
184 | |
174 | my $next_refresh = SDL::GetTicks; |
185 | my $next_refresh = SDL::GetTicks; |
175 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
186 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
176 | $last_refresh = $next_refresh; |
187 | $last_refresh = $next_refresh; |
177 | |
188 | |
178 | force_refresh; |
189 | force_refresh; |
… | |
… | |
286 | } |
297 | } |
287 | $ent->set_text ($value); |
298 | $ent->set_text ($value); |
288 | $ent->signal_connect (changed => sub { |
299 | $ent->signal_connect (changed => sub { |
289 | my ($ent) = @_; |
300 | my ($ent) = @_; |
290 | $cfg->{$key} = $ent->get_text; |
301 | $cfg->{$key} = $ent->get_text; |
|
|
302 | # TODO: Mapsize should be a slider in the game gui |
291 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
303 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
292 | $cfg->{$key} = 100; |
304 | $cfg->{$key} = 100; |
293 | $ent->set_text ('100'); |
|
|
294 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 0) { |
305 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
295 | $cfg->{$key} = 0; |
306 | $cfg->{$key} = 50; |
296 | $ent->set_text ('0'); |
|
|
297 | } |
307 | } |
298 | }); |
308 | }); |
299 | } |
309 | } |
300 | |
310 | |
301 | sub run_config_dialog { |
311 | sub run_config_dialog { |
… | |
… | |
361 | my $cb = $events{login} || sub {}; |
371 | my $cb = $events{login} || sub {}; |
362 | $cb->($::CFG->{user}, $::CFG->{password}); |
372 | $cb->($::CFG->{user}, $::CFG->{password}); |
363 | }); |
373 | }); |
364 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
374 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
365 | $cb->signal_connect (clicked => sub { |
375 | $cb->signal_connect (clicked => sub { |
366 | my $cb = $events{login} || sub {}; |
376 | my $cb = $events{logout} || sub {}; |
367 | $cb->(); |
377 | $cb->(); |
368 | }); |
378 | }); |
369 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
379 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
370 | $cb->signal_connect (clicked => sub { $w->destroy }); |
380 | $cb->signal_connect (clicked => sub { $w->destroy }); |
371 | |
381 | |