ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.41 by elmex, Sun Apr 9 01:21:11 2006 UTC vs.
Revision 1.50 by root, Sun Apr 9 21:05:50 2006 UTC

44our $ALT_ENTER_MESSAGE; 44our $ALT_ENTER_MESSAGE;
45 45
46our $TOPLEVEL; 46our $TOPLEVEL;
47 47
48our $tw; # Test widget #d# 48our $tw; # Test widget #d#
49
50my $last_refresh;
51my %ANIMATE;
52my $refresh_handler;
49 53
50sub init_screen { 54sub init_screen {
51 $SDL_APP = new SDL::App 55 $SDL_APP = new SDL::App
52 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 56 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
53 -title => "Crossfire+ Client", 57 -title => "Crossfire+ Client",
59 -blue_size => 8, 63 -blue_size => 8,
60 -double_buffer => 1, 64 -double_buffer => 1,
61 -fullscreen => $FULLSCREEN, 65 -fullscreen => $FULLSCREEN,
62 -resizeable => 0; 66 -resizeable => 0;
63 67
68 $last_refresh = SDL::GetTicks;
69
64 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 70 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
65 71
66 $GL_EXT{GL_ARB_texture_non_power_of_two} 72 $GL_EXT{GL_ARB_texture_non_power_of_two}
67 or warn "WARNING: non-power-of-two opengl extension required"; 73 or warn "WARNING: non-power-of-two opengl extension required";
68 74
73 "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 79 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
74 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); 80 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
75 $TOPLEVEL->add ($ALT_ENTER_MESSAGE); 81 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
76 82
77 # Test code #d# 83 # Test code #d#
78 { 84 unless ($tw) { # haha...
85 $tw = new Crossfire::Client::Widget::Animator;
86 my $lbl1 = new Crossfire::Client::Widget::Label
87 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
88 my $lbl2 = new Crossfire::Client::Widget::Label
89 0, 0, 10, $FONTSIZE, "LBL2";
90
91 my $vb = new Crossfire::Client::Widget::VBox;
79 my $frm = new Crossfire::Client::Widget::Frame; 92 my $f = new Crossfire::Client::Widget::FancyFrame;
80 $tw = new Crossfire::Client::Widget::Window; 93 my $f2 = new Crossfire::Client::Widget::FancyFrame;
81 $frm->add (my $te = new Crossfire::Client::Widget::TextEntry 0, 0, 10, $FONTSIZE, "Foo in the garden!"); 94 $f->add ($lbl1);
95 $f2->add ($lbl2);
96 $vb->add ($f);
97 $vb->add ($f2, 1);
98
82 $tw->add ($frm); 99 $tw->add ($vb);
83 100 $tw->w (400);
101 $tw->h (300);
102 $tw->move ($WIDTH - 200, 0);
84 $tw->move (0, $HEIGHT - 120); 103 $tw->moveto (0, 0);
85 $TOPLEVEL->add ($tw); 104 $TOPLEVEL->add ($tw);
86# $te->focus_in; 105
106# $f->move ($WIDTH - 200, 0);
107# $TOPLEVEL->add ($f);
87 } 108 }
88 109
89 glClearColor 0, 0, 0, 0; 110 glClearColor 0, 0, 0, 0;
90 111
91 glEnable GL_TEXTURE_2D; 112 glEnable GL_TEXTURE_2D;
96 117
97 $_->() for @GL_INIT; 118 $_->() for @GL_INIT;
98} 119}
99 120
100sub start_game { 121sub start_game {
101 $SDL_TIMER = add Glib::Timeout 1000/100, sub { 122 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
102 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 123 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
103 while $SDL_EV->poll; 124 while $SDL_EV->poll;
104 125
105 1 126 1
106 }; 127 };
108 $WIDTH = $CFG->{width}; 129 $WIDTH = $CFG->{width};
109 $HEIGHT = $CFG->{height}; 130 $HEIGHT = $CFG->{height};
110 $FULLSCREEN = 0; 131 $FULLSCREEN = 0;
111 132
112 init_screen; 133 init_screen;
134
135 my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
113 136
114 $CONN = new conn 137 $CONN = new conn
115 host => $CFG->{host}, 138 host => $CFG->{host},
116 port => $CFG->{port}, 139 port => $CFG->{port},
117 user => $CFG->{user}, 140 user => $CFG->{user},
118 pass => $CFG->{password}, 141 pass => $CFG->{password},
119 mapw => 50, 142 mapw => $mapsize,
120 maph => 37, 143 maph => $mapsize,
121 ; 144 ;
145
146 Crossfire::Client::lowdelay fileno $CONN->{fh};
122} 147}
123 148
124sub stop_game { 149sub stop_game {
125 remove Glib::Source $SDL_TIMER; 150 remove Glib::Source $SDL_TIMER;
151 remove Glib::Source $refresh_handler;
152 undef $refresh_handler;
126 153
127 undef $SDL_APP; 154 undef $SDL_APP;
155 undef $CONN;
128 SDL::Quit; 156 SDL::Quit;
129} 157}
130 158
131 159
132sub force_refresh { 160sub force_refresh {
133 glViewport 0, 0, $WIDTH, $HEIGHT; 161 glViewport 0, 0, $WIDTH, $HEIGHT;
134 162
135 glMatrixMode GL_PROJECTION; 163 glMatrixMode GL_PROJECTION;
136 glLoadIdentity; 164 glLoadIdentity;
137 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; 165 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000;
138 glMatrixMode GL_MODELVIEW; 166 glMatrixMode GL_MODELVIEW;
139 167
140 glClear GL_COLOR_BUFFER_BIT; 168 glClear GL_COLOR_BUFFER_BIT;
141 169
142 $TOPLEVEL->draw; 170 $TOPLEVEL->draw;
143 171
144 SDL::GLSwapBuffers; 172 SDL::GLSwapBuffers;
145} 173}
146
147my $refresh_handler;
148 174
149sub refresh { 175sub refresh {
150 $refresh_handler ||= add Glib::Idle sub { 176 $refresh_handler ||= add Glib::Idle sub {
177 return unless $SDL_APP;
178
179 my $next_refresh = SDL::GetTicks;
180 my $interval = ($next_refresh - $last_refresh) * 0.001;
181 $last_refresh = $next_refresh;
182
151 force_refresh; 183 force_refresh;
184 $_->animate ($interval) for grep $_, values %ANIMATE;
185
186 if (%ANIMATE) {
187 1
188 } else {
152 undef $refresh_handler; 189 undef $refresh_handler;
190 0
153 0 191 }
154 }; 192 };
193}
194
195sub animation_start {
196 my ($widget) = @_;
197 $ANIMATE{$widget} = $widget;
198 Scalar::Util::weaken $ANIMATE{$widget};
199
200 refresh;
201}
202
203sub animation_stop {
204 my ($widget) = @_;
205 delete $ANIMATE{$widget};
155} 206}
156 207
157%SDL_CB = ( 208%SDL_CB = (
158 SDL_QUIT() => sub { 209 SDL_QUIT() => sub {
159 main_quit Gtk2; 210 main_quit Gtk2;
198} 249}
199 250
200sub conn::map_scroll { 251sub conn::map_scroll {
201 my ($self, $dx, $dy) = @_; 252 my ($self, $dx, $dy) = @_;
202 253
203 refresh; 254# refresh;
204} 255}
205 256
206sub conn::map_clear { 257sub conn::map_clear {
207 my ($self) = @_; 258 my ($self) = @_;
208 259
209 refresh; 260# refresh;
210} 261}
211 262
212sub conn::face_find { 263sub conn::face_find {
213 my ($self, $face) = @_; 264 my ($self, $face) = @_;
214 265
240 } 291 }
241 $ent->set_text ($value); 292 $ent->set_text ($value);
242 $ent->signal_connect (changed => sub { 293 $ent->signal_connect (changed => sub {
243 my ($ent) = @_; 294 my ($ent) = @_;
244 $cfg->{$key} = $ent->get_text; 295 $cfg->{$key} = $ent->get_text;
296 # TODO: Mapsize should be a slider in the game gui
297 if ($key eq 'mapsize' and $cfg->{$key} > 100) {
298 $cfg->{$key} = 100;
299 } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
300 $cfg->{$key} = 50;
301 }
245 }); 302 });
246} 303}
247 304
248sub run_config_dialog { 305sub run_config_dialog {
249 my (%events) = @_; 306 my (%events) = @_;
251 my $w = Gtk2::Window->new; 308 my $w = Gtk2::Window->new;
252 309
253 my @cfg = ( 310 my @cfg = (
254 [qw/Host host/], 311 [qw/Host host/],
255 [qw/Port port/], 312 [qw/Port port/],
313 [qw/Mapsize% mapsize/],
256 [qw/Username user/], 314 [qw/Username user/],
257 [qw/Password password/], 315 [qw/Password password/],
258 ); 316 );
259 317
260 my $cfg = {}; 318 my $cfg = {};
307 my $cb = $events{login} || sub {}; 365 my $cb = $events{login} || sub {};
308 $cb->($::CFG->{user}, $::CFG->{password}); 366 $cb->($::CFG->{user}, $::CFG->{password});
309 }); 367 });
310 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); 368 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
311 $cb->signal_connect (clicked => sub { 369 $cb->signal_connect (clicked => sub {
312 my $cb = $events{login} || sub {}; 370 my $cb = $events{logout} || sub {};
313 $cb->(); 371 $cb->();
314 }); 372 });
315 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); 373 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
316 $cb->signal_connect (clicked => sub { $w->destroy }); 374 $cb->signal_connect (clicked => sub { $w->destroy });
317 375
335Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 393Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
336 394
337$CFG ||= { 395$CFG ||= {
338 width => 640, 396 width => 640,
339 height => 480, 397 height => 480,
398 mapsize => 100,
340 fullscreen => 0, 399 fullscreen => 0,
341 host => "crossfire.schmorp.de", 400 host => "crossfire.schmorp.de",
342 port => 13327, 401 port => 13327,
343}; 402};
344 403
345Crossfire::Client::add_font Crossfire::Client::find_rcfile "uifont.ttf"; 404Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf";
346Crossfire::Client::set_font "[Bitstream Vera Sans Mono]";
347 405
348$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 406$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
349 407
350run_config_dialog 408run_config_dialog
351 login => sub { start_game }, 409 login => sub { start_game },

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines