ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.11
Committed: Wed Dec 26 20:46:39 2007 UTC (16 years, 5 months ago) by root
Branch: MAIN
Changes since 1.10: +8 -8 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 package dc::UI::ChatView;
2
3 use strict;
4 use utf8;
5
6 our @ISA = dc::UI::Dockable::;
7
8 sub new {
9 my $class = shift;
10
11 my $self = $class->SUPER::new (
12 @_,
13 can_close => 1,
14 child => (my $vbox = new dc::UI::VBox),
15 );
16
17 $vbox->add ($self->{txt} = new dc::UI::TextScroller (
18 expand => 1,
19 font => $::FONT_FIXED,
20 fontsize => $::CFG->{log_fontsize},
21 indent => -4,
22 can_hover => 1,
23 can_events => 1,
24 max_par => $::CFG->{logview_max_par},
25 tooltip =>
26 $self->{text_tooltip}
27 || "<b>Server Log</b>. This text viewer contains all recent messages "
28 ."sent by the server.",
29 ));
30
31 $vbox->add (my $hb = dc::UI::HBox->new);
32
33 if ($self->{say_command}) {
34 $hb->add (dc::UI::Label->new (markup => $self->{say_command}));
35 }
36
37 $hb->add ($self->{input} = dc::UI::Entry->new (
38 expand => 1,
39 tooltip =>
40 $self->{entry_tooltip}
41 || "<b>Command Entry</b>. If you enter something and press return/enter here, "
42 . "the line you entered will be sent to the server as a command.",
43 on_focus_in => sub {
44 my ($input, $prev_focus) = @_;
45
46 delete $input->{refocus_map};
47
48 if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
49 $input->{refocus_map} = 1;
50 }
51 delete $input->{auto_activated};
52
53 0
54 },
55 on_activate => sub {
56 my ($input, $text) = @_;
57 $input->set_text ('');
58
59 return unless $::CONN;
60
61 if ($text =~ /^\/(.*)/) {
62 $::CONN->user_send ($1);
63 } elsif (length $text) {
64 my $say_cmd = $self->{say_command};
65 $::CONN->user_send ($say_cmd . $text);
66 } else {
67 $input->{refocus_map} = 1;
68 }
69 if (delete $input->{refocus_map}) {
70 $::MAPWIDGET->grab_focus;
71 }
72
73 0
74 },
75 on_key_down => sub {
76 my ($input, $ev) = @_;
77 my $uni = $ev->{unicode};
78 my $mod = $ev->{mod};
79
80 if ($uni >= ord "0" && $uni <= ord "9" && $mod & dc::KMOD_ALT) {
81 $::MAPWIDGET->emit (key_down => $ev);
82 return 1;
83 }
84
85 0
86 },
87 on_escape => sub {
88 $::MAPWIDGET->grab_focus;
89
90 0
91 },
92 ));
93
94 $self
95 }
96
97 sub message {
98 my ($self, $para) = @_;
99
100 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
101
102 $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
103
104 my $txt = $self->{txt};
105 $txt->add_paragraph ($para);
106 $txt->scroll_to_bottom;
107 }
108
109 sub activate_console {
110 my ($self, $preset) = @_;
111
112 $self->{input}->{auto_activated} = 1;
113 $self->{input}->grab_focus;
114
115 if ($preset && $self->{input}->get_text eq '') {
116 $self->{input}->set_text ($preset);
117 }
118 }
119
120 sub set_fontsize {
121 my ($self, $size) = @_;
122 $self->{txt}->set_fontsize ($size);
123 }
124
125 sub set_max_para {
126 my ($self, $max_par) = @_;
127 $self->{txt}{max_par} = $max_par;
128 }
129
130 sub clear_log {
131 my ($self) = @_;
132
133 $self->{txt}->clear;
134 }
135
136 1