--- deliantra/Deliantra-Client/bin/pclient 2006/04/27 08:55:35 1.190
+++ deliantra/Deliantra-Client/bin/pclient 2006/05/08 20:55:49 1.203
@@ -78,6 +78,7 @@
our $LOGVIEW;
our $CONSOLE;
our $METASERVER;
+our $LOGIN_BUTTON;
our $FLOORBOX;
our $GAUGES;
@@ -94,6 +95,9 @@
our $STATUS_LINE;
our $DEBUG_STATUS;
+our $INVWIN;
+our $INV;
+
sub status {
$STATUS_LINE->set_text ($_[0]);
$STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
@@ -110,27 +114,43 @@
my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
$MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
-
$MAP = new CFClient::Map $mapsize, $mapsize;
my ($host, $port) = split /:/, $CFG->{host};
- $CONN = new conn
- host => $host,
- port => $port || 13327,
- user => $CFG->{user},
- pass => $CFG->{password},
- mapw => $mapsize,
- maph => $mapsize,
- ;
+ $CONN = eval {
+ new conn
+ host => $host,
+ port => $port || 13327,
+ user => $CFG->{user},
+ pass => $CFG->{password},
+ mapw => $mapsize,
+ maph => $mapsize,
+ ;
+ };
+
+ if ($CONN) {
+ $LOGIN_BUTTON->set_text ("Logout");
- status "login successful";
+ status "login successful";
- CFClient::lowdelay fileno $CONN->{fh};
+ CFClient::lowdelay fileno $CONN->{fh};
+ } else {
+ status "unable to connect";
+ stop_game();
+ }
}
sub stop_game {
- undef $CONN;
+ return unless $CONN;
+
+ status "connection closed";
+ $LOGIN_BUTTON->set_text ("Login");
+ $CONN->destroy;
+ $CONN = 0; # false, does not autovivify
+
+ undef $MAPCACHE;
+ undef $MAP;
}
sub client_setup {
@@ -564,7 +584,7 @@
sub metaserver_dialog {
my $dialog = new CFClient::UI::FancyFrame
- title => "Metaserver",
+ title => "Server List",
child => (my $vbox = new CFClient::UI::VBox);
$vbox->add ($dialog->{table} = new CFClient::UI::Table);
@@ -676,9 +696,9 @@
$vbox->add (new CFClient::UI::Flopper
expand => 1,
- text => "Metaserver",
+ text => "Server List",
other => $METASERVER,
- tooltip => "Show a list of avaible crossfire servers",
+ tooltip => "Show a list of available crossfire servers",
connect_open => sub {
update_metaserver $HOST;
}
@@ -719,9 +739,15 @@
},
);
- $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
- start_game;
- });
+ $table->add (1, 8, $LOGIN_BUTTON = new CFClient::UI::Button
+ expand => 1,
+ align => 0,
+ text => "Login",
+ connect_activate => sub {
+ $CONN ? stop_game
+ : start_game;
+ },
+ );
$dialog
}
@@ -780,6 +806,12 @@
$window
}
+sub make_inventory_window {
+ my $invwin = new CFClient::UI::FancyFrame user_w => 300, user_h => 300, title => "Inventory";
+ $invwin->add ($INV = new CFClient::UI::Inventory expand => 1);
+ $invwin
+}
+
sub sdl_init {
CFClient::SDL_Init
and die "SDL::Init failed!\n";
@@ -788,6 +820,8 @@
sub video_init {
sdl_init;
+ $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
+
($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
$FULLSCREEN = $CFG->{fullscreen};
$FAST = $CFG->{fast};
@@ -796,81 +830,95 @@
or die "SDL_SetVideoMode failed!\n";
$SDL_ACTIVE = 1;
-
$LAST_REFRESH = time - 0.01;
CFClient::gl_init;
$FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
+ $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
+
#############################################################################
- $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
- $DEBUG_STATUS->show;
-
- $STATUS_LINE = new CFClient::UI::Label
- padding => 0,
- y => $HEIGHT - $FONTSIZE * 1.8;
- $STATUS_LINE->show;
-
- $ALT_ENTER_MESSAGE = new CFClient::UI::Label
- padding => 0,
- fontsize => 0.8,
- markup => "Use Alt-Enter to toggle fullscreen mode";
- $ALT_ENTER_MESSAGE->show;
- $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
-
- CFClient::UI::FancyFrame->new (
- border_bg => [1, 1, 1, 192/255],
- bg => [1, 1, 1, 0],
- child => ($MAPMAP = new CFClient::MapWidget::MapMap),
- )->show;
-
- $MAPWIDGET = new CFClient::MapWidget;
- $MAPWIDGET->connect (activate_console => sub {
- my ($mapwidget, $preset) = @_;
-
- if ($CONSOLE) {
- $CONSOLE->{input}->{auto_activated} = 1;
- $CONSOLE->{input}->focus_in;
+ if ($DEBUG_STATUS) {
+ # reconfigure all widgets
+ $CFClient::UI::ROOT->reconfigure;
- if ($preset && $CONSOLE->{input}->get_text eq '') {
- $CONSOLE->{input}->set_text ($preset);
+ } else {
+ # create the widgets
+
+ $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
+ $DEBUG_STATUS->show;
+
+ $STATUS_LINE = new CFClient::UI::Label
+ padding => 0,
+ y => $HEIGHT - $FONTSIZE * 1.8;
+ $STATUS_LINE->show;
+
+ $ALT_ENTER_MESSAGE = new CFClient::UI::Label
+ padding => 0,
+ fontsize => 0.8,
+ markup => "Use Alt-Enter to toggle fullscreen mode";
+ $ALT_ENTER_MESSAGE->show;
+ $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
+
+ CFClient::UI::FancyFrame->new (
+ border_bg => [1, 1, 1, 192/255],
+ bg => [1, 1, 1, 0],
+ child => ($MAPMAP = new CFClient::MapWidget::MapMap),
+ )->show;
+
+ $MAPWIDGET = new CFClient::MapWidget;
+ $MAPWIDGET->connect (activate_console => sub {
+ my ($mapwidget, $preset) = @_;
+
+ if ($CONSOLE) {
+ $CONSOLE->{input}->{auto_activated} = 1;
+ $CONSOLE->{input}->focus_in;
+
+ if ($preset && $CONSOLE->{input}->get_text eq '') {
+ $CONSOLE->{input}->set_text ($preset);
+ }
}
- }
- });
- $MAPWIDGET->show;
- $MAPWIDGET->focus_in;
+ });
+ $MAPWIDGET->show;
+ $MAPWIDGET->focus_in;
- $BUTTONBAR = new CFClient::UI::HBox;
+ $BUTTONBAR = new CFClient::UI::HBox;
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
- $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
- $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
+ make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
- $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
- CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
- status "Configuration Saved";
- });
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
+ $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
- $BUTTONBAR->show;
+ $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
+ CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
+ status "Configuration Saved";
+ });
- $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
+ $BUTTONBAR->show;
+
+ $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
+ }
}
sub video_shutdown {
- $CFClient::UI::ROOT->{children} = [];
- undef $CFClient::UI::GRAB;
- undef $CFClient::UI::HOVER;
undef $SDL_ACTIVE;
}
my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
my $bgmusic;#TODO#hack#d#
+sub audio_channel_finished {
+ my ($channel) = @_;
+
+ warn "channel $channel finished\n";#d#
+}
+
sub audio_music_finished {
return unless $CFG->{bgm_enable};
@@ -883,7 +931,7 @@
sub audio_init {
if ($CFG->{audio_enable}) {
- if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
+ if (open my $fh, "<", CFClient::find_rcfile "sounds/config") {
$SDL_MIXER = !CFClient::Mix_OpenAudio;
CFClient::Mix_AllocateChannels 8;
CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
@@ -1304,82 +1352,52 @@
$MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
$MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
}
+
+ $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
+ $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
+ $MAPWIDGET->add_command ("pet\\_mode sad", "Search & Destroy - tell pets to roam about and attack enemies");
+ $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
+}
+
+sub conn::eof {
+ stop_game;
}
sub update_floorbox {
$CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
+ return unless $CONN;
+
$FLOORBOX->clear;
$FLOORBOX->add (new CFClient::UI::Empty expand => 1);
- my @items = values %{ $CONN->{container}{0} };
-
# we basically have to use the same sorting as everybody else
- @items = sort { $a->{type} <=> $b->{type} } @items;
-
- for my $item (reverse @items) {
- my $desc = $item->{nrof} < 2
- ? $item->{name}
- : "$item->{nrof} $item->{name_pl}";
- # todo: animation widget, face widget, weight(?) etc.
- $FLOORBOX->add (my $hbox = new CFClient::UI::HBox
- tooltip => (CFClient::UI::Label->escape ($desc)
- . "\nleftclick - pick up\nmiddle click - apply\nrightclick - menu"),
- can_hover => 1,
- can_events => 1,
- connect_button_down => sub {
- my ($self, $ev, $x, $y) = @_;
-
- # todo: maybe put examine on 1? but should just be a tooltip :(
- if ($ev->{button} == 1) {
- $CONN->send ("move $CONN->{player}{tag} $item->{tag} 0");
- } elsif ($ev->{button} == 2) {
- $CONN->send ("apply $item->{tag}");
- } elsif ($ev->{button} == 3) {
- CFClient::UI::Menu->new (
- items => [
- ["examine", sub { $CONN->send ("examine $item->{tag}") }],
- [
- $item->{flags} & Crossfire::Protocol::F_LOCKED ? "lock" : "unlock",
- sub { $CONN->send ("lock $item->{tag}") },
- ],
- ["mark", sub { $CONN->send ("mark $item->{tag}") }],
- ["apply", sub { $CONN->send ("apply $item->{tag}") }],
- ],
- )->popup ($ev);
- }
-
- 1
- },
- );
-
- $hbox->add (new CFClient::UI::Face
- can_events => 0,
- face => $item->{face},
- anim => $item->{anim},
- animspeed => $item->{animspeed},
- );
-
- $hbox->add (new CFClient::UI::Label
- can_events => 0,
- text => $desc,
- );
+ for my $item (@{ $CONN->{container}{0} }) {
+ $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item);
}
});
refresh;
}
sub conn::container_add {
- my ($self, $id, $items) = @_;
+ my ($self, $tag, $items) = @_;
+
+ update_floorbox if $tag == 0;
+
+ $INV->set_items ($self->{container}{$self->{player}{tag}})
+ if $tag == $self->{player}{tag};
- update_floorbox if $id == 0;
# $self-<{player}{tag} => player inv
#use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
}
sub conn::container_clear {
- my ($self, $id) = @_;
+ my ($self, $tag) = @_;
+
+ update_floorbox if $tag == 0;
+
+ $INV->set_items ($self->{container}{$tag})
+ if $tag == $self->{player}{tag};
- update_floorbox if $id == 0;
# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
}
@@ -1388,6 +1406,9 @@
for (@items) {
update_floorbox if $_->{container} == 0;
+
+ $INV->set_items ($self->{container}{$_->{container}})
+ if $_->{container} == $self->{player}{tag};
}
}
@@ -1395,6 +1416,9 @@
my ($self, $item) = @_;
update_floorbox if $item->{container} == 0;
+
+ $INV->set_items ($self->{container}{$item->{container}})
+ if $item->{container}; == $self->{player}{tag};
}
%SDL_CB = (
@@ -1417,22 +1441,28 @@
CFClient::UI::feed_sdl_key_down_event ($_[0]);
}
},
- CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
- CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
+ CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
+ CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
- CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
- CFClient::SDL_USEREVENT => \&audio_music_finished,
+ CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
+ CFClient::SDL_USEREVENT => sub {
+ if ($_[0]{code} == 1) {
+ audio_channel_finished $_[0]{data1};
+ } elsif ($_[0]{code} == 0) {
+ audio_music_finished;
+ }
+ },
);
#############################################################################
$SIG{INT} = $SIG{TERM} = sub { exit };
+CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
+
$TILECACHE = CFClient::db_table "tilecache";
$FACEMAP = CFClient::db_table "facemap";
-CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
-
my %DEF_CFG = (
sdl_mode => 0,
width => 640,