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.26 by elmex, Fri Apr 7 20:57:29 2006 UTC vs.
Revision 1.48 by elmex, Sun Apr 9 18:30:03 2006 UTC

15 15
16use Crossfire; 16use Crossfire;
17use Crossfire::Client; 17use Crossfire::Client;
18use Crossfire::Protocol; 18use Crossfire::Protocol;
19 19
20use Crossfire::Client::Util;
21use Crossfire::Client::Widget; 20use Crossfire::Client::Widget;
22 21
23our $FACECACHE; 22our $FACECACHE;
24 23
25our $VERSION = '0.1'; 24our $VERSION = '0.1';
25
26our %GL_EXT;
26 27
27our $CFG; 28our $CFG;
28our $CONN; 29our $CONN;
29 30
31our $WIDTH;
32our $HEIGHT;
33our $FULLSCREEN;
34
30our $UIFONT; 35our $FONTSIZE;
31 36
32our $SDL_TIMER; 37our $SDL_TIMER;
33our $SDL_APP; 38our $SDL_APP;
34our $SDL_EV = new SDL::Event; 39our $SDL_EV = new SDL::Event;
35our %SDL_CB; 40our %SDL_CB;
36 41
37our @GL_INIT; # hooks called on every gl init 42our @GL_INIT; # hooks called on every gl init
38 43
44our $ALT_ENTER_MESSAGE;
45
46our $TOPLEVEL;
47
48our $tw; # Test widget #d#
49
50my $last_refresh;
51
39sub init_screen { 52sub init_screen {
40 $SDL_APP = new SDL::App 53 $SDL_APP = new SDL::App
41 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 54 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
42 -title => "Crossfire+ Client", 55 -title => "Crossfire+ Client",
43 -width => $CFG->{width}, 56 -width => $WIDTH,
44 -height => $CFG->{height}, 57 -height => $HEIGHT,
45 -opengl => 1, 58 -opengl => 1,
46 -red_size => 8, 59 -red_size => 8,
47 -green_size => 8, 60 -green_size => 8,
48 -blue_size => 8, 61 -blue_size => 8,
49 -double_buffer => 1, 62 -double_buffer => 1,
50 -fullscreen => $CFG->{fullscreen}, 63 -fullscreen => $FULLSCREEN,
51 -resizeable => 0; 64 -resizeable => 0;
52 65
66 $last_refresh = SDL::GetTicks;
67
68 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
69
70 $GL_EXT{GL_ARB_texture_non_power_of_two}
71 or warn "WARNING: non-power-of-two opengl extension required";
72
73 $FONTSIZE = int $HEIGHT / 50;
74
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";
78 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
79 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
80
81 # Test code #d#
82 unless ($tw) { # haha...
83 $tw = new Crossfire::Client::Widget::Animator;
84 my $lbl1 = new Crossfire::Client::Widget::Label
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";
88
89 my $vb = new Crossfire::Client::Widget::VBox;
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 }
107
53 glClearColor 0, 0, 0, 0; 108 glClearColor 0, 0, 0, 0;
54 109
55 glEnable GL_TEXTURE_2D; 110 glEnable GL_TEXTURE_2D;
111 glEnable GL_COLOR_MATERIAL;
56 glShadeModel GL_FLAT; 112 glShadeModel GL_FLAT;
57 glDisable GL_DEPTH_TEST; 113 glDisable GL_DEPTH_TEST;
58 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 114 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
59 115
116 $_->() for @GL_INIT;
117}
118
119sub start_game {
120 $SDL_TIMER = add Glib::Timeout 1000/100, sub {
121 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
122 while $SDL_EV->poll;
123
124 1
125 };
126
127 $WIDTH = $CFG->{width};
128 $HEIGHT = $CFG->{height};
129 $FULLSCREEN = 0;
130
131 init_screen;
132
133 $CONN = new conn
134 host => $CFG->{host},
135 port => $CFG->{port},
136 user => $CFG->{user},
137 pass => $CFG->{password},
138 mapw => 50,
139 maph => 37,
140 ;
141
142 Crossfire::Client::lowdelay fileno $CONN->{fh};
143}
144
145sub stop_game {
146 remove Glib::Source $SDL_TIMER;
147
148 undef $SDL_APP;
149 SDL::Quit;
150}
151
152
153sub force_refresh {
154 glViewport 0, 0, $WIDTH, $HEIGHT;
155
60 glMatrixMode GL_PROJECTION; 156 glMatrixMode GL_PROJECTION;
61 glLoadIdentity; 157 glLoadIdentity;
62 glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; 158 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000;
63
64 glMatrixMode GL_MODELVIEW; 159 glMatrixMode GL_MODELVIEW;
65 160
66 $_->() for @GL_INIT; 161 glClear GL_COLOR_BUFFER_BIT;
67}
68 162
69my $label;#d# 163 $TOPLEVEL->draw;
70 164
71sub start_game { 165 SDL::GLSwapBuffers;
72 $SDL_TIMER = add Glib::Timeout 1000/20, sub { 166}
73 while ($SDL_EV->poll) { 167
74 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); 168my %ANIMATE;
169
170my $refresh_handler;
171
172sub refresh {
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
178 force_refresh;
179 $_->animate ($interval) for grep $_, values %ANIMATE;
180
181 if (%ANIMATE) {
182 1
183 } else {
184 undef $refresh_handler;
185 0
75 } 186 }
76
77 1
78 }; 187 };
79
80 init_screen;
81
82 $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]";
83 $label->activate;
84
85 $CONN = new conn
86 host => $CFG->{host},
87 port => $CFG->{port};
88} 188}
89 189
90sub stop_game { 190sub animation_start {
91 remove Glib::Source $SDL_TIMER; 191 my ($widget) = @_;
192 $ANIMATE{$widget} = $widget;
193 Scalar::Util::weaken $ANIMATE{$widget};
92 194
93 undef $SDL_APP; 195 refresh;
94 SDL::Quit;
95} 196}
96 197
97sub refresh { 198sub animation_stop {
98 glClear GL_COLOR_BUFFER_BIT; 199 my ($widget) = @_;
99 200 delete $ANIMATE{$widget};
100 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS;
101
102 SDL::GLSwapBuffers;
103} 201}
104 202
105%SDL_CB = ( 203%SDL_CB = (
106 SDL_QUIT() => sub { 204 SDL_QUIT() => sub {
107 main_quit Gtk2; 205 main_quit Gtk2;
112 refresh; 210 refresh;
113 }, 211 },
114 SDL_KEYDOWN() => sub { 212 SDL_KEYDOWN() => sub {
115 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 213 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
116 # alt-enter 214 # alt-enter
117 $CFG->{fullscreen} = !$CFG->{fullscreen}; 215 $FULLSCREEN = !$FULLSCREEN;
118 init_screen; 216 init_screen;
119 } else { 217 } else {
120 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); 218 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV);
121 } 219 }
122 }, 220 },
146} 244}
147 245
148sub conn::map_scroll { 246sub conn::map_scroll {
149 my ($self, $dx, $dy) = @_; 247 my ($self, $dx, $dy) = @_;
150 248
151 refresh; 249# refresh;
152} 250}
153 251
154sub conn::map_clear { 252sub conn::map_clear {
155 my ($self) = @_; 253 my ($self) = @_;
156 254
157 refresh; 255# refresh;
158} 256}
159 257
160sub conn::face_find { 258sub conn::face_find {
161 my ($self, $face) = @_; 259 my ($self, $face) = @_;
162 260
167 my ($self, $face) = @_; 265 my ($self, $face) = @_;
168 266
169 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 267 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
170 268
171 $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#
172} 276}
173 277
174sub gtk_add_cfg_field { 278sub gtk_add_cfg_field {
175 my ($tbl, $cfg, $klbl, $key, $value) = @_; 279 my ($tbl, $cfg, $klbl, $key, $value) = @_;
176 my $i = $cfg->{_i}++; 280 my $i = $cfg->{_i}++;
182 } 286 }
183 $ent->set_text ($value); 287 $ent->set_text ($value);
184 $ent->signal_connect (changed => sub { 288 $ent->signal_connect (changed => sub {
185 my ($ent) = @_; 289 my ($ent) = @_;
186 $cfg->{$key} = $ent->get_text; 290 $cfg->{$key} = $ent->get_text;
291 if ($key eq 'mapsize' and $cfg->{$key} > 100) {
292 $cfg->{$key} = 100;
293 $ent->set_text ('100');
294 } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
295 $cfg->{$key} = 50;
296 $ent->set_text ('50');
297 }
187 }); 298 });
188} 299}
189 300
190sub run_config_dialog { 301sub run_config_dialog {
191 my (%events) = @_; 302 my (%events) = @_;
193 my $w = Gtk2::Window->new; 304 my $w = Gtk2::Window->new;
194 305
195 my @cfg = ( 306 my @cfg = (
196 [qw/Host host/], 307 [qw/Host host/],
197 [qw/Port port/], 308 [qw/Port port/],
309 [qw/Mapsize% mapsize/],
198 [qw/Username user/], 310 [qw/Username user/],
199 [qw/Password password/], 311 [qw/Password password/],
200 ); 312 );
201 313
202 my $cfg = {}; 314 my $cfg = {};
265 377
266############################################################################# 378#############################################################################
267 379
268SDL::Init SDL_INIT_EVERYTHING; 380SDL::Init SDL_INIT_EVERYTHING;
269 381
382$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
383
270my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 384my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
271 385
272$mapwidget->activate; 386$TOPLEVEL->add ($mapwidget);
273$mapwidget->focus_in; 387$mapwidget->focus_in;
274 388
275Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 389Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
276 390
277$CFG ||= { 391$CFG ||= {
278 width => 640, 392 width => 640,
279 height => 480, 393 height => 480,
394 mapsize => 100,
280 fullscreen => 0, 395 fullscreen => 0,
281 host => "crossfire.schmorp.de", 396 host => "crossfire.schmorp.de",
282 port => 13327, 397 port => 13327,
283}; 398};
284 399
400Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf";
401
285$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 402$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
286
287SDL::TTFInit;
288
289$UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", 24
290 or die "TTFOpenFont: $!";
291 403
292run_config_dialog 404run_config_dialog
293 login => sub { start_game }, 405 login => sub { start_game },
294 logout => sub { stop_game }; 406 logout => sub { stop_game };
295 407

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines