ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/SpellList.pm
Revision: 1.4
Committed: Wed Dec 26 21:03:21 2007 UTC (16 years, 7 months ago) by root
Branch: MAIN
Changes since 1.3: +21 -21 lines
Log Message:
initial module hiding

File Contents

# User Rev Content
1 root 1.4 package DC::UI::SpellList;
2 root 1.1
3     use strict;
4     use utf8;
5    
6 root 1.4 use DC::Macro;
7 root 1.1
8 root 1.4 our @ISA = DC::UI::Table::;
9 root 1.1
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 root 1.4 $DC::UI::ROOT->on_refresh ($self => sub {
37 root 1.1 $self->clear;
38    
39     return unless $::CONN;
40    
41 root 1.2 my @add;
42    
43     push @add,
44 root 1.4 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 root 1.2 ;
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 root 1.4 my $shortname = DC::shorten $spell->{name}, 14;
67     (new DC::UI::Menu
68 root 1.1 items => [
69 root 1.4 ["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 root 1.1 ],
72     )->popup ($ev);
73     } else {
74     return 0;
75     }
76    
77     1
78     };
79    
80 root 1.4 my $tooltip = (DC::asxml $spell->{message}) . $TOOLTIP_ALL;
81 root 1.1
82     #TODO: add path info to tooltip
83 root 1.4 #push @add, 6, $row, new DC::UI::Label text => $spell->{path};
84 root 1.1
85 root 1.4 push @add, 0, $row, new DC::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.4 push @add, 1, $row, new DC::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 root 1.4 2, $row, (new DC::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL),
104     3, $row, (new DC::UI::Label text => $spell->{level}, @TOOLTIP_LVL),
105     4, $row, (new DC::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP),
106     5, $row, (new DC::UI::Label text => $spell->{damage}, @TOOLTIP_DMG),
107 root 1.2 ;
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