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.71 by root, Tue Apr 11 17:02:36 2006 UTC vs.
Revision 1.81 by root, Wed Apr 12 02:05:46 2006 UTC

15 15
16use Crossfire; 16use Crossfire;
17use Crossfire::Protocol; 17use Crossfire::Protocol;
18 18
19use CFClient; 19use CFClient;
20use CFClient::Widget; 20use CFClient::UI;
21 21
22our $VERSION = '0.1'; 22our $VERSION = '0.1';
23 23
24my $MAX_FPS = 30; 24my $MAX_FPS = 60;
25my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame 25my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame
26 26
27our $FACECACHE; 27our $FACECACHE;
28 28
29our $CFG; 29our $CFG;
30our $CONN; 30our $CONN;
31our $FAST; # fast, low-quality mode
31 32
33our @SDL_MODES;
32our $WIDTH; 34our $WIDTH;
33our $HEIGHT; 35our $HEIGHT;
34our $FULLSCREEN; 36our $FULLSCREEN;
35 37
36our $NOW; 38our $NOW;
49 51
50my $last_refresh; 52my $last_refresh;
51my %ANIMATE; 53my %ANIMATE;
52my $refresh_handler; 54my $refresh_handler;
53 55
54our ($tw, $te); # Test widget #d# 56sub config_dialog {
57 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100,
58 child => (my $vbox = new CFClient::UI::VBox);
59 $vbox->add (new CFClient::UI::Label align => 0, text => "Setup");
60 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
61
62 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode");
63 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
64
65 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
66 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8);
67
68 $mode_slider->connect (changed => sub {
69 my ($self, $value) = @_;
70
71 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
72 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
73 });
74 $mode_slider->emit (changed => $mode_slider->{range}[0]);
75
76 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Host");
77 $table->add (1, 1, my $host = new CFClient::UI::Entry text => $CFG->{host});
78
79 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Port");
80 $table->add (1, 2, my $port = new CFClient::UI::Entry text => $CFG->{port});
81
82 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Username");
83 $table->add (1, 3, my $user = new CFClient::UI::Entry text => $CFG->{user});
84
85 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Password");
86 $table->add (1, 4, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
87
88 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Map Size");
89 $table->add (1, 5, new CFClient::UI::Slider
90 req_w => 100,
91 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
92 connect_changed => sub {
93 my ($self, $value) = @_;
94
95 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
96 },
97 );
98
99 $vbox->add (my $hbox = new CFClient::UI::HBox);
100 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
101 warn "save\n";
102 });
103 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
104 warn "login\n";
105 });
106 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
107 warn "apply\n";
108 });
109
110 $CFClient::UI::TOPLEVEL->add ($dialog);
111}
55 112
56sub init_screen { 113sub init_screen {
57 $SDL_APP = new SDL::App 114 $SDL_APP = new SDL::App
58 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 115 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
59 -title => "Crossfire+ Client", 116 -title => "Crossfire+ Client",
69 -resizeable => 0; 126 -resizeable => 0;
70 127
71 $SDL_EV = new SDL::Event; 128 $SDL_EV = new SDL::Event;
72 $SDL_EV->set_unicode (1); 129 $SDL_EV->set_unicode (1);
73 130
74 $SDL_TIMER = add Glib::Timeout 1000/50, sub { 131 $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub {
75 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 132 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
76 while $SDL_EV->poll; 133 while $SDL_EV->poll;
77 134
78 1 135 1
79 }; 136 };
80 137
81 $last_refresh = SDL::GetTicks; 138 $last_refresh = SDL::GetTicks;
82 139
83 CFClient::gl_init; 140 CFClient::gl_init;
84 141
85 $FONTSIZE = int $HEIGHT / 50; 142 $FONTSIZE = int $HEIGHT / 40;
86 143
87 ############################################################################# 144 #############################################################################
88 145
89 glClearColor 0.45, 0.45, 0.45, 1;
90
91 glEnable GL_TEXTURE_2D;
92 glEnable GL_COLOR_MATERIAL;
93 glShadeModel GL_FLAT;
94 glDisable GL_DEPTH_TEST;
95 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
96
97 #############################################################################
98
99 $DEBUG_STATUS = new CFClient::Widget::Label; 146 $DEBUG_STATUS = new CFClient::UI::Label padding => 0;
100 $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); 147 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
101 148
102 $STATUS_LINE = new CFClient::Widget::Label 149 $STATUS_LINE = new CFClient::UI::Label
150 padding => 0,
103 y => $HEIGHT * 59 / 60 - $FONTSIZE; 151 y => $HEIGHT * 49 / 50 - $FONTSIZE;
104 $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); 152 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
105 153
106 $ALT_ENTER_MESSAGE = new CFClient::Widget::Label 154 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
155 padding => 0,
107 y => $HEIGHT * 59 / 60, 156 y => $HEIGHT * 49 / 50,
108 height => $HEIGHT / 60, 157 height => $HEIGHT / 50,
109 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 158 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
110 $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 159 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
111 160
112 $MAPWIDGET = new CFClient::Widget::MapWidget; 161 $MAPWIDGET = new CFClient::UI::MapWidget;
113 $CFClient::Widget::TOPLEVEL->add ($MAPWIDGET); 162 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
114 $MAPWIDGET->focus_in; 163 $MAPWIDGET->focus_in;
115 164
116 # Test code #d# 165 config_dialog;
117 unless ($tw) { # haha...
118 my $w = new CFClient::Widget::Window
119 w => 300, h => 300,
120 child => (my $frame = new CFClient::Widget::FancyFrame);
121 $CFClient::Widget::TOPLEVEL->add ($w);
122
123 $frame->add (my $vbox = new CFClient::Widget::VBox);
124
125 $vbox->add (new CFClient::Widget::Entry text => "hallo");
126 $vbox->add (new CFClient::Widget::Slider);
127
128 $tw = new CFClient::Widget::Animator x => $WIDTH - 200, w => 600, h => 300;
129 my $lbl1 = new CFClient::Widget::Label text => "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
130 my $lbl2 = new CFClient::Widget::Label text => "LBL2";
131 my $vb = new CFClient::Widget::VBox;
132 my $f = new CFClient::Widget::FancyFrame;
133 my $f2 = new CFClient::Widget::FancyFrame;
134 $f->add ($lbl1);
135 $f2->add ($lbl2);
136 $vb->add ($f);
137 $vb->add ($f2, 1);
138
139 $tw->add ($vb);
140 $tw->moveto (0, 0);
141 $CFClient::Widget::TOPLEVEL->add ($tw);
142
143# $f->move ($WIDTH - 200, 0);
144# $CFClient::Widget::TOPLEVEL->add ($f);
145 }
146} 166}
147 167
148sub destroy_screen { 168sub destroy_screen {
169 $CFClient::UI::TOPLEVEL->{children} = [];
149 remove Glib::Source $SDL_TIMER; 170 remove Glib::Source $SDL_TIMER;
150 undef $SDL_APP; 171 undef $SDL_APP;
151 undef $SDL_EV; 172 undef $SDL_EV;
152 SDL::Quit; 173 SDL::Quit;
153} 174}
186 207
187 glMatrixMode GL_PROJECTION; 208 glMatrixMode GL_PROJECTION;
188 glLoadIdentity; 209 glLoadIdentity;
189 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; 210 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
190 glMatrixMode GL_MODELVIEW; 211 glMatrixMode GL_MODELVIEW;
212 glLoadIdentity;
191 213
192 glClear GL_COLOR_BUFFER_BIT; 214 glClear GL_COLOR_BUFFER_BIT;
193 215
194 $CFClient::Widget::TOPLEVEL->draw; 216 $CFClient::UI::TOPLEVEL->draw;
195 217
196 SDL::GLSwapBuffers; 218 SDL::GLSwapBuffers;
197} 219}
198 220
199sub debug { 221sub debug {
200 $DEBUG_STATUS->set_text ($_[0]); 222 $DEBUG_STATUS->set_text ($_[0]);
201 $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request); 223 my ($w, $h) = $DEBUG_STATUS->size_request;
202 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0); 224 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
203} 225}
204 226
205my $FPS; 227my $FPS;
206 228
207sub refresh { 229sub refresh {
217 my $interval = ($NOW - $last_refresh) * 0.001; 239 my $interval = ($NOW - $last_refresh) * 0.001;
218 $last_refresh = $NOW; 240 $last_refresh = $NOW;
219 241
220 if ($interval) { 242 if ($interval) {
221 $FPS ||= 1 / $interval; 243 $FPS ||= 1 / $interval;
222 $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; 244 $FPS = $FPS * 0.9 + (1 / $interval) * 0.1;
223 debug sprintf "%5.02f", $FPS; 245 debug sprintf "%5.02f", $FPS;
224 } 246 }
225 247
226 force_refresh; 248 force_refresh;
227 $_->animate ($interval) for grep $_, values %ANIMATE; 249 $_->animate ($interval) for grep $_, values %ANIMATE;
263 }, 285 },
264 SDL_KEYDOWN() => sub { 286 SDL_KEYDOWN() => sub {
265 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 287 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
266 # alt-enter 288 # alt-enter
267 $FULLSCREEN = !$FULLSCREEN; 289 $FULLSCREEN = !$FULLSCREEN;
290 destroy_screen;
268 init_screen; 291 init_screen;
269 } else { 292 } else {
270 CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); 293 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
271 } 294 }
272 }, 295 },
273 SDL_KEYUP() => sub { 296 SDL_KEYUP() => sub {
274 CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); 297 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
275 }, 298 },
276 SDL_MOUSEMOTION() => sub { 299 SDL_MOUSEMOTION() => sub {
277 CFClient::Widget::feed_sdl_motion_event ($SDL_EV); 300 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
278 }, 301 },
279 SDL_MOUSEBUTTONDOWN() => sub { 302 SDL_MOUSEBUTTONDOWN() => sub {
280 CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); 303 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
281 }, 304 },
282 SDL_MOUSEBUTTONUP() => sub { 305 SDL_MOUSEBUTTONUP() => sub {
283 CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); 306 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
284 }, 307 },
285 SDL_ACTIVEEVENT() => sub { 308 SDL_ACTIVEEVENT() => sub {
286# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 309# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
287 }, 310 },
288); 311);
362 [qw/Password password/], 385 [qw/Password password/],
363 ); 386 );
364 387
365 my $cfg = {}; 388 my $cfg = {};
366 389
367 my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE);
368 my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a;
369
370 $w->add (my $vb = Gtk2::VBox->new); 390 $w->add (my $vb = Gtk2::VBox->new);
371 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); 391 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0);
372 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; 392 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height};
373 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); 393 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1);
374 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); 394 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1);
375 my $i = 0; 395 my $i = 0;
376 my $act = 0; 396 my $act = 0;
377 for (map { "$_->[0]x$_->[1]" } reverse @modes) { 397 for (map { "$_->[0]x$_->[1]" } @SDL_MODES) {
378 if ($_ eq $selmode) { $act = $i } 398 if ($_ eq $selmode) { $act = $i }
379 $cb->append_text ($_); 399 $cb->append_text ($_);
380 $i++; 400 $i++;
381 } 401 }
382 $cb->set_active ($act); 402 $cb->set_active ($act);
428 448
429############################################################################# 449#############################################################################
430 450
431SDL::Init SDL_INIT_EVERYTHING; 451SDL::Init SDL_INIT_EVERYTHING;
432 452
453@SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)],
454 @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE };
455
433CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 456CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
434 457
435$CFG ||= { 458$CFG ||= {
436 width => 640, 459 width => 640,
437 height => 480, 460 height => 480,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines