ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.4
Committed: Thu Aug 9 05:55:40 2007 UTC (16 years, 11 months ago) by root
Branch: MAIN
Changes since 1.3: +3 -5 lines
Log Message:
doh

File Contents

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