… | |
… | |
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 | |
39 | sub init_screen { |
46 | sub init_screen { |
40 | $SDL_APP = new SDL::App |
47 | $SDL_APP = new SDL::App |
41 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
48 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
42 | -title => "Crossfire+ Client", |
49 | -title => "Crossfire+ Client", |
43 | -width => $CFG->{width}, |
50 | -width => $WIDTH, |
44 | -height => $CFG->{height}, |
51 | -height => $HEIGHT, |
45 | -opengl => 1, |
52 | -opengl => 1, |
46 | -red_size => 8, |
53 | -red_size => 8, |
47 | -green_size => 8, |
54 | -green_size => 8, |
48 | -blue_size => 8, |
55 | -blue_size => 8, |
49 | -double_buffer => 1, |
56 | -double_buffer => 1, |
50 | -fullscreen => $CFG->{fullscreen}, |
57 | -fullscreen => $FULLSCREEN, |
51 | -resizeable => 0; |
58 | -resizeable => 0; |
|
|
59 | |
|
|
60 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
|
|
61 | |
|
|
62 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
|
|
63 | or warn "WARNING: non-power-of-two opengl extension required"; |
|
|
64 | |
|
|
65 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 |
|
|
66 | or die "TTFOpenFont: $!"; |
|
|
67 | |
|
|
68 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; |
|
|
69 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
|
|
70 | $ALT_ENTER_MESSAGE->activate; |
52 | |
71 | |
53 | glClearColor 0, 0, 0, 0; |
72 | glClearColor 0, 0, 0, 0; |
54 | |
73 | |
55 | glEnable GL_TEXTURE_2D; |
74 | glEnable GL_TEXTURE_2D; |
56 | glShadeModel GL_FLAT; |
75 | glShadeModel GL_FLAT; |
57 | glDisable GL_DEPTH_TEST; |
76 | glDisable GL_DEPTH_TEST; |
58 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
77 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
59 | |
78 | |
60 | glMatrixMode GL_PROJECTION; |
79 | glMatrixMode GL_PROJECTION; |
61 | glLoadIdentity; |
80 | glLoadIdentity; |
62 | glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; |
81 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
63 | |
82 | |
64 | glMatrixMode GL_MODELVIEW; |
83 | glMatrixMode GL_MODELVIEW; |
65 | |
84 | |
66 | $_->() for @GL_INIT; |
85 | $_->() for @GL_INIT; |
67 | } |
86 | } |
68 | |
87 | |
69 | my $label;#d# |
|
|
70 | |
|
|
71 | sub start_game { |
88 | sub start_game { |
72 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
89 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
73 | while ($SDL_EV->poll) { |
|
|
74 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
90 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
75 | } |
91 | while $SDL_EV->poll; |
76 | |
92 | |
77 | 1 |
93 | 1 |
78 | }; |
94 | }; |
79 | |
95 | |
|
|
96 | $WIDTH = $CFG->{width}; |
|
|
97 | $HEIGHT = $CFG->{height}; |
|
|
98 | $FULLSCREEN = 0; |
|
|
99 | |
80 | init_screen; |
100 | init_screen; |
81 | |
|
|
82 | $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]"; |
|
|
83 | $label->activate; |
|
|
84 | |
101 | |
85 | $CONN = new conn |
102 | $CONN = new conn |
86 | host => $CFG->{host}, |
103 | host => $CFG->{host}, |
87 | port => $CFG->{port}; |
104 | port => $CFG->{port}, |
|
|
105 | user => $CFG->{user}, |
|
|
106 | pass => $CFG->{password}; |
88 | } |
107 | } |
89 | |
108 | |
90 | sub stop_game { |
109 | sub stop_game { |
91 | remove Glib::Source $SDL_TIMER; |
110 | remove Glib::Source $SDL_TIMER; |
92 | |
111 | |
93 | undef $SDL_APP; |
112 | undef $SDL_APP; |
94 | SDL::Quit; |
113 | SDL::Quit; |
95 | } |
114 | } |
96 | |
115 | |
|
|
116 | |
|
|
117 | sub force_refresh { |
|
|
118 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
119 | glClear GL_COLOR_BUFFER_BIT; |
|
|
120 | |
|
|
121 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
|
|
122 | |
|
|
123 | SDL::GLSwapBuffers; |
|
|
124 | } |
|
|
125 | |
|
|
126 | my $refresh_handler; |
|
|
127 | |
97 | sub refresh { |
128 | sub refresh { |
98 | glClear GL_COLOR_BUFFER_BIT; |
129 | $refresh_handler ||= add Glib::Idle sub { |
99 | |
130 | force_refresh; |
100 | $_->draw for values %Crossfire::Client::Widget::ACTIVE_WIDGETS; |
131 | undef $refresh_handler; |
101 | |
132 | 0 |
102 | SDL::GLSwapBuffers; |
133 | }; |
103 | } |
134 | } |
104 | |
135 | |
105 | %SDL_CB = ( |
136 | %SDL_CB = ( |
106 | SDL_QUIT() => sub { |
137 | SDL_QUIT() => sub { |
107 | main_quit Gtk2; |
138 | main_quit Gtk2; |
… | |
… | |
112 | refresh; |
143 | refresh; |
113 | }, |
144 | }, |
114 | SDL_KEYDOWN() => sub { |
145 | SDL_KEYDOWN() => sub { |
115 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
146 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
116 | # alt-enter |
147 | # alt-enter |
117 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
148 | $FULLSCREEN = !$FULLSCREEN; |
118 | init_screen; |
149 | init_screen; |
119 | } else { |
150 | } else { |
120 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
151 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
121 | } |
152 | } |
122 | }, |
153 | }, |
… | |
… | |
264 | |
295 | |
265 | |
296 | |
266 | ############################################################################# |
297 | ############################################################################# |
267 | |
298 | |
268 | SDL::Init SDL_INIT_EVERYTHING; |
299 | SDL::Init SDL_INIT_EVERYTHING; |
|
|
300 | SDL::TTFInit; |
269 | |
301 | |
270 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
302 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
271 | |
303 | |
272 | $mapwidget->activate; |
304 | $mapwidget->activate; |
273 | $mapwidget->focus_in; |
305 | $mapwidget->focus_in; |
… | |
… | |
282 | port => 13327, |
314 | port => 13327, |
283 | }; |
315 | }; |
284 | |
316 | |
285 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
317 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
286 | |
318 | |
287 | SDL::TTFInit; |
|
|
288 | |
|
|
289 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", 24 |
|
|
290 | or die "TTFOpenFont: $!"; |
|
|
291 | |
|
|
292 | run_config_dialog |
319 | run_config_dialog |
293 | login => sub { start_game }, |
320 | login => sub { start_game }, |
294 | logout => sub { stop_game }; |
321 | logout => sub { stop_game }; |
295 | |
322 | |
296 | main Gtk2; |
323 | main Gtk2; |