00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SHAPEID_H
00020 #define SHAPEID_H 1
00021
00022 #include "exult_constants.h"
00023 #include "shapevga.h"
00024 #include "singles.h"
00025
00026 class Shape_frame;
00027 class Shape_info;
00028 class Fonts_vga_file;
00029 class Font;
00030 class Image_buffer8;
00031
00032 enum ShapeFile {
00033 SF_SHAPES_VGA = 0,
00034 SF_GUMPS_VGA,
00035 SF_PAPERDOL_VGA,
00036 SF_SPRITES_VGA,
00037 SF_FACES_VGA,
00038 SF_EXULT_FLX,
00039 SF_GAME_FLX,
00040 SF_BG_SIGUMP_FLX,
00041 SF_BG_SISHAPES_VGA,
00042
00043
00044
00045 SF_OTHER,
00046 SF_COUNT
00047 };
00048
00049
00050 enum Pixel_colors {POISON_PIXEL = 0, PROTECT_PIXEL, CURSED_PIXEL, HIT_PIXEL,
00051 NPIXCOLORS};
00052
00053
00054
00055
00056 class Shape_manager : public Game_singletons
00057 {
00058 static Shape_manager *instance;
00059 Shapes_vga_file shapes;
00060 Vga_file files[(int) SF_COUNT];
00061 Fonts_vga_file *fonts;
00062 Xform_palette xforms[11];
00063
00064 Xform_palette *invis_xform;
00065 unsigned char special_pixels[NPIXCOLORS];
00066 bool bg_paperdolls_allowed;
00067
00068 bool bg_paperdolls;
00069 bool bg_multiracial_allowed;
00070
00071 public:
00072 friend class ShapeID;
00073 Shape_manager();
00074 ~Shape_manager();
00075 static Shape_manager *get_instance()
00076 { return instance; }
00077 void load();
00078 void reload_shapes(int dragtype);
00079 Vga_file& get_file(enum ShapeFile f)
00080 { return files[(int) f]; };
00081 Shapes_vga_file& get_shapes()
00082 { return shapes; }
00083 inline Xform_palette& get_xform(int i)
00084 { return xforms[i]; }
00085
00086 inline bool can_use_paperdolls() const
00087 { return bg_paperdolls_allowed; }
00088
00089 inline bool get_bg_paperdolls() const
00090 { return bg_paperdolls; }
00091
00092 inline void set_bg_paperdolls(bool p)
00093 { bg_paperdolls = p; }
00094
00095 inline bool can_use_multiracial() const
00096 { return bg_multiracial_allowed; }
00097
00098
00099 void paint_shape(int xoff, int yoff, Shape_frame *shape,
00100 int translucent = 0)
00101 {
00102 if (!shape || !shape->data)
00103 CERR("NULL SHAPE!!!");
00104 else if (!shape->rle)
00105 shape->paint(xoff, yoff);
00106 else if (!translucent)
00107 shape->paint_rle(xoff, yoff);
00108 else
00109 shape->paint_rle_translucent(xoff, yoff, xforms,
00110 sizeof(xforms)/sizeof(xforms[0]));
00111 }
00112
00113 inline void paint_invisible(int xoff, int yoff, Shape_frame *shape)
00114 {
00115 if (shape) shape->paint_rle_transformed(
00116 xoff, yoff, *invis_xform);
00117 }
00118
00119 inline void paint_outline(int xoff, int yoff, Shape_frame *shape,
00120 Pixel_colors pix)
00121 {
00122 if (shape) shape->paint_rle_outline(
00123 xoff, yoff, special_pixels[(int) pix]);
00124 }
00125 unsigned char get_special_pixel(Pixel_colors pix)
00126 { return special_pixels[(int) pix]; }
00127
00128
00129 int paint_text_box(int fontnum, const char *text, int x, int y, int w,
00130 int h, int vert_lead = 0, int pbreak = 0, int shading = -1);
00131 int paint_text(int fontnum, const char *text, int xoff, int yoff);
00132 int paint_text(int fontnum, const char *text, int textlen,
00133 int xoff, int yoff);
00134
00135 int get_text_width(int fontnum, const char *text);
00136 int get_text_width(int fontnum, const char *text, int textlen);
00137
00138 int get_text_height(int fontnum);
00139 int get_text_baseline(int fontnum);
00140 Font *get_font(int fontnum);
00141 };
00142
00143
00144
00145
00146
00147 class ShapeID : public Game_singletons
00148 {
00149 short shapenum;
00150 signed char framenum;
00151 char has_trans;
00152 ShapeFile shapefile;
00153 Shape_frame *shape;
00154
00155 Shape_frame* cache_shape();
00156
00157 public:
00158
00159 ShapeID(unsigned char l, unsigned char h)
00160 : shapenum(l + 256*(h&0x3)), framenum(h >> 2), has_trans(0),
00161 shapefile(SF_SHAPES_VGA), shape(0)
00162 { }
00163
00164 ShapeID(unsigned char *& data)
00165 : has_trans(0), shapefile(SF_SHAPES_VGA), shape(0)
00166 {
00167 unsigned char l = *data++;
00168 unsigned char h = *data++;
00169 shapenum = l + 256*(h&0x3);
00170 framenum = h >> 2;
00171 }
00172
00173 ShapeID() : shapenum(-1), framenum(-1), has_trans(0), shapefile(SF_SHAPES_VGA), shape(0)
00174 { }
00175
00176 virtual ~ShapeID()
00177 { }
00178
00179 int is_invalid() const
00180 { return shapenum == -1; }
00181 int is_eol() const
00182 { return is_invalid(); }
00183
00184 inline int get_shapenum() const
00185 { return shapenum; }
00186 inline int get_framenum() const
00187 { return framenum; }
00188 inline ShapeFile get_shapefile() const
00189 { return shapefile; }
00190 inline Shape_frame *get_shape()
00191 { return (shape!=0)?shape:cache_shape(); }
00192 inline void set_translucent(int trans)
00193 { has_trans=trans; }
00194 inline bool is_translucent()
00195 { if (shape==0) cache_shape(); return has_trans!=0; }
00196
00197 void set_shape(int shnum, int frnum)
00198 {
00199 shapenum = shnum;
00200 framenum = frnum;
00201 shape = 0;
00202 }
00203 ShapeID(int shnum, int frnum, ShapeFile shfile = SF_SHAPES_VGA) :
00204 shapenum(shnum), framenum(frnum), shapefile(shfile),
00205 shape(0), has_trans(0)
00206 { }
00207
00208 void set_shape(int shnum)
00209 { shapenum = shnum; shape = 0; }
00210 void set_frame(int frnum)
00211 { framenum = frnum; shape = 0; }
00212 void set_file(ShapeFile shfile)
00213 { shapefile = shfile; shape = 0; }
00214
00215 void paint_shape(int xoff, int yoff, bool force_trans = false)
00216 {
00217 sman->paint_shape(xoff, yoff, get_shape(),
00218 has_trans || force_trans);
00219 }
00220 void paint_invisible(int xoff, int yoff)
00221 { sman->paint_invisible(xoff, yoff, get_shape()); }
00222
00223 inline void paint_outline(int xoff, int yoff, Pixel_colors pix)
00224 { sman->paint_outline(xoff, yoff, get_shape(), pix); }
00225 int get_num_frames() const;
00226 Shape_info& get_info() const
00227 { return Shape_manager::instance->shapes.get_info(shapenum); }
00228 static Shape_info& get_info(int shnum)
00229 { return Shape_manager::instance->shapes.get_info(shnum); }
00230 };
00231
00232
00233
00234
00235 class Paintable
00236 {
00237 public:
00238 virtual void paint() = 0;
00239 };
00240
00241 #endif