… | |
… | |
423 | my ($self) = @_; |
423 | my ($self) = @_; |
424 | |
424 | |
425 | return if $FOCUS == $self; |
425 | return if $FOCUS == $self; |
426 | return unless $self->{can_focus}; |
426 | return unless $self->{can_focus}; |
427 | |
427 | |
428 | my $focus = $FOCUS; $FOCUS = $self; |
428 | $FOCUS = $self; |
429 | |
429 | |
430 | $focus->update if $focus; |
430 | $self->update; |
431 | $FOCUS->update; |
|
|
432 | |
431 | |
433 | 0 |
432 | 0 |
434 | } |
433 | } |
435 | |
434 | |
436 | sub invoke_focus_out { |
435 | sub invoke_focus_out { |
437 | my ($self) = @_; |
436 | my ($self) = @_; |
438 | |
437 | |
439 | return unless $FOCUS == $self; |
438 | return unless $FOCUS == $self; |
440 | |
439 | |
441 | my $focus = $FOCUS; undef $FOCUS; |
440 | undef $FOCUS; |
442 | |
441 | |
443 | $focus->update if $focus; #? |
442 | $self->update; |
444 | |
443 | |
445 | $::MAPWIDGET->grab_focus #d# focus mapwidget if no other widget has focus |
444 | $::MAPWIDGET->grab_focus #d# focus mapwidget if no other widget has focus |
446 | unless $FOCUS; |
445 | unless $FOCUS; |
447 | |
446 | |
448 | 0 |
447 | 0 |
449 | } |
448 | } |
450 | |
449 | |
451 | sub grab_focus { |
450 | sub grab_focus { |
452 | my ($self) = @_; |
451 | my ($self) = @_; |
453 | |
452 | |
|
|
453 | $FOCUS->emit ("focus_out") if $FOCUS; |
454 | $self->emit ("focus_in"); |
454 | $self->emit ("focus_in"); |
455 | } |
455 | } |
456 | |
456 | |
457 | sub invoke_mouse_motion { 1 } |
457 | sub invoke_mouse_motion { 1 } |
458 | sub invoke_button_up { 1 } |
458 | sub invoke_button_up { 1 } |
… | |
… | |
1096 | |
1096 | |
1097 | if ($self->{has_close_button}) { |
1097 | if ($self->{has_close_button}) { |
1098 | $self->{close_button} = |
1098 | $self->{close_button} = |
1099 | new CFClient::UI::ImageButton |
1099 | new CFClient::UI::ImageButton |
1100 | path => 'x1_close.png', |
1100 | path => 'x1_close.png', |
1101 | on_activate => sub { $self->hide }; |
1101 | on_activate => sub { $self->emit ("delete") }; |
1102 | |
1102 | |
1103 | $self->CFClient::UI::Container::add ($self->{close_button}); |
1103 | $self->CFClient::UI::Container::add ($self->{close_button}); |
1104 | } |
1104 | } |
1105 | |
1105 | |
1106 | $self |
1106 | $self |
… | |
… | |
1152 | $self->child->configure ($border, $border, $w, $h); |
1152 | $self->child->configure ($border, $border, $w, $h); |
1153 | |
1153 | |
1154 | $self->{close_button}->configure ($self->{w} - $border, 0, $border, $border) |
1154 | $self->{close_button}->configure ($self->{w} - $border, 0, $border, $border) |
1155 | if $self->{close_button}; |
1155 | if $self->{close_button}; |
1156 | |
1156 | |
|
|
1157 | 1 |
|
|
1158 | } |
|
|
1159 | |
|
|
1160 | sub invoke_delete { |
|
|
1161 | my ($self) = @_; |
|
|
1162 | |
|
|
1163 | $self->hide; |
|
|
1164 | |
1157 | 1 |
1165 | 1 |
1158 | } |
1166 | } |
1159 | |
1167 | |
1160 | sub invoke_button_down { |
1168 | sub invoke_button_down { |
1161 | my ($self, $ev, $x, $y) = @_; |
1169 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
1654 | |
1662 | |
1655 | sub set_fontsize { |
1663 | sub set_fontsize { |
1656 | my ($self, $fontsize) = @_; |
1664 | my ($self, $fontsize) = @_; |
1657 | |
1665 | |
1658 | $self->{fontsize} = $fontsize; |
1666 | $self->{fontsize} = $fontsize; |
|
|
1667 | delete $self->{size_req}; |
1659 | delete $self->{texture}; |
1668 | delete $self->{texture}; |
1660 | |
1669 | |
1661 | $self->realloc; |
1670 | $self->realloc; |
1662 | } |
1671 | } |
1663 | |
1672 | |
… | |
… | |
2059 | my ($self) = @_; |
2068 | my ($self) = @_; |
2060 | |
2069 | |
2061 | (6) x 2 |
2070 | (6) x 2 |
2062 | } |
2071 | } |
2063 | |
2072 | |
|
|
2073 | sub toggle { |
|
|
2074 | my ($self) = @_; |
|
|
2075 | |
|
|
2076 | $self->{state} = !$self->{state}; |
|
|
2077 | $self->emit (changed => $self->{state}); |
|
|
2078 | $self->update; |
|
|
2079 | } |
|
|
2080 | |
2064 | sub invoke_button_down { |
2081 | sub invoke_button_down { |
2065 | my ($self, $ev, $x, $y) = @_; |
2082 | my ($self, $ev, $x, $y) = @_; |
2066 | |
2083 | |
2067 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
2084 | if ($x >= $self->{padding_x} && $x < $self->{w} - $self->{padding_x} |
2068 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
2085 | && $y >= $self->{padding_y} && $y < $self->{h} - $self->{padding_y}) { |
2069 | $self->{state} = !$self->{state}; |
2086 | $self->toggle; |
2070 | $self->emit (changed => $self->{state}); |
|
|
2071 | } else { |
2087 | } else { |
2072 | return 0 |
2088 | return 0 |
2073 | } |
2089 | } |
2074 | |
2090 | |
2075 | 1 |
2091 | 1 |
… | |
… | |
2246 | my $ycut1 = max 0, min 1, $ycut; |
2262 | my $ycut1 = max 0, min 1, $ycut; |
2247 | my $ycut2 = max 0, min 1, $ycut - 1; |
2263 | my $ycut2 = max 0, min 1, $ycut - 1; |
2248 | |
2264 | |
2249 | my $h1 = $self->{h} * (1 - $ycut1); |
2265 | my $h1 = $self->{h} * (1 - $ycut1); |
2250 | my $h2 = $self->{h} * (1 - $ycut2); |
2266 | my $h2 = $self->{h} * (1 - $ycut2); |
|
|
2267 | my $h3 = $self->{h}; |
|
|
2268 | |
|
|
2269 | $_ = $_ * (284-4)/288 + 4/288 for ($h1, $h2, $h3); |
2251 | |
2270 | |
2252 | glEnable GL_BLEND; |
2271 | glEnable GL_BLEND; |
2253 | glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
2272 | glBlendFuncSeparate GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
2254 | GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2273 | GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2255 | glEnable GL_TEXTURE_2D; |
2274 | glEnable GL_TEXTURE_2D; |
… | |
… | |
2274 | |
2293 | |
2275 | if ($t3) { |
2294 | if ($t3) { |
2276 | glBindTexture GL_TEXTURE_2D, $t3->{name}; |
2295 | glBindTexture GL_TEXTURE_2D, $t3->{name}; |
2277 | glBegin GL_QUADS; |
2296 | glBegin GL_QUADS; |
2278 | glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; |
2297 | glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2; |
2279 | glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h}; |
2298 | glTexCoord 0 , $t3->{t}; glVertex 0 , $h3; |
2280 | glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h}; |
2299 | glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $h3; |
2281 | glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; |
2300 | glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2; |
2282 | glEnd; |
2301 | glEnd; |
2283 | } |
2302 | } |
2284 | |
2303 | |
2285 | glDisable GL_BLEND; |
2304 | glDisable GL_BLEND; |
… | |
… | |
3150 | |
3169 | |
3151 | $self->{current} = $self->{children}[0] |
3170 | $self->{current} = $self->{children}[0] |
3152 | if @{ $self->{children} }; |
3171 | if @{ $self->{children} }; |
3153 | } |
3172 | } |
3154 | |
3173 | |
|
|
3174 | sub get_current_page { |
|
|
3175 | my ($self) = @_; |
|
|
3176 | |
|
|
3177 | $self->{current} |
|
|
3178 | } |
|
|
3179 | |
3155 | sub set_current_page { |
3180 | sub set_current_page { |
3156 | my ($self, $page_or_widget) = @_; |
3181 | my ($self, $page_or_widget) = @_; |
3157 | |
3182 | |
3158 | my $widget = ref $page_or_widget |
3183 | my $widget = ref $page_or_widget |
3159 | ? $page_or_widget |
3184 | ? $page_or_widget |
… | |
… | |
3223 | tooltip => $tooltip, |
3248 | tooltip => $tooltip, |
3224 | on_activate => sub { $self->set_current_page ($widget) }, |
3249 | on_activate => sub { $self->set_current_page ($widget) }, |
3225 | ); |
3250 | ); |
3226 | |
3251 | |
3227 | $self->{multiplexer}->add ($widget); |
3252 | $self->{multiplexer}->add ($widget); |
|
|
3253 | } |
|
|
3254 | |
|
|
3255 | sub get_current_page { |
|
|
3256 | my ($self) = @_; |
|
|
3257 | |
|
|
3258 | $self->{multiplexer}->get_current_page |
3228 | } |
3259 | } |
3229 | |
3260 | |
3230 | sub set_current_page { |
3261 | sub set_current_page { |
3231 | my ($self, $page) = @_; |
3262 | my ($self, $page) = @_; |
3232 | |
3263 | |
… | |
… | |
3437 | |
3468 | |
3438 | ############################################################################# |
3469 | ############################################################################# |
3439 | |
3470 | |
3440 | package CFClient::UI::Inventory; |
3471 | package CFClient::UI::Inventory; |
3441 | |
3472 | |
3442 | our @ISA = CFClient::UI::ScrolledWindow::; |
3473 | our @ISA = CFClient::UI::Table::; |
3443 | |
3474 | |
3444 | sub new { |
3475 | sub new { |
3445 | my $class = shift; |
3476 | my $class = shift; |
3446 | |
3477 | |
3447 | my $self = $class->SUPER::new ( |
3478 | my $self = $class->SUPER::new ( |
3448 | child => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
3479 | col_expand => [0, 1, 0], |
3449 | @_, |
3480 | @_, |
3450 | ); |
3481 | ); |
3451 | |
3482 | |
3452 | $self |
3483 | $self |
3453 | } |
3484 | } |
3454 | |
3485 | |
3455 | sub set_items { |
3486 | sub set_items { |
3456 | my ($self, $items) = @_; |
3487 | my ($self, $items) = @_; |
3457 | |
3488 | |
3458 | $self->{child}->clear; |
3489 | $self->clear; |
3459 | return unless $items; |
3490 | return unless $items; |
3460 | |
3491 | |
3461 | my @items = sort { |
3492 | my @items = sort { |
3462 | ($a->{type} <=> $b->{type}) |
3493 | ($a->{type} <=> $b->{type}) |
3463 | or ($a->{name} cmp $b->{name}) |
3494 | or ($a->{name} cmp $b->{name}) |
… | |
… | |
3467 | |
3498 | |
3468 | my $row = 0; |
3499 | my $row = 0; |
3469 | for my $item (@items) { |
3500 | for my $item (@items) { |
3470 | CFClient::Item::update_widgets $item; |
3501 | CFClient::Item::update_widgets $item; |
3471 | |
3502 | |
3472 | $self->{child}->add (0, $row, $item->{face_widget}); |
3503 | $self->add (0, $row, $item->{face_widget}); |
3473 | $self->{child}->add (1, $row, $item->{desc_widget}); |
3504 | $self->add (1, $row, $item->{desc_widget}); |
3474 | $self->{child}->add (2, $row, $item->{weight_widget}); |
3505 | $self->add (2, $row, $item->{weight_widget}); |
3475 | |
3506 | |
3476 | $row++; |
3507 | $row++; |
3477 | } |
3508 | } |
3478 | } |
3509 | } |
3479 | |
3510 | |