… | |
… | |
12 | use SDL::Surface; |
12 | use SDL::Surface; |
13 | use SDL::OpenGL; |
13 | use SDL::OpenGL; |
14 | use SDL::OpenGL::Constants; |
14 | use SDL::OpenGL::Constants; |
15 | |
15 | |
16 | use Crossfire; |
16 | use Crossfire; |
17 | use Crossfire::Client; |
|
|
18 | use Crossfire::Protocol; |
17 | use Crossfire::Protocol; |
19 | |
18 | |
20 | use Crossfire::Client::Widget; |
19 | use CFClient; |
|
|
20 | use CFClient::UI; |
|
|
21 | |
|
|
22 | our $VERSION = '0.1'; |
|
|
23 | |
|
|
24 | my $MAX_FPS = 60; |
|
|
25 | my $MIN_FPS = 5; # unused |
|
|
26 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
21 | |
27 | |
22 | our $FACECACHE; |
28 | our $FACECACHE; |
23 | |
|
|
24 | our $VERSION = '0.1'; |
|
|
25 | |
|
|
26 | our %GL_EXT; |
|
|
27 | |
29 | |
28 | our $CFG; |
30 | our $CFG; |
29 | our $CONN; |
31 | our $CONN; |
|
|
32 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
30 | |
33 | |
|
|
34 | our @SDL_MODES; |
31 | our $WIDTH; |
35 | our $WIDTH; |
32 | our $HEIGHT; |
36 | our $HEIGHT; |
33 | our $FULLSCREEN; |
37 | our $FULLSCREEN; |
34 | |
38 | |
|
|
39 | our $NOW; |
|
|
40 | |
|
|
41 | our $MAPWIDGET; |
35 | our $FONTSIZE; |
42 | our $FONTSIZE; |
36 | our $FOCUS; |
|
|
37 | our $HOVER; |
|
|
38 | |
43 | |
39 | our $SDL_TIMER; |
44 | our $SDL_TIMER; |
40 | our $SDL_APP; |
45 | our $SDL_APP; |
41 | our $SDL_EV = new SDL::Event; |
46 | our $SDL_EV; |
42 | our %SDL_CB; |
47 | our %SDL_CB; |
43 | |
|
|
44 | our @GL_INIT; # hooks called on every gl init |
|
|
45 | |
48 | |
46 | our $ALT_ENTER_MESSAGE; |
49 | our $ALT_ENTER_MESSAGE; |
47 | our $STATUS_LINE; |
50 | our $STATUS_LINE; |
48 | |
51 | our $DEBUG_STATUS; |
49 | our $TOPLEVEL; |
|
|
50 | |
|
|
51 | our $tw; # Test widget #d# |
|
|
52 | |
52 | |
53 | my $last_refresh; |
53 | my $last_refresh; |
54 | my %ANIMATE; |
54 | my %ANIMATE; |
55 | my $refresh_handler; |
55 | my $refresh_handler; |
56 | |
56 | |
|
|
57 | sub status { |
|
|
58 | $STATUS_LINE->set_text ($_[0]); |
|
|
59 | my ($w, $h) = $STATUS_LINE->size_request; |
|
|
60 | $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); |
|
|
61 | } |
|
|
62 | |
|
|
63 | sub debug { |
|
|
64 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
65 | my ($w, $h) = $DEBUG_STATUS->size_request; |
|
|
66 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
67 | } |
|
|
68 | |
|
|
69 | sub start_game { |
|
|
70 | status "logging in..."; |
|
|
71 | |
|
|
72 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
73 | |
|
|
74 | $CONN = new conn |
|
|
75 | host => $CFG->{host}, |
|
|
76 | port => $CFG->{port}, |
|
|
77 | user => $CFG->{user}, |
|
|
78 | pass => $CFG->{password}, |
|
|
79 | mapw => $mapsize, |
|
|
80 | maph => $mapsize, |
|
|
81 | ; |
|
|
82 | |
|
|
83 | status "login successful"; |
|
|
84 | |
|
|
85 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
86 | } |
|
|
87 | |
|
|
88 | sub stop_game { |
|
|
89 | undef $CONN; |
|
|
90 | } |
|
|
91 | |
|
|
92 | sub config_dialog { |
|
|
93 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
|
|
94 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
95 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
|
|
96 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
97 | |
|
|
98 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
|
|
99 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
|
|
100 | |
|
|
101 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
102 | $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); |
|
|
103 | |
|
|
104 | $mode_slider->connect (changed => sub { |
|
|
105 | my ($self, $value) = @_; |
|
|
106 | |
|
|
107 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
|
|
108 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
109 | }); |
|
|
110 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
|
|
111 | |
|
|
112 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); |
|
|
113 | $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { |
|
|
114 | my ($self, $value) = @_; |
|
|
115 | $CFG->{fullscreen} = $value; |
|
|
116 | }); |
|
|
117 | |
|
|
118 | $table->add (1, 2, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
119 | destroy_screen (); |
|
|
120 | init_screen (); |
|
|
121 | }); |
|
|
122 | |
|
|
123 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server"); |
|
|
124 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
125 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); |
|
|
126 | $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host}); |
|
|
127 | |
|
|
128 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); |
|
|
129 | $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}); |
|
|
130 | |
|
|
131 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); |
|
|
132 | $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user}); |
|
|
133 | |
|
|
134 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); |
|
|
135 | $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); |
|
|
136 | |
|
|
137 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size"); |
|
|
138 | $table->add (1, 6, new CFClient::UI::Slider |
|
|
139 | req_w => 100, |
|
|
140 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
141 | connect_changed => sub { |
|
|
142 | my ($self, $value) = @_; |
|
|
143 | |
|
|
144 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
|
|
145 | }, |
|
|
146 | ); |
|
|
147 | |
|
|
148 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
|
|
149 | start_game; |
|
|
150 | }); |
|
|
151 | |
|
|
152 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
153 | |
|
|
154 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
|
|
155 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
156 | status "Configuration Saved"; |
|
|
157 | }); |
|
|
158 | $CFClient::UI::TOPLEVEL->add ($dialog); |
|
|
159 | } |
|
|
160 | |
57 | sub init_screen { |
161 | sub init_screen { |
|
|
162 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
163 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
164 | |
58 | $SDL_APP = new SDL::App |
165 | $SDL_APP = new SDL::App |
59 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
166 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
60 | -title => "Crossfire+ Client", |
167 | -title => "Crossfire+ Client", |
61 | -width => $WIDTH, |
168 | -width => $WIDTH, |
62 | -height => $HEIGHT, |
169 | -height => $HEIGHT, |
… | |
… | |
67 | -alpha_size => 0, |
174 | -alpha_size => 0, |
68 | -double_buffer => 1, |
175 | -double_buffer => 1, |
69 | -fullscreen => $FULLSCREEN, |
176 | -fullscreen => $FULLSCREEN, |
70 | -resizeable => 0; |
177 | -resizeable => 0; |
71 | |
178 | |
72 | $last_refresh = SDL::GetTicks; |
179 | $SDL_EV = new SDL::Event; |
|
|
180 | $SDL_EV->set_unicode (1); |
73 | |
181 | |
74 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
|
|
75 | |
|
|
76 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
|
|
77 | or warn "WARNING: non-power-of-two opengl extension required"; |
|
|
78 | |
|
|
79 | $FONTSIZE = int $HEIGHT / 50; |
|
|
80 | |
|
|
81 | ############################################################################# |
|
|
82 | |
|
|
83 | glClearColor 0, 0, 0, 0; |
|
|
84 | |
|
|
85 | glEnable GL_TEXTURE_2D; |
|
|
86 | glEnable GL_COLOR_MATERIAL; |
|
|
87 | glShadeModel GL_FLAT; |
|
|
88 | glDisable GL_DEPTH_TEST; |
|
|
89 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
90 | |
|
|
91 | $_->() for @GL_INIT; |
|
|
92 | |
|
|
93 | ############################################################################# |
|
|
94 | |
|
|
95 | $STATUS_LINE = new Crossfire::Client::Widget::Label |
|
|
96 | 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, |
|
|
97 | ""; |
|
|
98 | $TOPLEVEL->add ($STATUS_LINE); |
|
|
99 | |
|
|
100 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
|
|
101 | 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, |
|
|
102 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
103 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
104 | |
|
|
105 | # Test code #d# |
|
|
106 | unless ($tw) { # haha... |
|
|
107 | $tw = new Crossfire::Client::Widget::Animator; |
|
|
108 | my $lbl1 = new Crossfire::Client::Widget::Label |
|
|
109 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
110 | my $lbl2 = new Crossfire::Client::Widget::Label |
|
|
111 | 0, 0, 10, $FONTSIZE, "LBL2"; |
|
|
112 | |
|
|
113 | my $vb = new Crossfire::Client::Widget::VBox; |
|
|
114 | my $f = new Crossfire::Client::Widget::FancyFrame; |
|
|
115 | my $f2 = new Crossfire::Client::Widget::FancyFrame; |
|
|
116 | $f->add ($lbl1); |
|
|
117 | $f2->add ($lbl2); |
|
|
118 | $vb->add ($f); |
|
|
119 | $vb->add ($f2, 1); |
|
|
120 | |
|
|
121 | $tw->add ($vb); |
|
|
122 | $tw->w (400); |
|
|
123 | $tw->h (300); |
|
|
124 | $tw->move ($WIDTH - 200, 0); |
|
|
125 | $tw->moveto (0, 0); |
|
|
126 | $TOPLEVEL->add ($tw); |
|
|
127 | |
|
|
128 | # $f->move ($WIDTH - 200, 0); |
|
|
129 | # $TOPLEVEL->add ($f); |
|
|
130 | } |
|
|
131 | } |
|
|
132 | |
|
|
133 | sub start_game { |
|
|
134 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
182 | $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { |
135 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
183 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
136 | while $SDL_EV->poll; |
184 | while $SDL_EV->poll; |
137 | |
185 | |
138 | 1 |
186 | 1 |
139 | }; |
187 | }; |
140 | |
188 | |
141 | $WIDTH = $CFG->{width}; |
189 | $last_refresh = SDL::GetTicks; |
142 | $HEIGHT = $CFG->{height}; |
|
|
143 | $FULLSCREEN = 0; |
|
|
144 | |
190 | |
145 | init_screen; |
191 | CFClient::gl_init; |
146 | |
192 | |
147 | my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
193 | $FONTSIZE = int $HEIGHT / 40; |
148 | |
194 | |
149 | $CONN = new conn |
195 | ############################################################################# |
150 | host => $CFG->{host}, |
196 | |
151 | port => $CFG->{port}, |
197 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
152 | user => $CFG->{user}, |
198 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
153 | pass => $CFG->{password}, |
|
|
154 | mapw => $mapsize, |
|
|
155 | maph => $mapsize, |
|
|
156 | ; |
199 | |
|
|
200 | $STATUS_LINE = new CFClient::UI::Label |
|
|
201 | padding => 0, |
|
|
202 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
|
|
203 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
157 | |
204 | |
158 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
205 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
159 | } |
206 | padding => 0, |
|
|
207 | y => $HEIGHT * 49 / 50, |
|
|
208 | height => $HEIGHT / 50, |
|
|
209 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
210 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
160 | |
211 | |
161 | sub stop_game { |
212 | $MAPWIDGET = new CFClient::UI::MapWidget; |
|
|
213 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
|
|
214 | $MAPWIDGET->focus_in; |
|
|
215 | |
|
|
216 | config_dialog; |
|
|
217 | } |
|
|
218 | |
|
|
219 | sub destroy_screen { |
|
|
220 | $CFClient::UI::TOPLEVEL->{children} = []; |
162 | remove Glib::Source $SDL_TIMER; |
221 | remove Glib::Source $SDL_TIMER; |
163 | remove Glib::Source $refresh_handler if $refresh_handler; |
222 | remove Glib::Source $refresh_handler if $refresh_handler; |
164 | undef $refresh_handler; |
223 | undef $refresh_handler; |
165 | |
|
|
166 | undef $SDL_APP; |
224 | undef $SDL_APP; |
167 | undef $CONN; |
225 | undef $SDL_EV; |
168 | SDL::Quit; |
226 | SDL::Quit; |
169 | } |
227 | } |
170 | |
|
|
171 | |
228 | |
172 | sub force_refresh { |
229 | sub force_refresh { |
173 | glViewport 0, 0, $WIDTH, $HEIGHT; |
230 | glViewport 0, 0, $WIDTH, $HEIGHT; |
174 | |
231 | |
175 | glMatrixMode GL_PROJECTION; |
232 | glMatrixMode GL_PROJECTION; |
176 | glLoadIdentity; |
233 | glLoadIdentity; |
177 | glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; |
234 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
178 | glMatrixMode GL_MODELVIEW; |
235 | glMatrixMode GL_MODELVIEW; |
|
|
236 | glLoadIdentity; |
179 | |
237 | |
180 | glClear GL_COLOR_BUFFER_BIT; |
238 | glClear GL_COLOR_BUFFER_BIT; |
181 | |
239 | |
182 | $TOPLEVEL->draw; |
240 | $CFClient::UI::TOPLEVEL->draw; |
183 | |
241 | |
184 | SDL::GLSwapBuffers; |
242 | SDL::GLSwapBuffers; |
185 | } |
243 | } |
|
|
244 | |
|
|
245 | my $FPS; |
186 | |
246 | |
187 | sub refresh { |
247 | sub refresh { |
188 | $refresh_handler ||= add Glib::Idle sub { |
248 | $refresh_handler ||= add Glib::Idle sub { |
189 | return unless $SDL_APP; |
249 | if ($SDL_APP) { |
|
|
250 | $NOW = SDL::GetTicks; |
190 | |
251 | |
191 | my $next_refresh = SDL::GetTicks; |
252 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
|
|
253 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
|
|
254 | $NOW = SDL::GetTicks; |
|
|
255 | } |
|
|
256 | |
192 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
257 | my $interval = ($NOW - $last_refresh) * 0.001; |
193 | $last_refresh = $next_refresh; |
258 | $last_refresh = $NOW; |
194 | |
259 | |
|
|
260 | if ($interval) { |
|
|
261 | $FPS ||= 1 / $interval; |
|
|
262 | $FPS = $FPS * 0.9 + (1 / $interval) * 0.1; |
|
|
263 | debug sprintf "%5.02f", $FPS; |
|
|
264 | } |
|
|
265 | |
195 | force_refresh; |
266 | force_refresh; |
196 | $_->animate ($interval) for grep $_, values %ANIMATE; |
267 | $_->animate ($interval) for grep $_, values %ANIMATE; |
197 | |
268 | |
198 | if (%ANIMATE) { |
269 | if (%ANIMATE) { |
|
|
270 | 1 |
|
|
271 | } else { |
|
|
272 | undef $refresh_handler; |
|
|
273 | 0 |
199 | 1 |
274 | } |
200 | } else { |
275 | } else { |
201 | undef $refresh_handler; |
276 | undef $refresh_handler; |
202 | 0 |
277 | 0 |
203 | } |
278 | } |
204 | }; |
279 | }; |
… | |
… | |
228 | }, |
303 | }, |
229 | SDL_KEYDOWN() => sub { |
304 | SDL_KEYDOWN() => sub { |
230 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
305 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
231 | # alt-enter |
306 | # alt-enter |
232 | $FULLSCREEN = !$FULLSCREEN; |
307 | $FULLSCREEN = !$FULLSCREEN; |
|
|
308 | destroy_screen; |
233 | init_screen; |
309 | init_screen; |
234 | } else { |
310 | } else { |
235 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
311 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
236 | } |
312 | } |
237 | }, |
313 | }, |
238 | SDL_KEYUP() => sub { |
314 | SDL_KEYUP() => sub { |
239 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
315 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
240 | }, |
316 | }, |
241 | SDL_MOUSEMOTION() => sub { |
317 | SDL_MOUSEMOTION() => sub { |
242 | my ($x, $y) = ($SDL_EV->motion_x, $SDL_EV->motion_y); |
318 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
243 | $HOVER = $TOPLEVEL->find_widget ($x, $y); |
|
|
244 | ::refresh; |
|
|
245 | |
|
|
246 | warn "mouse $x, $y = $HOVER\n"; |
|
|
247 | }, |
319 | }, |
248 | SDL_MOUSEBUTTONDOWN() => sub { |
320 | SDL_MOUSEBUTTONDOWN() => sub { |
249 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
321 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
250 | }, |
322 | }, |
251 | SDL_MOUSEBUTTONUP() => sub { |
323 | SDL_MOUSEBUTTONUP() => sub { |
252 | Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
324 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
253 | }, |
325 | }, |
254 | SDL_ACTIVEEVENT() => sub { |
326 | SDL_ACTIVEEVENT() => sub { |
255 | warn "active\n";#d# |
327 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
256 | }, |
328 | }, |
257 | ); |
329 | ); |
258 | |
330 | |
259 | @conn::ISA = Crossfire::Protocol::; |
331 | @conn::ISA = Crossfire::Protocol::; |
260 | |
332 | |
261 | sub conn::map_update { |
333 | sub conn::map_update { |
262 | my ($self, $dirty) = @_; |
334 | my ($self, $dirty) = @_; |
263 | |
335 | |
264 | refresh; |
336 | $MAPWIDGET->update; |
265 | } |
337 | } |
266 | |
338 | |
267 | sub conn::map_scroll { |
339 | sub conn::map_scroll { |
268 | my ($self, $dx, $dy) = @_; |
340 | my ($self, $dx, $dy) = @_; |
269 | |
341 | |
… | |
… | |
285 | sub conn::face_update { |
357 | sub conn::face_update { |
286 | my ($self, $face) = @_; |
358 | my ($self, $face) = @_; |
287 | |
359 | |
288 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
360 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
289 | |
361 | |
290 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
362 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
291 | } |
363 | } |
292 | |
364 | |
293 | sub conn::query { |
365 | sub conn::query { |
294 | my ($self, $flags, $prompt) = @_; |
366 | my ($self, $flags, $prompt) = @_; |
295 | |
367 | |
… | |
… | |
331 | [qw/Password password/], |
403 | [qw/Password password/], |
332 | ); |
404 | ); |
333 | |
405 | |
334 | my $cfg = {}; |
406 | my $cfg = {}; |
335 | |
407 | |
336 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
337 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
338 | |
|
|
339 | $w->add (my $vb = Gtk2::VBox->new); |
408 | $w->add (my $vb = Gtk2::VBox->new); |
340 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
409 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
341 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
410 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
342 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
411 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
343 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
412 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
344 | my $i = 0; |
413 | my $i = 0; |
345 | my $act = 0; |
414 | my $act = 0; |
346 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
415 | for (map { "$_->[0]x$_->[1]" } @SDL_MODES) { |
347 | if ($_ eq $selmode) { $act = $i } |
416 | if ($_ eq $selmode) { $act = $i } |
348 | $cb->append_text ($_); |
417 | $cb->append_text ($_); |
349 | $i++; |
418 | $i++; |
350 | } |
419 | } |
351 | $cb->set_active ($act); |
420 | $cb->set_active ($act); |
… | |
… | |
368 | $cb->signal_connect (clicked => sub { |
437 | $cb->signal_connect (clicked => sub { |
369 | for (keys %$cfg) { |
438 | for (keys %$cfg) { |
370 | $::CFG->{$_} = $cfg->{$_} |
439 | $::CFG->{$_} = $cfg->{$_} |
371 | if $_ ne '_i'; |
440 | if $_ ne '_i'; |
372 | } |
441 | } |
373 | Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc"; |
442 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
374 | }); |
443 | }); |
375 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
444 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
376 | $cb->signal_connect (clicked => sub { |
445 | $cb->signal_connect (clicked => sub { |
377 | for (keys %$cfg) { |
446 | for (keys %$cfg) { |
378 | $::CFG->{$_} = $cfg->{$_} |
447 | $::CFG->{$_} = $cfg->{$_} |
… | |
… | |
397 | |
466 | |
398 | ############################################################################# |
467 | ############################################################################# |
399 | |
468 | |
400 | SDL::Init SDL_INIT_EVERYTHING; |
469 | SDL::Init SDL_INIT_EVERYTHING; |
401 | |
470 | |
402 | $TOPLEVEL = Crossfire::Client::Widget::Toplevel->new; |
471 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
|
|
472 | @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; |
403 | |
473 | |
404 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
|
|
405 | |
|
|
406 | $TOPLEVEL->add ($mapwidget); |
|
|
407 | $mapwidget->focus_in; |
|
|
408 | |
|
|
409 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
474 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
410 | |
475 | |
411 | $CFG ||= { |
476 | $CFG ||= { |
412 | width => 640, |
477 | width => 640, |
413 | height => 480, |
478 | height => 480, |
|
|
479 | fullscreen => 0, |
|
|
480 | sdl_mode => 0, |
414 | mapsize => 100, |
481 | mapsize => 100, |
415 | fullscreen => 0, |
|
|
416 | host => "crossfire.schmorp.de", |
482 | host => "crossfire.schmorp.de", |
417 | port => 13327, |
483 | port => 13327, |
418 | }; |
484 | }; |
419 | |
485 | |
420 | Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf"; |
486 | { |
|
|
487 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
|
|
488 | |
|
|
489 | CFClient::add_font $_ for @fonts; |
|
|
490 | CFClient::set_font $fonts[0]; |
|
|
491 | } |
421 | |
492 | |
422 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
493 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
423 | |
494 | |
424 | run_config_dialog |
495 | init_screen; |
425 | login => sub { start_game }, |
|
|
426 | logout => sub { stop_game }; |
|
|
427 | |
496 | |
428 | main Gtk2; |
497 | main Gtk2; |
429 | |
498 | |
430 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
499 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
|
|
500 | |