ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/MapWidget.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/MapWidget.pm (file contents):
Revision 1.62 by root, Thu Jun 15 16:44:20 2006 UTC vs.
Revision 1.69 by root, Mon Jun 26 21:59:04 2006 UTC

38 . "To enter a verbatim command to send to the server, just type the command, " 38 . "To enter a verbatim command to send to the server, just type the command, "
39 . "followed by a space, and press return. " 39 . "followed by a space, and press return. "
40 . "Typing the initial letters of words (or just any letters) displays guesses " 40 . "Typing the initial letters of words (or just any letters) displays guesses "
41 . "for commands you might want to use.\n" 41 . "for commands you might want to use.\n"
42 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n" 42 . "You can use the cursor-up and cursor-down keys to select between those guesses.\n"
43 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining keybindings.", 43 . "<b>Right-Click</b> opens a menu where you cna select further options, sich as redefining key bindings.",
44 ; 44 ;
45 45
46 $self 46 $self
47} 47}
48 48
62 my ($self) = @_; 62 my ($self) = @_;
63 63
64 %{$self->{completer}{command}} = (); 64 %{$self->{completer}{command}} = ();
65} 65}
66 66
67sub button_down { 67sub invoke_button_down {
68 my ($self, $ev, $x, $y) = @_; 68 my ($self, $ev, $x, $y) = @_;
69 69
70 return unless $::CONN; 70 return unless $::CONN;
71 71
72 $self->focus_in; 72 $self->grab_focus;
73 73
74 if ($ev->{button} == 1) { 74 if ($ev->{button} == 1) {
75 my $x = CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx}; 75 my $x = 1 + CFClient::floor +($ev->{x} - $self->{sx0}) / $self->{tilesize} - $self->{sx};
76 my $y = CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy}; 76 my $y = 1 + CFClient::floor +($ev->{y} - $self->{sy0}) / $self->{tilesize} - $self->{sy};
77 77
78 $x -= int 0.5 * $self->{sw}; 78 $x -= int 0.5 * $self->{sw};
79 $y -= int 0.5 * $self->{sh}; 79 $y -= int 0.5 * $self->{sh};
80 80
81 $::CONN->lookat ($x, $y) 81 $::CONN->lookat ($x, $y)
98 } 98 }
99 99
100 1 100 1
101} 101}
102 102
103sub button_up { 103sub invoke_button_up {
104 my ($self, $ev, $x, $y) = @_; 104 my ($self, $ev, $x, $y) = @_;
105 105
106 delete $self->{motion}; 106 delete $self->{motion};
107 107
108 1 108 1
109} 109}
110 110
111sub mouse_motion { 111sub invoke_mouse_motion {
112 my ($self, $ev, $x, $y) = @_; 112 my ($self, $ev, $x, $y) = @_;
113 113
114 if ($self->{motion}) { 114 if ($self->{motion}) {
115 $self->{motion}->($ev, $x, $y); 115 $self->{motion}->($ev, $x, $y);
116 } else { 116 } else {
120 1 120 1
121} 121}
122 122
123sub size_request { 123sub size_request {
124 ( 124 (
125 1 + 32 * int $::WIDTH / 32, 125 32 * CFClient::ceil $::WIDTH / 32,
126 1 + 32 * int $::HEIGHT / 32, 126 32 * CFClient::ceil $::HEIGHT / 32,
127 ) 127 )
128} 128}
129 129
130sub update { 130sub update {
131 my ($self) = @_; 131 my ($self) = @_;
148 CFClient::SDLK_RIGHT, [3, "east"], 148 CFClient::SDLK_RIGHT, [3, "east"],
149 CFClient::SDLK_DOWN, [5, "south"], 149 CFClient::SDLK_DOWN, [5, "south"],
150 CFClient::SDLK_LEFT, [7, "west"], 150 CFClient::SDLK_LEFT, [7, "west"],
151); 151);
152 152
153sub key_down { 153sub invoke_key_down {
154 my ($self, $ev) = @_; 154 my ($self, $ev) = @_;
155 155
156 return 0 unless $::CONN; 156 return 0 unless $::CONN;
157 157
158 my $mod = $ev->{mod}; 158 my $mod = $ev->{mod};
195 } 195 }
196 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) { 196 } elsif ($sym == CFClient::SDLK_INSERT && $mod & CFClient::KMOD_CTRL) {
197 $::BIND_EDITOR->set_binding (undef, undef, [], 197 $::BIND_EDITOR->set_binding (undef, undef, [],
198 sub { 198 sub {
199 my ($mod, $sym, $cmds) = @_; 199 my ($mod, $sym, $cmds) = @_;
200 $::CFG->{bindings}->{$mod}->{$sym} = $cmds; 200 $::BIND_EDITOR->cfg_bind ($mod, $sym, $cmds);
201 }); 201 });
202 $::BIND_EDITOR->start; 202 $::BIND_EDITOR->start;
203 $::BIND_EDITOR->show; 203 $::BIND_EDITOR->show;
204 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) { 204 } elsif ($sym == CFClient::SDLK_INSERT && not ($mod & CFClient::KMOD_CTRL)) {
205 $::BIND_EDITOR->stop; 205 $::BIND_EDITOR->stop;
206 $::BIND_EDITOR->ask_for_bind_and_commit; 206 $::BIND_EDITOR->ask_for_bind_and_commit;
207 $::BIND_EDITOR->hide; 207 $::BIND_EDITOR->hide;
208 } elsif (my $bind_cmd = $::CFG->{bindings}->{$mod}->{$sym}) { 208 } elsif (my $bind_cmd = $::CFG->{profile}{default}{bindings}{$mod}{$sym}) {
209 $::CONN->user_send ($_) for @$bind_cmd; 209 $::CONN->user_send ($_) for @$bind_cmd;
210 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) { 210 } elsif ((ord 'a') <= $uni && $uni <= (ord 'z')) {
211 $self->{completer}->key_down ($ev); 211 $self->{completer}->invoke_key_down ($ev);
212 $self->{completer}->show; 212 $self->{completer}->show;
213 } else { 213 } else {
214 return 0; 214 return 0;
215 } 215 }
216 216
217 1 217 1
218} 218}
219 219
220sub key_up { 220sub invoke_key_up {
221 my ($self, $ev) = @_; 221 my ($self, $ev) = @_;
222 222
223 my $res = 0; 223 my $res = 0;
224 my $mod = $ev->{mod}; 224 my $mod = $ev->{mod};
225 my $sym = $ev->{sym}; 225 my $sym = $ev->{sym};
380 380
381sub size_request { 381sub size_request {
382 ($::HEIGHT * 0.25, $::HEIGHT * 0.25) 382 ($::HEIGHT * 0.25, $::HEIGHT * 0.25)
383} 383}
384 384
385sub size_allocate { 385sub invoke_size_allocate {
386 my ($self, $w, $h) = @_; 386 my ($self, $w, $h) = @_;
387 387
388 $self->SUPER::size_allocate ($w, $h);
389 $self->update; 388 $self->update;
389
390 1
390} 391}
391 392
392sub update { 393sub update {
393 my ($self) = @_; 394 my ($self) = @_;
394 395
479 ]; 480 ];
480 481
481 $self->{entry} = new CFClient::UI::Entry 482 $self->{entry} = new CFClient::UI::Entry
482 on_changed => sub { 483 on_changed => sub {
483 $self->update_labels; 484 $self->update_labels;
485 0
484 }, 486 },
485 on_button_down => sub { 487 on_button_down => sub {
486 my ($entry, $ev, $x, $y) = @_; 488 my ($entry, $ev, $x, $y) = @_;
487 489
488 if ($ev->{button} == 3) { 490 if ($ev->{button} == 3) {
489 (new CFClient::UI::Menu 491 (new CFClient::UI::Menu
490 items => [ 492 items => [
493 ["bind <i>" . (CFClient::UI::Label::escape $self->{select}) . "</i> to a key"
491 ["bind to a key" => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->focus_in }) }] 494 => sub { $::BIND_EDITOR->do_quick_binding ([$self->{select}], sub { $entry->grab_focus }) }]
492 ], 495 ],
493 )->popup ($ev); 496 )->popup ($ev);
494 return 1; 497 return 1;
495 } 498 }
496 0 499 0
503 if ($ev->{sym} == 13) { 506 if ($ev->{sym} == 13) {
504 if (exists $self->{select}) { 507 if (exists $self->{select}) {
505 $self->{last_command} = $self->{select}; 508 $self->{last_command} = $self->{select};
506 $::CONN->user_send ($self->{select}); 509 $::CONN->user_send ($self->{select});
507 510
508 unshift @{$self->{history}}, $self->{select}; 511 unshift @{$self->{history}}, $self->{entry}->get_text;
509 $self->{hist_ptr} = 0; 512 $self->{hist_ptr} = 0;
510 513
511 $self->hide; 514 $self->hide;
512 } 515 }
513 } elsif ($ev->{sym} == 27) { 516 } elsif ($ev->{sym} == 27) {
514 $self->{hist_ptr} = 0; 517 $self->{hist_ptr} = 0;
515 $self->hide; 518 $self->hide;
516 return;
517 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) { 519 } elsif ($ev->{sym} == CFClient::SDLK_DOWN) {
518 if ($self->{hist_ptr} > 1) { 520 if ($self->{hist_ptr} > 1) {
519 $self->{hist_ptr}--; 521 $self->{hist_ptr}--;
520 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]); 522 $self->{entry}->set_text ($self->{history}->[$self->{hist_ptr} - 1]);
521 } elsif ($self->{hist_ptr} > 0) { 523 } elsif ($self->{hist_ptr} > 0) {
561 563
562 $self->{entry}->set_text ($prefix); 564 $self->{entry}->set_text ($prefix);
563 $self->show; 565 $self->show;
564} 566}
565 567
566sub size_allocate { 568sub invoke_size_allocate {
567 my ($self, $w, $h) = @_; 569 my ($self, $w, $h) = @_;
568 570
569 $self->SUPER::size_allocate ($w, $h);
570 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10); 571 $self->move_abs (($::WIDTH - $w) * 0.5, ($::HEIGHT - $h) * 0.6, 10);
572
573 $self->SUPER::invoke_size_allocate ($w, $h)
571} 574}
572 575
573sub show { 576sub show {
574 my ($self) = @_; 577 my ($self) = @_;
575 578
576 $self->SUPER::show; 579 $self->SUPER::show;
577 $self->{entry}->focus_in; 580 $self->{entry}->grab_focus;
578} 581}
579 582
580sub hide { 583sub hide {
581 my ($self) = @_; 584 my ($self) = @_;
582 585
583 $self->SUPER::hide; 586 $self->SUPER::hide;
584 $self->{entry}->set_text (""); 587 $self->{entry}->set_text ("");
585} 588}
586 589
587sub key_down { 590sub invoke_key_down {
588 my ($self, $ev) = @_; 591 my ($self, $ev) = @_;
589 592
590 $self->{entry}->key_down ($ev) 593 $self->{entry}->emit (key_down => $ev)
591} 594}
592 595
593sub update_labels { 596sub update_labels {
594 my ($self) = @_; 597 my ($self) = @_;
595 598
682 $label->set_text (""); 685 $label->set_text ("");
683 $label->set_tooltip (""); 686 $label->set_tooltip ("");
684 } 687 }
685 688
686 $self->update; 689 $self->update;
687 ###
688} 690}
689 691
690sub _draw { 692sub _draw {
691 my ($self) = @_; 693 my ($self) = @_;
692 694

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines