… | |
… | |
30 | |
30 | |
31 | our $WIDTH; |
31 | our $WIDTH; |
32 | our $HEIGHT; |
32 | our $HEIGHT; |
33 | our $FULLSCREEN; |
33 | our $FULLSCREEN; |
34 | |
34 | |
35 | our $UIFONT; |
35 | our $FONTSIZE; |
36 | |
36 | |
37 | our $SDL_TIMER; |
37 | our $SDL_TIMER; |
38 | our $SDL_APP; |
38 | our $SDL_APP; |
39 | our $SDL_EV = new SDL::Event; |
39 | our $SDL_EV = new SDL::Event; |
40 | our %SDL_CB; |
40 | our %SDL_CB; |
41 | |
41 | |
42 | our @GL_INIT; # hooks called on every gl init |
42 | our @GL_INIT; # hooks called on every gl init |
43 | |
43 | |
44 | our $ALT_ENTER_MESSAGE; |
44 | our $ALT_ENTER_MESSAGE; |
|
|
45 | |
|
|
46 | our $TOPLEVEL; |
45 | |
47 | |
46 | our $tw; # Test widget #d# |
48 | our $tw; # Test widget #d# |
47 | |
49 | |
48 | sub init_screen { |
50 | sub init_screen { |
49 | $SDL_APP = new SDL::App |
51 | $SDL_APP = new SDL::App |
… | |
… | |
62 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
64 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
63 | |
65 | |
64 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
66 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
65 | or warn "WARNING: non-power-of-two opengl extension required"; |
67 | or warn "WARNING: non-power-of-two opengl extension required"; |
66 | |
68 | |
67 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 |
69 | $FONTSIZE = int $HEIGHT / 50; |
68 | or die "TTFOpenFont: $!"; |
|
|
69 | |
70 | |
70 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; |
71 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
|
|
72 | 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, |
|
|
73 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
71 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
74 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
72 | $ALT_ENTER_MESSAGE->activate; |
75 | $TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
73 | |
76 | |
74 | # Test code #d# |
77 | # Test code #d# |
|
|
78 | unless ($tw) { # haha... |
75 | my $frm = new Crossfire::Client::Widget::Frame; |
79 | my $frm = new Crossfire::Client::Widget::Frame; |
76 | $tw = new Crossfire::Client::Widget::Window; |
80 | $tw = new Crossfire::Client::Widget::Window; |
77 | $frm->add (new Crossfire::Client::Widget::Label 0, 0, 10, $UIFONT, "Foo in the garden!"); |
81 | $frm->add (my $te = new Crossfire::Client::Widget::TextEntry 0, 0, 10, $FONTSIZE, "Foo in the garden!"); |
78 | $tw->add ($frm); |
82 | $tw->add ($frm); |
79 | |
83 | |
80 | $tw->move (0, $HEIGHT - 120); |
84 | $tw->move (0, $HEIGHT - 120); |
81 | $tw->activate; |
85 | $TOPLEVEL->add ($tw); |
82 | # Test code end #d# |
86 | $te->focus_in; |
|
|
87 | } |
83 | |
88 | |
84 | glClearColor 0, 0, 0, 0; |
89 | glClearColor 0, 0, 0, 0; |
85 | |
90 | |
86 | glEnable GL_TEXTURE_2D; |
91 | glEnable GL_TEXTURE_2D; |
87 | glEnable GL_COLOR_MATERIAL; |
92 | glEnable GL_COLOR_MATERIAL; |
… | |
… | |
108 | |
113 | |
109 | $CONN = new conn |
114 | $CONN = new conn |
110 | host => $CFG->{host}, |
115 | host => $CFG->{host}, |
111 | port => $CFG->{port}, |
116 | port => $CFG->{port}, |
112 | user => $CFG->{user}, |
117 | user => $CFG->{user}, |
113 | pass => $CFG->{password}; |
118 | pass => $CFG->{password}, |
|
|
119 | mapw => 50, |
|
|
120 | maph => 37, |
|
|
121 | ; |
114 | } |
122 | } |
115 | |
123 | |
116 | sub stop_game { |
124 | sub stop_game { |
117 | remove Glib::Source $SDL_TIMER; |
125 | remove Glib::Source $SDL_TIMER; |
118 | |
126 | |
… | |
… | |
129 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
137 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
130 | glMatrixMode GL_MODELVIEW; |
138 | glMatrixMode GL_MODELVIEW; |
131 | |
139 | |
132 | glClear GL_COLOR_BUFFER_BIT; |
140 | glClear GL_COLOR_BUFFER_BIT; |
133 | |
141 | |
134 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
142 | $TOPLEVEL->draw; |
135 | |
143 | |
136 | SDL::GLSwapBuffers; |
144 | SDL::GLSwapBuffers; |
137 | } |
145 | } |
138 | |
146 | |
139 | my $refresh_handler; |
147 | my $refresh_handler; |
… | |
… | |
314 | |
322 | |
315 | |
323 | |
316 | ############################################################################# |
324 | ############################################################################# |
317 | |
325 | |
318 | SDL::Init SDL_INIT_EVERYTHING; |
326 | SDL::Init SDL_INIT_EVERYTHING; |
319 | SDL::TTFInit; |
327 | |
|
|
328 | $TOPLEVEL = Crossfire::Client::Widget::Toplevel->new; |
320 | |
329 | |
321 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
330 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
322 | |
331 | |
323 | $mapwidget->activate; |
332 | $TOPLEVEL->add ($mapwidget); |
324 | $mapwidget->focus_in; |
333 | $mapwidget->focus_in; |
325 | |
334 | |
326 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
335 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
327 | |
336 | |
328 | $CFG ||= { |
337 | $CFG ||= { |
… | |
… | |
331 | fullscreen => 0, |
340 | fullscreen => 0, |
332 | host => "crossfire.schmorp.de", |
341 | host => "crossfire.schmorp.de", |
333 | port => 13327, |
342 | port => 13327, |
334 | }; |
343 | }; |
335 | |
344 | |
|
|
345 | Crossfire::Client::set_font Crossfire::Client::find_rcfile "uifont.ttf"; |
|
|
346 | |
336 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
347 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
337 | |
348 | |
338 | run_config_dialog |
349 | run_config_dialog |
339 | login => sub { start_game }, |
350 | login => sub { start_game }, |
340 | logout => sub { stop_game }; |
351 | logout => sub { stop_game }; |