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.82 by root, Wed Apr 12 12:16:59 2006 UTC vs.
Revision 1.85 by root, Wed Apr 12 17:11:02 2006 UTC

20use CFClient::UI; 20use CFClient::UI;
21 21
22our $VERSION = '0.1'; 22our $VERSION = '0.1';
23 23
24my $MAX_FPS = 60; 24my $MAX_FPS = 60;
25my $MIN_FPS = 5; # unused
25my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame 26my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame
26 27
27our $FACECACHE; 28our $FACECACHE;
28 29
29our $CFG; 30our $CFG;
30our $CONN; 31our $CONN;
31our $FAST; # fast, low-quality mode 32our $FAST; # fast, low-quality mode, possibly useful for software-rendering
32 33
33our @SDL_MODES; 34our @SDL_MODES;
34our $WIDTH; 35our $WIDTH;
35our $HEIGHT; 36our $HEIGHT;
36our $FULLSCREEN; 37our $FULLSCREEN;
61 62
62sub debug { 63sub debug {
63 $DEBUG_STATUS->set_text ($_[0]); 64 $DEBUG_STATUS->set_text ($_[0]);
64 my ($w, $h) = $DEBUG_STATUS->size_request; 65 my ($w, $h) = $DEBUG_STATUS->size_request;
65 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h); 66 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
67}
68
69sub start_game {
70 status "logging in...";
71
72 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
73
74 $CONN = new conn
75 host => $CFG->{host},
76 port => $CFG->{port},
77 user => $CFG->{user},
78 pass => $CFG->{password},
79 mapw => $mapsize,
80 maph => $mapsize,
81 ;
82
83 status "login successful";
84
85 CFClient::lowdelay fileno $CONN->{fh};
86}
87
88sub stop_game {
89 undef $CONN;
66} 90}
67 91
68sub config_dialog { 92sub config_dialog {
69 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, 93 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100,
70 child => (my $vbox = new CFClient::UI::VBox); 94 child => (my $vbox = new CFClient::UI::VBox);
83 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 107 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
84 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 108 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
85 }); 109 });
86 $mode_slider->emit (changed => $mode_slider->{range}[0]); 110 $mode_slider->emit (changed => $mode_slider->{range}[0]);
87 111
112 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen");
113 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
114 my ($self, $value) = @_;
115 $CFG->{fullscreen} = $value;
116 });
117
88 $table->add (1, 1, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 118 $table->add (1, 2, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
89 warn "apply\n"; 119 destroy_screen ();
120 init_screen ();
90 }); 121 });
91 122
92 $vbox->add (new CFClient::UI::Label align => 0, text => "Server"); 123 $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]); 124 $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"); 125 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host");
113 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 144 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
114 }, 145 },
115 ); 146 );
116 147
117 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 148 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
118 warn "login\n"; 149 start_game;
119 }); 150 });
120 151
121 $vbox->add (my $hbox = new CFClient::UI::HBox); 152 $vbox->add (my $hbox = new CFClient::UI::HBox);
122 153
123 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub { 154 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
124 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; 155 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
125 status "Configuration Saved"; 156 status "Configuration Saved";
126 }); 157 });
127 $CFClient::UI::TOPLEVEL->add ($dialog); 158 $CFClient::UI::TOPLEVEL->add ($dialog);
128} 159}
129 160
130sub init_screen { 161sub init_screen {
162 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
163 $FULLSCREEN = $CFG->{fullscreen};
164
131 $SDL_APP = new SDL::App 165 $SDL_APP = new SDL::App
132 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 166 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
133 -title => "Crossfire+ Client", 167 -title => "Crossfire+ Client",
134 -width => $WIDTH, 168 -width => $WIDTH,
135 -height => $HEIGHT, 169 -height => $HEIGHT,
183} 217}
184 218
185sub destroy_screen { 219sub destroy_screen {
186 $CFClient::UI::TOPLEVEL->{children} = []; 220 $CFClient::UI::TOPLEVEL->{children} = [];
187 remove Glib::Source $SDL_TIMER; 221 remove Glib::Source $SDL_TIMER;
222 remove Glib::Source $refresh_handler if $refresh_handler;
223 undef $refresh_handler;
188 undef $SDL_APP; 224 undef $SDL_APP;
189 undef $SDL_EV; 225 undef $SDL_EV;
190 SDL::Quit; 226 SDL::Quit;
191}
192
193sub start_game {
194 $WIDTH = $CFG->{width};
195 $HEIGHT = $CFG->{height};
196 $FULLSCREEN = 0;
197
198 init_screen;
199
200 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
201
202 $CONN = new conn
203 host => $CFG->{host},
204 port => $CFG->{port},
205 user => $CFG->{user},
206 pass => $CFG->{password},
207 mapw => $mapsize,
208 maph => $mapsize,
209 ;
210
211 CFClient::lowdelay fileno $CONN->{fh};
212}
213
214sub stop_game {
215 remove Glib::Source $refresh_handler if $refresh_handler;
216 undef $refresh_handler;
217
218 undef $CONN;
219 destroy_screen;
220} 227}
221 228
222sub force_refresh { 229sub force_refresh {
223 glViewport 0, 0, $WIDTH, $HEIGHT; 230 glViewport 0, 0, $WIDTH, $HEIGHT;
224 231
483 CFClient::set_font $fonts[0]; 490 CFClient::set_font $fonts[0];
484} 491}
485 492
486$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 493$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
487 494
488run_config_dialog 495init_screen;
489 login => sub { start_game },
490 logout => sub { stop_game };
491 496
492main Gtk2; 497main Gtk2;
493 498
494Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; 499Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";
495 500

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines