ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI/MessageWindow.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI/MessageWindow.pm (file contents):
Revision 1.2 by root, Mon Jul 23 15:30:46 2007 UTC vs.
Revision 1.3 by elmex, Mon Jul 23 18:13:33 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines