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