package dc::UI::SpellList; use strict; use utf8; use dc::Macro; our @ISA = dc::UI::Table::; sub new { my $class = shift; my $self = $class->SUPER::new ( binding => [], commands => [], @_, ) } my $TOOLTIP_ALL = "\n\nLeft click - ready spell\nMiddle click - invoke spell\nRight click - further options"; my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => "Name. The name of the spell.$TOOLTIP_ALL"); my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => "Skill. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => "Level. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => "Spell points / Grace points. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => "Damage. The amount of damage the spell deals when it hits.$TOOLTIP_ALL"); sub rebuild_spell_list { my ($self) = @_; $dc::UI::ROOT->on_refresh ($self => sub { $self->clear; return unless $::CONN; my @add; push @add, 1, 0, (new dc::UI::Label text => "Spell Name", @TOOLTIP_NAME), 2, 0, (new dc::UI::Label text => "Skill", @TOOLTIP_SKILL), 3, 0, (new dc::UI::Label text => "Lvl" , @TOOLTIP_LVL), 4, 0, (new dc::UI::Label text => "Sp/Gp", @TOOLTIP_SP), 5, 0, (new dc::UI::Label text => "Dmg" , @TOOLTIP_DMG), ; my $row = 0; for (sort { $a cmp $b } keys %{ $self->{spell} }) { my $spell = $self->{spell}{$_}; $row++; my $spell_cb = sub { my ($widget, $ev) = @_; if ($ev->{button} == 1) { $::CONN->user_send ("cast $spell->{name}"); } elsif ($ev->{button} == 2) { $::CONN->user_send ("invoke $spell->{name}"); } elsif ($ev->{button} == 3) { my $shortname = dc::shorten $spell->{name}, 14; (new dc::UI::Menu items => [ ["bind cast $shortname to a key" => sub { dc::Macro::quick_macro ["cast $spell->{name}"] }], ["bind invoke $shortname to a key" => sub { dc::Macro::quick_macro ["invoke $spell->{name}"] }], ], )->popup ($ev); } else { return 0; } 1 }; my $tooltip = (dc::asxml $spell->{message}) . $TOOLTIP_ALL; #TODO: add path info to tooltip #push @add, 6, $row, new dc::UI::Label text => $spell->{path}; push @add, 0, $row, new dc::UI::Face face => $spell->{face}, can_hover => 1, can_events => 1, tooltip => $tooltip, on_button_down => $spell_cb, ; push @add, 1, $row, new dc::UI::Label expand => 1, text => $spell->{name}, can_hover => 1, can_events => 1, tooltip => $tooltip, on_button_down => $spell_cb, ; push @add, 2, $row, (new dc::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL), 3, $row, (new dc::UI::Label text => $spell->{level}, @TOOLTIP_LVL), 4, $row, (new dc::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP), 5, $row, (new dc::UI::Label text => $spell->{damage}, @TOOLTIP_DMG), ; } $self->add_at (@add); }); } sub add_spell { my ($self, $spell) = @_; $self->{spell}->{$spell->{name}} = $spell; $self->rebuild_spell_list; } sub remove_spell { my ($self, $spell) = @_; delete $self->{spell}->{$spell->{name}}; $self->rebuild_spell_list; } sub clear_spells { my ($self) = @_; $self->{spell} = {}; $self->rebuild_spell_list; } 1