… | |
… | |
32 | our $HEIGHT; |
32 | our $HEIGHT; |
33 | our $FULLSCREEN; |
33 | our $FULLSCREEN; |
34 | |
34 | |
35 | our $FONTSIZE; |
35 | our $FONTSIZE; |
36 | |
36 | |
|
|
37 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
|
|
38 | |
37 | our $SDL_TIMER; |
39 | our $SDL_TIMER; |
38 | our $SDL_APP; |
40 | our $SDL_APP; |
39 | our $SDL_EV = new SDL::Event; |
41 | our $SDL_EV = new SDL::Event; |
40 | our %SDL_CB; |
42 | our %SDL_CB; |
41 | |
43 | |
42 | our @GL_INIT; # hooks called on every gl init |
44 | our @GL_INIT; # hooks called on every gl init |
43 | |
45 | |
44 | our $ALT_ENTER_MESSAGE; |
46 | our $ALT_ENTER_MESSAGE; |
|
|
47 | our $STATUS_LINE; |
45 | |
48 | |
46 | our $TOPLEVEL; |
49 | our $TOPLEVEL; |
47 | |
50 | |
48 | our $tw; # Test widget #d# |
51 | our $tw; # Test widget #d# |
49 | |
52 | |
50 | my $last_refresh; |
53 | my $last_refresh; |
|
|
54 | my %ANIMATE; |
|
|
55 | my $refresh_handler; |
51 | |
56 | |
52 | sub init_screen { |
57 | sub init_screen { |
53 | $SDL_APP = new SDL::App |
58 | $SDL_APP = new SDL::App |
54 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
59 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
55 | -title => "Crossfire+ Client", |
60 | -title => "Crossfire+ Client", |
56 | -width => $WIDTH, |
61 | -width => $WIDTH, |
57 | -height => $HEIGHT, |
62 | -height => $HEIGHT, |
58 | -opengl => 1, |
63 | -opengl => 1, |
59 | -red_size => 8, |
64 | -red_size => 5, |
60 | -green_size => 8, |
65 | -green_size => 5, |
61 | -blue_size => 8, |
66 | -blue_size => 5, |
|
|
67 | -alpha_size => 0, |
62 | -double_buffer => 1, |
68 | -double_buffer => 1, |
63 | -fullscreen => $FULLSCREEN, |
69 | -fullscreen => $FULLSCREEN, |
64 | -resizeable => 0; |
70 | -resizeable => 0; |
65 | |
71 | |
66 | $last_refresh = SDL::GetTicks; |
72 | $last_refresh = SDL::GetTicks; |
… | |
… | |
70 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
76 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
71 | or warn "WARNING: non-power-of-two opengl extension required"; |
77 | or warn "WARNING: non-power-of-two opengl extension required"; |
72 | |
78 | |
73 | $FONTSIZE = int $HEIGHT / 50; |
79 | $FONTSIZE = int $HEIGHT / 50; |
74 | |
80 | |
|
|
81 | ############################################################################# |
|
|
82 | |
|
|
83 | glClearColor 0, 0, 0, 0; |
|
|
84 | |
|
|
85 | glEnable GL_TEXTURE_2D; |
|
|
86 | glEnable GL_COLOR_MATERIAL; |
|
|
87 | glShadeModel GL_FLAT; |
|
|
88 | glDisable GL_DEPTH_TEST; |
|
|
89 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
90 | |
|
|
91 | $_->() for @GL_INIT; |
|
|
92 | |
|
|
93 | ############################################################################# |
|
|
94 | |
|
|
95 | $STATUS_LINE = new Crossfire::Client::Widget::Label |
|
|
96 | 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, |
|
|
97 | ""; |
|
|
98 | $TOPLEVEL->add ($STATUS_LINE); |
|
|
99 | |
75 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
100 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
76 | 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, |
101 | 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, |
77 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
102 | "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); |
103 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
80 | |
104 | |
81 | # Test code #d# |
105 | # Test code #d# |
82 | unless ($tw) { # haha... |
106 | unless ($tw) { # haha... |
83 | $tw = new Crossfire::Client::Widget::Animator; |
107 | $tw = new Crossfire::Client::Widget::Animator; |
… | |
… | |
102 | $TOPLEVEL->add ($tw); |
126 | $TOPLEVEL->add ($tw); |
103 | |
127 | |
104 | # $f->move ($WIDTH - 200, 0); |
128 | # $f->move ($WIDTH - 200, 0); |
105 | # $TOPLEVEL->add ($f); |
129 | # $TOPLEVEL->add ($f); |
106 | } |
130 | } |
107 | |
|
|
108 | glClearColor 0, 0, 0, 0; |
|
|
109 | |
|
|
110 | glEnable GL_TEXTURE_2D; |
|
|
111 | glEnable GL_COLOR_MATERIAL; |
|
|
112 | glShadeModel GL_FLAT; |
|
|
113 | glDisable GL_DEPTH_TEST; |
|
|
114 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
115 | |
|
|
116 | $_->() for @GL_INIT; |
|
|
117 | } |
131 | } |
118 | |
132 | |
119 | sub start_game { |
133 | sub start_game { |
120 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
134 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
121 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
135 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
122 | while $SDL_EV->poll; |
136 | while $SDL_EV->poll; |
123 | |
137 | |
124 | 1 |
138 | 1 |
125 | }; |
139 | }; |
… | |
… | |
127 | $WIDTH = $CFG->{width}; |
141 | $WIDTH = $CFG->{width}; |
128 | $HEIGHT = $CFG->{height}; |
142 | $HEIGHT = $CFG->{height}; |
129 | $FULLSCREEN = 0; |
143 | $FULLSCREEN = 0; |
130 | |
144 | |
131 | init_screen; |
145 | init_screen; |
|
|
146 | |
|
|
147 | my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
132 | |
148 | |
133 | $CONN = new conn |
149 | $CONN = new conn |
134 | host => $CFG->{host}, |
150 | host => $CFG->{host}, |
135 | port => $CFG->{port}, |
151 | port => $CFG->{port}, |
136 | user => $CFG->{user}, |
152 | user => $CFG->{user}, |
137 | pass => $CFG->{password}, |
153 | pass => $CFG->{password}, |
138 | mapw => 50, |
154 | mapw => $mapsize, |
139 | maph => 37, |
155 | maph => $mapsize, |
140 | ; |
156 | ; |
141 | |
157 | |
142 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
158 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
143 | } |
159 | } |
144 | |
160 | |
145 | sub stop_game { |
161 | sub stop_game { |
146 | remove Glib::Source $SDL_TIMER; |
162 | remove Glib::Source $SDL_TIMER; |
|
|
163 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
164 | undef $refresh_handler; |
147 | |
165 | |
148 | undef $SDL_APP; |
166 | undef $SDL_APP; |
|
|
167 | undef $CONN; |
149 | SDL::Quit; |
168 | SDL::Quit; |
150 | } |
169 | } |
151 | |
170 | |
152 | |
171 | |
153 | sub force_refresh { |
172 | sub force_refresh { |
… | |
… | |
163 | $TOPLEVEL->draw; |
182 | $TOPLEVEL->draw; |
164 | |
183 | |
165 | SDL::GLSwapBuffers; |
184 | SDL::GLSwapBuffers; |
166 | } |
185 | } |
167 | |
186 | |
168 | my %ANIMATE; |
|
|
169 | |
|
|
170 | my $refresh_handler; |
|
|
171 | |
|
|
172 | sub refresh { |
187 | sub refresh { |
173 | $refresh_handler ||= add Glib::Idle sub { |
188 | $refresh_handler ||= add Glib::Idle sub { |
|
|
189 | return unless $SDL_APP; |
|
|
190 | |
174 | my $next_refresh = SDL::GetTicks; |
191 | my $next_refresh = SDL::GetTicks; |
175 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
192 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
176 | $last_refresh = $next_refresh; |
193 | $last_refresh = $next_refresh; |
177 | |
194 | |
178 | force_refresh; |
195 | force_refresh; |
… | |
… | |
220 | }, |
237 | }, |
221 | SDL_KEYUP() => sub { |
238 | SDL_KEYUP() => sub { |
222 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
239 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
223 | }, |
240 | }, |
224 | SDL_MOUSEMOTION() => sub { |
241 | SDL_MOUSEMOTION() => sub { |
225 | warn "sdl motion\n";#d# |
242 | my ($x, $y) = ($SDL_EV->motion_x, $SDL_EV->motion_y); |
|
|
243 | $HOVER = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
|
|
244 | ::refresh; |
226 | }, |
245 | }, |
227 | SDL_MOUSEBUTTONDOWN() => sub { |
246 | SDL_MOUSEBUTTONDOWN() => sub { |
228 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
247 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
229 | }, |
248 | }, |
230 | SDL_MOUSEBUTTONUP() => sub { |
249 | SDL_MOUSEBUTTONUP() => sub { |
… | |
… | |
286 | } |
305 | } |
287 | $ent->set_text ($value); |
306 | $ent->set_text ($value); |
288 | $ent->signal_connect (changed => sub { |
307 | $ent->signal_connect (changed => sub { |
289 | my ($ent) = @_; |
308 | my ($ent) = @_; |
290 | $cfg->{$key} = $ent->get_text; |
309 | $cfg->{$key} = $ent->get_text; |
|
|
310 | # TODO: Mapsize should be a slider in the game gui |
291 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
311 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
292 | $cfg->{$key} = 100; |
312 | $cfg->{$key} = 100; |
293 | $ent->set_text ('100'); |
|
|
294 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
313 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
295 | $cfg->{$key} = 50; |
314 | $cfg->{$key} = 50; |
296 | $ent->set_text ('50'); |
|
|
297 | } |
315 | } |
298 | }); |
316 | }); |
299 | } |
317 | } |
300 | |
318 | |
301 | sub run_config_dialog { |
319 | sub run_config_dialog { |
… | |
… | |
361 | my $cb = $events{login} || sub {}; |
379 | my $cb = $events{login} || sub {}; |
362 | $cb->($::CFG->{user}, $::CFG->{password}); |
380 | $cb->($::CFG->{user}, $::CFG->{password}); |
363 | }); |
381 | }); |
364 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
382 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
365 | $cb->signal_connect (clicked => sub { |
383 | $cb->signal_connect (clicked => sub { |
366 | my $cb = $events{login} || sub {}; |
384 | my $cb = $events{logout} || sub {}; |
367 | $cb->(); |
385 | $cb->(); |
368 | }); |
386 | }); |
369 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
387 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
370 | $cb->signal_connect (clicked => sub { $w->destroy }); |
388 | $cb->signal_connect (clicked => sub { $w->destroy }); |
371 | |
389 | |