ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/ChatView.pm
Revision: 1.8
Committed: Thu Aug 30 07:08:17 2007 UTC (16 years, 9 months ago) by root
Branch: MAIN
Changes since 1.7: +2 -4 lines
Log Message:
minor tuning

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>Command Entry</b>. If you enter something and press return/enter here, "
36 . "the line you entered will be sent to the server as a command.",
37 on_focus_in => sub {
38 my ($input, $prev_focus) = @_;
39
40 delete $input->{refocus_map};
41
42 if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
43 $input->{refocus_map} = 1;
44 }
45 delete $input->{auto_activated};
46
47 0
48 },
49 on_activate => sub {
50 my ($input, $text) = @_;
51 $input->set_text ('');
52
53 return unless $::CONN;
54
55 if ($text =~ /^\/(.*)/) {
56 $::CONN->user_send ($1);
57 } elsif (length $text) {
58 my $say_cmd = $self->{say_command};
59 $::CONN->user_send ($say_cmd . $text);
60 } else {
61 $input->{refocus_map} = 1;
62 }
63 if (delete $input->{refocus_map}) {
64 $::MAPWIDGET->grab_focus;
65 }
66
67 0
68 },
69 on_key_down => sub {
70 my ($input, $ev) = @_;
71 my $uni = $ev->{unicode};
72 my $mod = $ev->{mod};
73
74 if ($uni >= ord "0" && $uni <= ord "9" && $mod & CFPlus::KMOD_ALT) {
75 $::MAPWIDGET->emit (key_down => $ev);
76 return 1;
77 }
78
79 0
80 },
81 on_escape => sub {
82 $::MAPWIDGET->grab_focus;
83
84 0
85 },
86 ));
87
88 $self
89 }
90
91 sub message {
92 my ($self, $para) = @_;
93
94 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
95
96 $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
97
98 my $txt = $self->{txt};
99 $txt->add_paragraph ($para);
100 $txt->scroll_to_bottom;
101 }
102
103 sub activate_console {
104 my ($self, $preset) = @_;
105
106 $self->{input}->{auto_activated} = 1;
107 $self->{input}->grab_focus;
108
109 if ($preset && $self->{input}->get_text eq '') {
110 $self->{input}->set_text ($preset);
111 }
112 }
113
114 sub set_fontsize {
115 my ($self, $size) = @_;
116 $self->{txt}->set_fontsize ($size);
117 }
118
119 sub set_max_para {
120 my ($self, $max_par) = @_;
121 $self->{txt}{max_par} = $max_par;
122 }
123