ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/SpellList.pm
Revision: 1.5
Committed: Sat Dec 29 13:44:31 2007 UTC (16 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-2_03, rel-2_02, rel-0_9965, rel-0_9964, rel-0_9963, rel-2_05, rel-2_04, rel-0_9968, rel-2_0, rel-2_10, rel-0_9972, rel-0_9973, rel-0_9974, rel-0_9975, rel-0_9976, rel-0_9977, rel-0_9978, rel-0_9971, rel-0_9967, rel-1_21, rel-0_9966
Changes since 1.4: +3 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package DC::UI::SpellList;
2
3 use strict;
4 use utf8;
5
6 use DC::Macro;
7
8 our @ISA = DC::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 => 0, can_events => 1, can_hover => 1, tooltip =>
23 "<b>Name</b>. The name of the spell.$TOOLTIP_ALL");
24 my @TOOLTIP_SKILL = (align => 0, 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 $DC::UI::ROOT->on_refresh ($self => sub {
37 $self->clear;
38
39 return unless $::CONN;
40
41 my @add;
42
43 push @add,
44 1, 0, (new DC::UI::Label text => "Spell Name", @TOOLTIP_NAME),
45 2, 0, (new DC::UI::Label text => "Skill", @TOOLTIP_SKILL),
46 3, 0, (new DC::UI::Label text => "Lvl" , @TOOLTIP_LVL),
47 4, 0, (new DC::UI::Label text => "Sp/Gp", @TOOLTIP_SP),
48 5, 0, (new DC::UI::Label text => "Dmg" , @TOOLTIP_DMG),
49 ;
50
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 = DC::shorten $spell->{name}, 14;
67 (new DC::UI::Menu
68 items => [
69 ["bind <i>cast $shortname</i> to a key" => sub { DC::Macro::quick_macro ["cast $spell->{name}"] }],
70 ["bind <i>invoke $shortname</i> to a key" => sub { DC::Macro::quick_macro ["invoke $spell->{name}"] }],
71 ],
72 )->popup ($ev);
73 } else {
74 return 0;
75 }
76
77 1
78 };
79
80 my $tooltip = (DC::asxml $spell->{message}) . $TOOLTIP_ALL;
81
82 #TODO: add path info to tooltip
83 #push @add, 6, $row, new DC::UI::Label text => $spell->{path};
84
85 push @add, 0, $row, new DC::UI::Face
86 face => $spell->{face},
87 can_hover => 1,
88 can_events => 1,
89 tooltip => $tooltip,
90 on_button_down => $spell_cb,
91 ;
92
93 push @add, 1, $row, new DC::UI::Label
94 expand => 1,
95 text => $spell->{name},
96 align => 0,
97 can_hover => 1,
98 can_events => 1,
99 tooltip => $tooltip,
100 on_button_down => $spell_cb,
101 ;
102
103 push @add,
104 2, $row, (new DC::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL),
105 3, $row, (new DC::UI::Label text => $spell->{level}, @TOOLTIP_LVL),
106 4, $row, (new DC::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP),
107 5, $row, (new DC::UI::Label text => $spell->{damage}, @TOOLTIP_DMG),
108 ;
109 }
110
111 $self->add_at (@add);
112 });
113 }
114
115 sub add_spell {
116 my ($self, $spell) = @_;
117
118 $self->{spell}->{$spell->{name}} = $spell;
119 $self->rebuild_spell_list;
120 }
121
122 sub remove_spell {
123 my ($self, $spell) = @_;
124
125 delete $self->{spell}->{$spell->{name}};
126 $self->rebuild_spell_list;
127 }
128
129 sub clear_spells {
130 my ($self) = @_;
131
132 $self->{spell} = {};
133 $self->rebuild_spell_list;
134 }
135
136 1
137