ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.26 by elmex, Fri Apr 7 20:57:29 2006 UTC vs.
Revision 1.33 by root, Sat Apr 8 18:15:59 2006 UTC

15 15
16use Crossfire; 16use Crossfire;
17use Crossfire::Client; 17use Crossfire::Client;
18use Crossfire::Protocol; 18use Crossfire::Protocol;
19 19
20use Crossfire::Client::Util;
21use Crossfire::Client::Widget; 20use Crossfire::Client::Widget;
22 21
23our $FACECACHE; 22our $FACECACHE;
24 23
25our $VERSION = '0.1'; 24our $VERSION = '0.1';
25
26our %GL_EXT;
26 27
27our $CFG; 28our $CFG;
28our $CONN; 29our $CONN;
30
31our $WIDTH;
32our $HEIGHT;
33our $FULLSCREEN;
29 34
30our $UIFONT; 35our $UIFONT;
31 36
32our $SDL_TIMER; 37our $SDL_TIMER;
33our $SDL_APP; 38our $SDL_APP;
34our $SDL_EV = new SDL::Event; 39our $SDL_EV = new SDL::Event;
35our %SDL_CB; 40our %SDL_CB;
36 41
37our @GL_INIT; # hooks called on every gl init 42our @GL_INIT; # hooks called on every gl init
38 43
44our $ALT_ENTER_MESSAGE;
45
46our $tw;
47
39sub init_screen { 48sub init_screen {
40 $SDL_APP = new SDL::App 49 $SDL_APP = new SDL::App
41 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 50 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
42 -title => "Crossfire+ Client", 51 -title => "Crossfire+ Client",
43 -width => $CFG->{width}, 52 -width => $WIDTH,
44 -height => $CFG->{height}, 53 -height => $HEIGHT,
45 -opengl => 1, 54 -opengl => 1,
46 -red_size => 8, 55 -red_size => 8,
47 -green_size => 8, 56 -green_size => 8,
48 -blue_size => 8, 57 -blue_size => 8,
49 -double_buffer => 1, 58 -double_buffer => 1,
50 -fullscreen => $CFG->{fullscreen}, 59 -fullscreen => $FULLSCREEN,
51 -resizeable => 0; 60 -resizeable => 0;
61
62 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
63
64 $GL_EXT{GL_ARB_texture_non_power_of_two}
65 or warn "WARNING: non-power-of-two opengl extension required";
66
67 $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40
68 or die "TTFOpenFont: $!";
69
70 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode";
71 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
72 $ALT_ENTER_MESSAGE->activate;
73
74 $tw = new Crossfire::Client::Widget::Window;
75 $tw->add (my $lbl = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!");
76# $tw = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!";
77
78 $tw->move (0, $HEIGHT - 50);
79 $tw->activate;
52 80
53 glClearColor 0, 0, 0, 0; 81 glClearColor 0, 0, 0, 0;
54 82
55 glEnable GL_TEXTURE_2D; 83 glEnable GL_TEXTURE_2D;
56 glShadeModel GL_FLAT; 84 glShadeModel GL_FLAT;
57 glDisable GL_DEPTH_TEST; 85 glDisable GL_DEPTH_TEST;
58 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 86 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
59 87
60 glMatrixMode GL_PROJECTION; 88 glMatrixMode GL_PROJECTION;
61 glLoadIdentity; 89 glLoadIdentity;
62 glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; 90 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100;
63 91
64 glMatrixMode GL_MODELVIEW; 92 glMatrixMode GL_MODELVIEW;
65 93
66 $_->() for @GL_INIT; 94 $_->() for @GL_INIT;
67} 95}
68 96
69my $label;#d#
70
71sub start_game { 97sub start_game {
72 $SDL_TIMER = add Glib::Timeout 1000/20, sub { 98 $SDL_TIMER = add Glib::Timeout 1000/100, sub {
73 while ($SDL_EV->poll) {
74 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); 99 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
75 } 100 while $SDL_EV->poll;
76 101
77 1 102 1
78 }; 103 };
79 104
105 $WIDTH = $CFG->{width};
106 $HEIGHT = $CFG->{height};
107 $FULLSCREEN = 0;
108
80 init_screen; 109 init_screen;
81
82 $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]";
83 $label->activate;
84 110
85 $CONN = new conn 111 $CONN = new conn
86 host => $CFG->{host}, 112 host => $CFG->{host},
87 port => $CFG->{port}; 113 port => $CFG->{port},
114 user => $CFG->{user},
115 pass => $CFG->{password};
88} 116}
89 117
90sub stop_game { 118sub stop_game {
91 remove Glib::Source $SDL_TIMER; 119 remove Glib::Source $SDL_TIMER;
92 120
93 undef $SDL_APP; 121 undef $SDL_APP;
94 SDL::Quit; 122 SDL::Quit;
95} 123}
96 124
125
126sub force_refresh {
127 glViewport 0, 0, $WIDTH, $HEIGHT;
128 glClear GL_COLOR_BUFFER_BIT;
129
130 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS;
131
132 SDL::GLSwapBuffers;
133}
134
135my $refresh_handler;
136
97sub refresh { 137sub refresh {
98 glClear GL_COLOR_BUFFER_BIT; 138 $refresh_handler ||= add Glib::Idle sub {
99 139 force_refresh;
100 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; 140 undef $refresh_handler;
101 141 0
102 SDL::GLSwapBuffers; 142 };
103} 143}
104 144
105%SDL_CB = ( 145%SDL_CB = (
106 SDL_QUIT() => sub { 146 SDL_QUIT() => sub {
107 main_quit Gtk2; 147 main_quit Gtk2;
112 refresh; 152 refresh;
113 }, 153 },
114 SDL_KEYDOWN() => sub { 154 SDL_KEYDOWN() => sub {
115 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 155 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
116 # alt-enter 156 # alt-enter
117 $CFG->{fullscreen} = !$CFG->{fullscreen}; 157 $FULLSCREEN = !$FULLSCREEN;
118 init_screen; 158 init_screen;
119 } else { 159 } else {
120 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); 160 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV);
121 } 161 }
122 }, 162 },
167 my ($self, $face) = @_; 207 my ($self, $face) = @_;
168 208
169 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 209 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
170 210
171 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; 211 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
212}
213
214sub conn::query {
215 my ($self, $flags, $prompt) = @_;
216
217 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
172} 218}
173 219
174sub gtk_add_cfg_field { 220sub gtk_add_cfg_field {
175 my ($tbl, $cfg, $klbl, $key, $value) = @_; 221 my ($tbl, $cfg, $klbl, $key, $value) = @_;
176 my $i = $cfg->{_i}++; 222 my $i = $cfg->{_i}++;
264 310
265 311
266############################################################################# 312#############################################################################
267 313
268SDL::Init SDL_INIT_EVERYTHING; 314SDL::Init SDL_INIT_EVERYTHING;
315SDL::TTFInit;
269 316
270my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 317my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
271 318
272$mapwidget->activate; 319$mapwidget->activate;
273$mapwidget->focus_in; 320$mapwidget->focus_in;
282 port => 13327, 329 port => 13327,
283}; 330};
284 331
285$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 332$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
286 333
287SDL::TTFInit;
288
289$UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", 24
290 or die "TTFOpenFont: $!";
291
292run_config_dialog 334run_config_dialog
293 login => sub { start_game }, 335 login => sub { start_game },
294 logout => sub { stop_game }; 336 logout => sub { stop_game };
295 337
296main Gtk2; 338main Gtk2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines