… | |
… | |
15 | |
15 | |
16 | use Crossfire; |
16 | use Crossfire; |
17 | use Crossfire::Protocol; |
17 | use Crossfire::Protocol; |
18 | |
18 | |
19 | use CFClient; |
19 | use CFClient; |
20 | use CFClient::Widget; |
20 | use CFClient::UI; |
21 | |
21 | |
22 | our $VERSION = '0.1'; |
22 | our $VERSION = '0.1'; |
23 | |
23 | |
24 | my $MAX_FPS = 30; |
24 | my $MAX_FPS = 60; |
|
|
25 | my $MIN_FPS = 5; # unused |
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
26 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
26 | |
27 | |
27 | our $FACECACHE; |
28 | our $FACECACHE; |
28 | |
29 | |
29 | our $CFG; |
30 | our $CFG; |
30 | our $CONN; |
31 | our $CONN; |
|
|
32 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
31 | |
33 | |
|
|
34 | our @SDL_MODES; |
32 | our $WIDTH; |
35 | our $WIDTH; |
33 | our $HEIGHT; |
36 | our $HEIGHT; |
34 | our $FULLSCREEN; |
37 | our $FULLSCREEN; |
35 | |
38 | |
|
|
39 | our $NOW; |
|
|
40 | |
|
|
41 | our $MAPWIDGET; |
36 | our $FONTSIZE; |
42 | our $FONTSIZE; |
37 | |
43 | |
38 | our $SDL_TIMER; |
44 | our $SDL_TIMER; |
39 | our $SDL_APP; |
45 | our $SDL_APP; |
40 | our $SDL_EV; |
46 | our $SDL_EV; |
… | |
… | |
46 | |
52 | |
47 | my $last_refresh; |
53 | my $last_refresh; |
48 | my %ANIMATE; |
54 | my %ANIMATE; |
49 | my $refresh_handler; |
55 | my $refresh_handler; |
50 | |
56 | |
51 | our ($tw, $te); # Test widget #d# |
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 | } |
52 | |
160 | |
53 | sub init_screen { |
161 | sub init_screen { |
|
|
162 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
163 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
164 | |
54 | $SDL_APP = new SDL::App |
165 | $SDL_APP = new SDL::App |
55 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
166 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
56 | -title => "Crossfire+ Client", |
167 | -title => "Crossfire+ Client", |
57 | -width => $WIDTH, |
168 | -width => $WIDTH, |
58 | -height => $HEIGHT, |
169 | -height => $HEIGHT, |
… | |
… | |
66 | -resizeable => 0; |
177 | -resizeable => 0; |
67 | |
178 | |
68 | $SDL_EV = new SDL::Event; |
179 | $SDL_EV = new SDL::Event; |
69 | $SDL_EV->set_unicode (1); |
180 | $SDL_EV->set_unicode (1); |
70 | |
181 | |
71 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
182 | $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub { |
72 | ($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 })->() |
73 | while $SDL_EV->poll; |
184 | while $SDL_EV->poll; |
74 | |
185 | |
75 | 1 |
186 | 1 |
76 | }; |
187 | }; |
77 | |
188 | |
78 | $last_refresh = SDL::GetTicks; |
189 | $last_refresh = SDL::GetTicks; |
79 | |
190 | |
80 | CFClient::gl_init; |
191 | CFClient::gl_init; |
81 | |
192 | |
82 | $FONTSIZE = int $HEIGHT / 50; |
193 | $FONTSIZE = int $HEIGHT / 40; |
83 | |
194 | |
84 | ############################################################################# |
195 | ############################################################################# |
85 | |
196 | |
86 | glClearColor 0.45, 0.45, 0.45, 1; |
197 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0; |
87 | |
|
|
88 | glEnable GL_TEXTURE_2D; |
|
|
89 | glEnable GL_COLOR_MATERIAL; |
|
|
90 | glShadeModel GL_FLAT; |
|
|
91 | glDisable GL_DEPTH_TEST; |
|
|
92 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
93 | |
|
|
94 | ############################################################################# |
|
|
95 | |
|
|
96 | $DEBUG_STATUS = new CFClient::Widget::Label 0, 0, 1, $FONTSIZE, ""; |
|
|
97 | $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); |
198 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
98 | |
199 | |
99 | $STATUS_LINE = new CFClient::Widget::Label |
200 | $STATUS_LINE = new CFClient::UI::Label |
100 | 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, |
201 | padding => 0, |
101 | ""; |
202 | y => $HEIGHT * 49 / 50 - $FONTSIZE; |
102 | $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); |
203 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
103 | |
204 | |
104 | $ALT_ENTER_MESSAGE = new CFClient::Widget::Label |
205 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
105 | 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, |
206 | padding => 0, |
|
|
207 | y => $HEIGHT * 49 / 50, |
|
|
208 | height => $HEIGHT / 50, |
106 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
209 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
107 | $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
210 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
108 | |
211 | |
109 | # Test code #d# |
212 | $MAPWIDGET = new CFClient::UI::MapWidget; |
110 | unless ($tw) { # haha... |
|
|
111 | $te = new CFClient::Widget::FancyFrame; |
|
|
112 | $te->add (new CFClient::Widget::Entry); |
|
|
113 | $te->move (300, 0, 2); |
|
|
114 | $CFClient::Widget::TOPLEVEL->add ($te); |
|
|
115 | |
|
|
116 | $tw = new CFClient::Widget::Animator; |
|
|
117 | my $lbl1 = new CFClient::Widget::Label |
|
|
118 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
119 | my $lbl2 = new CFClient::Widget::Label |
|
|
120 | 0, 0, 10, $FONTSIZE, "LBL2"; |
|
|
121 | |
|
|
122 | my $vb = new CFClient::Widget::VBox; |
|
|
123 | my $f = new CFClient::Widget::FancyFrame; |
|
|
124 | my $f2 = new CFClient::Widget::FancyFrame; |
|
|
125 | $f->add ($lbl1); |
|
|
126 | $f2->add ($lbl2); |
|
|
127 | $vb->add ($f); |
|
|
128 | $vb->add ($f2, 1); |
|
|
129 | |
|
|
130 | $tw->add ($vb); |
|
|
131 | $tw->w (400); |
|
|
132 | $tw->h (300); |
|
|
133 | $tw->move ($WIDTH - 200, 0); |
|
|
134 | $tw->moveto (0, 0); |
|
|
135 | $CFClient::Widget::TOPLEVEL->add ($tw); |
|
|
136 | |
|
|
137 | # $f->move ($WIDTH - 200, 0); |
|
|
138 | # $CFClient::Widget::TOPLEVEL->add ($f); |
213 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
139 | } |
214 | $MAPWIDGET->focus_in; |
|
|
215 | |
|
|
216 | config_dialog; |
140 | } |
217 | } |
141 | |
218 | |
142 | sub destroy_screen { |
219 | sub destroy_screen { |
|
|
220 | $CFClient::UI::TOPLEVEL->{children} = []; |
143 | remove Glib::Source $SDL_TIMER; |
221 | remove Glib::Source $SDL_TIMER; |
|
|
222 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
223 | undef $refresh_handler; |
144 | undef $SDL_APP; |
224 | undef $SDL_APP; |
145 | undef $SDL_EV; |
225 | undef $SDL_EV; |
146 | SDL::Quit; |
226 | SDL::Quit; |
147 | } |
|
|
148 | |
|
|
149 | sub start_game { |
|
|
150 | $WIDTH = $CFG->{width}; |
|
|
151 | $HEIGHT = $CFG->{height}; |
|
|
152 | $FULLSCREEN = 0; |
|
|
153 | |
|
|
154 | init_screen; |
|
|
155 | |
|
|
156 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
157 | |
|
|
158 | $CONN = new conn |
|
|
159 | host => $CFG->{host}, |
|
|
160 | port => $CFG->{port}, |
|
|
161 | user => $CFG->{user}, |
|
|
162 | pass => $CFG->{password}, |
|
|
163 | mapw => $mapsize, |
|
|
164 | maph => $mapsize, |
|
|
165 | ; |
|
|
166 | |
|
|
167 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
168 | } |
|
|
169 | |
|
|
170 | sub stop_game { |
|
|
171 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
172 | undef $refresh_handler; |
|
|
173 | |
|
|
174 | undef $CONN; |
|
|
175 | destroy_screen; |
|
|
176 | } |
227 | } |
177 | |
228 | |
178 | sub force_refresh { |
229 | sub force_refresh { |
179 | glViewport 0, 0, $WIDTH, $HEIGHT; |
230 | glViewport 0, 0, $WIDTH, $HEIGHT; |
180 | |
231 | |
181 | glMatrixMode GL_PROJECTION; |
232 | glMatrixMode GL_PROJECTION; |
182 | glLoadIdentity; |
233 | glLoadIdentity; |
183 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
234 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
184 | glMatrixMode GL_MODELVIEW; |
235 | glMatrixMode GL_MODELVIEW; |
|
|
236 | glLoadIdentity; |
185 | |
237 | |
186 | glClear GL_COLOR_BUFFER_BIT; |
238 | glClear GL_COLOR_BUFFER_BIT; |
187 | |
239 | |
188 | $CFClient::Widget::TOPLEVEL->draw; |
240 | $CFClient::UI::TOPLEVEL->draw; |
189 | |
241 | |
190 | SDL::GLSwapBuffers; |
242 | SDL::GLSwapBuffers; |
191 | } |
|
|
192 | |
|
|
193 | sub debug { |
|
|
194 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
195 | $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request); |
|
|
196 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0); |
|
|
197 | } |
243 | } |
198 | |
244 | |
199 | my $FPS; |
245 | my $FPS; |
200 | |
246 | |
201 | sub refresh { |
247 | sub refresh { |
202 | $refresh_handler ||= add Glib::Idle sub { |
248 | $refresh_handler ||= add Glib::Idle sub { |
203 | if ($SDL_APP) { |
249 | if ($SDL_APP) { |
204 | my $next_refresh = SDL::GetTicks; |
250 | $NOW = SDL::GetTicks; |
205 | |
251 | |
206 | if ($next_refresh - $last_refresh < $TICKS_PER_FRAME) { |
252 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
207 | SDL::Delay $TICKS_PER_FRAME - ($next_refresh - $last_refresh); |
253 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
208 | $next_refresh = SDL::GetTicks; |
254 | $NOW = SDL::GetTicks; |
209 | } |
255 | } |
210 | |
256 | |
211 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
257 | my $interval = ($NOW - $last_refresh) * 0.001; |
212 | $last_refresh = $next_refresh; |
258 | $last_refresh = $NOW; |
213 | |
259 | |
214 | if ($interval) { |
260 | if ($interval) { |
215 | $FPS ||= 1 / $interval; |
261 | $FPS ||= 1 / $interval; |
216 | $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; |
262 | $FPS = $FPS * 0.9 + (1 / $interval) * 0.1; |
217 | debug sprintf "%5.02f", $FPS; |
263 | debug sprintf "%5.02f", $FPS; |
218 | } |
264 | } |
219 | |
265 | |
220 | force_refresh; |
266 | force_refresh; |
221 | $_->animate ($interval) for grep $_, values %ANIMATE; |
267 | $_->animate ($interval) for grep $_, values %ANIMATE; |
… | |
… | |
257 | }, |
303 | }, |
258 | SDL_KEYDOWN() => sub { |
304 | SDL_KEYDOWN() => sub { |
259 | 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) { |
260 | # alt-enter |
306 | # alt-enter |
261 | $FULLSCREEN = !$FULLSCREEN; |
307 | $FULLSCREEN = !$FULLSCREEN; |
|
|
308 | destroy_screen; |
262 | init_screen; |
309 | init_screen; |
263 | } else { |
310 | } else { |
264 | CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); |
311 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
265 | } |
312 | } |
266 | }, |
313 | }, |
267 | SDL_KEYUP() => sub { |
314 | SDL_KEYUP() => sub { |
268 | CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); |
315 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
269 | }, |
316 | }, |
270 | SDL_MOUSEMOTION() => sub { |
317 | SDL_MOUSEMOTION() => sub { |
271 | CFClient::Widget::feed_sdl_motion_event ($SDL_EV); |
318 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
272 | }, |
319 | }, |
273 | SDL_MOUSEBUTTONDOWN() => sub { |
320 | SDL_MOUSEBUTTONDOWN() => sub { |
274 | CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); |
321 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
275 | }, |
322 | }, |
276 | SDL_MOUSEBUTTONUP() => sub { |
323 | SDL_MOUSEBUTTONUP() => sub { |
277 | CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); |
324 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
278 | }, |
325 | }, |
279 | SDL_ACTIVEEVENT() => sub { |
326 | SDL_ACTIVEEVENT() => sub { |
280 | printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
327 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
281 | }, |
328 | }, |
282 | ); |
329 | ); |
283 | |
330 | |
284 | @conn::ISA = Crossfire::Protocol::; |
331 | @conn::ISA = Crossfire::Protocol::; |
285 | |
332 | |
286 | sub conn::map_update { |
333 | sub conn::map_update { |
287 | my ($self, $dirty) = @_; |
334 | my ($self, $dirty) = @_; |
288 | |
335 | |
289 | refresh; |
336 | $MAPWIDGET->update; |
290 | } |
337 | } |
291 | |
338 | |
292 | sub conn::map_scroll { |
339 | sub conn::map_scroll { |
293 | my ($self, $dx, $dy) = @_; |
340 | my ($self, $dx, $dy) = @_; |
294 | |
341 | |
… | |
… | |
356 | [qw/Password password/], |
403 | [qw/Password password/], |
357 | ); |
404 | ); |
358 | |
405 | |
359 | my $cfg = {}; |
406 | my $cfg = {}; |
360 | |
407 | |
361 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
362 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
363 | |
|
|
364 | $w->add (my $vb = Gtk2::VBox->new); |
408 | $w->add (my $vb = Gtk2::VBox->new); |
365 | $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); |
366 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
410 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
367 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
411 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
368 | $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); |
369 | my $i = 0; |
413 | my $i = 0; |
370 | my $act = 0; |
414 | my $act = 0; |
371 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
415 | for (map { "$_->[0]x$_->[1]" } @SDL_MODES) { |
372 | if ($_ eq $selmode) { $act = $i } |
416 | if ($_ eq $selmode) { $act = $i } |
373 | $cb->append_text ($_); |
417 | $cb->append_text ($_); |
374 | $i++; |
418 | $i++; |
375 | } |
419 | } |
376 | $cb->set_active ($act); |
420 | $cb->set_active ($act); |
… | |
… | |
422 | |
466 | |
423 | ############################################################################# |
467 | ############################################################################# |
424 | |
468 | |
425 | SDL::Init SDL_INIT_EVERYTHING; |
469 | SDL::Init SDL_INIT_EVERYTHING; |
426 | |
470 | |
427 | my $mapwidget = CFClient::Widget::MapWidget->new; |
471 | @SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], |
428 | |
472 | @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; |
429 | $CFClient::Widget::TOPLEVEL->add ($mapwidget); |
|
|
430 | $mapwidget->focus_in; |
|
|
431 | |
473 | |
432 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
474 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
433 | |
475 | |
434 | $CFG ||= { |
476 | $CFG ||= { |
435 | width => 640, |
477 | width => 640, |
436 | height => 480, |
478 | height => 480, |
|
|
479 | fullscreen => 0, |
|
|
480 | sdl_mode => 0, |
437 | mapsize => 100, |
481 | mapsize => 100, |
438 | fullscreen => 0, |
|
|
439 | host => "crossfire.schmorp.de", |
482 | host => "crossfire.schmorp.de", |
440 | port => 13327, |
483 | port => 13327, |
441 | }; |
484 | }; |
442 | |
485 | |
443 | { |
486 | { |
… | |
… | |
447 | CFClient::set_font $fonts[0]; |
490 | CFClient::set_font $fonts[0]; |
448 | } |
491 | } |
449 | |
492 | |
450 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
493 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
451 | |
494 | |
452 | run_config_dialog |
495 | init_screen; |
453 | login => sub { start_game }, |
|
|
454 | logout => sub { stop_game }; |
|
|
455 | |
496 | |
456 | main Gtk2; |
497 | main Gtk2; |
457 | |
498 | |
458 | CFsave_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
499 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
|
|
500 | |