00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022
00023 #include "SDL_events.h"
00024 #include "files/U7file.h"
00025 #include "gamewin.h"
00026 #include "game.h"
00027 #include "browser.h"
00028 #include "exult.h"
00029 #include "font.h"
00030 #include "items.h"
00031 #include "shapeid.h"
00032
00033 #ifndef HAVE_SNPRINTF
00034 extern int snprintf(char *, size_t, const char *, ...);
00035 namespace std {
00036 using ::snprintf;
00037 }
00038 #else
00039 #endif
00040
00041 ShapeBrowser::ShapeBrowser()
00042 {
00043 num_shapes = 0;
00044 current_shape = 0;
00045 num_frames = 0;
00046 current_frame = 0;
00047 num_files = game->get_resource("files/shapes/count").num;
00048 current_file = 0;
00049 shapes = 0;
00050 num_palettes = game->get_resource("palettes/count").num;
00051 current_palette = 0;
00052 num_xforms = game->get_resource("xforms/count").num;
00053 current_xform = -1;
00054 }
00055
00056 ShapeBrowser::~ShapeBrowser()
00057 {
00058 if(shapes)
00059 delete shapes;
00060 }
00061
00062 static void handle_key(int shift, int& value, int max, int amt = 1)
00063 {
00064 if (max == 0) return;
00065
00066 if(shift)
00067 value -= amt;
00068 else
00069 value += amt;
00070
00071 while (value<0)
00072 value = max+value;
00073 while (value>=max)
00074 value = value-max;
00075 }
00076
00077 void ShapeBrowser::browse_shapes()
00078 {
00079
00080 Game_window *gwin = Game_window::get_instance();
00081 Shape_manager *sman = Shape_manager::get_instance();
00082 Image_buffer8 *ibuf = gwin->get_win()->get_ib8();
00083 Font *font = fontManager.get_font("MENU_FONT");
00084
00085 int maxx = gwin->get_width();
00086 int centerx = maxx/2;
00087 int maxy = gwin->get_height();
00088 int centery = maxy/2;
00089 Palette pal;
00090 char buf[255];
00091 str_int_pair pal_tuple, xform_tuple;
00092 const char *fname;
00093
00094 snprintf(buf,255,"files/shapes/%d",current_file);
00095 fname = game->get_resource(buf).str;
00096 if(!shapes)
00097 shapes = new Vga_file(fname);
00098 bool looping = true;
00099 bool redraw = true;
00100 SDL_Event event;
00101
00102
00103 do {
00104 if (redraw) {
00105 gwin->clear_screen();
00106 snprintf(buf,255,"palettes/%d",current_palette);
00107 pal_tuple = game->get_resource(buf);
00108 char xfrsc[256];
00109 if (current_xform > 0)
00110 {
00111 snprintf(xfrsc, 255, "xforms/%d",
00112 current_xform);
00113 xform_tuple = game->
00114 get_resource(xfrsc);
00115 pal.load(pal_tuple.str, pal_tuple.num,
00116 xform_tuple.str,
00117 xform_tuple.num);
00118 }
00119 else
00120 pal.load(pal_tuple.str,pal_tuple.num);
00121
00122 snprintf(buf,255,"VGA File: '%s'", fname);
00123
00124 font->paint_text_fixedwidth(ibuf, buf, 2, maxy-30, 8);
00125
00126 num_shapes = shapes->get_num_shapes();
00127 snprintf(buf,255,"Shape: %2d/%d", current_shape, num_shapes-1);
00128
00129 font->paint_text_fixedwidth(ibuf, buf, 2, maxy-20, 8);
00130
00131 num_frames = shapes->get_num_frames(current_shape);
00132 snprintf(buf,255,"Frame: %2d/%d", current_frame, num_frames-1);
00133
00134 font->paint_text_fixedwidth(ibuf, buf, 162, maxy-20, 8);
00135
00136 snprintf(buf,255,"Palette: %s, %d", pal_tuple.str, pal_tuple.num);
00137
00138 font->paint_text_fixedwidth(ibuf, buf, 2, maxy-10, 8);
00139
00140 if (num_frames) {
00141 Shape_frame *frame = shapes->get_shape(
00142 current_shape, current_frame);
00143
00144 if (frame) {
00145 snprintf(buf,255,"%d x %d", frame->get_width(), frame->get_height());
00146
00147 font->paint_text_fixedwidth(ibuf, buf, 2, 22, 8);
00148
00149 Shape_info& info =
00150 ShapeID::get_info(current_shape);
00151
00152 snprintf(buf,255,"class: %2i ready_type: 0x%02x", info.get_shape_class(), info.get_ready_type());
00153 font->paint_text_fixedwidth(ibuf, buf, 2, 12, 8);
00154
00155
00156 font->paint_text_fixedwidth(ibuf, item_names[current_shape], 2, 2, 8);
00157
00158
00159 gwin->get_win()->fill8(255,
00160 frame->get_width()+4, frame->get_height()+4,
00161 gwin->get_width()/2 - frame->get_xleft() - 2,
00162 gwin->get_height()/2 - frame->get_yabove() - 2);
00163 gwin->get_win()->fill8(0,
00164 frame->get_width()+2, frame->get_height()+2,
00165 gwin->get_width()/2 - frame->get_xleft()-1,
00166 gwin->get_height()/2 - frame->get_yabove()-1);
00167
00168
00169 sman->paint_shape(gwin->get_width()/2, gwin->get_height()/2, frame, 1);
00170
00171 } else
00172 font->draw_text(ibuf, centerx-20, centery-5, "No Shape");
00173 } else
00174 font->draw_text(ibuf, centerx-20, centery-5, "No Shape");
00175
00176 pal.apply();
00177 redraw = false;
00178 }
00179 SDL_WaitEvent(&event);
00180 if(event.type==SDL_KEYDOWN) {
00181 redraw = true;
00182 int shift = event.key.keysym.mod & KMOD_SHIFT;
00183
00184 switch(event.key.keysym.sym) {
00185 case SDLK_ESCAPE:
00186 looping = false;
00187 break;
00188 case SDLK_v:
00189 handle_key(shift, current_file, num_files);
00190 current_shape = 0;
00191 current_frame = 0;
00192 delete shapes;
00193 snprintf(buf,255,"files/shapes/%d",current_file);
00194 fname = game->get_resource(buf).str;
00195 shapes = new Vga_file(fname);
00196 break;
00197 case SDLK_p:
00198 handle_key(shift, current_palette, num_palettes);
00199 current_xform = -1;
00200 break;
00201 case SDLK_x:
00202 handle_key(shift, current_xform,
00203 num_xforms);
00204 break;
00205
00206 case SDLK_s:
00207 if ((event.key.keysym.mod & KMOD_ALT) && (event.key.keysym.mod & KMOD_CTRL))
00208 make_screenshot(true);
00209 else {
00210 handle_key(shift, current_shape, num_shapes);
00211 current_frame = 0;
00212 }
00213 break;
00214 case SDLK_UP:
00215 handle_key(1, current_shape, num_shapes);
00216 current_frame = 0;
00217 break;
00218 case SDLK_DOWN:
00219 handle_key(0, current_shape, num_shapes);
00220 current_frame = 0;
00221 break;
00222 case SDLK_j:
00223 handle_key(shift, current_shape,
00224 num_shapes, 20);
00225 current_frame = 0;
00226 break;
00227 case SDLK_PAGEUP:
00228 handle_key(1, current_shape, num_shapes, 20);
00229 current_frame = 0;
00230 break;
00231 case SDLK_PAGEDOWN:
00232 handle_key(0, current_shape, num_shapes, 20);
00233 current_frame = 0;
00234 break;
00235
00236 case SDLK_f:
00237 handle_key(shift, current_frame, num_frames);
00238 break;
00239 case SDLK_LEFT:
00240 handle_key(1, current_frame, num_frames);
00241 break;
00242 case SDLK_RIGHT:
00243 handle_key(0, current_frame, num_frames);
00244 break;
00245
00246 default:
00247 break;
00248 }
00249 }
00250 } while(looping);
00251 }
00252
00253 bool ShapeBrowser::get_shape(int& shape, int& frame)
00254 {
00255 if(!shapes || current_file!=0)
00256 return false;
00257 else {
00258 shape = current_shape;
00259 frame = current_frame;
00260 return true;
00261 }
00262 }