ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/Deliantra-Client/DC/Util.pm
Revision: 1.11
Committed: Fri Apr 7 20:15:00 2006 UTC (18 years, 3 months ago) by elmex
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +0 -0 lines
State: FILE REMOVED
Log Message:
removed Util

File Contents

# Content
1 package Crossfire::Client::Util;
2
3 use strict;
4
5 use Data::Dumper;
6
7 use SDL;
8 use Gtk2;
9
10 sub gtk_add_cfg_field {
11 my ($tbl, $cfg, $klbl, $key, $value) = @_;
12 my $i = $cfg->{_i}++;
13 $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1);
14 $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1);
15 if ($key eq 'password') {
16 $ent->set_invisible_char ("*");
17 $ent->set (visibility => 0)
18 }
19 $ent->set_text ($value);
20 $ent->signal_connect (changed => sub {
21 my ($ent) = @_;
22 $cfg->{$key} = $ent->get_text;
23 });
24 }
25
26 sub run_config_dialog {
27 my (%events) = @_;
28
29 my $w = Gtk2::Window->new;
30
31 my @cfg = (
32 [qw/Host host/],
33 [qw/Port port/],
34 [qw/Username user/],
35 [qw/Password password/],
36 );
37
38 my $cfg = {};
39
40 my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE);
41 my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a;
42
43 $w->add (my $vb = Gtk2::VBox->new);
44 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0);
45 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height};
46 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1);
47 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1);
48 my $i = 0;
49 my $act = 0;
50 for (map { "$_->[0]x$_->[1]" } reverse @modes) {
51 if ($_ eq $selmode) { $act = $i }
52 $cb->append_text ($_);
53 $i++;
54 }
55 $cb->set_active ($act);
56 $cb->signal_connect (changed => sub {
57 my ($cb) = @_;
58 my $txt = $cb->get_active_text;
59 if ($txt =~ m/(\d+)x(\d+)/) {
60 $::CFG->{width} = $1;
61 $::CFG->{height} = $2;
62 }
63 });
64
65 $cfg->{_i} = 1;
66 for (@cfg) {
67 gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]});
68 }
69
70 $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
71 $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5);
72 $cb->signal_connect (clicked => sub {
73 for (keys %$cfg) {
74 $::CFG->{$_} = $cfg->{$_}
75 if $_ ne '_i';
76 }
77 Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc";
78 });
79 $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5);
80 $cb->signal_connect (clicked => sub {
81 for (keys %$cfg) {
82 $::CFG->{$_} = $cfg->{$_}
83 if $_ ne '_i';
84 }
85 my $cb = $events{login} || sub {};
86 $cb->($::CFG->{user}, $::CFG->{password});
87 });
88 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
89 $cb->signal_connect (clicked => sub {
90 my $cb = $events{login} || sub {};
91 $cb->();
92 });
93 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
94 $cb->signal_connect (clicked => sub { $w->destroy });
95
96 $w->show_all;
97
98 $w->signal_connect (destroy => sub { Gtk2->main_quit });
99 }
100
101 1;