ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.6
Committed: Fri Aug 17 21:27:33 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
Changes since 1.5: +6 -4 lines
Log Message:
tweak new chat tab logic a bit to my liking

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 root 1.6 } elsif (length $text) {
60 elmex 1.2 my $say_cmd = $self->{say_command};
61 root 1.4 $::CONN->user_send ($say_cmd . $text);
62 root 1.6 } else {
63     $input->{refocus_map} = 1;
64 elmex 1.1 }
65 root 1.6 if (delete $input->{refocus_map}) {
66     $::MAPWIDGET->emit ("focus_in");
67 elmex 1.1 }
68    
69     0
70     },
71 elmex 1.5 on_key_down => sub {
72     my ($input, $ev) = @_;
73     my $uni = $ev->{unicode};
74     my $mod = $ev->{mod};
75    
76     if ($uni >= ord "0" && $uni <= ord "9" && $mod & CFPlus::KMOD_ALT) {
77     $::MAPWIDGET->emit (key_down => $ev);
78     return 1;
79     }
80    
81     0
82     },
83 elmex 1.1 on_escape => sub {
84     $::MAPWIDGET->grab_focus;
85    
86     0
87     },
88     ));
89    
90     $self
91     }
92    
93     sub message {
94     my ($self, $para) = @_;
95    
96     my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
97    
98     $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
99    
100     my $txt = $self->{txt};
101     $txt->add_paragraph ($para);
102     $txt->scroll_to_bottom;
103     }
104    
105     sub activate_console {
106     my ($self, $preset) = @_;
107    
108     $self->{input}->{auto_activated} = 1;
109     $self->{input}->grab_focus;
110    
111     if ($preset && $self->{input}->get_text eq '') {
112     $self->{input}->set_text ($preset);
113     }
114     }
115    
116     sub set_fontsize {
117     my ($self, $size) = @_;
118     $self->{txt}->set_fontsize ($size);
119     }
120    
121     sub set_max_para {
122     my ($self, $max_par) = @_;
123     $self->{txt}{max_par} = $max_par;
124     }
125 root 1.6