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.32 by elmex, Sat Apr 8 17:21:01 2006 UTC vs.
Revision 1.46 by elmex, Sun Apr 9 17:39:56 2006 UTC

30 30
31our $WIDTH; 31our $WIDTH;
32our $HEIGHT; 32our $HEIGHT;
33our $FULLSCREEN; 33our $FULLSCREEN;
34 34
35our $UIFONT; 35our $FONTSIZE;
36 36
37our $SDL_TIMER; 37our $SDL_TIMER;
38our $SDL_APP; 38our $SDL_APP;
39our $SDL_EV = new SDL::Event; 39our $SDL_EV = new SDL::Event;
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;
45 45
46our $tw; 46our $TOPLEVEL;
47
48our $tw; # Test widget #d#
49
50my $last_refresh;
47 51
48sub init_screen { 52sub init_screen {
49 $SDL_APP = new SDL::App 53 $SDL_APP = new SDL::App
50 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 54 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
51 -title => "Crossfire+ Client", 55 -title => "Crossfire+ Client",
57 -blue_size => 8, 61 -blue_size => 8,
58 -double_buffer => 1, 62 -double_buffer => 1,
59 -fullscreen => $FULLSCREEN, 63 -fullscreen => $FULLSCREEN,
60 -resizeable => 0; 64 -resizeable => 0;
61 65
66 $last_refresh = SDL::GetTicks;
67
62 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 68 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
63 69
64 $GL_EXT{GL_ARB_texture_non_power_of_two} 70 $GL_EXT{GL_ARB_texture_non_power_of_two}
65 or warn "WARNING: non-power-of-two opengl extension required"; 71 or warn "WARNING: non-power-of-two opengl extension required";
66 72
67 $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 73 $FONTSIZE = int $HEIGHT / 50;
68 or die "TTFOpenFont: $!";
69 74
70 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; 75 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
76 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE,
77 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
71 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); 78 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
72 $ALT_ENTER_MESSAGE->activate; 79 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
73 80
81 # Test code #d#
82 unless ($tw) { # haha...
74 $tw = new Crossfire::Client::Widget::Window; 83 $tw = new Crossfire::Client::Widget::Animator;
75 $tw->add (my $lbl = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!"); 84 my $lbl1 = new Crossfire::Client::Widget::Label
76# $tw = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!"; 85 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
86 my $lbl2 = new Crossfire::Client::Widget::Label
87 0, 0, 10, $FONTSIZE, "LBL2";
77 88
78 $tw->move (0, $HEIGHT - 50); 89 my $vb = new Crossfire::Client::Widget::VBox;
79 $tw->activate; 90 my $f = new Crossfire::Client::Widget::FancyFrame;
91 my $f2 = new Crossfire::Client::Widget::FancyFrame;
92 $f->add ($lbl1);
93 $f2->add ($lbl2);
94 $vb->add ($f);
95 $vb->add ($f2, 1);
96
97 $tw->add ($vb);
98 $tw->w (400);
99 $tw->h (300);
100 $tw->move ($WIDTH - 200, 0);
101 $tw->moveto (0, 0);
102 $TOPLEVEL->add ($tw);
103
104# $f->move ($WIDTH - 200, 0);
105# $TOPLEVEL->add ($f);
106 }
80 107
81 glClearColor 0, 0, 0, 0; 108 glClearColor 0, 0, 0, 0;
82 109
83 glEnable GL_TEXTURE_2D; 110 glEnable GL_TEXTURE_2D;
111 glEnable GL_COLOR_MATERIAL;
84 glShadeModel GL_FLAT; 112 glShadeModel GL_FLAT;
85 glDisable GL_DEPTH_TEST; 113 glDisable GL_DEPTH_TEST;
86 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 114 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
87
88 glMatrixMode GL_PROJECTION;
89 glLoadIdentity;
90 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100;
91
92 glMatrixMode GL_MODELVIEW;
93 115
94 $_->() for @GL_INIT; 116 $_->() for @GL_INIT;
95} 117}
96 118
97sub start_game { 119sub start_game {
110 132
111 $CONN = new conn 133 $CONN = new conn
112 host => $CFG->{host}, 134 host => $CFG->{host},
113 port => $CFG->{port}, 135 port => $CFG->{port},
114 user => $CFG->{user}, 136 user => $CFG->{user},
115 pass => $CFG->{password}; 137 pass => $CFG->{password},
138 mapw => 50,
139 maph => 37,
140 ;
141
142 Crossfire::Client::lowdelay fileno $CONN->{fh};
116} 143}
117 144
118sub stop_game { 145sub stop_game {
119 remove Glib::Source $SDL_TIMER; 146 remove Glib::Source $SDL_TIMER;
120 147
123} 150}
124 151
125 152
126sub force_refresh { 153sub force_refresh {
127 glViewport 0, 0, $WIDTH, $HEIGHT; 154 glViewport 0, 0, $WIDTH, $HEIGHT;
155
156 glMatrixMode GL_PROJECTION;
157 glLoadIdentity;
158 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000;
159 glMatrixMode GL_MODELVIEW;
160
128 glClear GL_COLOR_BUFFER_BIT; 161 glClear GL_COLOR_BUFFER_BIT;
129 162
130 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; 163 $TOPLEVEL->draw;
131 164
132 SDL::GLSwapBuffers; 165 SDL::GLSwapBuffers;
133} 166}
167
168my %ANIMATE;
134 169
135my $refresh_handler; 170my $refresh_handler;
136 171
137sub refresh { 172sub refresh {
138 $refresh_handler ||= add Glib::Idle sub { 173 $refresh_handler ||= add Glib::Idle sub {
174 my $next_refresh = SDL::GetTicks;
175 my $interval = ($next_refresh - $last_refresh) * 0.001;
176 $last_refresh = $next_refresh;
177
139 force_refresh; 178 force_refresh;
179 $_->animate ($interval) for grep $_, values %ANIMATE;
180
181 if (%ANIMATE) {
182 1
183 } else {
140 undef $refresh_handler; 184 undef $refresh_handler;
185 0
141 0 186 }
142 }; 187 };
188}
189
190sub animation_start {
191 my ($widget) = @_;
192 $ANIMATE{$widget} = $widget;
193 Scalar::Util::weaken $ANIMATE{$widget};
194
195 refresh;
196}
197
198sub animation_stop {
199 my ($widget) = @_;
200 delete $ANIMATE{$widget};
143} 201}
144 202
145%SDL_CB = ( 203%SDL_CB = (
146 SDL_QUIT() => sub { 204 SDL_QUIT() => sub {
147 main_quit Gtk2; 205 main_quit Gtk2;
186} 244}
187 245
188sub conn::map_scroll { 246sub conn::map_scroll {
189 my ($self, $dx, $dy) = @_; 247 my ($self, $dx, $dy) = @_;
190 248
191 refresh; 249# refresh;
192} 250}
193 251
194sub conn::map_clear { 252sub conn::map_clear {
195 my ($self) = @_; 253 my ($self) = @_;
196 254
197 refresh; 255# refresh;
198} 256}
199 257
200sub conn::face_find { 258sub conn::face_find {
201 my ($self, $face) = @_; 259 my ($self, $face) = @_;
202 260
207 my ($self, $face) = @_; 265 my ($self, $face) = @_;
208 266
209 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 267 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
210 268
211 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; 269 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
270}
271
272sub conn::query {
273 my ($self, $flags, $prompt) = @_;
274
275 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
212} 276}
213 277
214sub gtk_add_cfg_field { 278sub gtk_add_cfg_field {
215 my ($tbl, $cfg, $klbl, $key, $value) = @_; 279 my ($tbl, $cfg, $klbl, $key, $value) = @_;
216 my $i = $cfg->{_i}++; 280 my $i = $cfg->{_i}++;
304 368
305 369
306############################################################################# 370#############################################################################
307 371
308SDL::Init SDL_INIT_EVERYTHING; 372SDL::Init SDL_INIT_EVERYTHING;
309SDL::TTFInit; 373
374$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
310 375
311my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 376my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
312 377
313$mapwidget->activate; 378$TOPLEVEL->add ($mapwidget);
314$mapwidget->focus_in; 379$mapwidget->focus_in;
315 380
316Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 381Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
317 382
318$CFG ||= { 383$CFG ||= {
321 fullscreen => 0, 386 fullscreen => 0,
322 host => "crossfire.schmorp.de", 387 host => "crossfire.schmorp.de",
323 port => 13327, 388 port => 13327,
324}; 389};
325 390
391Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf";
392
326$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 393$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
327 394
328run_config_dialog 395run_config_dialog
329 login => sub { start_game }, 396 login => sub { start_game },
330 logout => sub { stop_game }; 397 logout => sub { stop_game };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines