| 1 |
package DC::UI::SpellList; |
| 2 |
|
| 3 |
use common::sense; |
| 4 |
|
| 5 |
use DC::Macro; |
| 6 |
|
| 7 |
our @ISA = DC::UI::Table::; |
| 8 |
|
| 9 |
sub new { |
| 10 |
my $class = shift; |
| 11 |
|
| 12 |
my $self = $class->SUPER::new ( |
| 13 |
binding => [], |
| 14 |
commands => [], |
| 15 |
@_, |
| 16 |
) |
| 17 |
} |
| 18 |
|
| 19 |
my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
| 20 |
|
| 21 |
my @TOOLTIP_NAME = (align => 0, can_events => 1, can_hover => 1, tooltip => |
| 22 |
"<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
| 23 |
my @TOOLTIP_SKILL = (align => 0, can_events => 1, can_hover => 1, tooltip => |
| 24 |
"<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
| 25 |
my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
| 26 |
"<b>Effective Casting Level</b>. The effective level of the spell - figures in caster level, attuned and repelled.$TOOLTIP_ALL"); |
| 27 |
my @TOOLTIP_MIN = (align => 1, can_events => 1, can_hover => 1, tooltip => |
| 28 |
"<b>Minmimum</b>. Minimum level (without attuned/repelled adjustment) that the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
| 29 |
my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
| 30 |
"<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
| 31 |
|
| 32 |
sub rebuild_spell_list { |
| 33 |
my ($self) = @_; |
| 34 |
|
| 35 |
$DC::UI::ROOT->on_refresh ($self => sub { |
| 36 |
$self->clear; |
| 37 |
|
| 38 |
return unless $::CONN; |
| 39 |
|
| 40 |
my @add; |
| 41 |
|
| 42 |
push @add, |
| 43 |
1, 0, (new DC::UI::Label text => "Spell Name", @TOOLTIP_NAME), |
| 44 |
2, 0, (new DC::UI::Label text => "Skill", @TOOLTIP_SKILL), |
| 45 |
3, 0, (new DC::UI::Label text => "Min" , @TOOLTIP_MIN), |
| 46 |
4, 0, (new DC::UI::Label text => "Lvl" , @TOOLTIP_LVL), |
| 47 |
5, 0, (new DC::UI::Label text => "Sp/Gp", @TOOLTIP_SP), |
| 48 |
; |
| 49 |
|
| 50 |
my $row = 0; |
| 51 |
|
| 52 |
for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
| 53 |
my $spell = $self->{spell}{$_}; |
| 54 |
|
| 55 |
$row++; |
| 56 |
|
| 57 |
my $spell_cb = sub { |
| 58 |
my ($widget, $ev) = @_; |
| 59 |
|
| 60 |
if ($ev->{button} == 1) { |
| 61 |
$::CONN->user_send ("cast $spell->{name}"); |
| 62 |
} elsif ($ev->{button} == 2) { |
| 63 |
$::CONN->user_send ("invoke $spell->{name}"); |
| 64 |
} elsif ($ev->{button} == 3) { |
| 65 |
my $shortname = DC::shorten $spell->{name}, 14; |
| 66 |
(new DC::UI::Menu |
| 67 |
items => [ |
| 68 |
["bind <i>cast $shortname</i> to a key" => sub { DC::Macro::quick_macro ["cast $spell->{name}"] }], |
| 69 |
["bind <i>invoke $shortname</i> to a key" => sub { DC::Macro::quick_macro ["invoke $spell->{name}"] }], |
| 70 |
], |
| 71 |
)->popup ($ev); |
| 72 |
} else { |
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
1 |
| 77 |
}; |
| 78 |
|
| 79 |
my $tooltip = "#(spell/$spell->{name})$TOOLTIP_ALL"; |
| 80 |
|
| 81 |
#TODO: add path info to tooltip |
| 82 |
#push @add, 6, $row, new DC::UI::Label text => $spell->{path}; |
| 83 |
|
| 84 |
push @add, 0, $row, new DC::UI::Face |
| 85 |
face => $spell->{face}, |
| 86 |
can_hover => 1, |
| 87 |
can_events => 1, |
| 88 |
tooltip => $tooltip, |
| 89 |
on_button_down => $spell_cb, |
| 90 |
; |
| 91 |
|
| 92 |
push @add, 1, $row, new DC::UI::Label |
| 93 |
expand => 1, |
| 94 |
text => $spell->{name}, |
| 95 |
align => 0, |
| 96 |
can_hover => 1, |
| 97 |
can_events => 1, |
| 98 |
tooltip => $tooltip, |
| 99 |
on_button_down => $spell_cb, |
| 100 |
; |
| 101 |
|
| 102 |
push @add, |
| 103 |
2, $row, (new DC::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL), |
| 104 |
3, $row, (new DC::UI::Label text => $spell->{minlevel}, @TOOLTIP_MIN), |
| 105 |
4, $row, (new DC::UI::Label text => $spell->{level}, @TOOLTIP_LVL), |
| 106 |
5, $row, (new DC::UI::Label text => $spell->{mana} ? "$spell->{mana} sp" : "$spell->{grace} gp", @TOOLTIP_SP), |
| 107 |
; |
| 108 |
} |
| 109 |
|
| 110 |
$self->add_at (@add); |
| 111 |
}); |
| 112 |
} |
| 113 |
|
| 114 |
sub add_spell { |
| 115 |
my ($self, $spell) = @_; |
| 116 |
|
| 117 |
$self->{spell}->{$spell->{name}} = $spell; |
| 118 |
$self->rebuild_spell_list; |
| 119 |
} |
| 120 |
|
| 121 |
sub remove_spell { |
| 122 |
my ($self, $spell) = @_; |
| 123 |
|
| 124 |
delete $self->{spell}->{$spell->{name}}; |
| 125 |
$self->rebuild_spell_list; |
| 126 |
} |
| 127 |
|
| 128 |
sub clear_spells { |
| 129 |
my ($self) = @_; |
| 130 |
|
| 131 |
$self->{spell} = {}; |
| 132 |
$self->rebuild_spell_list; |
| 133 |
} |
| 134 |
|
| 135 |
1 |
| 136 |
|