… | |
… | |
272 | |
272 | |
273 | return unless $self->{visible}; |
273 | return unless $self->{visible}; |
274 | |
274 | |
275 | $_->set_invisible for $self->children; |
275 | $_->set_invisible for $self->children; |
276 | |
276 | |
|
|
277 | delete $self->{visible}; |
277 | delete $self->{root}; |
278 | delete $self->{root}; |
278 | delete $self->{visible}; |
|
|
279 | |
279 | |
280 | undef $GRAB if $GRAB == $self; |
280 | undef $GRAB if $GRAB == $self; |
281 | undef $HOVER if $HOVER == $self; |
281 | undef $HOVER if $HOVER == $self; |
282 | |
282 | |
283 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
283 | $CFClient::UI::TOOLTIP_WATCHER->cb->() |
… | |
… | |
593 | |
593 | |
594 | sub DESTROY { |
594 | sub DESTROY { |
595 | my ($self) = @_; |
595 | my ($self) = @_; |
596 | |
596 | |
597 | delete $WIDGET{$self+0}; |
597 | delete $WIDGET{$self+0}; |
598 | #$self->deactivate; |
598 | |
|
|
599 | eval { $self->destroy }; |
|
|
600 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
599 | } |
601 | } |
600 | |
602 | |
601 | ############################################################################# |
603 | ############################################################################# |
602 | |
604 | |
603 | package CFClient::UI::DrawBG; |
605 | package CFClient::UI::DrawBG; |
… | |
… | |
768 | } |
770 | } |
769 | |
771 | |
770 | sub add { |
772 | sub add { |
771 | my ($self, $child) = @_; |
773 | my ($self, $child) = @_; |
772 | |
774 | |
773 | $self->{children} = []; |
775 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
774 | |
|
|
775 | $self->SUPER::add ($child); |
776 | $self->SUPER::add ($child); |
776 | } |
777 | } |
777 | |
778 | |
778 | sub remove { |
779 | sub remove { |
779 | my ($self, $widget) = @_; |
780 | my ($self, $widget) = @_; |
… | |
… | |
1071 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1072 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1072 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1073 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1073 | |
1074 | |
1074 | sub new { |
1075 | sub new { |
1075 | my ($class, %arg) = @_; |
1076 | my ($class, %arg) = @_; |
1076 | |
|
|
1077 | my $title = delete $arg{title}; |
|
|
1078 | |
1077 | |
1079 | my $self = $class->SUPER::new ( |
1078 | my $self = $class->SUPER::new ( |
1080 | bg => [1, 1, 1, 1], |
1079 | bg => [1, 1, 1, 1], |
1081 | border_bg => [1, 1, 1, 1], |
1080 | border_bg => [1, 1, 1, 1], |
1082 | border => 0.6, |
1081 | border => 0.6, |
… | |
… | |
1084 | min_w => 16, |
1083 | min_w => 16, |
1085 | min_h => 16, |
1084 | min_h => 16, |
1086 | %arg, |
1085 | %arg, |
1087 | ); |
1086 | ); |
1088 | |
1087 | |
1089 | $self->{title} = new CFClient::UI::Label |
1088 | $self->{title_widget} = new CFClient::UI::Label |
1090 | align => 0, |
1089 | align => 0, |
1091 | valign => 1, |
1090 | valign => 1, |
1092 | text => $title, |
1091 | text => $self->{title}, |
1093 | fontsize => $self->{border} |
1092 | fontsize => $self->{border}, |
1094 | if defined $title; |
1093 | if exists $self->{title}; |
1095 | |
1094 | |
1096 | $self |
1095 | $self |
1097 | } |
1096 | } |
1098 | |
1097 | |
1099 | sub add { |
1098 | sub add { |
1100 | my ($self, @widgets) = @_; |
1099 | my ($self, @widgets) = @_; |
1101 | |
1100 | |
1102 | $self->SUPER::add (@widgets); |
1101 | $self->SUPER::add (@widgets); |
1103 | $self->CFClient::UI::Container::add ($self->{title}) if $self->{title}; |
1102 | $self->CFClient::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1104 | } |
1103 | } |
1105 | |
1104 | |
1106 | sub border { |
1105 | sub border { |
1107 | int $_[0]{border} * $::FONTSIZE |
1106 | int $_[0]{border} * $::FONTSIZE |
1108 | } |
1107 | } |
1109 | |
1108 | |
1110 | sub size_request { |
1109 | sub size_request { |
1111 | my ($self) = @_; |
1110 | my ($self) = @_; |
1112 | |
1111 | |
1113 | $self->{title}->size_request |
1112 | $self->{title_widget}->size_request |
1114 | if $self->{title}; |
1113 | if $self->{title_widget}; |
1115 | |
1114 | |
1116 | my ($w, $h) = $self->SUPER::size_request; |
1115 | my ($w, $h) = $self->SUPER::size_request; |
1117 | |
1116 | |
1118 | ( |
1117 | ( |
1119 | $w + $self->border * 2, |
1118 | $w + $self->border * 2, |
… | |
… | |
1122 | } |
1121 | } |
1123 | |
1122 | |
1124 | sub size_allocate { |
1123 | sub size_allocate { |
1125 | my ($self, $w, $h) = @_; |
1124 | my ($self, $w, $h) = @_; |
1126 | |
1125 | |
1127 | if ($self->{title}) { |
1126 | if ($self->{title_widget}) { |
1128 | $self->{title}{w} = $w; |
1127 | $self->{title_widget}{w} = $w; |
1129 | $self->{title}{h} = $h; |
1128 | $self->{title_widget}{h} = $h; |
1130 | $self->{title}->size_allocate ($w, $h); |
1129 | $self->{title_widget}->size_allocate ($w, $h); |
1131 | } |
1130 | } |
1132 | |
1131 | |
1133 | my $border = $self->border; |
1132 | my $border = $self->border; |
1134 | |
1133 | |
1135 | $h -= List::Util::max 0, $border * 2; |
1134 | $h -= List::Util::max 0, $border * 2; |
… | |
… | |
1233 | |
1232 | |
1234 | glDisable GL_TEXTURE_2D; |
1233 | glDisable GL_TEXTURE_2D; |
1235 | |
1234 | |
1236 | $child->draw; |
1235 | $child->draw; |
1237 | |
1236 | |
1238 | if ($self->{title}) { |
1237 | if ($self->{title_widget}) { |
1239 | glTranslate 0, $border - $self->{h}; |
1238 | glTranslate 0, $border - $self->{h}; |
1240 | $self->{title}->_draw; |
1239 | $self->{title_widget}->_draw; |
1241 | } |
1240 | } |
1242 | } |
1241 | } |
1243 | |
1242 | |
1244 | ############################################################################# |
1243 | ############################################################################# |
1245 | |
1244 | |
… | |
… | |
1269 | |
1268 | |
1270 | $child->set_parent ($self); |
1269 | $child->set_parent ($self); |
1271 | $self->{children}[$y][$x] = $child; |
1270 | $self->{children}[$y][$x] = $child; |
1272 | |
1271 | |
1273 | $self->realloc; |
1272 | $self->realloc; |
|
|
1273 | } |
|
|
1274 | |
|
|
1275 | sub remove { |
|
|
1276 | my ($self, $child) = @_; |
|
|
1277 | |
|
|
1278 | # TODO: not yet implemented |
1274 | } |
1279 | } |
1275 | |
1280 | |
1276 | # TODO: move to container class maybe? send children a signal on removal? |
1281 | # TODO: move to container class maybe? send children a signal on removal? |
1277 | sub clear { |
1282 | sub clear { |
1278 | my ($self) = @_; |
1283 | my ($self) = @_; |
… | |
… | |
2897 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2902 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2898 | glDisable GL_TEXTURE_2D; |
2903 | glDisable GL_TEXTURE_2D; |
2899 | } |
2904 | } |
2900 | } |
2905 | } |
2901 | |
2906 | |
2902 | sub DESTROY { |
2907 | sub destroy { |
2903 | my ($self) = @_; |
2908 | my ($self) = @_; |
2904 | |
2909 | |
2905 | $self->{timer}->cancel |
2910 | $self->{timer}->cancel |
2906 | if $self->{timer}; |
2911 | if $self->{timer}; |
2907 | |
2912 | |
2908 | $self->SUPER::DESTROY; |
2913 | $self->SUPER::destroy; |
2909 | } |
2914 | } |
2910 | |
2915 | |
2911 | ############################################################################# |
2916 | ############################################################################# |
2912 | |
2917 | |
2913 | package CFClient::UI::Buttonbar; |
2918 | package CFClient::UI::Buttonbar; |
… | |
… | |
3263 | $item->{count}++; |
3268 | $item->{count}++; |
3264 | } else { |
3269 | } else { |
3265 | $item->{count} = 1; |
3270 | $item->{count} = 1; |
3266 | $item->{text} = $item->{tooltip} = $text; |
3271 | $item->{text} = $item->{tooltip} = $text; |
3267 | } |
3272 | } |
3268 | $item->{id} = ++$self->{id}; |
3273 | $item->{id} += 0.2;#d# |
3269 | $item->{timeout} = $timeout; |
3274 | $item->{timeout} = $timeout; |
3270 | delete $item->{label}; |
3275 | delete $item->{label}; |
3271 | } else { |
3276 | } else { |
3272 | $self->{item}{$group} = { |
3277 | $self->{item}{$group} = { |
3273 | id => ++$self->{id}, |
3278 | id => ++$self->{id}, |
… | |
… | |
3292 | |
3297 | |
3293 | $self->reorder; |
3298 | $self->reorder; |
3294 | $self->SUPER::reconfigure; |
3299 | $self->SUPER::reconfigure; |
3295 | } |
3300 | } |
3296 | |
3301 | |
3297 | sub DESTROY { |
3302 | sub destroy { |
3298 | my ($self) = @_; |
3303 | my ($self) = @_; |
3299 | |
3304 | |
3300 | $self->{timer}->cancel; |
3305 | $self->{timer}->cancel; |
3301 | |
3306 | |
3302 | $self->SUPER::DESTROY; |
3307 | $self->SUPER::destroy; |
3303 | } |
3308 | } |
3304 | |
3309 | |
3305 | ############################################################################# |
3310 | ############################################################################# |
3306 | |
3311 | |
3307 | package CFClient::UI::Inventory; |
3312 | package CFClient::UI::Inventory; |
… | |
… | |
3557 | ) |
3562 | ) |
3558 | } |
3563 | } |
3559 | |
3564 | |
3560 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
3565 | my $TOOLTIP_ALL = "\n\n<small>Left click - ready spell\nMiddle click - invoke spell\nRight click - further options</small>"; |
3561 | |
3566 | |
3562 | my @TOOLTIP_NAME = (align => 0, can_events => 1, can_hover => 1, tooltip => |
3567 | my @TOOLTIP_NAME = (align => -1, can_events => 1, can_hover => 1, tooltip => |
3563 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
3568 | "<b>Name</b>. The name of the spell.$TOOLTIP_ALL"); |
|
|
3569 | my @TOOLTIP_SKILL = (align => -1, can_events => 1, can_hover => 1, tooltip => |
|
|
3570 | "<b>Skill</b>. The skill (or magic school) required to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3564 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3571 | my @TOOLTIP_LVL = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3565 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3572 | "<b>Level</b>. Minimum level the caster needs in the associated skill to be able to attempt casting this spell.$TOOLTIP_ALL"); |
3566 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3573 | my @TOOLTIP_SP = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3567 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
3574 | "<b>Spell points / Grace points</b>. Amount of spell or grace points used by each invocation.$TOOLTIP_ALL"); |
3568 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
3575 | my @TOOLTIP_DMG = (align => 1, can_events => 1, can_hover => 1, tooltip => |
… | |
… | |
3572 | my ($self) = @_; |
3579 | my ($self) = @_; |
3573 | |
3580 | |
3574 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3581 | $CFClient::UI::ROOT->on_refresh ($self => sub { |
3575 | $self->clear; |
3582 | $self->clear; |
3576 | |
3583 | |
|
|
3584 | return unless $::CONN; |
|
|
3585 | |
3577 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
3586 | $self->add (1, 0, new CFClient::UI::Label text => "Spell Name", @TOOLTIP_NAME); |
|
|
3587 | $self->add (2, 0, new CFClient::UI::Label text => "Skill", @TOOLTIP_SKILL); |
3578 | $self->add (2, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3588 | $self->add (3, 0, new CFClient::UI::Label text => "Lvl" , @TOOLTIP_LVL); |
3579 | $self->add (3, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3589 | $self->add (4, 0, new CFClient::UI::Label text => "Sp/Gp", @TOOLTIP_SP); |
3580 | $self->add (4, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3590 | $self->add (5, 0, new CFClient::UI::Label text => "Dmg" , @TOOLTIP_DMG); |
3581 | |
3591 | |
3582 | my $row = 0; |
3592 | my $row = 0; |
3583 | |
3593 | |
3584 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3594 | for (sort { $a cmp $b } keys %{ $self->{spell} }) { |
3585 | my $spell = $self->{spell}{$_}; |
3595 | my $spell = $self->{spell}{$_}; |
… | |
… | |
3605 | } |
3615 | } |
3606 | |
3616 | |
3607 | 1 |
3617 | 1 |
3608 | }; |
3618 | }; |
3609 | |
3619 | |
|
|
3620 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
|
|
3621 | |
|
|
3622 | #TODO: add path info to tooltip |
|
|
3623 | #$self->add (6, $row, new CFClient::UI::Label text => $spell->{path}); |
|
|
3624 | |
3610 | $self->add (0, $row, new CFClient::UI::Face |
3625 | $self->add (0, $row, new CFClient::UI::Face |
3611 | face => $spell->{face}, |
3626 | face => $spell->{face}, |
3612 | can_hover => 1, |
3627 | can_hover => 1, |
3613 | can_events => 1, |
3628 | can_events => 1, |
3614 | tooltip => $spell->{message}, |
3629 | tooltip => $tooltip, |
3615 | on_button_down => $spell_cb, |
3630 | on_button_down => $spell_cb, |
3616 | ); |
3631 | ); |
3617 | |
3632 | |
3618 | $self->add (1, $row, new CFClient::UI::Label |
3633 | $self->add (1, $row, new CFClient::UI::Label |
3619 | expand => 1, |
3634 | expand => 1, |
3620 | text => $spell->{name}, |
3635 | text => $spell->{name}, |
3621 | can_hover => 1, |
3636 | can_hover => 1, |
3622 | can_events => 1, |
3637 | can_events => 1, |
3623 | tooltip => "$spell->{message}$TOOLTIP_ALL", |
3638 | tooltip => $tooltip, |
3624 | on_button_down => $spell_cb, |
3639 | on_button_down => $spell_cb, |
3625 | ); |
3640 | ); |
3626 | |
3641 | |
|
|
3642 | $self->add (2, $row, new CFClient::UI::Label text => $::CONN->{skill_info}{$spell->{skill}}, @TOOLTIP_SKILL); |
3627 | $self->add (2, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3643 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{level}, @TOOLTIP_LVL); |
3628 | $self->add (3, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3644 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{mana} || $spell->{grace}, @TOOLTIP_SP); |
3629 | $self->add (4, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3645 | $self->add (5, $row, new CFClient::UI::Label text => $spell->{damage}, @TOOLTIP_DMG); |
3630 | } |
3646 | } |
3631 | }); |
3647 | }); |
3632 | } |
3648 | } |
3633 | |
3649 | |
3634 | sub add_spell { |
3650 | sub add_spell { |
… | |
… | |
3640 | |
3656 | |
3641 | sub remove_spell { |
3657 | sub remove_spell { |
3642 | my ($self, $spell) = @_; |
3658 | my ($self, $spell) = @_; |
3643 | |
3659 | |
3644 | delete $self->{spell}->{$spell->{name}}; |
3660 | delete $self->{spell}->{$spell->{name}}; |
|
|
3661 | $self->rebuild_spell_list; |
|
|
3662 | } |
|
|
3663 | |
|
|
3664 | sub clear_spells { |
|
|
3665 | my ($self) = @_; |
|
|
3666 | |
|
|
3667 | $self->{spell} = {}; |
3645 | $self->rebuild_spell_list; |
3668 | $self->rebuild_spell_list; |
3646 | } |
3669 | } |
3647 | |
3670 | |
3648 | ############################################################################# |
3671 | ############################################################################# |
3649 | |
3672 | |