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.78 by root, Wed Apr 12 00:26:50 2006 UTC vs.
Revision 1.82 by root, Wed Apr 12 12:16:59 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 warn "apply\n";
90 });
91
92 $vbox->add (new CFClient::UI::Label align => 0, text => "Server");
93 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
94 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host");
95 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host});
96
97 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port");
98 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port});
99
100 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username");
101 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user});
102
103 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
104 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
105
106 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size");
107 $table->add (1, 6, new CFClient::UI::Slider
108 req_w => 100,
109 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
110 connect_changed => sub {
111 my ($self, $value) = @_;
112
113 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
114 },
115 );
116
117 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
118 warn "login\n";
119 });
120
121 $vbox->add (my $hbox = new CFClient::UI::HBox);
122
123 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
124 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc";
125 status "Configuration Saved";
126 });
127 $CFClient::UI::TOPLEVEL->add ($dialog);
128}
56 129
57sub init_screen { 130sub init_screen {
58 $SDL_APP = new SDL::App 131 $SDL_APP = new SDL::App
59 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 132 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
60 -title => "Crossfire+ Client", 133 -title => "Crossfire+ Client",
85 158
86 $FONTSIZE = int $HEIGHT / 40; 159 $FONTSIZE = int $HEIGHT / 40;
87 160
88 ############################################################################# 161 #############################################################################
89 162
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 padding => 0; 163 $DEBUG_STATUS = new CFClient::UI::Label padding => 0;
101 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 164 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
102 165
103 $STATUS_LINE = new CFClient::UI::Label 166 $STATUS_LINE = new CFClient::UI::Label
104 padding => 0, 167 padding => 0,
113 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 176 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
114 177
115 $MAPWIDGET = new CFClient::UI::MapWidget; 178 $MAPWIDGET = new CFClient::UI::MapWidget;
116 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); 179 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
117 $MAPWIDGET->focus_in; 180 $MAPWIDGET->focus_in;
181
182 config_dialog;
118} 183}
119 184
120sub destroy_screen { 185sub destroy_screen {
186 $CFClient::UI::TOPLEVEL->{children} = [];
121 remove Glib::Source $SDL_TIMER; 187 remove Glib::Source $SDL_TIMER;
122 undef $SDL_APP; 188 undef $SDL_APP;
123 undef $SDL_EV; 189 undef $SDL_EV;
124 SDL::Quit; 190 SDL::Quit;
125} 191}
126 192
127sub config_dialog {
128 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100,
129 child => (my $vbox = new CFClient::UI::VBox);
130 $vbox->add (new CFClient::UI::Label align => 0, text => "Setup");
131 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
132
133 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode");
134 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
135
136 $hbox->add (my $mode_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
137 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8);
138
139 $mode_slider->connect (changed => sub {
140 my (undef, $value) = @_;
141
142 $CFG->{sdl_mode} = $value = int $value + 0.5;
143 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
144 });
145 $mode_slider->emit (changed => $mode_slider->{range}[0]);
146
147 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Host");
148 $table->add (1, 1, my $host = new CFClient::UI::Entry text => $CFG->{host});
149
150 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Port");
151 $table->add (1, 2, my $port = new CFClient::UI::Entry text => $CFG->{port});
152
153 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Username");
154 $table->add (1, 3, my $user = new CFClient::UI::Entry text => $CFG->{user});
155
156 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Password");
157 $table->add (1, 4, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
158
159 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Map Size");
160 $table->add (1, 5, my $mapsize_slider = new CFClient::UI::Slider req_w => 100, range => [$CFG->{mapsize}, 10, 100 + 1, 1]);
161
162 $vbox->add (my $hbox = new CFClient::UI::HBox);
163 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
164 warn "save\n";
165 });
166 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
167 warn "login\n";
168 });
169 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
170 warn "apply\n";
171 });
172
173 $CFClient::UI::TOPLEVEL->add ($dialog);
174}
175
176sub start_game { 193sub start_game {
177 $WIDTH = $CFG->{width}; 194 $WIDTH = $CFG->{width};
178 $HEIGHT = $CFG->{height}; 195 $HEIGHT = $CFG->{height};
179 $FULLSCREEN = 0; 196 $FULLSCREEN = 0;
180 197
181 init_screen; 198 init_screen;
182
183 config_dialog;
184 199
185 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 200 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
186 201
187 $CONN = new conn 202 $CONN = new conn
188 host => $CFG->{host}, 203 host => $CFG->{host},
216 glClear GL_COLOR_BUFFER_BIT; 231 glClear GL_COLOR_BUFFER_BIT;
217 232
218 $CFClient::UI::TOPLEVEL->draw; 233 $CFClient::UI::TOPLEVEL->draw;
219 234
220 SDL::GLSwapBuffers; 235 SDL::GLSwapBuffers;
221}
222
223sub debug {
224 $DEBUG_STATUS->set_text ($_[0]);
225 my ($w, $h) = $DEBUG_STATUS->size_request;
226 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
227} 236}
228 237
229my $FPS; 238my $FPS;
230 239
231sub refresh { 240sub refresh {
287 }, 296 },
288 SDL_KEYDOWN() => sub { 297 SDL_KEYDOWN() => sub {
289 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 298 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
290 # alt-enter 299 # alt-enter
291 $FULLSCREEN = !$FULLSCREEN; 300 $FULLSCREEN = !$FULLSCREEN;
301 destroy_screen;
292 init_screen; 302 init_screen;
293 } else { 303 } else {
294 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 304 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
295 } 305 }
296 }, 306 },
457CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 467CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
458 468
459$CFG ||= { 469$CFG ||= {
460 width => 640, 470 width => 640,
461 height => 480, 471 height => 480,
472 fullscreen => 0,
473 sdl_mode => 0,
462 mapsize => 100, 474 mapsize => 100,
463 fullscreen => 0,
464 host => "crossfire.schmorp.de", 475 host => "crossfire.schmorp.de",
465 port => 13327, 476 port => 13327,
466}; 477};
467 478
468{ 479{
479 logout => sub { stop_game }; 490 logout => sub { stop_game };
480 491
481main Gtk2; 492main Gtk2;
482 493
483Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; 494Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";
495

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines