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.34 by elmex, Sat Apr 8 18:18:09 2006 UTC vs.
Revision 1.50 by root, Sun Apr 9 21:05:50 2006 UTC

30 30
31our $WIDTH; 31our $WIDTH;
32our $HEIGHT; 32our $HEIGHT;
33our $FULLSCREEN; 33our $FULLSCREEN;
34 34
35our $UIFONT; 35our $FONTSIZE;
36 36
37our $SDL_TIMER; 37our $SDL_TIMER;
38our $SDL_APP; 38our $SDL_APP;
39our $SDL_EV = new SDL::Event; 39our $SDL_EV = new SDL::Event;
40our %SDL_CB; 40our %SDL_CB;
41 41
42our @GL_INIT; # hooks called on every gl init 42our @GL_INIT; # hooks called on every gl init
43 43
44our $ALT_ENTER_MESSAGE; 44our $ALT_ENTER_MESSAGE;
45 45
46our $TOPLEVEL;
47
46our $tw; # Test widget #d# 48our $tw; # Test widget #d#
49
50my $last_refresh;
51my %ANIMATE;
52my $refresh_handler;
47 53
48sub init_screen { 54sub init_screen {
49 $SDL_APP = new SDL::App 55 $SDL_APP = new SDL::App
50 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 56 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
51 -title => "Crossfire+ Client", 57 -title => "Crossfire+ Client",
57 -blue_size => 8, 63 -blue_size => 8,
58 -double_buffer => 1, 64 -double_buffer => 1,
59 -fullscreen => $FULLSCREEN, 65 -fullscreen => $FULLSCREEN,
60 -resizeable => 0; 66 -resizeable => 0;
61 67
68 $last_refresh = SDL::GetTicks;
69
62 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 70 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
63 71
64 $GL_EXT{GL_ARB_texture_non_power_of_two} 72 $GL_EXT{GL_ARB_texture_non_power_of_two}
65 or warn "WARNING: non-power-of-two opengl extension required"; 73 or warn "WARNING: non-power-of-two opengl extension required";
66 74
67 $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 75 $FONTSIZE = int $HEIGHT / 50;
68 or die "TTFOpenFont: $!";
69 76
70 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; 77 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
78 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE,
79 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
71 $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]);
72 $ALT_ENTER_MESSAGE->activate; 81 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
73 82
74 # Test code #d# 83 # Test code #d#
84 unless ($tw) { # haha...
75 $tw = new Crossfire::Client::Widget::Window; 85 $tw = new Crossfire::Client::Widget::Animator;
76 $tw->add (my $lbl = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!"); 86 my $lbl1 = new Crossfire::Client::Widget::Label
77# $tw = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!"; 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";
78 90
79 $tw->move (0, $HEIGHT - 50); 91 my $vb = new Crossfire::Client::Widget::VBox;
80 $tw->activate; 92 my $f = new Crossfire::Client::Widget::FancyFrame;
81 # Test code end #d# 93 my $f2 = new Crossfire::Client::Widget::FancyFrame;
94 $f->add ($lbl1);
95 $f2->add ($lbl2);
96 $vb->add ($f);
97 $vb->add ($f2, 1);
98
99 $tw->add ($vb);
100 $tw->w (400);
101 $tw->h (300);
102 $tw->move ($WIDTH - 200, 0);
103 $tw->moveto (0, 0);
104 $TOPLEVEL->add ($tw);
105
106# $f->move ($WIDTH - 200, 0);
107# $TOPLEVEL->add ($f);
108 }
82 109
83 glClearColor 0, 0, 0, 0; 110 glClearColor 0, 0, 0, 0;
84 111
85 glEnable GL_TEXTURE_2D; 112 glEnable GL_TEXTURE_2D;
113 glEnable GL_COLOR_MATERIAL;
86 glShadeModel GL_FLAT; 114 glShadeModel GL_FLAT;
87 glDisable GL_DEPTH_TEST; 115 glDisable GL_DEPTH_TEST;
88 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 116 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
89 117
90 glMatrixMode GL_PROJECTION;
91 glLoadIdentity;
92 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100;
93
94 glMatrixMode GL_MODELVIEW;
95
96 $_->() for @GL_INIT; 118 $_->() for @GL_INIT;
97} 119}
98 120
99sub start_game { 121sub start_game {
100 $SDL_TIMER = add Glib::Timeout 1000/100, sub { 122 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
101 ($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 })->()
102 while $SDL_EV->poll; 124 while $SDL_EV->poll;
103 125
104 1 126 1
105 }; 127 };
107 $WIDTH = $CFG->{width}; 129 $WIDTH = $CFG->{width};
108 $HEIGHT = $CFG->{height}; 130 $HEIGHT = $CFG->{height};
109 $FULLSCREEN = 0; 131 $FULLSCREEN = 0;
110 132
111 init_screen; 133 init_screen;
134
135 my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
112 136
113 $CONN = new conn 137 $CONN = new conn
114 host => $CFG->{host}, 138 host => $CFG->{host},
115 port => $CFG->{port}, 139 port => $CFG->{port},
116 user => $CFG->{user}, 140 user => $CFG->{user},
117 pass => $CFG->{password}; 141 pass => $CFG->{password},
142 mapw => $mapsize,
143 maph => $mapsize,
144 ;
145
146 Crossfire::Client::lowdelay fileno $CONN->{fh};
118} 147}
119 148
120sub stop_game { 149sub stop_game {
121 remove Glib::Source $SDL_TIMER; 150 remove Glib::Source $SDL_TIMER;
151 remove Glib::Source $refresh_handler;
152 undef $refresh_handler;
122 153
123 undef $SDL_APP; 154 undef $SDL_APP;
155 undef $CONN;
124 SDL::Quit; 156 SDL::Quit;
125} 157}
126 158
127 159
128sub force_refresh { 160sub force_refresh {
129 glViewport 0, 0, $WIDTH, $HEIGHT; 161 glViewport 0, 0, $WIDTH, $HEIGHT;
162
163 glMatrixMode GL_PROJECTION;
164 glLoadIdentity;
165 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000;
166 glMatrixMode GL_MODELVIEW;
167
130 glClear GL_COLOR_BUFFER_BIT; 168 glClear GL_COLOR_BUFFER_BIT;
131 169
132 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; 170 $TOPLEVEL->draw;
133 171
134 SDL::GLSwapBuffers; 172 SDL::GLSwapBuffers;
135} 173}
136
137my $refresh_handler;
138 174
139sub refresh { 175sub refresh {
140 $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
141 force_refresh; 183 force_refresh;
184 $_->animate ($interval) for grep $_, values %ANIMATE;
185
186 if (%ANIMATE) {
187 1
188 } else {
142 undef $refresh_handler; 189 undef $refresh_handler;
190 0
143 0 191 }
144 }; 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};
145} 206}
146 207
147%SDL_CB = ( 208%SDL_CB = (
148 SDL_QUIT() => sub { 209 SDL_QUIT() => sub {
149 main_quit Gtk2; 210 main_quit Gtk2;
188} 249}
189 250
190sub conn::map_scroll { 251sub conn::map_scroll {
191 my ($self, $dx, $dy) = @_; 252 my ($self, $dx, $dy) = @_;
192 253
193 refresh; 254# refresh;
194} 255}
195 256
196sub conn::map_clear { 257sub conn::map_clear {
197 my ($self) = @_; 258 my ($self) = @_;
198 259
199 refresh; 260# refresh;
200} 261}
201 262
202sub conn::face_find { 263sub conn::face_find {
203 my ($self, $face) = @_; 264 my ($self, $face) = @_;
204 265
230 } 291 }
231 $ent->set_text ($value); 292 $ent->set_text ($value);
232 $ent->signal_connect (changed => sub { 293 $ent->signal_connect (changed => sub {
233 my ($ent) = @_; 294 my ($ent) = @_;
234 $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 }
235 }); 302 });
236} 303}
237 304
238sub run_config_dialog { 305sub run_config_dialog {
239 my (%events) = @_; 306 my (%events) = @_;
241 my $w = Gtk2::Window->new; 308 my $w = Gtk2::Window->new;
242 309
243 my @cfg = ( 310 my @cfg = (
244 [qw/Host host/], 311 [qw/Host host/],
245 [qw/Port port/], 312 [qw/Port port/],
313 [qw/Mapsize% mapsize/],
246 [qw/Username user/], 314 [qw/Username user/],
247 [qw/Password password/], 315 [qw/Password password/],
248 ); 316 );
249 317
250 my $cfg = {}; 318 my $cfg = {};
297 my $cb = $events{login} || sub {}; 365 my $cb = $events{login} || sub {};
298 $cb->($::CFG->{user}, $::CFG->{password}); 366 $cb->($::CFG->{user}, $::CFG->{password});
299 }); 367 });
300 $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);
301 $cb->signal_connect (clicked => sub { 369 $cb->signal_connect (clicked => sub {
302 my $cb = $events{login} || sub {}; 370 my $cb = $events{logout} || sub {};
303 $cb->(); 371 $cb->();
304 }); 372 });
305 $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);
306 $cb->signal_connect (clicked => sub { $w->destroy }); 374 $cb->signal_connect (clicked => sub { $w->destroy });
307 375
312 380
313 381
314############################################################################# 382#############################################################################
315 383
316SDL::Init SDL_INIT_EVERYTHING; 384SDL::Init SDL_INIT_EVERYTHING;
317SDL::TTFInit; 385
386$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
318 387
319my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 388my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
320 389
321$mapwidget->activate; 390$TOPLEVEL->add ($mapwidget);
322$mapwidget->focus_in; 391$mapwidget->focus_in;
323 392
324Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 393Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
325 394
326$CFG ||= { 395$CFG ||= {
327 width => 640, 396 width => 640,
328 height => 480, 397 height => 480,
398 mapsize => 100,
329 fullscreen => 0, 399 fullscreen => 0,
330 host => "crossfire.schmorp.de", 400 host => "crossfire.schmorp.de",
331 port => 13327, 401 port => 13327,
332}; 402};
333 403
404Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf";
405
334$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 406$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
335 407
336run_config_dialog 408run_config_dialog
337 login => sub { start_game }, 409 login => sub { start_game },
338 logout => sub { stop_game }; 410 logout => sub { stop_game };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines