ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
Revision: 1.1
Committed: Sat Jul 21 21:01:40 2007 UTC (17 years ago) by elmex
Branch: MAIN
Log Message:
forgot the message window

File Contents

# User Rev Content
1 elmex 1.1 package CFPlus::UI::MessageWindow;
2    
3     use strict;
4     use utf8;
5    
6     our @ISA = CFPlus::UI::Toplevel::;
7    
8     sub new {
9     my $class = shift;
10     my $self = $class->SUPER::new (
11     name => "message_window",
12     title => "Messages",
13     border_bg => [1, 1, 1, 1],
14     x => "max",
15     y => 0,
16     force_w => $::WIDTH * 0.4,
17     force_h => $::HEIGHT * 0.5,
18     child => (my $vbox = new CFPlus::UI::VBox),
19     has_close_button => 1
20     );
21     my $nb = $self->{nb} = CFPlus::UI::Notebook->new (expand => 1);
22     my $txt = $self->{log} = new CFPlus::UI::TextScroller
23     expand => 1,
24     font => $::FONT_FIXED,
25     fontsize => $::CFG->{log_fontsize},
26     indent => -4,
27     can_hover => 1,
28     can_events => 1,
29     max_par => $::CFG->{logview_max_par},
30     tooltip => "<b>Server Log</b>. This text viewer contains all recent messages sent by the server.",
31     ;
32     my $vb2 = CFPlus::UI::VBox->new;
33     $vb2->add ($txt);
34     $nb->add ("Log", $vb2, "This is the main log of the server.");
35     $vbox->add ($nb);
36    
37     $vbox->add ($self->{input} = CFPlus::UI::Entry->new (
38     tooltip => "<b>Chat Box</b>. If you enter a text and press return/enter here, the current <i>communication command</i> "
39     . "from the client setup will be prepended (e.g. <b>shout</b>, <b>chat</b>...). "
40     . "If you prepend a slash (/), you will submit a command instead (similar to IRC). "
41     . "A better way to submit commands (and the occasional chat command) is often the map command completer.",
42     on_focus_in => sub {
43     my ($input, $prev_focus) = @_;
44    
45     delete $input->{refocus_map};
46    
47     if ($prev_focus == $::MAPWIDGET && $input->{auto_activated}) {
48     $input->{refocus_map} = 1;
49     }
50     delete $input->{auto_activated};
51    
52     0
53     },
54     on_activate => sub {
55     my ($input, $text) = @_;
56     $input->set_text ('');
57    
58     if ($text =~ /^\/(.*)/) {
59     $::CONN->user_send ($1);
60     } else {
61     my $say_cmd = $::CFG->{say_command} || 'say';
62     $::CONN->user_send ("$say_cmd $text");
63     }
64     if ($input->{refocus_map}) {
65     delete $input->{refocus_map};
66     $::MAPWIDGET->focus_in
67     }
68    
69     0
70     },
71     on_escape => sub {
72     $::MAPWIDGET->grab_focus;
73    
74     0
75     },
76     ));
77    
78     $self
79     }
80    
81     sub message {
82     my ($self, $para) = @_;
83    
84     my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
85    
86     $para->{markup} = "<span foreground='#ffffff'>$time</span> $para->{markup}";
87    
88     my $log = $self->{log};
89     $log->add_paragraph ($para);
90     $log->scroll_to_bottom;
91     }
92    
93     sub activate_console {
94     my ($self, $preset) = @_;
95     $self->{input}->{auto_activated} = 1;
96     $self->{input}->grab_focus;
97     if ($preset && $self->{input}->get_text eq '') {
98     $self->{input}->set_text ($preset);
99     }
100     }
101    
102     sub set_fontsize {
103     my ($self, $size) = @_;
104     $self->{log}->set_fontsize ($size);
105     }
106    
107     sub set_max_para {
108     my ($self, $max_par) = @_;
109     $self->{log}->{max_par} = $max_par;
110     }