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.83 by root, Wed Apr 12 15:35:55 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 destroy_screen (); 119 destroy_screen ();
90 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
91 $FULLSCREEN = $CFG->{fullscreen};
92 init_screen (); 120 init_screen ();
93 }); 121 });
94 122
95 $vbox->add (new CFClient::UI::Label align => 0, text => "Server"); 123 $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]); 124 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
116 $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 144 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
117 }, 145 },
118 ); 146 );
119 147
120 $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 {
121 warn "login\n"; 149 start_game;
122 }); 150 });
123 151
124 $vbox->add (my $hbox = new CFClient::UI::HBox); 152 $vbox->add (my $hbox = new CFClient::UI::HBox);
125 153
126 $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 {
127 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; 155 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
128 status "Configuration Saved"; 156 status "Configuration Saved";
129 }); 157 });
130 $CFClient::UI::TOPLEVEL->add ($dialog); 158 $CFClient::UI::TOPLEVEL->add ($dialog);
131} 159}
132 160
133sub init_screen { 161sub init_screen {
162 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
163 $FULLSCREEN = $CFG->{fullscreen};
164
134 $SDL_APP = new SDL::App 165 $SDL_APP = new SDL::App
135 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 166 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
136 -title => "Crossfire+ Client", 167 -title => "Crossfire+ Client",
137 -width => $WIDTH, 168 -width => $WIDTH,
138 -height => $HEIGHT, 169 -height => $HEIGHT,
186} 217}
187 218
188sub destroy_screen { 219sub destroy_screen {
189 $CFClient::UI::TOPLEVEL->{children} = []; 220 $CFClient::UI::TOPLEVEL->{children} = [];
190 remove Glib::Source $SDL_TIMER; 221 remove Glib::Source $SDL_TIMER;
222 remove Glib::Source $refresh_handler if $refresh_handler;
223 undef $refresh_handler;
191 undef $SDL_APP; 224 undef $SDL_APP;
192 undef $SDL_EV; 225 undef $SDL_EV;
193 SDL::Quit; 226 SDL::Quit;
194}
195
196sub start_game {
197 $WIDTH = $CFG->{width};
198 $HEIGHT = $CFG->{height};
199 $FULLSCREEN = 0;
200
201 init_screen;
202
203 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
204
205 $CONN = new conn
206 host => $CFG->{host},
207 port => $CFG->{port},
208 user => $CFG->{user},
209 pass => $CFG->{password},
210 mapw => $mapsize,
211 maph => $mapsize,
212 ;
213
214 CFClient::lowdelay fileno $CONN->{fh};
215}
216
217sub stop_game {
218 remove Glib::Source $refresh_handler if $refresh_handler;
219 undef $refresh_handler;
220
221 undef $CONN;
222 destroy_screen;
223} 227}
224 228
225sub force_refresh { 229sub force_refresh {
226 glViewport 0, 0, $WIDTH, $HEIGHT; 230 glViewport 0, 0, $WIDTH, $HEIGHT;
227 231
486 CFClient::set_font $fonts[0]; 490 CFClient::set_font $fonts[0];
487} 491}
488 492
489$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 493$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
490 494
491run_config_dialog 495init_screen;
492 login => sub { start_game },
493 logout => sub { stop_game };
494 496
495main Gtk2; 497main Gtk2;
496 498
497Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; 499Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";
498 500

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines