… | |
… | |
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 $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
21 | |
26 | |
22 | our $FACECACHE; |
27 | our $FACECACHE; |
23 | |
|
|
24 | our $VERSION = '0.1'; |
|
|
25 | |
|
|
26 | our %GL_EXT; |
|
|
27 | |
28 | |
28 | our $CFG; |
29 | our $CFG; |
29 | our $CONN; |
30 | our $CONN; |
|
|
31 | our $FAST; # fast, low-quality mode |
30 | |
32 | |
|
|
33 | our @SDL_MODES; |
31 | our $WIDTH; |
34 | our $WIDTH; |
32 | our $HEIGHT; |
35 | our $HEIGHT; |
33 | our $FULLSCREEN; |
36 | our $FULLSCREEN; |
34 | |
37 | |
|
|
38 | our $NOW; |
|
|
39 | |
|
|
40 | our $MAPWIDGET; |
35 | our $FONTSIZE; |
41 | our $FONTSIZE; |
36 | |
|
|
37 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
|
|
38 | |
42 | |
39 | our $SDL_TIMER; |
43 | our $SDL_TIMER; |
40 | our $SDL_APP; |
44 | our $SDL_APP; |
41 | our $SDL_EV = new SDL::Event; |
45 | our $SDL_EV; |
42 | our %SDL_CB; |
46 | our %SDL_CB; |
43 | |
|
|
44 | our @GL_INIT; # hooks called on every gl init |
|
|
45 | |
47 | |
46 | our $ALT_ENTER_MESSAGE; |
48 | our $ALT_ENTER_MESSAGE; |
47 | our $STATUS_LINE; |
49 | our $STATUS_LINE; |
48 | |
50 | our $DEBUG_STATUS; |
49 | our $TOPLEVEL; |
|
|
50 | |
|
|
51 | our $tw; # Test widget #d# |
|
|
52 | |
51 | |
53 | my $last_refresh; |
52 | my $last_refresh; |
54 | my %ANIMATE; |
53 | my %ANIMATE; |
55 | my $refresh_handler; |
54 | my $refresh_handler; |
|
|
55 | |
|
|
56 | sub config_dialog { |
|
|
57 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
|
|
58 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
59 | $vbox->add (new CFClient::UI::Label align => 0, text => "Setup"); |
|
|
60 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
61 | |
|
|
62 | $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); |
|
|
63 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
|
|
64 | |
|
|
65 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
66 | $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); |
|
|
67 | |
|
|
68 | $mode_slider->connect (changed => sub { |
|
|
69 | my ($self, $value) = @_; |
|
|
70 | |
|
|
71 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
|
|
72 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
73 | }); |
|
|
74 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
|
|
75 | |
|
|
76 | $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Host"); |
|
|
77 | $table->add (1, 1, my $host = new CFClient::UI::Entry text => $CFG->{host}); |
|
|
78 | |
|
|
79 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Port"); |
|
|
80 | $table->add (1, 2, my $port = new CFClient::UI::Entry text => $CFG->{port}); |
|
|
81 | |
|
|
82 | $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Username"); |
|
|
83 | $table->add (1, 3, my $user = new CFClient::UI::Entry text => $CFG->{user}); |
|
|
84 | |
|
|
85 | $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Password"); |
|
|
86 | $table->add (1, 4, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1); |
|
|
87 | |
|
|
88 | $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Map Size"); |
|
|
89 | $table->add (1, 5, new CFClient::UI::Slider |
|
|
90 | req_w => 100, |
|
|
91 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
92 | connect_changed => sub { |
|
|
93 | my ($self, $value) = @_; |
|
|
94 | |
|
|
95 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
|
|
96 | }, |
|
|
97 | ); |
|
|
98 | |
|
|
99 | $vbox->add (my $hbox = new CFClient::UI::HBox); |
|
|
100 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { |
|
|
101 | warn "save\n"; |
|
|
102 | }); |
|
|
103 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
|
|
104 | warn "login\n"; |
|
|
105 | }); |
|
|
106 | $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
107 | warn "apply\n"; |
|
|
108 | }); |
|
|
109 | |
|
|
110 | $CFClient::UI::TOPLEVEL->add ($dialog); |
|
|
111 | } |
56 | |
112 | |
57 | sub init_screen { |
113 | sub init_screen { |
58 | $SDL_APP = new SDL::App |
114 | $SDL_APP = new SDL::App |
59 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
115 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
60 | -title => "Crossfire+ Client", |
116 | -title => "Crossfire+ Client", |
… | |
… | |
67 | -alpha_size => 0, |
123 | -alpha_size => 0, |
68 | -double_buffer => 1, |
124 | -double_buffer => 1, |
69 | -fullscreen => $FULLSCREEN, |
125 | -fullscreen => $FULLSCREEN, |
70 | -resizeable => 0; |
126 | -resizeable => 0; |
71 | |
127 | |
72 | $last_refresh = SDL::GetTicks; |
128 | $SDL_EV = new SDL::Event; |
|
|
129 | $SDL_EV->set_unicode (1); |
73 | |
130 | |
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 { |
131 | $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { |
135 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
132 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
136 | while $SDL_EV->poll; |
133 | while $SDL_EV->poll; |
137 | |
134 | |
138 | 1 |
135 | 1 |
139 | }; |
136 | }; |
140 | |
137 | |
|
|
138 | $last_refresh = SDL::GetTicks; |
|
|
139 | |
|
|
140 | CFClient::gl_init; |
|
|
141 | |
|
|
142 | $FONTSIZE = int $HEIGHT / 40; |
|
|
143 | |
|
|
144 | ############################################################################# |
|
|
145 | |
|
|
146 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
|
|
147 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
148 | |
|
|
149 | $STATUS_LINE = new CFClient::UI::Label |
|
|
150 | padding => 0, |
|
|
151 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
|
|
152 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
|
|
153 | |
|
|
154 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
155 | padding => 0, |
|
|
156 | y => $HEIGHT * 49 / 50, |
|
|
157 | height => $HEIGHT / 50, |
|
|
158 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
159 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
160 | |
|
|
161 | $MAPWIDGET = new CFClient::UI::MapWidget; |
|
|
162 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
|
|
163 | $MAPWIDGET->focus_in; |
|
|
164 | |
|
|
165 | config_dialog; |
|
|
166 | } |
|
|
167 | |
|
|
168 | sub destroy_screen { |
|
|
169 | $CFClient::UI::TOPLEVEL->{children} = []; |
|
|
170 | remove Glib::Source $SDL_TIMER; |
|
|
171 | undef $SDL_APP; |
|
|
172 | undef $SDL_EV; |
|
|
173 | SDL::Quit; |
|
|
174 | } |
|
|
175 | |
|
|
176 | sub start_game { |
141 | $WIDTH = $CFG->{width}; |
177 | $WIDTH = $CFG->{width}; |
142 | $HEIGHT = $CFG->{height}; |
178 | $HEIGHT = $CFG->{height}; |
143 | $FULLSCREEN = 0; |
179 | $FULLSCREEN = 0; |
144 | |
180 | |
145 | init_screen; |
181 | init_screen; |
146 | |
182 | |
147 | my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
183 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
148 | |
184 | |
149 | $CONN = new conn |
185 | $CONN = new conn |
150 | host => $CFG->{host}, |
186 | host => $CFG->{host}, |
151 | port => $CFG->{port}, |
187 | port => $CFG->{port}, |
152 | user => $CFG->{user}, |
188 | user => $CFG->{user}, |
153 | pass => $CFG->{password}, |
189 | pass => $CFG->{password}, |
154 | mapw => $mapsize, |
190 | mapw => $mapsize, |
155 | maph => $mapsize, |
191 | maph => $mapsize, |
156 | ; |
192 | ; |
157 | |
193 | |
158 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
194 | CFClient::lowdelay fileno $CONN->{fh}; |
159 | } |
195 | } |
160 | |
196 | |
161 | sub stop_game { |
197 | sub stop_game { |
162 | remove Glib::Source $SDL_TIMER; |
|
|
163 | remove Glib::Source $refresh_handler if $refresh_handler; |
198 | remove Glib::Source $refresh_handler if $refresh_handler; |
164 | undef $refresh_handler; |
199 | undef $refresh_handler; |
165 | |
200 | |
166 | undef $SDL_APP; |
|
|
167 | undef $CONN; |
201 | undef $CONN; |
168 | SDL::Quit; |
202 | destroy_screen; |
169 | } |
203 | } |
170 | |
|
|
171 | |
204 | |
172 | sub force_refresh { |
205 | sub force_refresh { |
173 | glViewport 0, 0, $WIDTH, $HEIGHT; |
206 | glViewport 0, 0, $WIDTH, $HEIGHT; |
174 | |
207 | |
175 | glMatrixMode GL_PROJECTION; |
208 | glMatrixMode GL_PROJECTION; |
176 | glLoadIdentity; |
209 | glLoadIdentity; |
177 | glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; |
210 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
178 | glMatrixMode GL_MODELVIEW; |
211 | glMatrixMode GL_MODELVIEW; |
|
|
212 | glLoadIdentity; |
179 | |
213 | |
180 | glClear GL_COLOR_BUFFER_BIT; |
214 | glClear GL_COLOR_BUFFER_BIT; |
181 | |
215 | |
182 | $TOPLEVEL->draw; |
216 | $CFClient::UI::TOPLEVEL->draw; |
183 | |
217 | |
184 | SDL::GLSwapBuffers; |
218 | SDL::GLSwapBuffers; |
185 | } |
219 | } |
|
|
220 | |
|
|
221 | sub debug { |
|
|
222 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
223 | my ($w, $h) = $DEBUG_STATUS->size_request; |
|
|
224 | $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); |
|
|
225 | } |
|
|
226 | |
|
|
227 | my $FPS; |
186 | |
228 | |
187 | sub refresh { |
229 | sub refresh { |
188 | $refresh_handler ||= add Glib::Idle sub { |
230 | $refresh_handler ||= add Glib::Idle sub { |
189 | return unless $SDL_APP; |
231 | if ($SDL_APP) { |
|
|
232 | $NOW = SDL::GetTicks; |
190 | |
233 | |
191 | my $next_refresh = SDL::GetTicks; |
234 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
|
|
235 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
|
|
236 | $NOW = SDL::GetTicks; |
|
|
237 | } |
|
|
238 | |
192 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
239 | my $interval = ($NOW - $last_refresh) * 0.001; |
193 | $last_refresh = $next_refresh; |
240 | $last_refresh = $NOW; |
194 | |
241 | |
|
|
242 | if ($interval) { |
|
|
243 | $FPS ||= 1 / $interval; |
|
|
244 | $FPS = $FPS * 0.9 + (1 / $interval) * 0.1; |
|
|
245 | debug sprintf "%5.02f", $FPS; |
|
|
246 | } |
|
|
247 | |
195 | force_refresh; |
248 | force_refresh; |
196 | $_->animate ($interval) for grep $_, values %ANIMATE; |
249 | $_->animate ($interval) for grep $_, values %ANIMATE; |
197 | |
250 | |
198 | if (%ANIMATE) { |
251 | if (%ANIMATE) { |
|
|
252 | 1 |
|
|
253 | } else { |
|
|
254 | undef $refresh_handler; |
|
|
255 | 0 |
199 | 1 |
256 | } |
200 | } else { |
257 | } else { |
201 | undef $refresh_handler; |
258 | undef $refresh_handler; |
202 | 0 |
259 | 0 |
203 | } |
260 | } |
204 | }; |
261 | }; |
… | |
… | |
228 | }, |
285 | }, |
229 | SDL_KEYDOWN() => sub { |
286 | SDL_KEYDOWN() => sub { |
230 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
287 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
231 | # alt-enter |
288 | # alt-enter |
232 | $FULLSCREEN = !$FULLSCREEN; |
289 | $FULLSCREEN = !$FULLSCREEN; |
|
|
290 | destroy_screen; |
233 | init_screen; |
291 | init_screen; |
234 | } else { |
292 | } else { |
235 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
293 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
236 | } |
294 | } |
237 | }, |
295 | }, |
238 | SDL_KEYUP() => sub { |
296 | SDL_KEYUP() => sub { |
239 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
297 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
240 | }, |
298 | }, |
241 | SDL_MOUSEMOTION() => sub { |
299 | SDL_MOUSEMOTION() => sub { |
242 | my ($x, $y) = ($SDL_EV->motion_x, $SDL_EV->motion_y); |
300 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
243 | $HOVER = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
|
|
244 | ::refresh; |
|
|
245 | }, |
301 | }, |
246 | SDL_MOUSEBUTTONDOWN() => sub { |
302 | SDL_MOUSEBUTTONDOWN() => sub { |
247 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
303 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
248 | }, |
304 | }, |
249 | SDL_MOUSEBUTTONUP() => sub { |
305 | SDL_MOUSEBUTTONUP() => sub { |
250 | Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
306 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
251 | }, |
307 | }, |
252 | SDL_ACTIVEEVENT() => sub { |
308 | SDL_ACTIVEEVENT() => sub { |
253 | warn "active\n";#d# |
309 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
254 | }, |
310 | }, |
255 | ); |
311 | ); |
256 | |
312 | |
257 | @conn::ISA = Crossfire::Protocol::; |
313 | @conn::ISA = Crossfire::Protocol::; |
258 | |
314 | |
259 | sub conn::map_update { |
315 | sub conn::map_update { |
260 | my ($self, $dirty) = @_; |
316 | my ($self, $dirty) = @_; |
261 | |
317 | |
262 | refresh; |
318 | $MAPWIDGET->update; |
263 | } |
319 | } |
264 | |
320 | |
265 | sub conn::map_scroll { |
321 | sub conn::map_scroll { |
266 | my ($self, $dx, $dy) = @_; |
322 | my ($self, $dx, $dy) = @_; |
267 | |
323 | |
… | |
… | |
283 | sub conn::face_update { |
339 | sub conn::face_update { |
284 | my ($self, $face) = @_; |
340 | my ($self, $face) = @_; |
285 | |
341 | |
286 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
342 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
287 | |
343 | |
288 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
344 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
289 | } |
345 | } |
290 | |
346 | |
291 | sub conn::query { |
347 | sub conn::query { |
292 | my ($self, $flags, $prompt) = @_; |
348 | my ($self, $flags, $prompt) = @_; |
293 | |
349 | |
… | |
… | |
329 | [qw/Password password/], |
385 | [qw/Password password/], |
330 | ); |
386 | ); |
331 | |
387 | |
332 | my $cfg = {}; |
388 | my $cfg = {}; |
333 | |
389 | |
334 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
335 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
336 | |
|
|
337 | $w->add (my $vb = Gtk2::VBox->new); |
390 | $w->add (my $vb = Gtk2::VBox->new); |
338 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
391 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
339 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
392 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
340 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
393 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
341 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
394 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
342 | my $i = 0; |
395 | my $i = 0; |
343 | my $act = 0; |
396 | my $act = 0; |
344 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
397 | for (map { "$_->[0]x$_->[1]" } @SDL_MODES) { |
345 | if ($_ eq $selmode) { $act = $i } |
398 | if ($_ eq $selmode) { $act = $i } |
346 | $cb->append_text ($_); |
399 | $cb->append_text ($_); |
347 | $i++; |
400 | $i++; |
348 | } |
401 | } |
349 | $cb->set_active ($act); |
402 | $cb->set_active ($act); |
… | |
… | |
366 | $cb->signal_connect (clicked => sub { |
419 | $cb->signal_connect (clicked => sub { |
367 | for (keys %$cfg) { |
420 | for (keys %$cfg) { |
368 | $::CFG->{$_} = $cfg->{$_} |
421 | $::CFG->{$_} = $cfg->{$_} |
369 | if $_ ne '_i'; |
422 | if $_ ne '_i'; |
370 | } |
423 | } |
371 | Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc"; |
424 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
372 | }); |
425 | }); |
373 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
426 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
374 | $cb->signal_connect (clicked => sub { |
427 | $cb->signal_connect (clicked => sub { |
375 | for (keys %$cfg) { |
428 | for (keys %$cfg) { |
376 | $::CFG->{$_} = $cfg->{$_} |
429 | $::CFG->{$_} = $cfg->{$_} |
… | |
… | |
395 | |
448 | |
396 | ############################################################################# |
449 | ############################################################################# |
397 | |
450 | |
398 | SDL::Init SDL_INIT_EVERYTHING; |
451 | SDL::Init SDL_INIT_EVERYTHING; |
399 | |
452 | |
400 | $TOPLEVEL = Crossfire::Client::Widget::Toplevel->new; |
453 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
|
|
454 | @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; |
401 | |
455 | |
402 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
|
|
403 | |
|
|
404 | $TOPLEVEL->add ($mapwidget); |
|
|
405 | $mapwidget->focus_in; |
|
|
406 | |
|
|
407 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
456 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
408 | |
457 | |
409 | $CFG ||= { |
458 | $CFG ||= { |
410 | width => 640, |
459 | width => 640, |
411 | height => 480, |
460 | height => 480, |
412 | mapsize => 100, |
461 | mapsize => 100, |
413 | fullscreen => 0, |
462 | fullscreen => 0, |
414 | host => "crossfire.schmorp.de", |
463 | host => "crossfire.schmorp.de", |
415 | port => 13327, |
464 | port => 13327, |
416 | }; |
465 | }; |
417 | |
466 | |
418 | Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf"; |
467 | { |
|
|
468 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
|
|
469 | |
|
|
470 | CFClient::add_font $_ for @fonts; |
|
|
471 | CFClient::set_font $fonts[0]; |
|
|
472 | } |
419 | |
473 | |
420 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
474 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
421 | |
475 | |
422 | run_config_dialog |
476 | run_config_dialog |
423 | login => sub { start_game }, |
477 | login => sub { start_game }, |