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