Deliantra-Client
view release on metacpan or search on metacpan
DC/MapWidget.pm view on Meta::CPAN
package DC::MapWidget;
use common::sense;
use List::Util qw(min max);
use DC;
use DC::OpenGL;
use DC::UI;
use DC::Macro;
our @ISA = DC::UI::Base::;
our @TEX_HIDDEN = map {
new_from_resource DC::Texture # MUST be POT
"hidden-$_.png", mipmap => 1, wrap => 1
} 0, 1, 2;
my $magicmap_tex =
new_from_resource DC::Texture "magicmap.png",
mipmap => 1, wrap => 0, internalformat => GL_ALPHA;
sub new {
my $class = shift;
my $self = $class->SUPER::new (
z => -1,
can_focus => 1,
tilesize => 32,
@_
);
$self
}
sub add_command {
my ($self, $command, $tooltip, $widget, $cb) = @_;
(my $data = $command) =~ s/\\//g;
$tooltip =~ s/^\s+//;
$tooltip = "<big>$data</big>\n\n$tooltip";
$tooltip =~ s/\s+$//;
$::COMPLETER->{command}{$command} = [$data, $tooltip, $widget, $cb, ++$self->{command_id}];
}
sub clr_commands {
my ($self) = @_;
%{$::COMPLETER->{command}} = ();
$::COMPLETER->hide
if $::COMPLETER;
}
sub server_login {
my ($server) = @_;
::stop_game ();
local $::PROFILE->{host} = $server;
::start_game ();
}
sub editor_invoke {
my $editsup = $::CONN && $::CONN->{editor_support}
or return;
DC::background {
print "preparing editor startup...\n";
DC/MapWidget.pm view on Meta::CPAN
glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
$self->{texture}->draw_quad (0, 0);
glDisable GL_TEXTURE_2D;
glTranslate 0.375, 0.375;
glColor 1, 1, 0, 1;
glBegin GL_LINE_LOOP;
glVertex $self->{x0} , $self->{y0} ;
glVertex $self->{x0} , $self->{y0} + $self->{sh};
glVertex $self->{x0} + $self->{sw}, $self->{y0} + $self->{sh};
glVertex $self->{x0} + $self->{sw}, $self->{y0} ;
glEnd;
glDisable GL_BLEND;
}
package DC::MapWidget::Command;
use common::sense;
use DC::OpenGL;
our @ISA = DC::UI::Frame::;
sub new {
my $class = shift;
my $self = $class->SUPER::new (
bg => [0, 0, 0, 0.8],
@_,
);
$self->add ($self->{vbox} = new DC::UI::VBox);
$self->{label} = [
map
DC::UI::Label->new (
align => 0,
can_hover => 1,
can_events => 1,
tooltip_width => 0.33,
fontsize => $_,
), (0.8) x 16
];
$self->{entry} = new DC::UI::Entry
on_changed => sub {
$self->update_labels;
0
},
on_button_down => sub {
my ($entry, $ev, $x, $y) = @_;
if ($ev->{button} == 3) {
(new DC::UI::Menu
items => [
["bind <i>" . (DC::asxml $self->{select}) . "</i> to a key"
=> sub { DC::Macro::quick_macro [$self->{select}], sub { $entry->grab_focus } }]
],
)->popup ($ev);
return 1;
}
0
},
on_key_down => sub {
my ($entry, $ev) = @_;
my $self = $entry->{parent}{parent};
if ($ev->{sym} == 13) {
if (exists $self->{select}) {
$self->{last_command} = $self->{select};
$::CONN->user_send ($self->{select});
unshift @{$self->{history}}, $self->{entry}->get_text;
$self->{hist_ptr} = 0;
$self->hide;
}
} elsif ($ev->{sym} == 27) {
$self->{hist_ptr} = 0;
$self->hide;
} elsif ($ev->{sym} == DC::SDLK_DOWN) {
if ($self->{hist_ptr} > 1) {
$self->{hist_ptr}--;
$self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
} elsif ($self->{hist_ptr} > 0) {
$self->{hist_ptr}--;
$self->{entry}->set_text ($self->{hist_saveback});
} else {
++$self->{select_offset}
if $self->{select_offset} < $#{ $self->{last_match} || [] };
}
$self->update_labels;
} elsif ($ev->{sym} == DC::SDLK_UP) {
if ($self->{select_offset}) {
--$self->{select_offset}
} else {
unless ($self->{hist_ptr}) {
$self->{hist_saveback} = $self->{entry}->get_text;
}
if ($self->{hist_ptr} <= $#{$self->{history}}) {
$self->{hist_ptr}++;
}
$self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1])
if exists $self->{history}->[$self->{hist_ptr} - 1];
}
$self->update_labels;
} else {
return 0;
}
1
}
;
$self->{vbox}->add (
$self->{entry},
( run in 1.060 second using v1.01-cache-2.11-cpan-0d23b851a93 )