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.42 by root, Sun Apr 9 01:35:40 2006 UTC vs.
Revision 1.53 by root, Sun Apr 9 22:17:40 2006 UTC

40our %SDL_CB; 40our %SDL_CB;
41 41
42our @GL_INIT; # hooks called on every gl init 42our @GL_INIT; # hooks called on every gl init
43 43
44our $ALT_ENTER_MESSAGE; 44our $ALT_ENTER_MESSAGE;
45our $STATUS_LINE;
45 46
46our $TOPLEVEL; 47our $TOPLEVEL;
47 48
48our $tw; # Test widget #d# 49our $tw; # Test widget #d#
50
51my $last_refresh;
52my %ANIMATE;
53my $refresh_handler;
49 54
50sub init_screen { 55sub init_screen {
51 $SDL_APP = new SDL::App 56 $SDL_APP = new SDL::App
52 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 57 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
53 -title => "Crossfire+ Client", 58 -title => "Crossfire+ Client",
54 -width => $WIDTH, 59 -width => $WIDTH,
55 -height => $HEIGHT, 60 -height => $HEIGHT,
56 -opengl => 1, 61 -opengl => 1,
57 -red_size => 8, 62 -red_size => 5,
58 -green_size => 8, 63 -green_size => 5,
59 -blue_size => 8, 64 -blue_size => 5,
65 -alpha_size => 0,
60 -double_buffer => 1, 66 -double_buffer => 1,
61 -fullscreen => $FULLSCREEN, 67 -fullscreen => $FULLSCREEN,
62 -resizeable => 0; 68 -resizeable => 0;
63 69
70 $last_refresh = SDL::GetTicks;
71
64 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 72 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
65 73
66 $GL_EXT{GL_ARB_texture_non_power_of_two} 74 $GL_EXT{GL_ARB_texture_non_power_of_two}
67 or warn "WARNING: non-power-of-two opengl extension required"; 75 or warn "WARNING: non-power-of-two opengl extension required";
68 76
69 $FONTSIZE = int $HEIGHT / 50; 77 $FONTSIZE = int $HEIGHT / 50;
70 78
71 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 79 #############################################################################
72 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE,
73 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
74 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
75 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
76
77 # Test code #d#
78 {
79 my $frm = new Crossfire::Client::Widget::Frame;
80 $tw = new Crossfire::Client::Widget::Window;
81 $frm->add (my $te = new Crossfire::Client::Widget::TextEntry 0, 0, 10, $FONTSIZE, "Foo in the garden!");
82 $tw->add ($frm);
83
84 $tw->move (0, $HEIGHT - 120);
85 $TOPLEVEL->add ($tw);
86# $te->focus_in;
87 }
88 80
89 glClearColor 0, 0, 0, 0; 81 glClearColor 0, 0, 0, 0;
90 82
91 glEnable GL_TEXTURE_2D; 83 glEnable GL_TEXTURE_2D;
92 glEnable GL_COLOR_MATERIAL; 84 glEnable GL_COLOR_MATERIAL;
93 glShadeModel GL_FLAT; 85 glShadeModel GL_FLAT;
94 glDisable GL_DEPTH_TEST; 86 glDisable GL_DEPTH_TEST;
95 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 87 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
96 88
97 $_->() for @GL_INIT; 89 $_->() for @GL_INIT;
90
91 #############################################################################
92
93 $STATUS_LINE = new Crossfire::Client::Widget::Label
94 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE,
95 "";
96 $TOPLEVEL->add ($STATUS_LINE);
97
98 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
99 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60,
100 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
101 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
102
103 # Test code #d#
104 unless ($tw) { # haha...
105 $tw = new Crossfire::Client::Widget::Animator;
106 my $lbl1 = new Crossfire::Client::Widget::Label
107 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
108 my $lbl2 = new Crossfire::Client::Widget::Label
109 0, 0, 10, $FONTSIZE, "LBL2";
110
111 my $vb = new Crossfire::Client::Widget::VBox;
112 my $f = new Crossfire::Client::Widget::FancyFrame;
113 my $f2 = new Crossfire::Client::Widget::FancyFrame;
114 $f->add ($lbl1);
115 $f2->add ($lbl2);
116 $vb->add ($f);
117 $vb->add ($f2, 1);
118
119 $tw->add ($vb);
120 $tw->w (400);
121 $tw->h (300);
122 $tw->move ($WIDTH - 200, 0);
123 $tw->moveto (0, 0);
124 $TOPLEVEL->add ($tw);
125
126# $f->move ($WIDTH - 200, 0);
127# $TOPLEVEL->add ($f);
128 }
98} 129}
99 130
100sub start_game { 131sub start_game {
101 $SDL_TIMER = add Glib::Timeout 1000/100, sub { 132 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
102 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 133 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
103 while $SDL_EV->poll; 134 while $SDL_EV->poll;
104 135
105 1 136 1
106 }; 137 };
108 $WIDTH = $CFG->{width}; 139 $WIDTH = $CFG->{width};
109 $HEIGHT = $CFG->{height}; 140 $HEIGHT = $CFG->{height};
110 $FULLSCREEN = 0; 141 $FULLSCREEN = 0;
111 142
112 init_screen; 143 init_screen;
144
145 my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
113 146
114 $CONN = new conn 147 $CONN = new conn
115 host => $CFG->{host}, 148 host => $CFG->{host},
116 port => $CFG->{port}, 149 port => $CFG->{port},
117 user => $CFG->{user}, 150 user => $CFG->{user},
118 pass => $CFG->{password}, 151 pass => $CFG->{password},
119 mapw => 50, 152 mapw => $mapsize,
120 maph => 37, 153 maph => $mapsize,
121 ; 154 ;
155
156 Crossfire::Client::lowdelay fileno $CONN->{fh};
122} 157}
123 158
124sub stop_game { 159sub stop_game {
125 remove Glib::Source $SDL_TIMER; 160 remove Glib::Source $SDL_TIMER;
161 remove Glib::Source $refresh_handler if $refresh_handler;
162 undef $refresh_handler;
126 163
127 undef $SDL_APP; 164 undef $SDL_APP;
165 undef $CONN;
128 SDL::Quit; 166 SDL::Quit;
129} 167}
130 168
131 169
132sub force_refresh { 170sub force_refresh {
133 glViewport 0, 0, $WIDTH, $HEIGHT; 171 glViewport 0, 0, $WIDTH, $HEIGHT;
134 172
135 glMatrixMode GL_PROJECTION; 173 glMatrixMode GL_PROJECTION;
136 glLoadIdentity; 174 glLoadIdentity;
137 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; 175 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000;
138 glMatrixMode GL_MODELVIEW; 176 glMatrixMode GL_MODELVIEW;
139 177
140 glClear GL_COLOR_BUFFER_BIT; 178 glClear GL_COLOR_BUFFER_BIT;
141 179
142 $TOPLEVEL->draw; 180 $TOPLEVEL->draw;
143 181
144 SDL::GLSwapBuffers; 182 SDL::GLSwapBuffers;
145} 183}
146
147my $refresh_handler;
148 184
149sub refresh { 185sub refresh {
150 $refresh_handler ||= add Glib::Idle sub { 186 $refresh_handler ||= add Glib::Idle sub {
187 return unless $SDL_APP;
188
189 my $next_refresh = SDL::GetTicks;
190 my $interval = ($next_refresh - $last_refresh) * 0.001;
191 $last_refresh = $next_refresh;
192
151 force_refresh; 193 force_refresh;
194 $_->animate ($interval) for grep $_, values %ANIMATE;
195
196 if (%ANIMATE) {
197 1
198 } else {
152 undef $refresh_handler; 199 undef $refresh_handler;
200 0
153 0 201 }
154 }; 202 };
203}
204
205sub animation_start {
206 my ($widget) = @_;
207 $ANIMATE{$widget} = $widget;
208 Scalar::Util::weaken $ANIMATE{$widget};
209
210 refresh;
211}
212
213sub animation_stop {
214 my ($widget) = @_;
215 delete $ANIMATE{$widget};
155} 216}
156 217
157%SDL_CB = ( 218%SDL_CB = (
158 SDL_QUIT() => sub { 219 SDL_QUIT() => sub {
159 main_quit Gtk2; 220 main_quit Gtk2;
174 }, 235 },
175 SDL_KEYUP() => sub { 236 SDL_KEYUP() => sub {
176 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); 237 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV);
177 }, 238 },
178 SDL_MOUSEMOTION() => sub { 239 SDL_MOUSEMOTION() => sub {
179 warn "sdl motion\n";#d# 240 my ($x, $y) = ($SDL_EV->motion_x, $SDL_EV->motion_y);
241 my $widget = $TOPLEVEL->find_widget ($x, $y);
242
243 warn "mouse $x, $y = $widget\n";
180 }, 244 },
181 SDL_MOUSEBUTTONDOWN() => sub { 245 SDL_MOUSEBUTTONDOWN() => sub {
182 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); 246 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV);
183 }, 247 },
184 SDL_MOUSEBUTTONUP() => sub { 248 SDL_MOUSEBUTTONUP() => sub {
198} 262}
199 263
200sub conn::map_scroll { 264sub conn::map_scroll {
201 my ($self, $dx, $dy) = @_; 265 my ($self, $dx, $dy) = @_;
202 266
203 refresh; 267# refresh;
204} 268}
205 269
206sub conn::map_clear { 270sub conn::map_clear {
207 my ($self) = @_; 271 my ($self) = @_;
208 272
209 refresh; 273# refresh;
210} 274}
211 275
212sub conn::face_find { 276sub conn::face_find {
213 my ($self, $face) = @_; 277 my ($self, $face) = @_;
214 278
240 } 304 }
241 $ent->set_text ($value); 305 $ent->set_text ($value);
242 $ent->signal_connect (changed => sub { 306 $ent->signal_connect (changed => sub {
243 my ($ent) = @_; 307 my ($ent) = @_;
244 $cfg->{$key} = $ent->get_text; 308 $cfg->{$key} = $ent->get_text;
309 # TODO: Mapsize should be a slider in the game gui
310 if ($key eq 'mapsize' and $cfg->{$key} > 100) {
311 $cfg->{$key} = 100;
312 } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
313 $cfg->{$key} = 50;
314 }
245 }); 315 });
246} 316}
247 317
248sub run_config_dialog { 318sub run_config_dialog {
249 my (%events) = @_; 319 my (%events) = @_;
251 my $w = Gtk2::Window->new; 321 my $w = Gtk2::Window->new;
252 322
253 my @cfg = ( 323 my @cfg = (
254 [qw/Host host/], 324 [qw/Host host/],
255 [qw/Port port/], 325 [qw/Port port/],
326 [qw/Mapsize% mapsize/],
256 [qw/Username user/], 327 [qw/Username user/],
257 [qw/Password password/], 328 [qw/Password password/],
258 ); 329 );
259 330
260 my $cfg = {}; 331 my $cfg = {};
307 my $cb = $events{login} || sub {}; 378 my $cb = $events{login} || sub {};
308 $cb->($::CFG->{user}, $::CFG->{password}); 379 $cb->($::CFG->{user}, $::CFG->{password});
309 }); 380 });
310 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); 381 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
311 $cb->signal_connect (clicked => sub { 382 $cb->signal_connect (clicked => sub {
312 my $cb = $events{login} || sub {}; 383 my $cb = $events{logout} || sub {};
313 $cb->(); 384 $cb->();
314 }); 385 });
315 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); 386 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
316 $cb->signal_connect (clicked => sub { $w->destroy }); 387 $cb->signal_connect (clicked => sub { $w->destroy });
317 388
335Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 406Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
336 407
337$CFG ||= { 408$CFG ||= {
338 width => 640, 409 width => 640,
339 height => 480, 410 height => 480,
411 mapsize => 100,
340 fullscreen => 0, 412 fullscreen => 0,
341 host => "crossfire.schmorp.de", 413 host => "crossfire.schmorp.de",
342 port => 13327, 414 port => 13327,
343}; 415};
344 416

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines