1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Glib; |
6 | use Time::HiRes 'time'; |
7 | use Gtk2 -init; |
|
|
8 | |
|
|
9 | use SDL; |
|
|
10 | use SDL::App; |
|
|
11 | use SDL::Event; |
7 | use Event; |
12 | use SDL::Surface; |
|
|
13 | use SDL::OpenGL; |
|
|
14 | use SDL::OpenGL::Constants; |
|
|
15 | |
8 | |
16 | use Crossfire; |
9 | use Crossfire; |
17 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
18 | |
11 | |
|
|
12 | use Compress::LZF; |
|
|
13 | |
19 | use CFClient; |
14 | use CFClient; |
|
|
15 | use CFClient::UI; |
20 | use CFClient::Widget; |
16 | use CFClient::MapWidget; |
21 | |
17 | |
22 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
23 | |
19 | |
24 | my $MAX_FPS = 30; |
20 | my $MAX_FPS = 60; |
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
21 | my $MIN_FPS = 5; # unused as of yet |
26 | |
22 | |
|
|
23 | our $META_SERVER = "crossfire.real-time.com:13326"; |
|
|
24 | |
|
|
25 | our $FACEMAP; |
|
|
26 | our $TILECACHE; |
27 | our $FACECACHE; |
27 | our $MAPCACHE; |
|
|
28 | |
|
|
29 | our $LAST_REFRESH; |
|
|
30 | our $NOW; |
28 | |
31 | |
29 | our $CFG; |
32 | our $CFG; |
30 | our $CONN; |
33 | our $CONN; |
|
|
34 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
31 | |
35 | |
|
|
36 | our @SDL_MODES; |
32 | our $WIDTH; |
37 | our $WIDTH; |
33 | our $HEIGHT; |
38 | our $HEIGHT; |
34 | our $FULLSCREEN; |
39 | our $FULLSCREEN; |
|
|
40 | our $FONTSIZE; |
35 | |
41 | |
36 | our $NOW; |
42 | our $FONT_PROP; |
|
|
43 | our $FONT_FIXED; |
37 | |
44 | |
|
|
45 | our $MAP; |
38 | our $MAPWIDGET; |
46 | our $MAPWIDGET; |
39 | our $FONTSIZE; |
47 | our $BUTTONBAR; |
|
|
48 | our $LOGVIEW; |
|
|
49 | our $CONSOLE; |
|
|
50 | our $METASERVER; |
40 | |
51 | |
|
|
52 | our $GAUGES; |
|
|
53 | our $STATWIDS; |
|
|
54 | |
41 | our $SDL_TIMER; |
55 | our $SDL_ACTIVE; |
42 | our $SDL_APP; |
|
|
43 | our $SDL_EV; |
|
|
44 | our %SDL_CB; |
56 | our %SDL_CB; |
|
|
57 | |
|
|
58 | our $SDL_MIXER; |
|
|
59 | our @SOUNDS; # event => file mapping |
|
|
60 | our %AUDIO_CHUNKS; # audio files |
45 | |
61 | |
46 | our $ALT_ENTER_MESSAGE; |
62 | our $ALT_ENTER_MESSAGE; |
47 | our $STATUS_LINE; |
63 | our $STATUS_LINE; |
48 | our $DEBUG_STATUS; |
64 | our $DEBUG_STATUS; |
49 | |
65 | |
50 | my $last_refresh; |
66 | sub status { |
51 | my %ANIMATE; |
67 | $STATUS_LINE->set_text ($_[0]); |
52 | my $refresh_handler; |
68 | $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); |
|
|
69 | } |
53 | |
70 | |
54 | our ($tw, $te); # Test widget #d# |
71 | sub debug { |
|
|
72 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
73 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); |
|
|
74 | } |
55 | |
75 | |
56 | sub init_screen { |
76 | sub start_game { |
57 | $SDL_APP = new SDL::App |
77 | status "logging in..."; |
58 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
|
|
59 | -title => "Crossfire+ Client", |
|
|
60 | -width => $WIDTH, |
|
|
61 | -height => $HEIGHT, |
|
|
62 | -opengl => 1, |
|
|
63 | -red_size => 5, |
|
|
64 | -green_size => 5, |
|
|
65 | -blue_size => 5, |
|
|
66 | -alpha_size => 0, |
|
|
67 | -double_buffer => 1, |
|
|
68 | -fullscreen => $FULLSCREEN, |
|
|
69 | -resizeable => 0; |
|
|
70 | |
78 | |
71 | $SDL_EV = new SDL::Event; |
79 | my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
72 | $SDL_EV->set_unicode (1); |
|
|
73 | |
80 | |
74 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
81 | $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; |
75 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
76 | while $SDL_EV->poll; |
|
|
77 | |
82 | |
78 | 1 |
83 | $MAP = new CFClient::Map $mapsize, $mapsize; |
79 | }; |
|
|
80 | |
84 | |
81 | $last_refresh = SDL::GetTicks; |
85 | my ($host, $port) = split /:/, $CFG->{host}; |
82 | |
|
|
83 | CFClient::gl_init; |
|
|
84 | |
|
|
85 | $FONTSIZE = int $HEIGHT / 50; |
|
|
86 | |
|
|
87 | ############################################################################# |
|
|
88 | |
|
|
89 | glClearColor 0.45, 0.45, 0.45, 1; |
|
|
90 | |
|
|
91 | glEnable GL_TEXTURE_2D; |
|
|
92 | glEnable GL_COLOR_MATERIAL; |
|
|
93 | glShadeModel GL_FLAT; |
|
|
94 | glDisable GL_DEPTH_TEST; |
|
|
95 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
96 | |
|
|
97 | ############################################################################# |
|
|
98 | |
|
|
99 | $DEBUG_STATUS = new CFClient::Widget::Label; |
|
|
100 | $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
101 | |
86 | |
102 | $STATUS_LINE = new CFClient::Widget::Label |
|
|
103 | y => $HEIGHT * 59 / 60 - $FONTSIZE; |
|
|
104 | $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); |
|
|
105 | |
|
|
106 | $ALT_ENTER_MESSAGE = new CFClient::Widget::Label |
|
|
107 | y => $HEIGHT * 59 / 60, |
|
|
108 | height => $HEIGHT / 60, |
|
|
109 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
110 | $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
111 | |
|
|
112 | $MAPWIDGET = new CFClient::Widget::MapWidget; |
|
|
113 | $CFClient::Widget::TOPLEVEL->add ($MAPWIDGET); |
|
|
114 | $MAPWIDGET->focus_in; |
|
|
115 | |
|
|
116 | # Test code #d# |
|
|
117 | unless ($tw) { # haha... |
|
|
118 | my $w = new CFClient::Widget::Window |
|
|
119 | w => 300, h => 300, |
|
|
120 | child => (my $frame = new CFClient::Widget::FancyFrame); |
|
|
121 | $CFClient::Widget::TOPLEVEL->add ($w); |
|
|
122 | |
|
|
123 | $frame->add (my $vbox = new CFClient::Widget::VBox); |
|
|
124 | |
|
|
125 | $vbox->add (new CFClient::Widget::Entry text => "hallo"); |
|
|
126 | $vbox->add (new CFClient::Widget::Slider); |
|
|
127 | |
|
|
128 | $tw = new CFClient::Widget::Animator x => $WIDTH - 200, w => 600, h => 300; |
|
|
129 | my $lbl1 = new CFClient::Widget::Label text => "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
130 | my $lbl2 = new CFClient::Widget::Label text => "LBL2"; |
|
|
131 | my $vb = new CFClient::Widget::VBox; |
|
|
132 | my $f = new CFClient::Widget::FancyFrame; |
|
|
133 | my $f2 = new CFClient::Widget::FancyFrame; |
|
|
134 | $f->add ($lbl1); |
|
|
135 | $f2->add ($lbl2); |
|
|
136 | $vb->add ($f); |
|
|
137 | $vb->add ($f2, 1); |
|
|
138 | |
|
|
139 | $tw->add ($vb); |
|
|
140 | $tw->moveto (0, 0); |
|
|
141 | $CFClient::Widget::TOPLEVEL->add ($tw); |
|
|
142 | |
|
|
143 | # $f->move ($WIDTH - 200, 0); |
|
|
144 | # $CFClient::Widget::TOPLEVEL->add ($f); |
|
|
145 | } |
|
|
146 | } |
|
|
147 | |
|
|
148 | sub destroy_screen { |
|
|
149 | remove Glib::Source $SDL_TIMER; |
|
|
150 | undef $SDL_APP; |
|
|
151 | undef $SDL_EV; |
|
|
152 | SDL::Quit; |
|
|
153 | } |
|
|
154 | |
|
|
155 | sub start_game { |
|
|
156 | $WIDTH = $CFG->{width}; |
|
|
157 | $HEIGHT = $CFG->{height}; |
|
|
158 | $FULLSCREEN = 0; |
|
|
159 | |
|
|
160 | init_screen; |
|
|
161 | |
|
|
162 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
163 | |
|
|
164 | $CONN = new conn |
87 | $CONN = new conn |
165 | host => $CFG->{host}, |
88 | host => $host, |
166 | port => $CFG->{port}, |
89 | port => $port || 13327, |
167 | user => $CFG->{user}, |
90 | user => $CFG->{user}, |
168 | pass => $CFG->{password}, |
91 | pass => $CFG->{password}, |
169 | mapw => $mapsize, |
92 | mapw => $mapsize, |
170 | maph => $mapsize, |
93 | maph => $mapsize, |
171 | ; |
94 | ; |
172 | |
95 | |
|
|
96 | status "login successful"; |
|
|
97 | |
173 | CFClient::lowdelay fileno $CONN->{fh}; |
98 | CFClient::lowdelay fileno $CONN->{fh}; |
174 | } |
99 | } |
175 | |
100 | |
176 | sub stop_game { |
101 | sub stop_game { |
177 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
178 | undef $refresh_handler; |
|
|
179 | |
|
|
180 | undef $CONN; |
102 | undef $CONN; |
181 | destroy_screen; |
|
|
182 | } |
103 | } |
183 | |
104 | |
184 | sub force_refresh { |
105 | sub client_setup { |
185 | glViewport 0, 0, $WIDTH, $HEIGHT; |
106 | my $dialog = new CFClient::UI::FancyFrame |
|
|
107 | title => "Client Setup", |
|
|
108 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
109 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
186 | |
110 | |
187 | glMatrixMode GL_PROJECTION; |
111 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
188 | glLoadIdentity; |
112 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
189 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
|
|
190 | glMatrixMode GL_MODELVIEW; |
|
|
191 | |
113 | |
192 | glClear GL_COLOR_BUFFER_BIT; |
114 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
|
|
115 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
193 | |
116 | |
194 | $CFClient::Widget::TOPLEVEL->draw; |
117 | $mode_slider->connect (changed => sub { |
|
|
118 | my ($self, $value) = @_; |
195 | |
119 | |
196 | SDL::GLSwapBuffers; |
120 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
197 | } |
121 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
|
|
122 | }); |
|
|
123 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
198 | |
124 | |
199 | sub debug { |
125 | my $row = 1; |
200 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
201 | $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request); |
|
|
202 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0); |
|
|
203 | } |
|
|
204 | |
126 | |
205 | my $FPS; |
127 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen"); |
|
|
128 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
129 | state => $CFG->{fullscreen}, |
|
|
130 | tooltip => "Bring the client into fullscreen mode", |
|
|
131 | connect_changed => sub { |
|
|
132 | my ($self, $value) = @_; |
|
|
133 | $CFG->{fullscreen} = $value; |
|
|
134 | } |
|
|
135 | ); |
206 | |
136 | |
207 | sub refresh { |
137 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
208 | $refresh_handler ||= add Glib::Idle sub { |
138 | $table->add (1, $row++, new CFClient::UI::CheckBox |
209 | if ($SDL_APP) { |
139 | state => $CFG->{fast}, |
210 | $NOW = SDL::GetTicks; |
140 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
|
|
141 | connect_changed => sub { |
|
|
142 | my ($self, $value) = @_; |
|
|
143 | $CFG->{fast} = $value; |
|
|
144 | } |
|
|
145 | ); |
211 | |
146 | |
212 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
147 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War"); |
213 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
148 | $table->add (1, $row++, new CFClient::UI::CheckBox |
214 | $NOW = SDL::GetTicks; |
149 | state => $CFG->{fow_enable}, |
|
|
150 | tooltip => "Fog-of-War marks areas that cannot be seen by the player", |
|
|
151 | connect_changed => sub { |
|
|
152 | my ($self, $value) = @_; |
|
|
153 | $CFG->{fow_enable} = $value; |
|
|
154 | } |
|
|
155 | ); |
|
|
156 | |
|
|
157 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity"); |
|
|
158 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
159 | range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], |
|
|
160 | tooltip => "The higher the intensity, the lighter the Fog-of-War color", |
|
|
161 | connect_changed => sub { |
|
|
162 | my ($self, $value) = @_; |
|
|
163 | $CFG->{fow_intensity} = $value; |
|
|
164 | } |
|
|
165 | ); |
|
|
166 | |
|
|
167 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth"); |
|
|
168 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
169 | state => $CFG->{fow_smooth}, |
|
|
170 | tooltip => "Smooth the Fog-of-War a bit to make it more realistic", |
|
|
171 | connect_changed => sub { |
|
|
172 | my ($self, $value) = @_; |
|
|
173 | $CFG->{fow_smooth} = $value; |
|
|
174 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
|
|
175 | } |
|
|
176 | ); |
|
|
177 | |
|
|
178 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
|
|
179 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
180 | range => [$CFG->{gui_fontsize}, 0.5, 2, 0.1], |
|
|
181 | tooltip => "The font size used by most GUI elements", |
|
|
182 | connect_changed => sub { |
|
|
183 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
184 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
185 | } |
|
|
186 | ); |
|
|
187 | |
|
|
188 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
|
|
189 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
190 | range => [$CFG->{log_fontsize}, 0.5, 2, 0.1], |
|
|
191 | tooltip => "The font size used by the server log window only", |
|
|
192 | connect_changed => sub { |
|
|
193 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
|
|
194 | } |
|
|
195 | ); |
|
|
196 | |
|
|
197 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize"); |
|
|
198 | |
|
|
199 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
200 | range => [$CFG->{stat_fontsize}, 0.5, 2, 0.1], |
|
|
201 | tooltip => "The font size used by the statistics window only", |
|
|
202 | connect_changed => sub { |
|
|
203 | $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10; |
|
|
204 | &set_stats_window_fontsize; |
|
|
205 | } |
|
|
206 | ); |
|
|
207 | |
|
|
208 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge size"); |
|
|
209 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
210 | range => [$CFG->{gauge_size}, 0.2, 0.8, 0.02], |
|
|
211 | tooltip => "Adjust the size of the stats gauges at the bottom right", |
|
|
212 | connect_changed => sub { |
|
|
213 | $CFG->{gauge_size} = $_[1]; |
|
|
214 | my $h = int $HEIGHT * $CFG->{gauge_size}; |
|
|
215 | $GAUGES->{win}->set_size ($WIDTH, $h); |
|
|
216 | $GAUGES->{win}->move (0, $HEIGHT - $h); |
|
|
217 | } |
|
|
218 | ); |
|
|
219 | |
|
|
220 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
|
|
221 | $table->add (1, $row++, new CFClient::UI::Slider |
|
|
222 | range => [$CFG->{gauge_fontsize}, 0.5, 2.0, 0.1], |
|
|
223 | tooltip => "Adjusts the fontsize of the gauges at the bottom right", |
|
|
224 | connect_changed => sub { |
|
|
225 | $CFG->{gauge_fontsize} = 0.1 * int $_[1] * 10; |
|
|
226 | &set_gauge_window_fontsize; |
|
|
227 | #$GAUGES->{win}->check_size; |
|
|
228 | #$GAUGES->{win}->update; |
|
|
229 | } |
|
|
230 | ); |
|
|
231 | |
|
|
232 | $table->add (1, $row++, new CFClient::UI::Button |
|
|
233 | expand => 1, align => 0, text => "Apply", |
|
|
234 | tooltip => "Apply the video settings", |
|
|
235 | connect_activate => sub { |
|
|
236 | video_shutdown (); |
|
|
237 | video_init (); |
|
|
238 | } |
|
|
239 | ); |
|
|
240 | |
|
|
241 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
|
|
242 | $table->add (1, $row++, new CFClient::UI::CheckBox |
|
|
243 | state => $CFG->{audio_enable}, |
|
|
244 | tooltip => "If enabled, sound effects and music will be played. If disabled, no audio will be used and the soundcard will not be opened.", |
|
|
245 | connect_changed => sub { |
|
|
246 | $CFG->{audio_enable} = $_[1]; |
|
|
247 | } |
|
|
248 | ); |
|
|
249 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
250 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
251 | # $CFG->{effects_volume} = $_[1]; |
|
|
252 | # }); |
|
|
253 | $table->add (0, $row, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
254 | $table->add (1, $row++, my $hbox = new CFClient::UI::HBox); |
|
|
255 | $hbox->add (new CFClient::UI::CheckBox |
|
|
256 | expand => 1, state => $CFG->{bgm_enable}, |
|
|
257 | tooltip => "Enable background music playing", |
|
|
258 | connect_changed => sub { |
|
|
259 | $CFG->{bgm_enable} = $_[1]; |
|
|
260 | } |
|
|
261 | ); |
|
|
262 | $hbox->add (new CFClient::UI::Slider |
|
|
263 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], |
|
|
264 | tooltip => "The volume of the background music", |
|
|
265 | connect_changed => sub { |
|
|
266 | $CFG->{bgm_volume} = $_[1]; |
|
|
267 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
268 | } |
|
|
269 | ); |
|
|
270 | |
|
|
271 | $table->add (1, $row++, new CFClient::UI::Button |
|
|
272 | expand => 1, align => 0, text => "Apply", |
|
|
273 | tooltip => "Apply the audio settings", |
|
|
274 | connect_activate => sub { |
|
|
275 | audio_shutdown (); |
|
|
276 | audio_init (); |
|
|
277 | } |
|
|
278 | ); |
|
|
279 | |
|
|
280 | $dialog |
|
|
281 | } |
|
|
282 | |
|
|
283 | sub set_stats_window_fontsize { |
|
|
284 | for (values %{$STATWIDS}) { |
|
|
285 | $_->set_fontsize ($::CFG->{stat_fontsize}); |
|
|
286 | } |
|
|
287 | } |
|
|
288 | |
|
|
289 | sub set_gauge_window_fontsize { |
|
|
290 | for (map { $GAUGES->{$_} } grep { $_ ne 'win' } keys %{$GAUGES}) { |
|
|
291 | $_->set_fontsize ($::CFG->{gauge_fontsize}); |
|
|
292 | } |
|
|
293 | } |
|
|
294 | |
|
|
295 | sub make_gauge_window { |
|
|
296 | my $gh = int ($HEIGHT * $CFG->{gauge_size}); |
|
|
297 | # my $gw = int ($WIDTH * $CFG->{gauge_w_size}); |
|
|
298 | |
|
|
299 | my $win = new CFClient::UI::Frame ( |
|
|
300 | y => $HEIGHT - $gh, x => 0, req_w => $WIDTH, req_h => $gh |
|
|
301 | ); |
|
|
302 | $win->add (my $vb = new CFClient::UI::VBox); |
|
|
303 | |
|
|
304 | $vb->add (my $hbg = new CFClient::UI::HBox expand => 1); |
|
|
305 | |
|
|
306 | |
|
|
307 | $hbg->add (new CFClient::UI::Empty expand => 1); |
|
|
308 | $hbg->add (my $hb = new CFClient::UI::HBox); |
|
|
309 | $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', tooltip => "Health points"); |
|
|
310 | $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', tooltip => "Spellpoints"); |
|
|
311 | $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', tooltip => "Grace"); |
|
|
312 | $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', tooltip => "Food"); |
|
|
313 | |
|
|
314 | $vb->add (my $exp = new CFClient::UI::Label valign => 0, align => 1, text => "XP: 0 LVL: 0"); |
|
|
315 | $vb->add (my $rng = new CFClient::UI::Label valign => 0, align => 1, text => "Rng:"); |
|
|
316 | |
|
|
317 | $GAUGES = { |
|
|
318 | exp => $exp, win => $win, range => $rng, |
|
|
319 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
|
|
320 | }; |
|
|
321 | $win |
|
|
322 | } |
|
|
323 | |
|
|
324 | sub make_stats_window { |
|
|
325 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats"); |
|
|
326 | |
|
|
327 | $tgw->add (my $vb = new CFClient::UI::VBox); |
|
|
328 | $vb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1); |
|
|
329 | $vb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1); |
|
|
330 | |
|
|
331 | $vb->add (my $hb = new CFClient::UI::HBox expand => 1); |
|
|
332 | |
|
|
333 | $hb->add (my $tbl = new CFClient::UI::Table expand => 1); |
|
|
334 | |
|
|
335 | $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
336 | $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
337 | $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
338 | $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
339 | $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
340 | $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
341 | $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => +1, template => "30"); |
|
|
342 | |
|
|
343 | $tbl->add (1, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Str"); |
|
|
344 | $tbl->add (1, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dex"); |
|
|
345 | $tbl->add (1, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Con"); |
|
|
346 | $tbl->add (1, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Int"); |
|
|
347 | $tbl->add (1, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wis"); |
|
|
348 | $tbl->add (1, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Pow"); |
|
|
349 | $tbl->add (1, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Cha"); |
|
|
350 | |
|
|
351 | $tbl->add (2, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
352 | $tbl->add (2, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => +1, template => "-120"); |
|
|
353 | $tbl->add (2, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
354 | $tbl->add (2, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => +1, template => "120"); |
|
|
355 | $tbl->add (2, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => +1, template => "10.54"); |
|
|
356 | $tbl->add (2, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => +1, template => "9"); |
|
|
357 | |
|
|
358 | $tbl->add (3, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc"); |
|
|
359 | $tbl->add (3, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac"); |
|
|
360 | $tbl->add (3, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam"); |
|
|
361 | $tbl->add (3, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm"); |
|
|
362 | $tbl->add (3, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp"); |
|
|
363 | $tbl->add (3, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp"); |
|
|
364 | |
|
|
365 | $hb->add (my $tbl2 = new CFClient::UI::Table expand => 1); |
|
|
366 | |
|
|
367 | my $row = 0; |
|
|
368 | my $col = 0; |
|
|
369 | |
|
|
370 | my %resist_names = ( |
|
|
371 | slow => "Slow", |
|
|
372 | holyw => "Holy Word", |
|
|
373 | conf => "Confusion", |
|
|
374 | fire => "Fire", |
|
|
375 | depl => "Depletion", |
|
|
376 | magic => "Magic", |
|
|
377 | drain => "Draining", |
|
|
378 | acid => "Acid", |
|
|
379 | pois => "Poison", |
|
|
380 | para => "Paralysation", |
|
|
381 | deat => "Death", |
|
|
382 | phys => "Physical", |
|
|
383 | blind => "Blind", |
|
|
384 | fear => "Fear", |
|
|
385 | tund => "Turn undead", |
|
|
386 | elec => "Electricity", |
|
|
387 | cold => "Cold", |
|
|
388 | ghit => "Ghost hit", |
|
|
389 | ); |
|
|
390 | for (qw/slow holyw conf fire depl magic |
|
|
391 | drain acid pois para deat phys |
|
|
392 | blind fear tund elec cold ghit/) |
|
|
393 | { |
|
|
394 | $tbl2->add ($col, $row, |
|
|
395 | $STATWIDS->{"res_$_"} = |
|
|
396 | new CFClient::UI::Label |
|
|
397 | template => "-100%", |
|
|
398 | align => +1, |
|
|
399 | valign => 0, |
|
|
400 | tooltip => $resist_names{$_} |
|
|
401 | ); |
|
|
402 | $tbl2->add ($col + 1, $row, new CFClient::UI::Image |
|
|
403 | can_hover => 1, |
|
|
404 | can_events => 1, |
|
|
405 | image => "ui/resist/resist_$_.png", |
|
|
406 | tooltip => $resist_names{$_} |
|
|
407 | ); |
|
|
408 | |
|
|
409 | $row++; |
|
|
410 | if ($row % 6 == 0) { |
|
|
411 | $col += 2; |
|
|
412 | $row = 0; |
|
|
413 | } |
|
|
414 | } |
|
|
415 | |
|
|
416 | &set_stats_window_fontsize; |
|
|
417 | update_stats_window ({}); |
|
|
418 | |
|
|
419 | $tgw |
|
|
420 | } |
|
|
421 | |
|
|
422 | sub update_stats_window { |
|
|
423 | my ($stats) = @_; |
|
|
424 | |
|
|
425 | # i love text protocols!!! |
|
|
426 | my $hp = $stats->{1} * 1; |
|
|
427 | my $hp_m = $stats->{2} * 1; |
|
|
428 | my $sp = $stats->{3} * 1; |
|
|
429 | my $sp_m = $stats->{4} * 1; |
|
|
430 | my $fo = $stats->{18} * 1; |
|
|
431 | my $fo_m = 999; |
|
|
432 | my $gr = $stats->{23} * 1; |
|
|
433 | my $gr_m = $stats->{24} * 1; |
|
|
434 | |
|
|
435 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
|
|
436 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
|
|
437 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
|
|
438 | $GAUGES->{grace} ->set_value ($gr, $gr_m); |
|
|
439 | $GAUGES->{exp} ->set_text ("XP: " . ($stats->{11} || $stats->{28}) * 1 |
|
|
440 | ." LVL: " . $stats->{12} * 1); |
|
|
441 | my $rng = $stats->{20}; |
|
|
442 | $rng =~ s/^Range: //; # thank you so much dear server |
|
|
443 | $GAUGES->{range} ->set_text ("Rng: " . $rng); |
|
|
444 | my $title = $stats->{21}; |
|
|
445 | $title =~ s/^Player: //; |
|
|
446 | $STATWIDS->{title} ->set_text ("Title: " . $title); |
|
|
447 | |
|
|
448 | $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5}); |
|
|
449 | $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8}); |
|
|
450 | $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9}); |
|
|
451 | $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6}); |
|
|
452 | $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7}); |
|
|
453 | $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22}); |
|
|
454 | $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10}); |
|
|
455 | $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13}); |
|
|
456 | $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14}); |
|
|
457 | $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15}); |
|
|
458 | $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16}); |
|
|
459 | $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17}); |
|
|
460 | $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19}); |
|
|
461 | |
|
|
462 | my %tbl = ( |
|
|
463 | phys => 100, |
|
|
464 | magic => 101, |
|
|
465 | fire => 102, |
|
|
466 | elec => 103, |
|
|
467 | cold => 104, |
|
|
468 | conf => 105, |
|
|
469 | acid => 106, |
|
|
470 | drain => 107, |
|
|
471 | ghit => 108, |
|
|
472 | pois => 109, |
|
|
473 | slow => 110, |
|
|
474 | para => 111, |
|
|
475 | tund => 112, |
|
|
476 | fear => 113, |
|
|
477 | depl => 113, |
|
|
478 | deat => 115, |
|
|
479 | holyw => 116, |
|
|
480 | blind => 117 |
|
|
481 | ); |
|
|
482 | |
|
|
483 | for (keys %tbl) { |
|
|
484 | $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}}); |
|
|
485 | } |
|
|
486 | |
|
|
487 | } |
|
|
488 | |
|
|
489 | sub metaserver_dialog { |
|
|
490 | my $dialog = new CFClient::UI::FancyFrame |
|
|
491 | title => "Metaserver", |
|
|
492 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
493 | |
|
|
494 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
|
|
495 | |
|
|
496 | $dialog |
|
|
497 | } |
|
|
498 | |
|
|
499 | sub update_metaserver { |
|
|
500 | my ($HOST) = @_; |
|
|
501 | |
|
|
502 | status "fetching metaserver list..."; |
|
|
503 | |
|
|
504 | my $buf; |
|
|
505 | |
|
|
506 | my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0; |
|
|
507 | |
|
|
508 | Event->io (fd => $fh, poll => 'r', cb => sub { |
|
|
509 | my $res = sysread $fh, $buf, 8192, length $buf; |
|
|
510 | |
|
|
511 | if (!defined $res) { |
|
|
512 | $_[0]->w->cancel; |
|
|
513 | status "metaserver: $!"; |
|
|
514 | } elsif ($res == 0) { |
|
|
515 | $_[0]->w->cancel; |
|
|
516 | status "server list retrieved"; |
|
|
517 | |
|
|
518 | my $table = $METASERVER->{table}; |
|
|
519 | |
|
|
520 | $table->clear; |
|
|
521 | |
|
|
522 | my @col = qw(Use #Users Host Uptime Version Description); |
|
|
523 | $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_]) |
|
|
524 | for 0 .. $#col; |
|
|
525 | |
|
|
526 | my @align = qw(1 0 1 1 -1); |
|
|
527 | |
|
|
528 | my $y = 0; |
|
|
529 | for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) { |
|
|
530 | my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m; |
|
|
531 | |
|
|
532 | for ($desc) { |
|
|
533 | s/<br>/\n/gi; |
|
|
534 | s/<li>/\n· /gi; |
|
|
535 | s/<.*?>//sgi; |
|
|
536 | s/&/&/g; |
|
|
537 | s/</</g; |
|
|
538 | s/>/>/g; |
|
|
539 | } |
|
|
540 | |
|
|
541 | $uptime = sprintf "%dd %02d:%02d:%02d", |
|
|
542 | (int $m->[8] / 86400), |
|
|
543 | (int $m->[8] / 3600) % 24, |
|
|
544 | (int $m->[8] / 60) % 60, |
|
|
545 | $m->[8] % 60; |
|
|
546 | |
|
|
547 | $m = [$users, $host, $uptime, $version, $desc]; |
|
|
548 | |
|
|
549 | $y++; |
|
|
550 | |
|
|
551 | $table->add (0, $y, new CFClient::UI::VBox children => [ |
|
|
552 | (new CFClient::UI::Button text => " ", connect_activate => sub { |
|
|
553 | $HOST->set_text ($CFG->{host} = $host); |
|
|
554 | }), |
|
|
555 | (new CFClient::UI::Empty expand => 1), |
|
|
556 | ]); |
|
|
557 | |
|
|
558 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
|
|
559 | for 0 .. $#$m; |
215 | } |
560 | } |
|
|
561 | } |
|
|
562 | }); |
|
|
563 | } |
|
|
564 | |
|
|
565 | sub server_setup { |
|
|
566 | my $dialog = new CFClient::UI::FancyFrame |
|
|
567 | title => "Server Setup", |
|
|
568 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
569 | |
|
|
570 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
|
|
571 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
|
|
572 | |
|
|
573 | { |
|
|
574 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
|
|
575 | |
|
|
576 | $vbox->add ( |
|
|
577 | my $HOST = new CFClient::UI::Entry |
|
|
578 | expand => 1, |
|
|
579 | text => $CFG->{host}, |
|
|
580 | tooltip => "The hostname or ip address of the Crossfire(+) server to connect to", |
|
|
581 | connect_changed => sub { |
|
|
582 | my ($self, $value) = @_; |
|
|
583 | $CFG->{host} = $value; |
216 | |
584 | } |
217 | my $interval = ($NOW - $last_refresh) * 0.001; |
585 | ); |
218 | $last_refresh = $NOW; |
|
|
219 | |
586 | |
220 | if ($interval) { |
587 | $METASERVER = metaserver_dialog; |
221 | $FPS ||= 1 / $interval; |
588 | |
222 | $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; |
589 | $vbox->add (new CFClient::UI::Flopper |
223 | debug sprintf "%5.02f", $FPS; |
590 | expand => 1, |
|
|
591 | text => "Metaserver", |
|
|
592 | other => $METASERVER, |
|
|
593 | tooltip => "Show a list of avaible crossfire servers", |
|
|
594 | connect_open => sub { |
|
|
595 | update_metaserver $HOST; |
224 | } |
596 | } |
|
|
597 | ); |
|
|
598 | } |
225 | |
599 | |
226 | force_refresh; |
600 | $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username"); |
227 | $_->animate ($interval) for grep $_, values %ANIMATE; |
601 | $table->add (1, 4, new CFClient::UI::Entry |
|
|
602 | text => $CFG->{user}, |
|
|
603 | tooltip => "The name of your character on the server", |
|
|
604 | connect_changed => sub { |
|
|
605 | my ($self, $value) = @_; |
|
|
606 | $CFG->{user} = $value; |
|
|
607 | } |
|
|
608 | ); |
228 | |
609 | |
229 | if (%ANIMATE) { |
610 | $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password"); |
|
|
611 | $table->add (1, 5, new CFClient::UI::Entry |
|
|
612 | text => $CFG->{password}, |
|
|
613 | hidden => 1, |
|
|
614 | tooltip => "The password for your character", |
|
|
615 | connect_changed => sub { |
|
|
616 | my ($self, $value) = @_; |
|
|
617 | $CFG->{password} = $value; |
|
|
618 | } |
|
|
619 | ); |
|
|
620 | |
|
|
621 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd"); |
|
|
622 | $table->add (1, 6, my $saycmd = new CFClient::UI::Entry |
|
|
623 | text => $CFG->{say_command}, |
|
|
624 | tooltip => "This is the command that will be used if you write a line in the message window entry. " |
|
|
625 | ."Usually you want to enter something like 'say' or 'shout' or 'gsay' here. " |
|
|
626 | ."But you could also set it to 'tell <playername>' to only chat with that user.", |
|
|
627 | connect_changed => sub { |
|
|
628 | my ($self, $value) = @_; |
|
|
629 | $CFG->{say_command} = $value; |
|
|
630 | } |
|
|
631 | ); |
|
|
632 | |
|
|
633 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size"); |
|
|
634 | $table->add (1, 7, new CFClient::UI::Slider |
|
|
635 | req_w => 100, |
|
|
636 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
|
|
637 | tooltip => "This is the size of the portion of the map update the server sends you. " |
|
|
638 | ."If you set this to a high value you will be able to see further for example.", |
|
|
639 | connect_changed => sub { |
|
|
640 | my ($self, $value) = @_; |
|
|
641 | |
|
|
642 | $CFG->{mapsize} = $self->{range}[0] = $value = int $value; |
|
|
643 | }, |
|
|
644 | ); |
|
|
645 | |
|
|
646 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { |
|
|
647 | start_game; |
|
|
648 | }); |
|
|
649 | |
|
|
650 | $dialog |
|
|
651 | } |
|
|
652 | |
|
|
653 | sub message_window { |
|
|
654 | my $window = new CFClient::UI::FancyFrame |
|
|
655 | title => "Messages", |
|
|
656 | border_bg => [1, 1, 1, 0.5], |
|
|
657 | bg => [0.3, 0.3, 0.3, 0.8], |
|
|
658 | user_w => int $::WIDTH / 3, |
|
|
659 | user_h => int $::HEIGHT / 5, |
|
|
660 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
661 | |
|
|
662 | $vbox->add ($LOGVIEW = new CFClient::UI::TextView |
|
|
663 | expand => 1, |
|
|
664 | font => $FONT_FIXED, |
|
|
665 | fontsize => $::CFG->{log_fontsize}, |
|
|
666 | ); |
|
|
667 | |
|
|
668 | $vbox->add (my $input = new CFClient::UI::Entry |
|
|
669 | connect_focus_in => sub { |
|
|
670 | my ($input, $prev_focus) = @_; |
|
|
671 | |
|
|
672 | delete $input->{refocus_map}; |
|
|
673 | |
|
|
674 | if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) { |
|
|
675 | $input->{refocus_map} = 1; |
230 | 1 |
676 | } |
|
|
677 | delete $input->{auto_activated}; |
|
|
678 | }, |
|
|
679 | connect_activate => sub { |
|
|
680 | my ($input, $text) = @_; |
|
|
681 | $input->set_text (''); |
|
|
682 | |
|
|
683 | if ($text =~ /^\/(.*)/) { |
|
|
684 | $::CONN->user_send ($1); |
231 | } else { |
685 | } else { |
232 | undef $refresh_handler; |
686 | my $say_cmd = $::CFG->{say_command} || 'say'; |
|
|
687 | $::CONN->user_send ("$say_cmd $text"); |
|
|
688 | } |
|
|
689 | if ($input->{refocus_map}) { |
|
|
690 | delete $input->{refocus_map}; |
|
|
691 | $MAPWIDGET->focus_in |
|
|
692 | } |
|
|
693 | }, |
|
|
694 | connect_escape => sub { |
|
|
695 | $MAPWIDGET->focus_in |
|
|
696 | }, |
|
|
697 | ); |
|
|
698 | |
|
|
699 | $CONSOLE = { |
|
|
700 | window => $window, |
|
|
701 | input => $input |
|
|
702 | }; |
|
|
703 | |
|
|
704 | $window |
|
|
705 | } |
|
|
706 | |
|
|
707 | sub sdl_init { |
|
|
708 | CFClient::SDL_Init |
|
|
709 | and die "SDL::Init failed!\n"; |
|
|
710 | } |
|
|
711 | |
|
|
712 | sub video_init { |
|
|
713 | sdl_init; |
|
|
714 | |
|
|
715 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
|
|
716 | $FULLSCREEN = $CFG->{fullscreen}; |
|
|
717 | $FAST = $CFG->{fast}; |
|
|
718 | |
|
|
719 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
|
|
720 | or die "SDL_SetVideoMode failed!\n"; |
|
|
721 | |
|
|
722 | $SDL_ACTIVE = 1; |
|
|
723 | |
|
|
724 | $LAST_REFRESH = time - 0.01; |
|
|
725 | |
|
|
726 | CFClient::gl_init; |
|
|
727 | |
|
|
728 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
729 | |
|
|
730 | ############################################################################# |
|
|
731 | |
|
|
732 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
|
|
733 | $DEBUG_STATUS->show; |
|
|
734 | |
|
|
735 | $STATUS_LINE = new CFClient::UI::Label |
|
|
736 | padding => 0, |
|
|
737 | y => $HEIGHT - $FONTSIZE * 1.8; |
|
|
738 | $STATUS_LINE->show; |
|
|
739 | |
|
|
740 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
741 | padding => 0, |
|
|
742 | fontsize => 0.8, |
|
|
743 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
744 | $ALT_ENTER_MESSAGE->show; |
|
|
745 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
|
|
746 | |
|
|
747 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
|
|
748 | $MAPWIDGET->focus_in; |
|
|
749 | $MAPWIDGET->connect (activate_console => sub { |
|
|
750 | my ($mapwidget, $preset) = @_; |
|
|
751 | |
|
|
752 | if ($CONSOLE) { |
|
|
753 | $CONSOLE->{input}->{auto_activated} = 1; |
|
|
754 | $CONSOLE->{input}->focus_in; |
|
|
755 | |
|
|
756 | if ($preset && $CONSOLE->{input}->get_text eq '') { |
|
|
757 | $CONSOLE->{input}->set_text ($preset); |
|
|
758 | } |
|
|
759 | } |
|
|
760 | }); |
|
|
761 | |
|
|
762 | $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox); |
|
|
763 | |
|
|
764 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); |
|
|
765 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); |
|
|
766 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); |
|
|
767 | |
|
|
768 | $CFClient::UI::ROOT->add (make_gauge_window); # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D |
|
|
769 | $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); |
|
|
770 | |
|
|
771 | $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { |
|
|
772 | CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; |
|
|
773 | status "Configuration Saved"; |
|
|
774 | }); |
|
|
775 | |
|
|
776 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
|
|
777 | } |
|
|
778 | |
|
|
779 | sub video_shutdown { |
|
|
780 | $CFClient::UI::ROOT->{children} = []; |
|
|
781 | undef $SDL_ACTIVE; |
|
|
782 | } |
|
|
783 | |
|
|
784 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
|
|
785 | my $bgmusic;#TODO#hack#d# |
|
|
786 | |
|
|
787 | sub audio_music_finished { |
|
|
788 | return unless $CFG->{bgm_enable}; |
|
|
789 | |
|
|
790 | # TODO: hack, do play loop and mood music |
|
|
791 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
792 | $bgmusic->play (0); |
|
|
793 | |
|
|
794 | push @bgmusic, shift @bgmusic; |
|
|
795 | } |
|
|
796 | |
|
|
797 | sub audio_init { |
|
|
798 | if ($CFG->{audio_enable}) { |
|
|
799 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
|
|
800 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
|
|
801 | CFClient::Mix_AllocateChannels 8; |
|
|
802 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
|
|
803 | |
|
|
804 | audio_music_finished; |
|
|
805 | |
|
|
806 | while (<$fh>) { |
|
|
807 | next if /^\s*#/; |
|
|
808 | next if /^\s*$/; |
|
|
809 | |
|
|
810 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
|
|
811 | |
|
|
812 | push @SOUNDS, "$volume,$file"; |
|
|
813 | |
|
|
814 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
|
|
815 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
|
|
816 | $chunk->volume ($volume * 128 / 100); |
|
|
817 | $chunk |
233 | 0 |
818 | }; |
234 | } |
819 | } |
235 | } else { |
820 | } else { |
236 | undef $refresh_handler; |
821 | status "unable to open sound config: $!"; |
237 | 0 |
|
|
238 | } |
822 | } |
239 | }; |
823 | } |
|
|
824 | } |
|
|
825 | |
|
|
826 | sub audio_shutdown { |
|
|
827 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
|
|
828 | undef $SDL_MIXER; |
|
|
829 | @SOUNDS = (); |
|
|
830 | %AUDIO_CHUNKS = (); |
|
|
831 | } |
|
|
832 | |
|
|
833 | my %animate_object; |
|
|
834 | my $animate_timer; |
|
|
835 | |
|
|
836 | my $want_refresh; |
|
|
837 | my $can_refresh; |
|
|
838 | |
|
|
839 | my $fps = 9; |
|
|
840 | |
|
|
841 | sub force_refresh { |
|
|
842 | $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; |
|
|
843 | debug sprintf "%3.2f", $fps; |
|
|
844 | |
|
|
845 | $want_refresh = 0; |
|
|
846 | $can_refresh = 0; |
|
|
847 | |
|
|
848 | $CFClient::UI::ROOT->draw; |
|
|
849 | |
|
|
850 | CFClient::SDL_GL_SwapBuffers; |
|
|
851 | |
|
|
852 | $LAST_REFRESH = $NOW; |
|
|
853 | } |
|
|
854 | |
|
|
855 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
|
|
856 | $NOW = time; |
|
|
857 | |
|
|
858 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
|
|
859 | for CFClient::SDL_PollEvent; |
|
|
860 | |
|
|
861 | if (%animate_object) { |
|
|
862 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
|
|
863 | $want_refresh++; |
|
|
864 | } |
|
|
865 | |
|
|
866 | if ($want_refresh) { |
|
|
867 | force_refresh; |
|
|
868 | } else { |
|
|
869 | $can_refresh = 1; |
|
|
870 | } |
|
|
871 | }); |
|
|
872 | |
|
|
873 | sub refresh { |
|
|
874 | $want_refresh++; |
240 | } |
875 | } |
241 | |
876 | |
242 | sub animation_start { |
877 | sub animation_start { |
243 | my ($widget) = @_; |
878 | my ($widget) = @_; |
244 | $ANIMATE{$widget} = $widget; |
879 | $animate_object{$widget} = $widget; |
245 | Scalar::Util::weaken $ANIMATE{$widget}; |
|
|
246 | |
|
|
247 | refresh; |
|
|
248 | } |
880 | } |
249 | |
881 | |
250 | sub animation_stop { |
882 | sub animation_stop { |
251 | my ($widget) = @_; |
883 | my ($widget) = @_; |
252 | delete $ANIMATE{$widget}; |
884 | delete $animate_object{$widget}; |
|
|
885 | } |
|
|
886 | |
|
|
887 | @conn::ISA = Crossfire::Protocol::; |
|
|
888 | |
|
|
889 | sub conn::stats_update { |
|
|
890 | my ($self, $stats) = @_; |
|
|
891 | |
|
|
892 | update_stats_window ($stats); |
|
|
893 | } |
|
|
894 | |
|
|
895 | sub conn::user_send { |
|
|
896 | my ($self, $command) = @_; |
|
|
897 | |
|
|
898 | $self->send_command ($command); |
|
|
899 | status $command; |
|
|
900 | } |
|
|
901 | |
|
|
902 | sub conn::map_scroll { |
|
|
903 | my ($self, $dx, $dy) = @_; |
|
|
904 | |
|
|
905 | $MAP->scroll ($dx, $dy); |
|
|
906 | } |
|
|
907 | |
|
|
908 | sub conn::feed_map1a { |
|
|
909 | my ($self, $data) = @_; |
|
|
910 | |
|
|
911 | # $self->Crossfire::Protocol::feed_map1a ($data); |
|
|
912 | |
|
|
913 | $MAP->map1a_update ($data); |
|
|
914 | $MAPWIDGET->update; |
|
|
915 | } |
|
|
916 | |
|
|
917 | sub conn::flush_map { |
|
|
918 | my ($self) = @_; |
|
|
919 | |
|
|
920 | my $map_info = delete $self->{map_info} |
|
|
921 | or return; |
|
|
922 | |
|
|
923 | my ($hash, $x, $y, $w, $h) = @$map_info; |
|
|
924 | |
|
|
925 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
|
|
926 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
|
|
927 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
|
|
928 | } |
|
|
929 | |
|
|
930 | sub conn::map_clear { |
|
|
931 | my ($self) = @_; |
|
|
932 | |
|
|
933 | $self->flush_map; |
|
|
934 | delete $self->{neigh_map}; |
|
|
935 | |
|
|
936 | $MAP->clear; |
|
|
937 | } |
|
|
938 | |
|
|
939 | |
|
|
940 | sub conn::load_map($$$) { |
|
|
941 | my ($self, $hash, $x, $y) = @_; |
|
|
942 | |
|
|
943 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
|
|
944 | $data = Compress::LZF::decompress $data; |
|
|
945 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
|
|
946 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
|
|
947 | my $data = $TILECACHE->get ($id) |
|
|
948 | or next; |
|
|
949 | |
|
|
950 | $self->set_texture ($id => $data); |
|
|
951 | } |
|
|
952 | } |
|
|
953 | } |
|
|
954 | |
|
|
955 | # this method does a "flood fill" into every tile direction |
|
|
956 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
957 | # i.e. a map is the same as the left of the right map etc. |
|
|
958 | # failure to comply are harmless and result in display errors |
|
|
959 | # at worst. |
|
|
960 | sub conn::flood_fill { |
|
|
961 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
|
|
962 | |
|
|
963 | # the server does not allow map paths > 6 |
|
|
964 | return if 6 <= length $path; |
|
|
965 | |
|
|
966 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
|
|
967 | |
|
|
968 | for ( |
|
|
969 | [1, 0, -1], |
|
|
970 | [2, 1, 0], |
|
|
971 | [3, 0, 1], |
|
|
972 | [4, -1, 0], |
|
|
973 | ) { |
|
|
974 | my ($tile, $dx, $dy) = @$_; |
|
|
975 | |
|
|
976 | my $gx = $gx + $dx; |
|
|
977 | my $gy = $gy + $dy; |
|
|
978 | |
|
|
979 | next unless $flags & (1 << ($tile - 1)); |
|
|
980 | next if $self->{neigh_grid}{$gx, $gy}++; |
|
|
981 | |
|
|
982 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
|
|
983 | if (my $info = $neigh->[$tile]) { |
|
|
984 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
|
|
985 | |
|
|
986 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
987 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
988 | |
|
|
989 | } else { |
|
|
990 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
991 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
992 | |
|
|
993 | return if $mode ne "spatial"; |
|
|
994 | |
|
|
995 | $x += $MAP->ox; |
|
|
996 | $y += $MAP->oy; |
|
|
997 | |
|
|
998 | $self->load_map ($hash, $x, $y) |
|
|
999 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
1000 | |
|
|
1001 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
1002 | |
|
|
1003 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
1004 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
1005 | }); |
|
|
1006 | } |
|
|
1007 | } |
|
|
1008 | } |
|
|
1009 | |
|
|
1010 | sub conn::map_change { |
|
|
1011 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
1012 | |
|
|
1013 | $self->flush_map; |
|
|
1014 | |
|
|
1015 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
|
|
1016 | |
|
|
1017 | my $mapmapw = 250; |
|
|
1018 | my $mapmaph = 250; |
|
|
1019 | |
|
|
1020 | $self->{neigh_rect} = [ |
|
|
1021 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
1022 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
1023 | ]; |
|
|
1024 | |
|
|
1025 | delete $self->{neigh_grid}; |
|
|
1026 | $self->flood_fill (0, 0, "", $hash, $flags); |
|
|
1027 | |
|
|
1028 | $x += $ox; |
|
|
1029 | $y += $oy; |
|
|
1030 | |
|
|
1031 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
|
|
1032 | |
|
|
1033 | my $map = $self->{map_info}[0]; |
|
|
1034 | $map =~ s/^.*?\/([^\/]+)$/\1/; |
|
|
1035 | $STATWIDS->{map}->set_text ("Map: " . $map); |
|
|
1036 | |
|
|
1037 | $self->load_map ($hash, $x, $y); |
|
|
1038 | } |
|
|
1039 | |
|
|
1040 | sub conn::face_find { |
|
|
1041 | my ($self, $facenum, $face) = @_; |
|
|
1042 | |
|
|
1043 | my $hash = "$face->{chksum},$face->{name}"; |
|
|
1044 | |
|
|
1045 | my $id = $FACEMAP->get ($hash); |
|
|
1046 | |
|
|
1047 | unless ($id) { |
|
|
1048 | # create new id for face |
|
|
1049 | # i love transactions |
|
|
1050 | for (1..100) { |
|
|
1051 | my $txn = $CFClient::DB_ENV->txn_begin; |
|
|
1052 | my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW); |
|
|
1053 | if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) { |
|
|
1054 | $id++; |
|
|
1055 | if ($FACEMAP->put (id => $id) == 0 |
|
|
1056 | && $FACEMAP->put ($hash => $id) == 0) { |
|
|
1057 | $txn->txn_commit; |
|
|
1058 | |
|
|
1059 | goto gotid; |
|
|
1060 | } |
|
|
1061 | } |
|
|
1062 | $txn->abort; |
|
|
1063 | } |
|
|
1064 | |
|
|
1065 | CFClient::fatal "maximum number of transaction retries reached - database problems?"; |
|
|
1066 | } |
|
|
1067 | |
|
|
1068 | gotid: |
|
|
1069 | $face->{id} = $id; |
|
|
1070 | $MAP->set_face ($facenum => $id); |
|
|
1071 | $TILECACHE->get ($id) |
|
|
1072 | } |
|
|
1073 | |
|
|
1074 | sub conn::face_update { |
|
|
1075 | my ($self, $facenum, $face) = @_; |
|
|
1076 | |
|
|
1077 | $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes |
|
|
1078 | |
|
|
1079 | $self->set_texture ($face->{id} => delete $face->{image}); |
|
|
1080 | } |
|
|
1081 | |
|
|
1082 | sub conn::set_texture { |
|
|
1083 | my ($self, $id, $data) = @_; |
|
|
1084 | |
|
|
1085 | $self->{texture}[$id] ||= do { |
|
|
1086 | my $tex = |
|
|
1087 | new_from_image CFClient::Texture |
|
|
1088 | $data, minify => 1; |
|
|
1089 | |
|
|
1090 | $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}}); |
|
|
1091 | $MAPWIDGET->update; |
|
|
1092 | |
|
|
1093 | $tex |
|
|
1094 | }; |
|
|
1095 | } |
|
|
1096 | |
|
|
1097 | sub conn::sound_play { |
|
|
1098 | my ($self, $x, $y, $soundnum, $type) = @_; |
|
|
1099 | |
|
|
1100 | $SDL_MIXER |
|
|
1101 | or return; |
|
|
1102 | |
|
|
1103 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
|
|
1104 | or return; |
|
|
1105 | |
|
|
1106 | $chunk->play; |
|
|
1107 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
|
|
1108 | } |
|
|
1109 | |
|
|
1110 | sub conn::query { |
|
|
1111 | my ($self, $flags, $prompt) = @_; |
|
|
1112 | |
|
|
1113 | #TODO, display dialog with relevant information |
|
|
1114 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
|
|
1115 | } |
|
|
1116 | |
|
|
1117 | sub conn::drawinfo { |
|
|
1118 | my ($self, $color, $text) = @_; |
|
|
1119 | |
|
|
1120 | my @color = ( |
|
|
1121 | [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], |
|
|
1122 | [1.00, 1.00, 1.00], |
|
|
1123 | [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55] |
|
|
1124 | [1.00, 0.00, 0.00], |
|
|
1125 | [1.00, 0.54, 0.00], |
|
|
1126 | [0.11, 0.56, 1.00], |
|
|
1127 | [0.93, 0.46, 0.00], |
|
|
1128 | [0.18, 0.54, 0.34], |
|
|
1129 | [0.56, 0.73, 0.56], |
|
|
1130 | [0.80, 0.80, 0.80], |
|
|
1131 | [0.55, 0.41, 0.13], |
|
|
1132 | [0.99, 0.77, 0.26], |
|
|
1133 | [0.74, 0.65, 0.41], |
|
|
1134 | ); |
|
|
1135 | |
|
|
1136 | $LOGVIEW->add_paragraph ($color[$color], $text); |
|
|
1137 | } |
|
|
1138 | |
|
|
1139 | sub conn::spell_add { |
|
|
1140 | my ($self, $spell) = @_; |
|
|
1141 | |
|
|
1142 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub { |
|
|
1143 | }); |
|
|
1144 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub { |
|
|
1145 | }); |
|
|
1146 | } |
|
|
1147 | |
|
|
1148 | sub conn::spell_delete { |
|
|
1149 | my ($self, $spell) = @_; |
|
|
1150 | } |
|
|
1151 | |
|
|
1152 | sub conn::addme_success { |
|
|
1153 | my ($self) = @_; |
|
|
1154 | |
|
|
1155 | for my $skill (values %{$self->{skill_info}}) { |
|
|
1156 | $MAPWIDGET->add_command ("ready_skill $skill", "", sub { |
|
|
1157 | }); |
|
|
1158 | $MAPWIDGET->add_command ("use_skill $skill", "", sub { |
|
|
1159 | }); |
|
|
1160 | } |
253 | } |
1161 | } |
254 | |
1162 | |
255 | %SDL_CB = ( |
1163 | %SDL_CB = ( |
256 | SDL_QUIT() => sub { |
1164 | CFClient::SDL_QUIT => sub { |
257 | main_quit Gtk2; |
1165 | Event::unloop -1; |
258 | }, |
1166 | }, |
259 | SDL_VIDEORESIZE() => sub { |
1167 | CFClient::SDL_VIDEORESIZE => sub { |
260 | }, |
1168 | }, |
261 | SDL_VIDEOEXPOSE() => sub { |
1169 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
262 | refresh; |
|
|
263 | }, |
|
|
264 | SDL_KEYDOWN() => sub { |
|
|
265 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
|
|
266 | # alt-enter |
|
|
267 | $FULLSCREEN = !$FULLSCREEN; |
|
|
268 | init_screen; |
|
|
269 | } else { |
|
|
270 | CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); |
|
|
271 | } |
|
|
272 | }, |
|
|
273 | SDL_KEYUP() => sub { |
|
|
274 | CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); |
|
|
275 | }, |
|
|
276 | SDL_MOUSEMOTION() => sub { |
|
|
277 | CFClient::Widget::feed_sdl_motion_event ($SDL_EV); |
|
|
278 | }, |
|
|
279 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
280 | CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); |
|
|
281 | }, |
|
|
282 | SDL_MOUSEBUTTONUP() => sub { |
|
|
283 | CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); |
|
|
284 | }, |
|
|
285 | SDL_ACTIVEEVENT() => sub { |
1170 | CFClient::SDL_ACTIVEEVENT => sub { |
286 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
1171 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
287 | }, |
1172 | }, |
|
|
1173 | CFClient::SDL_KEYDOWN => sub { |
|
|
1174 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
|
|
1175 | # alt-enter |
|
|
1176 | video_shutdown; |
|
|
1177 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
|
|
1178 | video_init; |
|
|
1179 | } else { |
|
|
1180 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
|
|
1181 | } |
|
|
1182 | }, |
|
|
1183 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
|
|
1184 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
|
|
1185 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
|
|
1186 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
|
|
1187 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
288 | ); |
1188 | ); |
289 | |
1189 | |
290 | @conn::ISA = Crossfire::Protocol::; |
|
|
291 | |
|
|
292 | sub conn::map_update { |
|
|
293 | my ($self, $dirty) = @_; |
|
|
294 | |
|
|
295 | $MAPWIDGET->update; |
|
|
296 | } |
|
|
297 | |
|
|
298 | sub conn::map_scroll { |
|
|
299 | my ($self, $dx, $dy) = @_; |
|
|
300 | |
|
|
301 | # refresh; |
|
|
302 | } |
|
|
303 | |
|
|
304 | sub conn::map_clear { |
|
|
305 | my ($self) = @_; |
|
|
306 | |
|
|
307 | # refresh; |
|
|
308 | } |
|
|
309 | |
|
|
310 | sub conn::face_find { |
|
|
311 | my ($self, $face) = @_; |
|
|
312 | |
|
|
313 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
|
|
314 | } |
|
|
315 | |
|
|
316 | sub conn::face_update { |
|
|
317 | my ($self, $face) = @_; |
|
|
318 | |
|
|
319 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
|
|
320 | |
|
|
321 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
|
|
322 | } |
|
|
323 | |
|
|
324 | sub conn::query { |
|
|
325 | my ($self, $flags, $prompt) = @_; |
|
|
326 | |
|
|
327 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
|
|
328 | } |
|
|
329 | |
|
|
330 | sub gtk_add_cfg_field { |
|
|
331 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
|
|
332 | my $i = $cfg->{_i}++; |
|
|
333 | $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); |
|
|
334 | $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1); |
|
|
335 | if ($key eq 'password') { |
|
|
336 | $ent->set_invisible_char ("*"); |
|
|
337 | $ent->set (visibility => 0) |
|
|
338 | } |
|
|
339 | $ent->set_text ($value); |
|
|
340 | $ent->signal_connect (changed => sub { |
|
|
341 | my ($ent) = @_; |
|
|
342 | $cfg->{$key} = $ent->get_text; |
|
|
343 | # TODO: Mapsize should be a slider in the game gui |
|
|
344 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
|
|
345 | $cfg->{$key} = 100; |
|
|
346 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
347 | $cfg->{$key} = 50; |
|
|
348 | } |
|
|
349 | }); |
|
|
350 | } |
|
|
351 | |
|
|
352 | sub run_config_dialog { |
|
|
353 | my (%events) = @_; |
|
|
354 | |
|
|
355 | my $w = Gtk2::Window->new; |
|
|
356 | |
|
|
357 | my @cfg = ( |
|
|
358 | [qw/Host host/], |
|
|
359 | [qw/Port port/], |
|
|
360 | [qw/Mapsize% mapsize/], |
|
|
361 | [qw/Username user/], |
|
|
362 | [qw/Password password/], |
|
|
363 | ); |
|
|
364 | |
|
|
365 | my $cfg = {}; |
|
|
366 | |
|
|
367 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
368 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
369 | |
|
|
370 | $w->add (my $vb = Gtk2::VBox->new); |
|
|
371 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
|
|
372 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
|
|
373 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
|
|
374 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
|
|
375 | my $i = 0; |
|
|
376 | my $act = 0; |
|
|
377 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
|
|
378 | if ($_ eq $selmode) { $act = $i } |
|
|
379 | $cb->append_text ($_); |
|
|
380 | $i++; |
|
|
381 | } |
|
|
382 | $cb->set_active ($act); |
|
|
383 | $cb->signal_connect (changed => sub { |
|
|
384 | my ($cb) = @_; |
|
|
385 | my $txt = $cb->get_active_text; |
|
|
386 | if ($txt =~ m/(\d+)x(\d+)/) { |
|
|
387 | $::CFG->{width} = $1; |
|
|
388 | $::CFG->{height} = $2; |
|
|
389 | } |
|
|
390 | }); |
|
|
391 | |
|
|
392 | $cfg->{_i} = 1; |
|
|
393 | for (@cfg) { |
|
|
394 | gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]}); |
|
|
395 | } |
|
|
396 | |
|
|
397 | $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
|
|
398 | $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5); |
|
|
399 | $cb->signal_connect (clicked => sub { |
|
|
400 | for (keys %$cfg) { |
|
|
401 | $::CFG->{$_} = $cfg->{$_} |
|
|
402 | if $_ ne '_i'; |
|
|
403 | } |
|
|
404 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
|
|
405 | }); |
|
|
406 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
|
|
407 | $cb->signal_connect (clicked => sub { |
|
|
408 | for (keys %$cfg) { |
|
|
409 | $::CFG->{$_} = $cfg->{$_} |
|
|
410 | if $_ ne '_i'; |
|
|
411 | } |
|
|
412 | my $cb = $events{login} || sub {}; |
|
|
413 | $cb->($::CFG->{user}, $::CFG->{password}); |
|
|
414 | }); |
|
|
415 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
|
|
416 | $cb->signal_connect (clicked => sub { |
|
|
417 | my $cb = $events{logout} || sub {}; |
|
|
418 | $cb->(); |
|
|
419 | }); |
|
|
420 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
|
|
421 | $cb->signal_connect (clicked => sub { $w->destroy }); |
|
|
422 | |
|
|
423 | $w->show_all; |
|
|
424 | |
|
|
425 | $w->signal_connect (destroy => sub { Gtk2->main_quit }); |
|
|
426 | } |
|
|
427 | |
|
|
428 | |
|
|
429 | ############################################################################# |
1190 | ############################################################################# |
430 | |
1191 | |
431 | SDL::Init SDL_INIT_EVERYTHING; |
1192 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
|
|
1193 | |
|
|
1194 | $TILECACHE = CFClient::db_table "tilecache"; |
|
|
1195 | $FACEMAP = CFClient::db_table "facemap"; |
432 | |
1196 | |
433 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
1197 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
434 | |
1198 | |
435 | $CFG ||= { |
1199 | my %DEF_CFG = ( |
|
|
1200 | sdl_mode => 0, |
436 | width => 640, |
1201 | width => 640, |
437 | height => 480, |
1202 | height => 480, |
|
|
1203 | fullscreen => 0, |
|
|
1204 | fast => 0, |
|
|
1205 | fow_enable => 1, |
|
|
1206 | fow_intensity => 0.45, |
|
|
1207 | fow_smooth => 0, |
|
|
1208 | gui_fontsize => 1, |
|
|
1209 | log_fontsize => 1, |
|
|
1210 | gauge_fontsize => 1, |
|
|
1211 | gauge_size => 0.35, |
|
|
1212 | stat_fontsize => 1, |
438 | mapsize => 100, |
1213 | mapsize => 100, |
439 | fullscreen => 0, |
|
|
440 | host => "crossfire.schmorp.de", |
1214 | host => "crossfire.schmorp.de", |
441 | port => 13327, |
1215 | say_command => 'say', |
442 | }; |
1216 | audio_enable => 1, |
|
|
1217 | bgm_enable => 1, |
|
|
1218 | bgm_volume => 0.25, |
|
|
1219 | ); |
|
|
1220 | |
|
|
1221 | while (my ($k, $v) = each %DEF_CFG) { |
|
|
1222 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
|
|
1223 | } |
|
|
1224 | |
|
|
1225 | sdl_init; |
|
|
1226 | |
|
|
1227 | @SDL_MODES = reverse |
|
|
1228 | grep $_->[0] >= 640 && $_->[1] >= 480, |
|
|
1229 | CFClient::SDL_ListModes; |
|
|
1230 | |
|
|
1231 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
|
|
1232 | |
|
|
1233 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
443 | |
1234 | |
444 | { |
1235 | { |
445 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
1236 | my @fonts = map CFClient::find_rcfile "fonts/$_", qw( |
|
|
1237 | DejaVuSans.ttf |
|
|
1238 | DejaVuSansMono.ttf |
|
|
1239 | DejaVuSans-Bold.ttf |
|
|
1240 | DejaVuSansMono-Bold.ttf |
|
|
1241 | DejaVuSans-Oblique.ttf |
|
|
1242 | DejaVuSansMono-Oblique.ttf |
|
|
1243 | DejaVuSans-BoldOblique.ttf |
|
|
1244 | DejaVuSansMono-BoldOblique.ttf |
|
|
1245 | ); |
446 | |
1246 | |
447 | CFClient::add_font $_ for @fonts; |
1247 | CFClient::add_font $_ for @fonts; |
448 | CFClient::set_font $fonts[0]; |
1248 | |
449 | } |
1249 | $FONT_PROP = new_from_file CFClient::Font $fonts[0]; |
|
|
1250 | $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; |
450 | |
1251 | |
451 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
1252 | $FONT_PROP->make_default; |
|
|
1253 | } |
452 | |
1254 | |
453 | run_config_dialog |
1255 | video_init; |
454 | login => sub { start_game }, |
1256 | audio_init; |
455 | logout => sub { stop_game }; |
|
|
456 | |
1257 | |
457 | main Gtk2; |
1258 | Event::loop; |
458 | |
1259 | |
459 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |
1260 | END { CFClient::SDL_Quit } |
|
|
1261 | |
|
|
1262 | |