… | |
… | |
15 | |
15 | |
16 | use Crossfire; |
16 | use Crossfire; |
17 | use Crossfire::Client; |
17 | use Crossfire::Client; |
18 | use Crossfire::Protocol; |
18 | use Crossfire::Protocol; |
19 | |
19 | |
20 | use Crossfire::Client::Util; |
|
|
21 | use Crossfire::Client::Widget; |
20 | use Crossfire::Client::Widget; |
22 | |
21 | |
23 | our $FACECACHE; |
22 | our $FACECACHE; |
24 | |
23 | |
25 | our $VERSION = '0.1'; |
24 | our $VERSION = '0.1'; |
|
|
25 | |
|
|
26 | our %GL_EXT; |
26 | |
27 | |
27 | our $CFG; |
28 | our $CFG; |
28 | our $CONN; |
29 | our $CONN; |
29 | |
30 | |
|
|
31 | our $WIDTH; |
|
|
32 | our $HEIGHT; |
|
|
33 | our $FULLSCREEN; |
|
|
34 | |
30 | our $UIFONT; |
35 | our $FONTSIZE; |
31 | |
36 | |
32 | our $SDL_TIMER; |
37 | our $SDL_TIMER; |
33 | our $SDL_APP; |
38 | our $SDL_APP; |
34 | our $SDL_EV = new SDL::Event; |
39 | our $SDL_EV = new SDL::Event; |
35 | our %SDL_CB; |
40 | our %SDL_CB; |
36 | |
41 | |
37 | our @GL_INIT; # hooks called on every gl init |
42 | our @GL_INIT; # hooks called on every gl init |
38 | |
43 | |
|
|
44 | our $ALT_ENTER_MESSAGE; |
|
|
45 | |
|
|
46 | our $TOPLEVEL; |
|
|
47 | |
|
|
48 | our $tw; # Test widget #d# |
|
|
49 | |
39 | sub init_screen { |
50 | sub init_screen { |
40 | $SDL_APP = new SDL::App |
51 | $SDL_APP = new SDL::App |
41 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
52 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
42 | -title => "Crossfire+ Client", |
53 | -title => "Crossfire+ Client", |
43 | -width => $CFG->{width}, |
54 | -width => $WIDTH, |
44 | -height => $CFG->{height}, |
55 | -height => $HEIGHT, |
45 | -opengl => 1, |
56 | -opengl => 1, |
46 | -red_size => 8, |
57 | -red_size => 8, |
47 | -green_size => 8, |
58 | -green_size => 8, |
48 | -blue_size => 8, |
59 | -blue_size => 8, |
49 | -double_buffer => 1, |
60 | -double_buffer => 1, |
50 | -fullscreen => $CFG->{fullscreen}, |
61 | -fullscreen => $FULLSCREEN, |
51 | -resizeable => 0; |
62 | -resizeable => 0; |
52 | |
63 | |
|
|
64 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
|
|
65 | |
|
|
66 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
|
|
67 | or warn "WARNING: non-power-of-two opengl extension required"; |
|
|
68 | |
|
|
69 | $FONTSIZE = int $HEIGHT / 50; |
|
|
70 | |
|
|
71 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
|
|
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 | |
53 | glClearColor 0, 0, 0, 0; |
89 | glClearColor 0, 0, 0, 0; |
54 | |
90 | |
55 | glEnable GL_TEXTURE_2D; |
91 | glEnable GL_TEXTURE_2D; |
|
|
92 | glEnable GL_COLOR_MATERIAL; |
56 | glShadeModel GL_FLAT; |
93 | glShadeModel GL_FLAT; |
57 | glDisable GL_DEPTH_TEST; |
94 | glDisable GL_DEPTH_TEST; |
58 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
95 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
59 | |
96 | |
|
|
97 | $_->() for @GL_INIT; |
|
|
98 | } |
|
|
99 | |
|
|
100 | sub start_game { |
|
|
101 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
|
|
102 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
103 | while $SDL_EV->poll; |
|
|
104 | |
|
|
105 | 1 |
|
|
106 | }; |
|
|
107 | |
|
|
108 | $WIDTH = $CFG->{width}; |
|
|
109 | $HEIGHT = $CFG->{height}; |
|
|
110 | $FULLSCREEN = 0; |
|
|
111 | |
|
|
112 | init_screen; |
|
|
113 | |
|
|
114 | $CONN = new conn |
|
|
115 | host => $CFG->{host}, |
|
|
116 | port => $CFG->{port}, |
|
|
117 | user => $CFG->{user}, |
|
|
118 | pass => $CFG->{password}, |
|
|
119 | mapw => 50, |
|
|
120 | maph => 37, |
|
|
121 | ; |
|
|
122 | } |
|
|
123 | |
|
|
124 | sub stop_game { |
|
|
125 | remove Glib::Source $SDL_TIMER; |
|
|
126 | |
|
|
127 | undef $SDL_APP; |
|
|
128 | SDL::Quit; |
|
|
129 | } |
|
|
130 | |
|
|
131 | |
|
|
132 | sub force_refresh { |
|
|
133 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
134 | |
60 | glMatrixMode GL_PROJECTION; |
135 | glMatrixMode GL_PROJECTION; |
61 | glLoadIdentity; |
136 | glLoadIdentity; |
62 | glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; |
137 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
63 | |
|
|
64 | glMatrixMode GL_MODELVIEW; |
138 | glMatrixMode GL_MODELVIEW; |
65 | |
139 | |
66 | $_->() for @GL_INIT; |
140 | glClear GL_COLOR_BUFFER_BIT; |
67 | } |
|
|
68 | |
141 | |
69 | my $label;#d# |
142 | $TOPLEVEL->draw; |
70 | |
143 | |
71 | sub start_game { |
144 | SDL::GLSwapBuffers; |
72 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
145 | } |
73 | while ($SDL_EV->poll) { |
146 | |
74 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
147 | my $refresh_handler; |
|
|
148 | |
|
|
149 | sub refresh { |
|
|
150 | $refresh_handler ||= add Glib::Idle sub { |
|
|
151 | force_refresh; |
|
|
152 | undef $refresh_handler; |
75 | } |
153 | 0 |
76 | |
|
|
77 | 1 |
|
|
78 | }; |
154 | }; |
79 | |
|
|
80 | init_screen; |
|
|
81 | |
|
|
82 | $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]"; |
|
|
83 | $label->activate; |
|
|
84 | |
|
|
85 | $CONN = new conn |
|
|
86 | host => $CFG->{host}, |
|
|
87 | port => $CFG->{port}; |
|
|
88 | } |
|
|
89 | |
|
|
90 | sub stop_game { |
|
|
91 | remove Glib::Source $SDL_TIMER; |
|
|
92 | |
|
|
93 | undef $SDL_APP; |
|
|
94 | SDL::Quit; |
|
|
95 | } |
|
|
96 | |
|
|
97 | sub refresh { |
|
|
98 | glClear GL_COLOR_BUFFER_BIT; |
|
|
99 | |
|
|
100 | $_->draw for values %Crossfire::Client::Widget::ACTIVE_WIDGETS; |
|
|
101 | |
|
|
102 | SDL::GLSwapBuffers; |
|
|
103 | } |
155 | } |
104 | |
156 | |
105 | %SDL_CB = ( |
157 | %SDL_CB = ( |
106 | SDL_QUIT() => sub { |
158 | SDL_QUIT() => sub { |
107 | main_quit Gtk2; |
159 | main_quit Gtk2; |
… | |
… | |
112 | refresh; |
164 | refresh; |
113 | }, |
165 | }, |
114 | SDL_KEYDOWN() => sub { |
166 | SDL_KEYDOWN() => sub { |
115 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
167 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
116 | # alt-enter |
168 | # alt-enter |
117 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
169 | $FULLSCREEN = !$FULLSCREEN; |
118 | init_screen; |
170 | init_screen; |
119 | } else { |
171 | } else { |
120 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
172 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
121 | } |
173 | } |
122 | }, |
174 | }, |
… | |
… | |
167 | my ($self, $face) = @_; |
219 | my ($self, $face) = @_; |
168 | |
220 | |
169 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
221 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
170 | |
222 | |
171 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
223 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
|
|
224 | } |
|
|
225 | |
|
|
226 | sub conn::query { |
|
|
227 | my ($self, $flags, $prompt) = @_; |
|
|
228 | |
|
|
229 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
172 | } |
230 | } |
173 | |
231 | |
174 | sub gtk_add_cfg_field { |
232 | sub gtk_add_cfg_field { |
175 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
233 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
176 | my $i = $cfg->{_i}++; |
234 | my $i = $cfg->{_i}++; |
… | |
… | |
265 | |
323 | |
266 | ############################################################################# |
324 | ############################################################################# |
267 | |
325 | |
268 | SDL::Init SDL_INIT_EVERYTHING; |
326 | SDL::Init SDL_INIT_EVERYTHING; |
269 | |
327 | |
|
|
328 | $TOPLEVEL = Crossfire::Client::Widget::Toplevel->new; |
|
|
329 | |
270 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
330 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
271 | |
331 | |
272 | $mapwidget->activate; |
332 | $TOPLEVEL->add ($mapwidget); |
273 | $mapwidget->focus_in; |
333 | $mapwidget->focus_in; |
274 | |
334 | |
275 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
335 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
276 | |
336 | |
277 | $CFG ||= { |
337 | $CFG ||= { |
… | |
… | |
280 | fullscreen => 0, |
340 | fullscreen => 0, |
281 | host => "crossfire.schmorp.de", |
341 | host => "crossfire.schmorp.de", |
282 | port => 13327, |
342 | port => 13327, |
283 | }; |
343 | }; |
284 | |
344 | |
|
|
345 | Crossfire::Client::add_font Crossfire::Client::find_rcfile "uifont.ttf"; |
|
|
346 | Crossfire::Client::set_font "[Bitstream Vera Sans Mono]"; |
|
|
347 | |
285 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
348 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
286 | |
|
|
287 | SDL::TTFInit; |
|
|
288 | |
|
|
289 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", 24 |
|
|
290 | or die "TTFOpenFont: $!"; |
|
|
291 | |
349 | |
292 | run_config_dialog |
350 | run_config_dialog |
293 | login => sub { start_game }, |
351 | login => sub { start_game }, |
294 | logout => sub { stop_game }; |
352 | logout => sub { stop_game }; |
295 | |
353 | |