1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef NEVERHOOD_RESOURCE_H 24 #define NEVERHOOD_RESOURCE_H 25 26 #include "common/str.h" 27 #include "neverhood/neverhood.h" 28 #include "neverhood/graphics.h" 29 #include "neverhood/staticdata.h" 30 #include "neverhood/resourceman.h" 31 32 namespace Neverhood { 33 34 enum { 35 kResTypeBitmap = 2, 36 kResTypePalette = 3, 37 kResTypeAnimation = 4, 38 kResTypeData = 5, 39 kResTypeText = 6, 40 kResTypeSound = 7, 41 kResTypeMusic = 8, 42 kResTypeVideo = 10 43 }; 44 45 class SpriteResource { 46 public: 47 SpriteResource(NeverhoodEngine *vm); 48 ~SpriteResource(); 49 void draw(Graphics::Surface *destSurface, bool flipX, bool flipY); 50 bool load(uint32 fileHash, bool doLoadPosition = false); 51 void unload(); getDimensions()52 const NDimensions& getDimensions() { return _dimensions; } getPosition()53 NPoint& getPosition() { return _position; } isRle()54 bool isRle() const { return _rle; } getPixels()55 const byte *getPixels() const { return _pixels; } 56 protected: 57 NeverhoodEngine *_vm; 58 ResourceHandle _resourceHandle; 59 NDimensions _dimensions; 60 NPoint _position; 61 const byte *_pixels; 62 bool _rle; 63 }; 64 65 class PaletteResource { 66 public: 67 PaletteResource(NeverhoodEngine *vm); 68 ~PaletteResource(); 69 bool load(uint32 fileHash); 70 void unload(); 71 void copyPalette(byte *destPalette); palette()72 const byte *palette() { return _palette; } 73 protected: 74 NeverhoodEngine *_vm; 75 ResourceHandle _resourceHandle; 76 const byte *_palette; 77 }; 78 79 struct AnimFrameInfo { 80 uint32 frameHash; 81 int16 counter; 82 NDrawRect drawOffset; 83 int16 deltaX, deltaY; 84 NDrawRect collisionBoundsOffset; 85 uint32 spriteDataOffs; 86 }; 87 88 class AnimResource { 89 public: 90 AnimResource(NeverhoodEngine *vm); 91 ~AnimResource(); 92 void draw(uint frameIndex, Graphics::Surface *destSurface, bool flipX, bool flipY); 93 bool load(uint32 fileHash); 94 void unload(); 95 void clear(); getFrameCount()96 uint getFrameCount() const { return _frames.size(); } getFrameInfo(int16 index)97 const AnimFrameInfo& getFrameInfo(int16 index) const { return _frames[index]; } 98 int16 getFrameIndex(uint32 frameHash); setReplEnabled(bool value)99 void setReplEnabled(bool value) { _replEnabled = value; } 100 void setRepl(byte oldColor, byte newColor); 101 NDimensions loadSpriteDimensions(uint32 fileHash); 102 protected: 103 NeverhoodEngine *_vm; 104 ResourceHandle _resourceHandle; 105 int16 _width, _height; 106 const byte *_currSpriteData; 107 uint32 _fileHash; 108 const byte *_paletteData; 109 const byte *_spriteData; 110 bool _replEnabled; 111 byte _replOldColor; 112 byte _replNewColor; 113 Common::Array<AnimFrameInfo> _frames; 114 }; 115 116 class MouseCursorResource { 117 public: 118 MouseCursorResource(NeverhoodEngine *vm); 119 void load(uint32 fileHash); 120 void unload(); 121 NDrawRect& getRect(); 122 void draw(int frameNum, Graphics::Surface *destSurface); getCursorNum()123 int getCursorNum() const { return _cursorNum; } setCursorNum(int cursorNum)124 void setCursorNum(int cursorNum) { _cursorNum = cursorNum; } 125 protected: 126 int _cursorNum; 127 SpriteResource _cursorSprite; 128 NDrawRect _rect; 129 uint32 _currFileHash; 130 }; 131 132 class TextResource { 133 public: 134 TextResource(NeverhoodEngine *vm); 135 ~TextResource(); 136 void load(uint32 fileHash); 137 void unload(); 138 const char *getString(uint index, const char *&textEnd); getCount()139 uint getCount() const { return _count;} 140 protected: 141 NeverhoodEngine *_vm; 142 ResourceHandle _resourceHandle; 143 const byte *_textData; 144 uint _count; 145 }; 146 147 /* DataResource 148 1 Single NPoint 149 2 Array of NPoints 150 3 Array of NRects 151 4 MessageList 152 5 SubRectList 153 6 RectList 154 */ 155 156 class DataResource { 157 public: 158 DataResource(NeverhoodEngine *vm); 159 ~DataResource(); 160 void load(uint32 fileHash); 161 void unload(); 162 NPoint getPoint(uint32 nameHash); 163 NPointArray *getPointArray(uint32 nameHash); 164 NRectArray *getRectArray(uint32 nameHash); 165 HitRectList *getHitRectList(); 166 MessageList *getMessageListAtPos(int16 klaymenX, int16 klaymenY, int16 mouseX, int16 mouseY); 167 protected: 168 169 struct DRDirectoryItem { 170 uint32 nameHash; 171 uint16 offset; 172 uint16 type; 173 }; 174 175 struct DRRect { 176 NRect rect; 177 uint16 subRectIndex; 178 }; 179 180 struct DRSubRect { 181 NRect rect; 182 uint32 messageListHash; 183 uint16 messageListItemIndex; 184 }; 185 186 typedef Common::Array<DRSubRect> DRSubRectList; 187 188 NeverhoodEngine *_vm; 189 ResourceHandle _resourceHandle; 190 Common::Array<DRDirectoryItem> _directory; 191 Common::Array<NPoint> _points; 192 Common::Array<NPointArray*> _pointArrays; 193 Common::Array<NRectArray*> _rectArrays; 194 Common::Array<HitRectList*> _hitRectLists; 195 Common::Array<MessageList*> _messageLists; 196 Common::Array<DRRect> _drRects; 197 Common::Array<DRSubRectList*> _drSubRectLists; 198 DataResource::DRDirectoryItem *findDRDirectoryItem(uint32 nameHash, uint16 type); 199 }; 200 201 uint32 calcHash(const char *value); 202 203 } // End of namespace Neverhood 204 205 #endif /* NEVERHOOD_RESOURCE_H */ 206