ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.5
Committed: Tue Aug 14 13:25:26 2007 UTC (16 years, 11 months ago) by elmex
Branch: MAIN
Changes since 1.4: +12 -0 lines
Log Message:
added alt+numberkey functionality for message window, and added reply-message
detection with activation of the entry

File Contents

# User Rev Content
1 elmex 1.1 package CFPlus::UI::ChatView;
2    
3     use strict;
4     use utf8;
5    
6     our @ISA = CFPlus::UI::VBox::;
7    
8     sub new {
9     my $class = shift;
10     my $self = $class->SUPER::new (@_);
11    
12     $self->add ($self->{txt} = new CFPlus::UI::TextScroller (
13     expand => 1,
14     font => $::FONT_FIXED,
15     fontsize => $::CFG->{log_fontsize},
16     indent => -4,
17     can_hover => 1,
18     can_events => 1,
19     max_par => $::CFG->{logview_max_par},
20 elmex 1.3 tooltip =>
21     $self->{text_tooltip}
22     || "<b>Server Log</b>. This text viewer contains all recent messages "
23     ."sent by the server.",
24 elmex 1.1 ));
25    
26 elmex 1.3 $self->add (my $hb = CFPlus::UI::HBox->new);
27    
28     if ($self->{say_command}) {
29     $hb->add (CFPlus::UI::Label->new (markup => $self->{say_command}));
30     }
31     $hb->add ($self->{input} = CFPlus::UI::Entry->new (
32     expand => 1,
33     tooltip =>
34     $self->{entry_tooltip}
35     || "<b>Chat Box</b>. If you enter a text and press return/enter here, the current <i>communication command</i> "
36 elmex 1.1 . "from the client setup will be prepended (e.g. <b>shout</b>, <b>chat</b>...). "
37     . "If you prepend a slash (/), you will submit a command instead (similar to IRC). "
38     . "A better way to submit commands (and the occasional chat command) is often the map command completer.",
39     on_focus_in => sub {
40     my ($input, $prev_focus) = @_;
41    
42     delete $input->{refocus_map};
43    
44     if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
45     $input->{refocus_map} = 1;
46     }
47     delete $input->{auto_activated};
48    
49     0
50     },
51     on_activate => sub {
52     my ($input, $text) = @_;
53     $input->set_text ('');
54    
55 root 1.4 return unless $::CONN;
56    
57 elmex 1.1 if ($text =~ /^\/(.*)/) {
58     $::CONN->user_send ($1);
59     } else {
60 elmex 1.2 my $say_cmd = $self->{say_command};
61 root 1.4 $::CONN->user_send ($say_cmd . $text);
62 elmex 1.1 }
63     if ($input->{refocus_map}) {
64     delete $input->{refocus_map};
65     $::MAPWIDGET->focus_in
66     }
67    
68     0
69     },
70 elmex 1.5 on_key_down => sub {
71     my ($input, $ev) = @_;
72     my $uni = $ev->{unicode};
73     my $mod = $ev->{mod};
74    
75     if ($uni >= ord "0" && $uni <= ord "9" && $mod & CFPlus::KMOD_ALT) {
76     $::MAPWIDGET->emit (key_down => $ev);
77     return 1;
78     }
79    
80     0
81     },
82 elmex 1.1 on_escape => sub {
83     $::MAPWIDGET->grab_focus;
84    
85     0
86     },
87     ));
88    
89     $self
90     }
91    
92     sub message {
93     my ($self, $para) = @_;
94    
95     my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
96    
97     $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
98    
99     my $txt = $self->{txt};
100     $txt->add_paragraph ($para);
101     $txt->scroll_to_bottom;
102     }
103    
104     sub activate_console {
105     my ($self, $preset) = @_;
106    
107     $self->{input}->{auto_activated} = 1;
108     $self->{input}->grab_focus;
109    
110     if ($preset && $self->{input}->get_text eq '') {
111     $self->{input}->set_text ($preset);
112     }
113     }
114    
115     sub set_fontsize {
116     my ($self, $size) = @_;
117     $self->{txt}->set_fontsize ($size);
118     }
119    
120     sub set_max_para {
121     my ($self, $max_par) = @_;
122     $self->{txt}{max_par} = $max_par;
123     }