… | |
… | |
30 | |
30 | |
31 | our $WIDTH; |
31 | our $WIDTH; |
32 | our $HEIGHT; |
32 | our $HEIGHT; |
33 | our $FULLSCREEN; |
33 | our $FULLSCREEN; |
34 | |
34 | |
35 | our $UIFONT; |
35 | our $FONTSIZE; |
36 | |
36 | |
37 | our $SDL_TIMER; |
37 | our $SDL_TIMER; |
38 | our $SDL_APP; |
38 | our $SDL_APP; |
39 | our $SDL_EV = new SDL::Event; |
39 | our $SDL_EV = new SDL::Event; |
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 | |
|
|
46 | our $TOPLEVEL; |
|
|
47 | |
|
|
48 | our $tw; # Test widget #d# |
45 | |
49 | |
46 | sub init_screen { |
50 | sub init_screen { |
47 | $SDL_APP = new SDL::App |
51 | $SDL_APP = new SDL::App |
48 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
52 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
49 | -title => "Crossfire+ Client", |
53 | -title => "Crossfire+ Client", |
… | |
… | |
60 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
64 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
61 | |
65 | |
62 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
66 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
63 | or warn "WARNING: non-power-of-two opengl extension required"; |
67 | or warn "WARNING: non-power-of-two opengl extension required"; |
64 | |
68 | |
65 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 |
69 | $FONTSIZE = int $HEIGHT / 50; |
66 | or die "TTFOpenFont: $!"; |
|
|
67 | |
70 | |
68 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; |
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"; |
69 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
74 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
70 | $ALT_ENTER_MESSAGE->activate; |
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 | } |
71 | |
88 | |
72 | glClearColor 0, 0, 0, 0; |
89 | glClearColor 0, 0, 0, 0; |
73 | |
90 | |
74 | glEnable GL_TEXTURE_2D; |
91 | glEnable GL_TEXTURE_2D; |
|
|
92 | glEnable GL_COLOR_MATERIAL; |
75 | glShadeModel GL_FLAT; |
93 | glShadeModel GL_FLAT; |
76 | glDisable GL_DEPTH_TEST; |
94 | glDisable GL_DEPTH_TEST; |
77 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
95 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
78 | |
|
|
79 | glMatrixMode GL_PROJECTION; |
|
|
80 | glLoadIdentity; |
|
|
81 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
|
|
82 | |
|
|
83 | glMatrixMode GL_MODELVIEW; |
|
|
84 | |
96 | |
85 | $_->() for @GL_INIT; |
97 | $_->() for @GL_INIT; |
86 | } |
98 | } |
87 | |
99 | |
88 | sub start_game { |
100 | sub start_game { |
… | |
… | |
101 | |
113 | |
102 | $CONN = new conn |
114 | $CONN = new conn |
103 | host => $CFG->{host}, |
115 | host => $CFG->{host}, |
104 | port => $CFG->{port}, |
116 | port => $CFG->{port}, |
105 | user => $CFG->{user}, |
117 | user => $CFG->{user}, |
106 | pass => $CFG->{password}; |
118 | pass => $CFG->{password}, |
|
|
119 | mapw => 50, |
|
|
120 | maph => 37, |
|
|
121 | ; |
107 | } |
122 | } |
108 | |
123 | |
109 | sub stop_game { |
124 | sub stop_game { |
110 | remove Glib::Source $SDL_TIMER; |
125 | remove Glib::Source $SDL_TIMER; |
111 | |
126 | |
… | |
… | |
114 | } |
129 | } |
115 | |
130 | |
116 | |
131 | |
117 | sub force_refresh { |
132 | sub force_refresh { |
118 | glViewport 0, 0, $WIDTH, $HEIGHT; |
133 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
134 | |
|
|
135 | glMatrixMode GL_PROJECTION; |
|
|
136 | glLoadIdentity; |
|
|
137 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
|
|
138 | glMatrixMode GL_MODELVIEW; |
|
|
139 | |
119 | glClear GL_COLOR_BUFFER_BIT; |
140 | glClear GL_COLOR_BUFFER_BIT; |
120 | |
141 | |
121 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
142 | $TOPLEVEL->draw; |
122 | |
143 | |
123 | SDL::GLSwapBuffers; |
144 | SDL::GLSwapBuffers; |
124 | } |
145 | } |
125 | |
146 | |
126 | my $refresh_handler; |
147 | my $refresh_handler; |
… | |
… | |
198 | my ($self, $face) = @_; |
219 | my ($self, $face) = @_; |
199 | |
220 | |
200 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
221 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
201 | |
222 | |
202 | $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# |
203 | } |
230 | } |
204 | |
231 | |
205 | sub gtk_add_cfg_field { |
232 | sub gtk_add_cfg_field { |
206 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
233 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
207 | my $i = $cfg->{_i}++; |
234 | my $i = $cfg->{_i}++; |
… | |
… | |
295 | |
322 | |
296 | |
323 | |
297 | ############################################################################# |
324 | ############################################################################# |
298 | |
325 | |
299 | SDL::Init SDL_INIT_EVERYTHING; |
326 | SDL::Init SDL_INIT_EVERYTHING; |
300 | SDL::TTFInit; |
327 | |
|
|
328 | $TOPLEVEL = Crossfire::Client::Widget::Toplevel->new; |
301 | |
329 | |
302 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
330 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
303 | |
331 | |
304 | $mapwidget->activate; |
332 | $TOPLEVEL->add ($mapwidget); |
305 | $mapwidget->focus_in; |
333 | $mapwidget->focus_in; |
306 | |
334 | |
307 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
335 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
308 | |
336 | |
309 | $CFG ||= { |
337 | $CFG ||= { |
… | |
… | |
312 | fullscreen => 0, |
340 | fullscreen => 0, |
313 | host => "crossfire.schmorp.de", |
341 | host => "crossfire.schmorp.de", |
314 | port => 13327, |
342 | port => 13327, |
315 | }; |
343 | }; |
316 | |
344 | |
|
|
345 | Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf"; |
|
|
346 | |
317 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
347 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
318 | |
348 | |
319 | run_config_dialog |
349 | run_config_dialog |
320 | login => sub { start_game }, |
350 | login => sub { start_game }, |
321 | logout => sub { stop_game }; |
351 | logout => sub { stop_game }; |