1 |
root |
1.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 |
root |
1.2 |
my @add; |
42 |
|
|
|
43 |
|
|
push @add, |
44 |
|
|
1, 0, (new CFPlus::UI::Label text => "Spell Name", @TOOLTIP_NAME), |
45 |
|
|
2, 0, (new CFPlus::UI::Label text => "Skill", @TOOLTIP_SKILL), |
46 |
|
|
3, 0, (new CFPlus::UI::Label text => "Lvl" , @TOOLTIP_LVL), |
47 |
|
|
4, 0, (new CFPlus::UI::Label text => "Sp/Gp", @TOOLTIP_SP), |
48 |
|
|
5, 0, (new CFPlus::UI::Label text => "Dmg" , @TOOLTIP_DMG), |
49 |
|
|
; |
50 |
root |
1.1 |
|
51 |
|
|
my $row = 0; |
52 |
|
|
|
53 |
|
|
for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
54 |
|
|
my $spell = $self->{spell}{$_}; |
55 |
|
|
|
56 |
|
|
$row++; |
57 |
|
|
|
58 |
|
|
my $spell_cb = sub { |
59 |
|
|
my ($widget, $ev) = @_; |
60 |
|
|
|
61 |
|
|
if ($ev->{button} == 1) { |
62 |
|
|
$::CONN->user_send ("cast $spell->{name}"); |
63 |
|
|
} elsif ($ev->{button} == 2) { |
64 |
|
|
$::CONN->user_send ("invoke $spell->{name}"); |
65 |
|
|
} elsif ($ev->{button} == 3) { |
66 |
|
|
my $shortname = CFPlus::shorten $spell->{name}, 14; |
67 |
|
|
(new CFPlus::UI::Menu |
68 |
|
|
items => [ |
69 |
|
|
["bind <i>cast $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["cast $spell->{name}"] }], |
70 |
|
|
["bind <i>invoke $shortname</i> to a key" => sub { CFPlus::Macro::quick_macro ["invoke $spell->{name}"] }], |
71 |
|
|
], |
72 |
|
|
)->popup ($ev); |
73 |
|
|
} else { |
74 |
|
|
return 0; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
1 |
78 |
|
|
}; |
79 |
|
|
|
80 |
|
|
my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL; |
81 |
|
|
|
82 |
|
|
#TODO: add path info to tooltip |
83 |
root |
1.2 |
#push @add, 6, $row, new CFPlus::UI::Label text => $spell->{path}; |
84 |
root |
1.1 |
|
85 |
root |
1.2 |
push @add, 0, $row, new CFPlus::UI::Face |
86 |
root |
1.1 |
face => $spell->{face}, |
87 |
|
|
can_hover => 1, |
88 |
|
|
can_events => 1, |
89 |
|
|
tooltip => $tooltip, |
90 |
|
|
on_button_down => $spell_cb, |
91 |
root |
1.2 |
; |
92 |
root |
1.1 |
|
93 |
root |
1.2 |
push @add, 1, $row, new CFPlus::UI::Label |
94 |
root |
1.1 |
expand => 1, |
95 |
|
|
text => $spell->{name}, |
96 |
|
|
can_hover => 1, |
97 |
|
|
can_events => 1, |
98 |
|
|
tooltip => $tooltip, |
99 |
|
|
on_button_down => $spell_cb, |
100 |
root |
1.2 |
; |
101 |
root |
1.1 |
|
102 |
root |
1.2 |
push @add, |
103 |
|
|
2, $row, (new CFPlus::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL), |
104 |
|
|
3, $row, (new CFPlus::UI::Label text => $spell->{level}, @TOOLTIP_LVL), |
105 |
|
|
4, $row, (new CFPlus::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP), |
106 |
|
|
5, $row, (new CFPlus::UI::Label text => $spell->{damage}, @TOOLTIP_DMG), |
107 |
|
|
; |
108 |
root |
1.1 |
} |
109 |
root |
1.2 |
|
110 |
|
|
$self->add_at (@add); |
111 |
root |
1.1 |
}); |
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 |
|
|
|