00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pent_include.h"
00020 #include "ShapeViewerGump.h"
00021
00022 #include "ShapeArchive.h"
00023 #include "RenderSurface.h"
00024 #include "GUIApp.h"
00025 #include "Shape.h"
00026 #include "ShapeInfo.h"
00027
00028 #include "RenderedText.h"
00029 #include "Font.h"
00030 #include "FontManager.h"
00031
00032 #include "GameData.h"
00033 #include "FontShapeArchive.h"
00034 #include "MainShapeArchive.h"
00035 #include "GumpShapeArchive.h"
00036 #include "DesktopGump.h"
00037
00038 #include "FileSystem.h"
00039 #include "u8/ConvertShapeU8.h"
00040 #include "PaletteManager.h"
00041 #include "Usecode.h"
00042
00043 #include "IDataSource.h"
00044 #include "ODataSource.h"
00045
00046 DEFINE_RUNTIME_CLASSTYPE_CODE(ShapeViewerGump,ModalGump);
00047
00048 ShapeViewerGump::ShapeViewerGump()
00049 : ModalGump(), curflex(0), flex(0), curshape(0), curframe(0), background(0)
00050 {
00051
00052 }
00053
00054 ShapeViewerGump::ShapeViewerGump(int width, int height,
00055 std::vector<std::pair<std::string,ShapeArchive*> >& flexes_,
00056 uint32 _Flags, sint32 layer)
00057 : ModalGump(50, 50, width, height, 0, _Flags, layer),
00058 flexes(flexes_), curflex(0), curshape(0), curframe(0), background(0)
00059 {
00060 if (flexes.size())
00061 flex = flexes[0].second;
00062 else
00063 flex = 0;
00064 }
00065
00066 ShapeViewerGump::~ShapeViewerGump()
00067 {
00068
00069 }
00070
00071 void ShapeViewerGump::PaintThis(RenderSurface* surf, sint32 lerp_factor, bool )
00072 {
00073 if (flexes.empty()) {
00074 Close();
00075 return;
00076 }
00077
00078 surf->Fill32(background, 0, 0, dims.w, dims.h);
00079
00080 sint32 posx = (dims.w - shapew)/2 + shapex;
00081 sint32 posy = (dims.h - shapeh)/2 + shapey;
00082
00083 Shape* shape = flex->getShape(curshape);
00084 if (shape && curframe < shape->frameCount())
00085 surf->Paint(shape, curframe, posx, posy);
00086
00087 RenderedText* rendtext;
00088 Pentagram::Font* font = FontManager::get_instance()->getGameFont(0, true);
00089 unsigned int remaining;
00090
00091 char buf1[50];
00092 char buf2[200];
00093 if (!shape) {
00094 sprintf(buf1, "NULL");
00095 } else {
00096 sprintf(buf1, "Frame %d of %d", curframe, shape->frameCount());
00097 }
00098 sprintf(buf2, "%s\nShape %d, %s", flexes[curflex].first.c_str(),
00099 curshape, buf1);
00100 rendtext = font->renderText(buf2, remaining);
00101 rendtext->draw(surf, 20, 20);
00102 delete rendtext;
00103
00104 MainShapeArchive* mainshapes = p_dynamic_cast<MainShapeArchive*>(flex);
00105 if (!mainshapes || !shape) return;
00106
00107 char buf3[128];
00108 char buf4[128];
00109 char buf5[128];
00110 char buf6[512];
00111 ShapeInfo * info = mainshapes->getShapeInfo(curshape);
00112 if (info)
00113 {
00114 sprintf(buf3, "x = %d, y = %d, z = %d\n flags = 0x%04X, family = %d",
00115 info->x, info->y, info->z, info->flags, info->family);
00116 sprintf(buf4, "equip type = %d\n unknown flags = 0x%02X\n weight = %d",
00117 info->equiptype, info->unknown, info->weight);
00118 sprintf(buf5, "volume = %d\n animtype = %d, animdata = %d",
00119 info->animtype, info->animdata, info->volume);
00120 sprintf(buf6, "ShapeInfo:\n %s\n %s, %s\nUsecode: %s",
00121 buf3, buf4, buf5, GameData::get_instance()->getMainUsecode()->get_class_name(curshape));
00122 rendtext = font->renderText(buf6, remaining);
00123 rendtext->draw(surf, 300, 20);
00124 delete rendtext;
00125 }
00126 }
00127
00128 bool ShapeViewerGump::OnKeyDown(int key, int mod)
00129 {
00130 bool shapechanged = false;
00131 unsigned int delta = 1;
00132 if (mod & KMOD_SHIFT) delta = 10;
00133
00134 switch(key)
00135 {
00136 case SDLK_UP:
00137 if (delta >= flex->getCount()) delta = 1;
00138 if (curshape < delta)
00139 curshape = flex->getCount() + curshape - delta;
00140 else
00141 curshape -= delta;
00142 shapechanged = true;
00143 curframe = 0;
00144 break;
00145 case SDLK_DOWN:
00146 if (delta >= flex->getCount()) delta = 1;
00147 if (curshape + delta >= flex->getCount())
00148 curshape = curshape + delta - flex->getCount();
00149 else
00150 curshape += delta;
00151 curframe = 0;
00152 shapechanged = true;
00153 break;
00154 case SDLK_LEFT:
00155 {
00156 Shape* shape = flex->getShape(curshape);
00157 if (shape && shape->frameCount()) {
00158 if (delta >= shape->frameCount()) delta = 1;
00159 if (curframe < delta)
00160 curframe = shape->frameCount() + curframe - delta;
00161 else
00162 curframe -= delta;
00163 }
00164 } break;
00165 case SDLK_RIGHT:
00166 {
00167 Shape* shape = flex->getShape(curshape);
00168 if (shape && shape->frameCount()) {
00169 if (delta >= shape->frameCount()) delta = 1;
00170 if (curframe + delta >= shape->frameCount())
00171 curframe = curframe + delta - shape->frameCount();
00172 else
00173 curframe += delta;
00174 }
00175 } break;
00176 case SDLK_PAGEUP:
00177 {
00178 if (curflex == 0)
00179 curflex = flexes.size() - 1;
00180 else
00181 curflex--;
00182
00183 flex = flexes[curflex].second;
00184 shapechanged = true;
00185 curshape = 0;
00186 curframe = 0;
00187 } break;
00188 case SDLK_PAGEDOWN:
00189 {
00190 if (curflex+1 == flexes.size())
00191 curflex = 0;
00192 else
00193 curflex++;
00194
00195 flex = flexes[curflex].second;
00196 shapechanged = true;
00197 curshape = 0;
00198 curframe = 0;
00199 } break;
00200 case SDLK_ESCAPE:
00201 {
00202 Close();
00203 } break;
00204 default:
00205 break;
00206 }
00207
00208 if (shapechanged) {
00209 Shape* shape = flex->getShape(curshape);
00210 if (shape)
00211 shape->getTotalDimensions(shapew,shapeh,shapex,shapey);
00212 }
00213
00214 return true;
00215 }
00216
00217 bool ShapeViewerGump::OnTextInput(int unicode)
00218 {
00219 switch (unicode)
00220 {
00221 case 'b':
00222 background += 0x808080;
00223 background &= 0xF0F0F0;
00224 break;
00225 default:
00226 break;
00227 }
00228
00229 return true;
00230 }
00231
00232
00233
00234 void ShapeViewerGump::U8ShapeViewer()
00235 {
00236 GameData* gamedata = GameData::get_instance();
00237
00238 std::vector<std::pair<std::string,ShapeArchive*> > flexes;
00239 std::pair<std::string,ShapeArchive*> flex;
00240 flex.first = "u8shapes";
00241 flex.second = gamedata->getMainShapes();
00242 flexes.push_back(flex);
00243 flex.first = "u8gumps";
00244 flex.second = gamedata->getGumps();
00245 flexes.push_back(flex);
00246 flex.first = "u8fonts";
00247 flex.second = gamedata->getFonts();
00248 flexes.push_back(flex);
00249 FileSystem* filesys = FileSystem::get_instance();
00250 IDataSource* eintro = filesys->ReadFile("@game/static/eintro.skf");
00251 if (eintro) {
00252 ShapeArchive* eintroshapes = new ShapeArchive(eintro, GameData::OTHER,
00253 PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game),
00254 &U8SKFShapeFormat);
00255 flex.first = "eintro";
00256 flex.second = eintroshapes;
00257 flexes.push_back(flex);
00258
00259 }
00260
00261 IDataSource* endgame = filesys->ReadFile("@game/static/endgame.skf");
00262 if (endgame) {
00263 ShapeArchive* endgameshapes = new ShapeArchive(endgame, GameData::OTHER,
00264 PaletteManager::get_instance()->getPalette(PaletteManager::Pal_Game),
00265 &U8SKFShapeFormat);
00266 flex.first = "endgame";
00267 flex.second = endgameshapes;
00268 flexes.push_back(flex);
00269
00270 }
00271
00272 Gump* desktopGump = GUIApp::get_instance()->getDesktopGump();
00273 Pentagram::Rect res;
00274 desktopGump->GetDims(res);
00275
00276 ModalGump* gump = new ShapeViewerGump((res.w*3)/4, (res.h*3)/4, flexes);
00277 gump->InitGump(0);
00278 }
00279
00280 void ShapeViewerGump::ConCmd_U8ShapeViewer(const Console::ArgvType &argv)
00281 {
00282 ShapeViewerGump::U8ShapeViewer();
00283 }
00284
00285 bool ShapeViewerGump::loadData(IDataSource* ids)
00286 {
00287 CANT_HAPPEN_MSG("Trying to load ModalGump");
00288 return false;
00289 }
00290
00291 void ShapeViewerGump::saveData(ODataSource* ods)
00292 {
00293 CANT_HAPPEN_MSG("Trying to save ModalGump");
00294 }