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.76 by root, Tue Apr 11 22:14:14 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;
31 31
32our @SDL_MODES;
32our $WIDTH; 33our $WIDTH;
33our $HEIGHT; 34our $HEIGHT;
34our $FULLSCREEN; 35our $FULLSCREEN;
35 36
36our $NOW; 37our $NOW;
69 -resizeable => 0; 70 -resizeable => 0;
70 71
71 $SDL_EV = new SDL::Event; 72 $SDL_EV = new SDL::Event;
72 $SDL_EV->set_unicode (1); 73 $SDL_EV->set_unicode (1);
73 74
74 $SDL_TIMER = add Glib::Timeout 1000/50, sub { 75 $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub {
75 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 76 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
76 while $SDL_EV->poll; 77 while $SDL_EV->poll;
77 78
78 1 79 1
79 }; 80 };
94 glDisable GL_DEPTH_TEST; 95 glDisable GL_DEPTH_TEST;
95 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 96 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
96 97
97 ############################################################################# 98 #############################################################################
98 99
99 $DEBUG_STATUS = new CFClient::Widget::Label; 100 $DEBUG_STATUS = new CFClient::UI::Label;
100 $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); 101 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
101 102
102 $STATUS_LINE = new CFClient::Widget::Label 103 $STATUS_LINE = new CFClient::UI::Label
103 y => $HEIGHT * 59 / 60 - $FONTSIZE; 104 y => $HEIGHT * 59 / 60 - $FONTSIZE;
104 $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); 105 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
105 106
106 $ALT_ENTER_MESSAGE = new CFClient::Widget::Label 107 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
107 y => $HEIGHT * 59 / 60, 108 y => $HEIGHT * 59 / 60,
108 height => $HEIGHT / 60, 109 height => $HEIGHT / 60,
109 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 110 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
110 $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 111 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
111 112
112 $MAPWIDGET = new CFClient::Widget::MapWidget; 113 $MAPWIDGET = new CFClient::UI::MapWidget;
113 $CFClient::Widget::TOPLEVEL->add ($MAPWIDGET); 114 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
114 $MAPWIDGET->focus_in; 115 $MAPWIDGET->focus_in;
115
116 # Test code #d#
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} 116}
147 117
148sub destroy_screen { 118sub destroy_screen {
149 remove Glib::Source $SDL_TIMER; 119 remove Glib::Source $SDL_TIMER;
150 undef $SDL_APP; 120 undef $SDL_APP;
151 undef $SDL_EV; 121 undef $SDL_EV;
152 SDL::Quit; 122 SDL::Quit;
153} 123}
154 124
125sub config_dialog {
126 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100,
127 child => (my $vbox = new CFClient::UI::VBox);
128 $vbox->add (new CFClient::UI::Label align => 0, text => "Setup");
129 $vbox->add (my $table = new CFClient::UI::Table expand => 1);
130
131 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode");
132 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
133
134 $hbox->add (my $mode_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
135 $hbox->add (my $mode_label = new CFClient::UI::Label);
136
137 $mode_slider->connect (changed => sub {
138 my (undef, $value) = @_;
139
140 $CFG->{sdl_mode} = $value = int $value + 0.5;
141 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
142 });
143 $mode_slider->emit (changed => $mode_slider->{range}[0]);
144
145 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Host");
146 $table->add (1, 1, my $host = new CFClient::UI::Entry text => $CFG->{host});
147
148 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Port");
149 $table->add (1, 2, my $port = new CFClient::UI::Entry text => $CFG->{port});
150
151 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Username");
152 $table->add (1, 3, my $user = new CFClient::UI::Entry text => $CFG->{user});
153
154 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Password");
155 $table->add (1, 4, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
156
157 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Map Size");
158 $table->add (1, 5, my $mapsize_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{mapsize}, 10, 100 + 1, 1]);
159
160 $CFClient::UI::TOPLEVEL->add ($dialog);
161}
162
155sub start_game { 163sub start_game {
156 $WIDTH = $CFG->{width}; 164 $WIDTH = $CFG->{width};
157 $HEIGHT = $CFG->{height}; 165 $HEIGHT = $CFG->{height};
158 $FULLSCREEN = 0; 166 $FULLSCREEN = 0;
159 167
160 init_screen; 168 init_screen;
169
170 config_dialog;
161 171
162 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 172 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
163 173
164 $CONN = new conn 174 $CONN = new conn
165 host => $CFG->{host}, 175 host => $CFG->{host},
186 196
187 glMatrixMode GL_PROJECTION; 197 glMatrixMode GL_PROJECTION;
188 glLoadIdentity; 198 glLoadIdentity;
189 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; 199 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
190 glMatrixMode GL_MODELVIEW; 200 glMatrixMode GL_MODELVIEW;
201 glLoadIdentity;
191 202
192 glClear GL_COLOR_BUFFER_BIT; 203 glClear GL_COLOR_BUFFER_BIT;
193 204
194 $CFClient::Widget::TOPLEVEL->draw; 205 $CFClient::UI::TOPLEVEL->draw;
195 206
196 SDL::GLSwapBuffers; 207 SDL::GLSwapBuffers;
197} 208}
198 209
199sub debug { 210sub debug {
200 $DEBUG_STATUS->set_text ($_[0]); 211 $DEBUG_STATUS->set_text ($_[0]);
201 $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request); 212 my ($w, $h) = $DEBUG_STATUS->size_request;
202 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0); 213 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
203} 214}
204 215
205my $FPS; 216my $FPS;
206 217
207sub refresh { 218sub refresh {
265 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 276 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
266 # alt-enter 277 # alt-enter
267 $FULLSCREEN = !$FULLSCREEN; 278 $FULLSCREEN = !$FULLSCREEN;
268 init_screen; 279 init_screen;
269 } else { 280 } else {
270 CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); 281 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
271 } 282 }
272 }, 283 },
273 SDL_KEYUP() => sub { 284 SDL_KEYUP() => sub {
274 CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); 285 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
275 }, 286 },
276 SDL_MOUSEMOTION() => sub { 287 SDL_MOUSEMOTION() => sub {
277 CFClient::Widget::feed_sdl_motion_event ($SDL_EV); 288 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
278 }, 289 },
279 SDL_MOUSEBUTTONDOWN() => sub { 290 SDL_MOUSEBUTTONDOWN() => sub {
280 CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); 291 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
281 }, 292 },
282 SDL_MOUSEBUTTONUP() => sub { 293 SDL_MOUSEBUTTONUP() => sub {
283 CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); 294 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
284 }, 295 },
285 SDL_ACTIVEEVENT() => sub { 296 SDL_ACTIVEEVENT() => sub {
286# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 297# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
287 }, 298 },
288); 299);
362 [qw/Password password/], 373 [qw/Password password/],
363 ); 374 );
364 375
365 my $cfg = {}; 376 my $cfg = {};
366 377
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); 378 $w->add (my $vb = Gtk2::VBox->new);
371 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); 379 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0);
372 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; 380 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height};
373 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); 381 $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); 382 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1);
375 my $i = 0; 383 my $i = 0;
376 my $act = 0; 384 my $act = 0;
377 for (map { "$_->[0]x$_->[1]" } reverse @modes) { 385 for (map { "$_->[0]x$_->[1]" } @SDL_MODES) {
378 if ($_ eq $selmode) { $act = $i } 386 if ($_ eq $selmode) { $act = $i }
379 $cb->append_text ($_); 387 $cb->append_text ($_);
380 $i++; 388 $i++;
381 } 389 }
382 $cb->set_active ($act); 390 $cb->set_active ($act);
428 436
429############################################################################# 437#############################################################################
430 438
431SDL::Init SDL_INIT_EVERYTHING; 439SDL::Init SDL_INIT_EVERYTHING;
432 440
441@SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)],
442 @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE };
443
433CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 444CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
434 445
435$CFG ||= { 446$CFG ||= {
436 width => 640, 447 width => 640,
437 height => 480, 448 height => 480,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines