… | |
… | |
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; |
|
|
30 | |
|
|
31 | our $WIDTH; |
|
|
32 | our $HEIGHT; |
|
|
33 | our $FULLSCREEN; |
29 | |
34 | |
30 | our $UIFONT; |
35 | our $UIFONT; |
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 $tw; # Test widget #d# |
|
|
47 | |
39 | sub init_screen { |
48 | sub init_screen { |
40 | $SDL_APP = new SDL::App |
49 | $SDL_APP = new SDL::App |
41 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
50 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
42 | -title => "Crossfire+ Client", |
51 | -title => "Crossfire+ Client", |
43 | -width => $CFG->{width}, |
52 | -width => $WIDTH, |
44 | -height => $CFG->{height}, |
53 | -height => $HEIGHT, |
45 | -opengl => 1, |
54 | -opengl => 1, |
46 | -red_size => 8, |
55 | -red_size => 8, |
47 | -green_size => 8, |
56 | -green_size => 8, |
48 | -blue_size => 8, |
57 | -blue_size => 8, |
49 | -double_buffer => 1, |
58 | -double_buffer => 1, |
50 | -fullscreen => $CFG->{fullscreen}, |
59 | -fullscreen => $FULLSCREEN, |
51 | -resizeable => 0; |
60 | -resizeable => 0; |
52 | |
61 | |
|
|
62 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
|
|
63 | |
|
|
64 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
|
|
65 | or warn "WARNING: non-power-of-two opengl extension required"; |
|
|
66 | |
|
|
67 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 |
|
|
68 | or die "TTFOpenFont: $!"; |
|
|
69 | |
|
|
70 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; |
|
|
71 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
|
|
72 | $ALT_ENTER_MESSAGE->activate; |
|
|
73 | |
|
|
74 | # Test code #d# |
|
|
75 | my $frm = new Crossfire::Client::Widget::Frame; |
|
|
76 | $tw = new Crossfire::Client::Widget::Window; |
|
|
77 | $frm->add (new Crossfire::Client::Widget::Label 0, 0, 10, $UIFONT, "Foo in the garden!"); |
|
|
78 | $tw->add ($frm); |
|
|
79 | |
|
|
80 | $tw->move (0, $HEIGHT - 120); |
|
|
81 | $tw->activate; |
|
|
82 | # Test code end #d# |
|
|
83 | |
53 | glClearColor 0, 0, 0, 0; |
84 | glClearColor 0, 0, 0, 0; |
54 | |
85 | |
55 | glEnable GL_TEXTURE_2D; |
86 | glEnable GL_TEXTURE_2D; |
|
|
87 | glEnable GL_COLOR_MATERIAL; |
56 | glShadeModel GL_FLAT; |
88 | glShadeModel GL_FLAT; |
57 | glDisable GL_DEPTH_TEST; |
89 | glDisable GL_DEPTH_TEST; |
58 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
90 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
59 | |
91 | |
|
|
92 | $_->() for @GL_INIT; |
|
|
93 | } |
|
|
94 | |
|
|
95 | sub start_game { |
|
|
96 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
|
|
97 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
98 | while $SDL_EV->poll; |
|
|
99 | |
|
|
100 | 1 |
|
|
101 | }; |
|
|
102 | |
|
|
103 | $WIDTH = $CFG->{width}; |
|
|
104 | $HEIGHT = $CFG->{height}; |
|
|
105 | $FULLSCREEN = 0; |
|
|
106 | |
|
|
107 | init_screen; |
|
|
108 | |
|
|
109 | $CONN = new conn |
|
|
110 | host => $CFG->{host}, |
|
|
111 | port => $CFG->{port}, |
|
|
112 | user => $CFG->{user}, |
|
|
113 | pass => $CFG->{password}, |
|
|
114 | mapw => 50, |
|
|
115 | maph => 37, |
|
|
116 | ; |
|
|
117 | } |
|
|
118 | |
|
|
119 | sub stop_game { |
|
|
120 | remove Glib::Source $SDL_TIMER; |
|
|
121 | |
|
|
122 | undef $SDL_APP; |
|
|
123 | SDL::Quit; |
|
|
124 | } |
|
|
125 | |
|
|
126 | |
|
|
127 | sub force_refresh { |
|
|
128 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
129 | |
60 | glMatrixMode GL_PROJECTION; |
130 | glMatrixMode GL_PROJECTION; |
61 | glLoadIdentity; |
131 | glLoadIdentity; |
62 | glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; |
132 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
63 | |
|
|
64 | glMatrixMode GL_MODELVIEW; |
133 | glMatrixMode GL_MODELVIEW; |
65 | |
134 | |
66 | $_->() for @GL_INIT; |
135 | glClear GL_COLOR_BUFFER_BIT; |
67 | } |
|
|
68 | |
136 | |
69 | my $label;#d# |
137 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
70 | |
138 | |
71 | sub start_game { |
139 | SDL::GLSwapBuffers; |
72 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
140 | } |
73 | while ($SDL_EV->poll) { |
141 | |
74 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
142 | my $refresh_handler; |
|
|
143 | |
|
|
144 | sub refresh { |
|
|
145 | $refresh_handler ||= add Glib::Idle sub { |
|
|
146 | force_refresh; |
|
|
147 | undef $refresh_handler; |
75 | } |
148 | 0 |
76 | |
|
|
77 | 1 |
|
|
78 | }; |
149 | }; |
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 @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
|
|
101 | |
|
|
102 | SDL::GLSwapBuffers; |
|
|
103 | } |
150 | } |
104 | |
151 | |
105 | %SDL_CB = ( |
152 | %SDL_CB = ( |
106 | SDL_QUIT() => sub { |
153 | SDL_QUIT() => sub { |
107 | main_quit Gtk2; |
154 | main_quit Gtk2; |
… | |
… | |
112 | refresh; |
159 | refresh; |
113 | }, |
160 | }, |
114 | SDL_KEYDOWN() => sub { |
161 | SDL_KEYDOWN() => sub { |
115 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
162 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
116 | # alt-enter |
163 | # alt-enter |
117 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
164 | $FULLSCREEN = !$FULLSCREEN; |
118 | init_screen; |
165 | init_screen; |
119 | } else { |
166 | } else { |
120 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
167 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
121 | } |
168 | } |
122 | }, |
169 | }, |
… | |
… | |
167 | my ($self, $face) = @_; |
214 | my ($self, $face) = @_; |
168 | |
215 | |
169 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
216 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
170 | |
217 | |
171 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
218 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
|
|
219 | } |
|
|
220 | |
|
|
221 | sub conn::query { |
|
|
222 | my ($self, $flags, $prompt) = @_; |
|
|
223 | |
|
|
224 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
172 | } |
225 | } |
173 | |
226 | |
174 | sub gtk_add_cfg_field { |
227 | sub gtk_add_cfg_field { |
175 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
228 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
176 | my $i = $cfg->{_i}++; |
229 | my $i = $cfg->{_i}++; |
… | |
… | |
264 | |
317 | |
265 | |
318 | |
266 | ############################################################################# |
319 | ############################################################################# |
267 | |
320 | |
268 | SDL::Init SDL_INIT_EVERYTHING; |
321 | SDL::Init SDL_INIT_EVERYTHING; |
|
|
322 | SDL::TTFInit; |
269 | |
323 | |
270 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
324 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
271 | |
325 | |
272 | $mapwidget->activate; |
326 | $mapwidget->activate; |
273 | $mapwidget->focus_in; |
327 | $mapwidget->focus_in; |
… | |
… | |
282 | port => 13327, |
336 | port => 13327, |
283 | }; |
337 | }; |
284 | |
338 | |
285 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
339 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
286 | |
340 | |
287 | SDL::TTFInit; |
|
|
288 | |
|
|
289 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", 24 |
|
|
290 | or die "TTFOpenFont: $!"; |
|
|
291 | |
|
|
292 | run_config_dialog |
341 | run_config_dialog |
293 | login => sub { start_game }, |
342 | login => sub { start_game }, |
294 | logout => sub { stop_game }; |
343 | logout => sub { stop_game }; |
295 | |
344 | |
296 | main Gtk2; |
345 | main Gtk2; |