… | |
… | |
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 | |
53 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $CFG->{height} / 40 |
67 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 |
54 | or die "TTFOpenFont: $!"; |
68 | or die "TTFOpenFont: $!"; |
55 | |
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 | |
56 | glClearColor 0, 0, 0, 0; |
84 | glClearColor 0, 0, 0, 0; |
57 | |
85 | |
58 | glEnable GL_TEXTURE_2D; |
86 | glEnable GL_TEXTURE_2D; |
|
|
87 | glEnable GL_COLOR_MATERIAL; |
59 | glShadeModel GL_FLAT; |
88 | glShadeModel GL_FLAT; |
60 | glDisable GL_DEPTH_TEST; |
89 | glDisable GL_DEPTH_TEST; |
61 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
90 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
62 | |
91 | |
63 | glMatrixMode GL_PROJECTION; |
|
|
64 | glLoadIdentity; |
|
|
65 | glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; |
|
|
66 | |
|
|
67 | glMatrixMode GL_MODELVIEW; |
|
|
68 | |
|
|
69 | $_->() for @GL_INIT; |
92 | $_->() for @GL_INIT; |
70 | } |
93 | } |
71 | |
94 | |
72 | my $label;#d# |
|
|
73 | |
|
|
74 | sub start_game { |
95 | sub start_game { |
75 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
96 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
76 | while ($SDL_EV->poll) { |
|
|
77 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); |
97 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
78 | } |
98 | while $SDL_EV->poll; |
79 | |
99 | |
80 | 1 |
100 | 1 |
81 | }; |
101 | }; |
82 | |
102 | |
|
|
103 | $WIDTH = $CFG->{width}; |
|
|
104 | $HEIGHT = $CFG->{height}; |
|
|
105 | $FULLSCREEN = 0; |
|
|
106 | |
83 | init_screen; |
107 | init_screen; |
84 | |
|
|
85 | $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]"; |
|
|
86 | $label->activate; |
|
|
87 | |
108 | |
88 | $CONN = new conn |
109 | $CONN = new conn |
89 | host => $CFG->{host}, |
110 | host => $CFG->{host}, |
90 | port => $CFG->{port}, |
111 | port => $CFG->{port}, |
91 | user => $CFG->{user}, |
112 | user => $CFG->{user}, |
92 | pass => $CFG->{password}; |
113 | pass => $CFG->{password}, |
|
|
114 | mapw => 50, |
|
|
115 | maph => 37, |
|
|
116 | ; |
93 | } |
117 | } |
94 | |
118 | |
95 | sub stop_game { |
119 | sub stop_game { |
96 | remove Glib::Source $SDL_TIMER; |
120 | remove Glib::Source $SDL_TIMER; |
97 | |
121 | |
98 | undef $SDL_APP; |
122 | undef $SDL_APP; |
99 | SDL::Quit; |
123 | SDL::Quit; |
100 | } |
124 | } |
101 | |
125 | |
|
|
126 | |
|
|
127 | sub force_refresh { |
|
|
128 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
129 | |
|
|
130 | glMatrixMode GL_PROJECTION; |
|
|
131 | glLoadIdentity; |
|
|
132 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
|
|
133 | glMatrixMode GL_MODELVIEW; |
|
|
134 | |
|
|
135 | glClear GL_COLOR_BUFFER_BIT; |
|
|
136 | |
|
|
137 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
|
|
138 | |
|
|
139 | SDL::GLSwapBuffers; |
|
|
140 | } |
|
|
141 | |
|
|
142 | my $refresh_handler; |
|
|
143 | |
102 | sub refresh { |
144 | sub refresh { |
103 | glClear GL_COLOR_BUFFER_BIT; |
145 | $refresh_handler ||= add Glib::Idle sub { |
104 | |
146 | force_refresh; |
105 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
147 | undef $refresh_handler; |
106 | |
148 | 0 |
107 | SDL::GLSwapBuffers; |
149 | }; |
108 | } |
150 | } |
109 | |
151 | |
110 | %SDL_CB = ( |
152 | %SDL_CB = ( |
111 | SDL_QUIT() => sub { |
153 | SDL_QUIT() => sub { |
112 | main_quit Gtk2; |
154 | main_quit Gtk2; |
… | |
… | |
117 | refresh; |
159 | refresh; |
118 | }, |
160 | }, |
119 | SDL_KEYDOWN() => sub { |
161 | SDL_KEYDOWN() => sub { |
120 | 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) { |
121 | # alt-enter |
163 | # alt-enter |
122 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
164 | $FULLSCREEN = !$FULLSCREEN; |
123 | init_screen; |
165 | init_screen; |
124 | } else { |
166 | } else { |
125 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
167 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
126 | } |
168 | } |
127 | }, |
169 | }, |
… | |
… | |
172 | my ($self, $face) = @_; |
214 | my ($self, $face) = @_; |
173 | |
215 | |
174 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
216 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
175 | |
217 | |
176 | $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# |
177 | } |
225 | } |
178 | |
226 | |
179 | sub gtk_add_cfg_field { |
227 | sub gtk_add_cfg_field { |
180 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
228 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
181 | my $i = $cfg->{_i}++; |
229 | my $i = $cfg->{_i}++; |