--- deliantra/Deliantra-Client/bin/pclient 2006/04/07 22:11:10 1.28
+++ deliantra/Deliantra-Client/bin/pclient 2006/04/10 22:53:50 1.63
@@ -14,99 +14,220 @@
use SDL::OpenGL::Constants;
use Crossfire;
-use Crossfire::Client;
use Crossfire::Protocol;
-use Crossfire::Client::Util;
+use Crossfire::Client;
use Crossfire::Client::Widget;
-our $FACECACHE;
-
our $VERSION = '0.1';
+my $MAX_FPS = 30;
+my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame
+
+our $FACECACHE;
+
our $CFG;
our $CONN;
-our $UIFONT;
+our $WIDTH;
+our $HEIGHT;
+our $FULLSCREEN;
+
+our $FONTSIZE;
our $SDL_TIMER;
our $SDL_APP;
-our $SDL_EV = new SDL::Event;
+our $SDL_EV;
our %SDL_CB;
-our @GL_INIT; # hooks called on every gl init
+our $ALT_ENTER_MESSAGE;
+our $STATUS_LINE;
+
+my $last_refresh;
+my %ANIMATE;
+my $refresh_handler;
+
+our ($tw, $te); # Test widget #d#
sub init_screen {
$SDL_APP = new SDL::App
-flags => SDL_ANYFORMAT | SDL_HWSURFACE,
-title => "Crossfire+ Client",
- -width => $CFG->{width},
- -height => $CFG->{height},
+ -width => $WIDTH,
+ -height => $HEIGHT,
-opengl => 1,
- -red_size => 8,
- -green_size => 8,
- -blue_size => 8,
+ -red_size => 5,
+ -green_size => 5,
+ -blue_size => 5,
+ -alpha_size => 0,
-double_buffer => 1,
- -fullscreen => $CFG->{fullscreen},
+ -fullscreen => $FULLSCREEN,
-resizeable => 0;
- $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $CFG->{height} / 40
- or die "TTFOpenFont: $!";
+ $SDL_EV = new SDL::Event;
+ $SDL_EV->set_unicode (1);
+
+ $SDL_TIMER = add Glib::Timeout 1000/50, sub {
+ ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
+ while $SDL_EV->poll;
+
+ 1
+ };
+
+ $last_refresh = SDL::GetTicks;
+
+ Crossfire::Client::gl_init;
- glClearColor 0, 0, 0, 0;
+ $FONTSIZE = int $HEIGHT / 50;
+
+ #############################################################################
+
+ glClearColor 0.45, 0.45, 0.45, 1;
glEnable GL_TEXTURE_2D;
+ glEnable GL_COLOR_MATERIAL;
glShadeModel GL_FLAT;
glDisable GL_DEPTH_TEST;
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
- glMatrixMode GL_PROJECTION;
- glLoadIdentity;
- glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100;
-
- glMatrixMode GL_MODELVIEW;
-
- $_->() for @GL_INIT;
+ #############################################################################
+
+ $STATUS_LINE = new Crossfire::Client::Widget::Label
+ 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE,
+ "";
+ $Crossfire::Client::Widget::TOPLEVEL->add ($STATUS_LINE);
+
+ $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
+ 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60,
+ "Use Alt-Enter to toggle fullscreen mode";
+ $Crossfire::Client::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
+
+ # Test code #d#
+ unless ($tw) { # haha...
+ $te = new Crossfire::Client::Widget::FancyFrame;
+ $te->add (new Crossfire::Client::Widget::Entry);
+ $te->move (300, 0, 2);
+ $Crossfire::Client::Widget::TOPLEVEL->add ($te);
+
+ $tw = new Crossfire::Client::Widget::Animator;
+ my $lbl1 = new Crossfire::Client::Widget::Label
+ 0, 0, 10, $FONTSIZE, "This is a\nTEST!\nOf a themed\nFrame!";
+ my $lbl2 = new Crossfire::Client::Widget::Label
+ 0, 0, 10, $FONTSIZE, "LBL2";
+
+ my $vb = new Crossfire::Client::Widget::VBox;
+ my $f = new Crossfire::Client::Widget::FancyFrame;
+ my $f2 = new Crossfire::Client::Widget::FancyFrame;
+ $f->add ($lbl1);
+ $f2->add ($lbl2);
+ $vb->add ($f);
+ $vb->add ($f2, 1);
+
+ $tw->add ($vb);
+ $tw->w (400);
+ $tw->h (300);
+ $tw->move ($WIDTH - 200, 0);
+ $tw->moveto (0, 0);
+ $Crossfire::Client::Widget::TOPLEVEL->add ($tw);
+
+# $f->move ($WIDTH - 200, 0);
+# $Crossfire::Client::Widget::TOPLEVEL->add ($f);
+ }
}
-my $label;#d#
+sub destroy_screen {
+ remove Glib::Source $SDL_TIMER;
+ undef $SDL_APP;
+ undef $SDL_EV;
+ SDL::Quit;
+}
sub start_game {
- $SDL_TIMER = add Glib::Timeout 1000/20, sub {
- while ($SDL_EV->poll) {
- ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->();
- }
-
- 1
- };
+ $WIDTH = $CFG->{width};
+ $HEIGHT = $CFG->{height};
+ $FULLSCREEN = 0;
init_screen;
- $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]";
- $label->activate;
+ my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
$CONN = new conn
host => $CFG->{host},
port => $CFG->{port},
user => $CFG->{user},
- pass => $CFG->{password};
+ pass => $CFG->{password},
+ mapw => $mapsize,
+ maph => $mapsize,
+ ;
+
+ Crossfire::Client::lowdelay fileno $CONN->{fh};
}
sub stop_game {
- remove Glib::Source $SDL_TIMER;
+ remove Glib::Source $refresh_handler if $refresh_handler;
+ undef $refresh_handler;
- undef $SDL_APP;
- SDL::Quit;
+ undef $CONN;
+ destroy_screen;
}
-sub refresh {
+sub force_refresh {
+ glViewport 0, 0, $WIDTH, $HEIGHT;
+
+ glMatrixMode GL_PROJECTION;
+ glLoadIdentity;
+ glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
+ glMatrixMode GL_MODELVIEW;
+
glClear GL_COLOR_BUFFER_BIT;
- $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS;
+ $Crossfire::Client::Widget::TOPLEVEL->draw;
SDL::GLSwapBuffers;
}
+sub refresh {
+ $refresh_handler ||= add Glib::Idle sub {
+ if ($SDL_APP) {
+ my $next_refresh = SDL::GetTicks;
+
+ if ($next_refresh - $last_refresh < $TICKS_PER_FRAME) {
+ SDL::Delay $TICKS_PER_FRAME - ($next_refresh - $last_refresh);
+ $next_refresh = SDL::GetTicks;
+ }
+
+ my $interval = ($next_refresh - $last_refresh) * 0.001;
+ $last_refresh = $next_refresh;
+
+ force_refresh;
+ $_->animate ($interval) for grep $_, values %ANIMATE;
+
+ if (%ANIMATE) {
+ 1
+ } else {
+ undef $refresh_handler;
+ 0
+ }
+ } else {
+ undef $refresh_handler;
+ 0
+ }
+ };
+}
+
+sub animation_start {
+ my ($widget) = @_;
+ $ANIMATE{$widget} = $widget;
+ Scalar::Util::weaken $ANIMATE{$widget};
+
+ refresh;
+}
+
+sub animation_stop {
+ my ($widget) = @_;
+ delete $ANIMATE{$widget};
+}
+
%SDL_CB = (
SDL_QUIT() => sub {
main_quit Gtk2;
@@ -119,7 +240,7 @@
SDL_KEYDOWN() => sub {
if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
# alt-enter
- $CFG->{fullscreen} = !$CFG->{fullscreen};
+ $FULLSCREEN = !$FULLSCREEN;
init_screen;
} else {
Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV);
@@ -129,7 +250,7 @@
Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV);
},
SDL_MOUSEMOTION() => sub {
- warn "sdl motion\n";#d#
+ Crossfire::Client::Widget::feed_sdl_motion_event ($SDL_EV);
},
SDL_MOUSEBUTTONDOWN() => sub {
Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV);
@@ -138,7 +259,7 @@
Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV);
},
SDL_ACTIVEEVENT() => sub {
- warn "active\n";#d#
+ printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
},
);
@@ -153,13 +274,13 @@
sub conn::map_scroll {
my ($self, $dx, $dy) = @_;
- refresh;
+# refresh;
}
sub conn::map_clear {
my ($self) = @_;
- refresh;
+# refresh;
}
sub conn::face_find {
@@ -176,6 +297,12 @@
$face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
}
+sub conn::query {
+ my ($self, $flags, $prompt) = @_;
+
+ warn "<<<>>\n";#d#
+}
+
sub gtk_add_cfg_field {
my ($tbl, $cfg, $klbl, $key, $value) = @_;
my $i = $cfg->{_i}++;
@@ -189,6 +316,12 @@
$ent->signal_connect (changed => sub {
my ($ent) = @_;
$cfg->{$key} = $ent->get_text;
+ # TODO: Mapsize should be a slider in the game gui
+ if ($key eq 'mapsize' and $cfg->{$key} > 100) {
+ $cfg->{$key} = 100;
+ } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
+ $cfg->{$key} = 50;
+ }
});
}
@@ -200,6 +333,7 @@
my @cfg = (
[qw/Host host/],
[qw/Port port/],
+ [qw/Mapsize% mapsize/],
[qw/Username user/],
[qw/Password password/],
);
@@ -256,7 +390,7 @@
});
$hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
$cb->signal_connect (clicked => sub {
- my $cb = $events{login} || sub {};
+ my $cb = $events{logout} || sub {};
$cb->();
});
$hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
@@ -271,11 +405,10 @@
#############################################################################
SDL::Init SDL_INIT_EVERYTHING;
-SDL::TTFInit;
my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
-$mapwidget->activate;
+$Crossfire::Client::Widget::TOPLEVEL->add ($mapwidget);
$mapwidget->focus_in;
Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
@@ -283,11 +416,14 @@
$CFG ||= {
width => 640,
height => 480,
+ mapsize => 100,
fullscreen => 0,
host => "crossfire.schmorp.de",
port => 13327,
};
+Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf";
+
$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
run_config_dialog