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.31 by elmex, Sat Apr 8 16:34:47 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
46our $TOPLEVEL;
47
48our $tw; # Test widget #d#
49
50my $last_refresh;
51my %ANIMATE;
52my $refresh_handler;
45 53
46sub init_screen { 54sub init_screen {
47 $SDL_APP = new SDL::App 55 $SDL_APP = new SDL::App
48 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 56 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
49 -title => "Crossfire+ Client", 57 -title => "Crossfire+ Client",
55 -blue_size => 8, 63 -blue_size => 8,
56 -double_buffer => 1, 64 -double_buffer => 1,
57 -fullscreen => $FULLSCREEN, 65 -fullscreen => $FULLSCREEN,
58 -resizeable => 0; 66 -resizeable => 0;
59 67
68 $last_refresh = SDL::GetTicks;
69
60 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 70 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
61 71
62 $GL_EXT{GL_ARB_texture_non_power_of_two} 72 $GL_EXT{GL_ARB_texture_non_power_of_two}
63 or warn "WARNING: non-power-of-two opengl extension required"; 73 or warn "WARNING: non-power-of-two opengl extension required";
64 74
65 $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 75 $FONTSIZE = int $HEIGHT / 50;
66 or die "TTFOpenFont: $!";
67 76
68 $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";
69 $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]);
70 $ALT_ENTER_MESSAGE->activate; 81 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
82
83 # Test code #d#
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;
92 my $f = new Crossfire::Client::Widget::FancyFrame;
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 }
71 109
72 glClearColor 0, 0, 0, 0; 110 glClearColor 0, 0, 0, 0;
73 111
74 glEnable GL_TEXTURE_2D; 112 glEnable GL_TEXTURE_2D;
113 glEnable GL_COLOR_MATERIAL;
75 glShadeModel GL_FLAT; 114 glShadeModel GL_FLAT;
76 glDisable GL_DEPTH_TEST; 115 glDisable GL_DEPTH_TEST;
77 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 116 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
78 117
79 glMatrixMode GL_PROJECTION;
80 glLoadIdentity;
81 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100;
82
83 glMatrixMode GL_MODELVIEW;
84
85 $_->() for @GL_INIT; 118 $_->() for @GL_INIT;
86} 119}
87 120
88sub start_game { 121sub start_game {
89 $SDL_TIMER = add Glib::Timeout 1000/100, sub { 122 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
90 ($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 })->()
91 while $SDL_EV->poll; 124 while $SDL_EV->poll;
92 125
93 1 126 1
94 }; 127 };
96 $WIDTH = $CFG->{width}; 129 $WIDTH = $CFG->{width};
97 $HEIGHT = $CFG->{height}; 130 $HEIGHT = $CFG->{height};
98 $FULLSCREEN = 0; 131 $FULLSCREEN = 0;
99 132
100 init_screen; 133 init_screen;
134
135 my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
101 136
102 $CONN = new conn 137 $CONN = new conn
103 host => $CFG->{host}, 138 host => $CFG->{host},
104 port => $CFG->{port}, 139 port => $CFG->{port},
105 user => $CFG->{user}, 140 user => $CFG->{user},
106 pass => $CFG->{password}; 141 pass => $CFG->{password},
142 mapw => $mapsize,
143 maph => $mapsize,
144 ;
145
146 Crossfire::Client::lowdelay fileno $CONN->{fh};
107} 147}
108 148
109sub stop_game { 149sub stop_game {
110 remove Glib::Source $SDL_TIMER; 150 remove Glib::Source $SDL_TIMER;
151 remove Glib::Source $refresh_handler;
152 undef $refresh_handler;
111 153
112 undef $SDL_APP; 154 undef $SDL_APP;
155 undef $CONN;
113 SDL::Quit; 156 SDL::Quit;
114} 157}
115 158
116 159
117sub force_refresh { 160sub force_refresh {
118 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
119 glClear GL_COLOR_BUFFER_BIT; 168 glClear GL_COLOR_BUFFER_BIT;
120 169
121 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; 170 $TOPLEVEL->draw;
122 171
123 SDL::GLSwapBuffers; 172 SDL::GLSwapBuffers;
124} 173}
125
126my $refresh_handler;
127 174
128sub refresh { 175sub refresh {
129 $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
130 force_refresh; 183 force_refresh;
184 $_->animate ($interval) for grep $_, values %ANIMATE;
185
186 if (%ANIMATE) {
187 1
188 } else {
131 undef $refresh_handler; 189 undef $refresh_handler;
190 0
132 0 191 }
133 }; 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};
134} 206}
135 207
136%SDL_CB = ( 208%SDL_CB = (
137 SDL_QUIT() => sub { 209 SDL_QUIT() => sub {
138 main_quit Gtk2; 210 main_quit Gtk2;
177} 249}
178 250
179sub conn::map_scroll { 251sub conn::map_scroll {
180 my ($self, $dx, $dy) = @_; 252 my ($self, $dx, $dy) = @_;
181 253
182 refresh; 254# refresh;
183} 255}
184 256
185sub conn::map_clear { 257sub conn::map_clear {
186 my ($self) = @_; 258 my ($self) = @_;
187 259
188 refresh; 260# refresh;
189} 261}
190 262
191sub conn::face_find { 263sub conn::face_find {
192 my ($self, $face) = @_; 264 my ($self, $face) = @_;
193 265
198 my ($self, $face) = @_; 270 my ($self, $face) = @_;
199 271
200 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 272 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
201 273
202 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; 274 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
275}
276
277sub conn::query {
278 my ($self, $flags, $prompt) = @_;
279
280 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
203} 281}
204 282
205sub gtk_add_cfg_field { 283sub gtk_add_cfg_field {
206 my ($tbl, $cfg, $klbl, $key, $value) = @_; 284 my ($tbl, $cfg, $klbl, $key, $value) = @_;
207 my $i = $cfg->{_i}++; 285 my $i = $cfg->{_i}++;
213 } 291 }
214 $ent->set_text ($value); 292 $ent->set_text ($value);
215 $ent->signal_connect (changed => sub { 293 $ent->signal_connect (changed => sub {
216 my ($ent) = @_; 294 my ($ent) = @_;
217 $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 }
218 }); 302 });
219} 303}
220 304
221sub run_config_dialog { 305sub run_config_dialog {
222 my (%events) = @_; 306 my (%events) = @_;
224 my $w = Gtk2::Window->new; 308 my $w = Gtk2::Window->new;
225 309
226 my @cfg = ( 310 my @cfg = (
227 [qw/Host host/], 311 [qw/Host host/],
228 [qw/Port port/], 312 [qw/Port port/],
313 [qw/Mapsize% mapsize/],
229 [qw/Username user/], 314 [qw/Username user/],
230 [qw/Password password/], 315 [qw/Password password/],
231 ); 316 );
232 317
233 my $cfg = {}; 318 my $cfg = {};
280 my $cb = $events{login} || sub {}; 365 my $cb = $events{login} || sub {};
281 $cb->($::CFG->{user}, $::CFG->{password}); 366 $cb->($::CFG->{user}, $::CFG->{password});
282 }); 367 });
283 $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);
284 $cb->signal_connect (clicked => sub { 369 $cb->signal_connect (clicked => sub {
285 my $cb = $events{login} || sub {}; 370 my $cb = $events{logout} || sub {};
286 $cb->(); 371 $cb->();
287 }); 372 });
288 $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);
289 $cb->signal_connect (clicked => sub { $w->destroy }); 374 $cb->signal_connect (clicked => sub { $w->destroy });
290 375
295 380
296 381
297############################################################################# 382#############################################################################
298 383
299SDL::Init SDL_INIT_EVERYTHING; 384SDL::Init SDL_INIT_EVERYTHING;
300SDL::TTFInit; 385
386$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
301 387
302my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 388my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
303 389
304$mapwidget->activate; 390$TOPLEVEL->add ($mapwidget);
305$mapwidget->focus_in; 391$mapwidget->focus_in;
306 392
307Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 393Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
308 394
309$CFG ||= { 395$CFG ||= {
310 width => 640, 396 width => 640,
311 height => 480, 397 height => 480,
398 mapsize => 100,
312 fullscreen => 0, 399 fullscreen => 0,
313 host => "crossfire.schmorp.de", 400 host => "crossfire.schmorp.de",
314 port => 13327, 401 port => 13327,
315}; 402};
316 403
404Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf";
405
317$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 406$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
318 407
319run_config_dialog 408run_config_dialog
320 login => sub { start_game }, 409 login => sub { start_game },
321 logout => sub { stop_game }; 410 logout => sub { stop_game };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines