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.79 by root, Wed Apr 12 00:36:14 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 expand => 1, 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 ($self, $value) = @_;
141
142 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
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, new CFClient::UI::Slider
161 req_w => 100,
162 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
163 connect_changed => sub {
164 my ($self, $value) = @_;
165
166 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
167 },
168 );
169
170 $vbox->add (my $hbox = new CFClient::UI::HBox);
171 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
172 warn "save\n";
173 });
174 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
175 warn "login\n";
176 });
177 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
178 warn "apply\n";
179 });
180
181 $CFClient::UI::TOPLEVEL->add ($dialog);
182}
183
184sub start_game { 193sub start_game {
185 $WIDTH = $CFG->{width}; 194 $WIDTH = $CFG->{width};
186 $HEIGHT = $CFG->{height}; 195 $HEIGHT = $CFG->{height};
187 $FULLSCREEN = 0; 196 $FULLSCREEN = 0;
188 197
189 init_screen; 198 init_screen;
190
191 config_dialog;
192 199
193 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;
194 201
195 $CONN = new conn 202 $CONN = new conn
196 host => $CFG->{host}, 203 host => $CFG->{host},
224 glClear GL_COLOR_BUFFER_BIT; 231 glClear GL_COLOR_BUFFER_BIT;
225 232
226 $CFClient::UI::TOPLEVEL->draw; 233 $CFClient::UI::TOPLEVEL->draw;
227 234
228 SDL::GLSwapBuffers; 235 SDL::GLSwapBuffers;
229}
230
231sub debug {
232 $DEBUG_STATUS->set_text ($_[0]);
233 my ($w, $h) = $DEBUG_STATUS->size_request;
234 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
235} 236}
236 237
237my $FPS; 238my $FPS;
238 239
239sub refresh { 240sub refresh {
295 }, 296 },
296 SDL_KEYDOWN() => sub { 297 SDL_KEYDOWN() => sub {
297 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) {
298 # alt-enter 299 # alt-enter
299 $FULLSCREEN = !$FULLSCREEN; 300 $FULLSCREEN = !$FULLSCREEN;
301 destroy_screen;
300 init_screen; 302 init_screen;
301 } else { 303 } else {
302 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 304 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
303 } 305 }
304 }, 306 },
465CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 467CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
466 468
467$CFG ||= { 469$CFG ||= {
468 width => 640, 470 width => 640,
469 height => 480, 471 height => 480,
472 fullscreen => 0,
473 sdl_mode => 0,
470 mapsize => 100, 474 mapsize => 100,
471 fullscreen => 0,
472 host => "crossfire.schmorp.de", 475 host => "crossfire.schmorp.de",
473 port => 13327, 476 port => 13327,
474}; 477};
475 478
476{ 479{
487 logout => sub { stop_game }; 490 logout => sub { stop_game };
488 491
489main Gtk2; 492main Gtk2;
490 493
491Crossfire::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