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.76 by root, Tue Apr 11 22:14:14 2006 UTC vs.
Revision 1.83 by root, Wed Apr 12 15:35:55 2006 UTC

26 26
27our $FACECACHE; 27our $FACECACHE;
28 28
29our $CFG; 29our $CFG;
30our $CONN; 30our $CONN;
31our $FAST; # fast, low-quality mode
31 32
32our @SDL_MODES; 33our @SDL_MODES;
33our $WIDTH; 34our $WIDTH;
34our $HEIGHT; 35our $HEIGHT;
35our $FULLSCREEN; 36our $FULLSCREEN;
50 51
51my $last_refresh; 52my $last_refresh;
52my %ANIMATE; 53my %ANIMATE;
53my $refresh_handler; 54my $refresh_handler;
54 55
55our ($tw, $te); # Test widget #d# 56sub status {
57 $STATUS_LINE->set_text ($_[0]);
58 my ($w, $h) = $STATUS_LINE->size_request;
59 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h);
60}
61
62sub debug {
63 $DEBUG_STATUS->set_text ($_[0]);
64 my ($w, $h) = $DEBUG_STATUS->size_request;
65 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
66}
67
68sub config_dialog {
69 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100,
70 child => (my $vbox = new CFClient::UI::VBox);
71 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
72 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
73
74 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode");
75 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
76
77 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
78 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8);
79
80 $mode_slider->connect (changed => sub {
81 my ($self, $value) = @_;
82
83 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
84 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
85 });
86 $mode_slider->emit (changed => $mode_slider->{range}[0]);
87
88 $table->add (1, 1, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
89 destroy_screen ();
90 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
91 $FULLSCREEN = $CFG->{fullscreen};
92 init_screen ();
93 });
94
95 $vbox->add (new CFClient::UI::Label align => 0, text => "Server");
96 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
97 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host");
98 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host});
99
100 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port");
101 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port});
102
103 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username");
104 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user});
105
106 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
107 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
108
109 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size");
110 $table->add (1, 6, new CFClient::UI::Slider
111 req_w => 100,
112 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
113 connect_changed => sub {
114 my ($self, $value) = @_;
115
116 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
117 },
118 );
119
120 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
121 warn "login\n";
122 });
123
124 $vbox->add (my $hbox = new CFClient::UI::HBox);
125
126 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
127 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc";
128 status "Configuration Saved";
129 });
130 $CFClient::UI::TOPLEVEL->add ($dialog);
131}
56 132
57sub init_screen { 133sub init_screen {
58 $SDL_APP = new SDL::App 134 $SDL_APP = new SDL::App
59 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 135 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
60 -title => "Crossfire+ Client", 136 -title => "Crossfire+ Client",
81 157
82 $last_refresh = SDL::GetTicks; 158 $last_refresh = SDL::GetTicks;
83 159
84 CFClient::gl_init; 160 CFClient::gl_init;
85 161
86 $FONTSIZE = int $HEIGHT / 50; 162 $FONTSIZE = int $HEIGHT / 40;
87 163
88 ############################################################################# 164 #############################################################################
89 165
90 glClearColor 0.45, 0.45, 0.45, 1;
91
92 glEnable GL_TEXTURE_2D;
93 glEnable GL_COLOR_MATERIAL;
94 glShadeModel GL_FLAT;
95 glDisable GL_DEPTH_TEST;
96 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
97
98 #############################################################################
99
100 $DEBUG_STATUS = new CFClient::UI::Label; 166 $DEBUG_STATUS = new CFClient::UI::Label padding => 0;
101 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 167 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
102 168
103 $STATUS_LINE = new CFClient::UI::Label 169 $STATUS_LINE = new CFClient::UI::Label
170 padding => 0,
104 y => $HEIGHT * 59 / 60 - $FONTSIZE; 171 y => $HEIGHT * 49 / 50 - $FONTSIZE;
105 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); 172 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
106 173
107 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 174 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
175 padding => 0,
108 y => $HEIGHT * 59 / 60, 176 y => $HEIGHT * 49 / 50,
109 height => $HEIGHT / 60, 177 height => $HEIGHT / 50,
110 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 178 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
111 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 179 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
112 180
113 $MAPWIDGET = new CFClient::UI::MapWidget; 181 $MAPWIDGET = new CFClient::UI::MapWidget;
114 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); 182 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
115 $MAPWIDGET->focus_in; 183 $MAPWIDGET->focus_in;
184
185 config_dialog;
116} 186}
117 187
118sub destroy_screen { 188sub destroy_screen {
189 $CFClient::UI::TOPLEVEL->{children} = [];
119 remove Glib::Source $SDL_TIMER; 190 remove Glib::Source $SDL_TIMER;
120 undef $SDL_APP; 191 undef $SDL_APP;
121 undef $SDL_EV; 192 undef $SDL_EV;
122 SDL::Quit; 193 SDL::Quit;
123} 194}
124 195
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
163sub start_game { 196sub start_game {
164 $WIDTH = $CFG->{width}; 197 $WIDTH = $CFG->{width};
165 $HEIGHT = $CFG->{height}; 198 $HEIGHT = $CFG->{height};
166 $FULLSCREEN = 0; 199 $FULLSCREEN = 0;
167 200
168 init_screen; 201 init_screen;
169
170 config_dialog;
171 202
172 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 203 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
173 204
174 $CONN = new conn 205 $CONN = new conn
175 host => $CFG->{host}, 206 host => $CFG->{host},
205 $CFClient::UI::TOPLEVEL->draw; 236 $CFClient::UI::TOPLEVEL->draw;
206 237
207 SDL::GLSwapBuffers; 238 SDL::GLSwapBuffers;
208} 239}
209 240
210sub debug {
211 $DEBUG_STATUS->set_text ($_[0]);
212 my ($w, $h) = $DEBUG_STATUS->size_request;
213 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
214}
215
216my $FPS; 241my $FPS;
217 242
218sub refresh { 243sub refresh {
219 $refresh_handler ||= add Glib::Idle sub { 244 $refresh_handler ||= add Glib::Idle sub {
220 if ($SDL_APP) { 245 if ($SDL_APP) {
228 my $interval = ($NOW - $last_refresh) * 0.001; 253 my $interval = ($NOW - $last_refresh) * 0.001;
229 $last_refresh = $NOW; 254 $last_refresh = $NOW;
230 255
231 if ($interval) { 256 if ($interval) {
232 $FPS ||= 1 / $interval; 257 $FPS ||= 1 / $interval;
233 $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; 258 $FPS = $FPS * 0.9 + (1 / $interval) * 0.1;
234 debug sprintf "%5.02f", $FPS; 259 debug sprintf "%5.02f", $FPS;
235 } 260 }
236 261
237 force_refresh; 262 force_refresh;
238 $_->animate ($interval) for grep $_, values %ANIMATE; 263 $_->animate ($interval) for grep $_, values %ANIMATE;
274 }, 299 },
275 SDL_KEYDOWN() => sub { 300 SDL_KEYDOWN() => sub {
276 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 301 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
277 # alt-enter 302 # alt-enter
278 $FULLSCREEN = !$FULLSCREEN; 303 $FULLSCREEN = !$FULLSCREEN;
304 destroy_screen;
279 init_screen; 305 init_screen;
280 } else { 306 } else {
281 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 307 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
282 } 308 }
283 }, 309 },
444CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 470CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
445 471
446$CFG ||= { 472$CFG ||= {
447 width => 640, 473 width => 640,
448 height => 480, 474 height => 480,
475 fullscreen => 0,
476 sdl_mode => 0,
449 mapsize => 100, 477 mapsize => 100,
450 fullscreen => 0,
451 host => "crossfire.schmorp.de", 478 host => "crossfire.schmorp.de",
452 port => 13327, 479 port => 13327,
453}; 480};
454 481
455{ 482{
466 logout => sub { stop_game }; 493 logout => sub { stop_game };
467 494
468main Gtk2; 495main Gtk2;
469 496
470Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; 497Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";
498

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines