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.38 by root, Sun Apr 9 00:06:10 2006 UTC vs.
Revision 1.56 by root, Sun Apr 9 22:28:05 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines