ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.1
Committed: Mon Jul 23 18:13:33 2007 UTC (17 years ago) by elmex
Branch: MAIN
Log Message:
checking in some refactored code

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     tooltip => "<b>Server Log</b>. This text viewer contains all recent messages sent by the server.",
21     ));
22    
23     $self->add ($self->{input} = CFPlus::UI::Entry->new (
24     tooltip => "<b>Chat Box</b>. If you enter a text and press return/enter here, the current <i>communication command</i> "
25     . "from the client setup will be prepended (e.g. <b>shout</b>, <b>chat</b>...). "
26     . "If you prepend a slash (/), you will submit a command instead (similar to IRC). "
27     . "A better way to submit commands (and the occasional chat command) is often the map command completer.",
28     on_focus_in => sub {
29     my ($input, $prev_focus) = @_;
30    
31     delete $input->{refocus_map};
32    
33     if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
34     $input->{refocus_map} = 1;
35     }
36     delete $input->{auto_activated};
37    
38     0
39     },
40     on_activate => sub {
41     my ($input, $text) = @_;
42     $input->set_text ('');
43    
44     if ($text =~ /^\/(.*)/) {
45     $::CONN->user_send ($1);
46     } else {
47     my $say_cmd = $::CFG->{say_command} || 'say';
48     $::CONN->user_send ("$say_cmd $text");
49     }
50     if ($input->{refocus_map}) {
51     delete $input->{refocus_map};
52     $::MAPWIDGET->focus_in
53     }
54    
55     0
56     },
57     on_escape => sub {
58     $::MAPWIDGET->grab_focus;
59    
60     0
61     },
62     ));
63    
64     $self
65     }
66    
67     sub message {
68     my ($self, $para) = @_;
69    
70     my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
71    
72     $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
73    
74     my $txt = $self->{txt};
75     $txt->add_paragraph ($para);
76     $txt->scroll_to_bottom;
77     }
78    
79     sub activate_console {
80     my ($self, $preset) = @_;
81    
82     $self->{input}->{auto_activated} = 1;
83     $self->{input}->grab_focus;
84    
85     if ($preset && $self->{input}->get_text eq '') {
86     $self->{input}->set_text ($preset);
87     }
88     }
89    
90     sub set_fontsize {
91     my ($self, $size) = @_;
92     $self->{txt}->set_fontsize ($size);
93     }
94    
95     sub set_max_para {
96     my ($self, $max_par) = @_;
97     $self->{txt}{max_par} = $max_par;
98     }