ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.3
Committed: Wed Jul 25 15:06:21 2007 UTC (17 years ago) by elmex
Branch: MAIN
Changes since 1.2: +14 -3 lines
Log Message:
fixed some issues with the tabs

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     if ($text =~ /^\/(.*)/) {
56     $::CONN->user_send ($1);
57     } else {
58 elmex 1.2 my $say_cmd = $self->{say_command};
59     if ($say_cmd eq '') {
60     $::CONN->user_send ($text);
61     } else {
62     $::CONN->user_send ("$say_cmd $text");
63     }
64 elmex 1.1 }
65     if ($input->{refocus_map}) {
66     delete $input->{refocus_map};
67     $::MAPWIDGET->focus_in
68     }
69    
70     0
71     },
72     on_escape => sub {
73     $::MAPWIDGET->grab_focus;
74    
75     0
76     },
77     ));
78    
79     $self
80     }
81    
82     sub message {
83     my ($self, $para) = @_;
84    
85     my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
86    
87     $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
88    
89     my $txt = $self->{txt};
90     $txt->add_paragraph ($para);
91     $txt->scroll_to_bottom;
92     }
93    
94     sub activate_console {
95     my ($self, $preset) = @_;
96    
97     $self->{input}->{auto_activated} = 1;
98     $self->{input}->grab_focus;
99    
100     if ($preset && $self->{input}->get_text eq '') {
101     $self->{input}->set_text ($preset);
102     }
103     }
104    
105     sub set_fontsize {
106     my ($self, $size) = @_;
107     $self->{txt}->set_fontsize ($size);
108     }
109    
110     sub set_max_para {
111     my ($self, $max_par) = @_;
112     $self->{txt}{max_par} = $max_par;
113     }