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 /*
24  * This file is based on WME Lite.
25  * http://dead-code.org/redir.php?target=wmelite
26  * Copyright (c) 2011 Jan Nedoma
27  */
28 
29 #ifndef WINTERMUTE_BASE_OBJECT_H
30 #define WINTERMUTE_BASE_OBJECT_H
31 
32 
33 #include "engines/wintermute/base/base_script_holder.h"
34 #include "engines/wintermute/persistent.h"
35 #include "common/events.h"
36 #include "graphics/transform_struct.h"
37 
38 #ifdef ENABLE_WME3D
39 #include "math/angle.h"
40 #include "math/matrix4.h"
41 #include "math/vector3d.h"
42 #endif
43 
44 namespace Wintermute {
45 
46 class BaseSprite;
47 class BaseSound;
48 class BaseSurface;
49 class BaseScriptHolder;
50 class ScValue;
51 class ScStack;
52 class ScScript;
53 
54 #ifdef ENABLE_WME3D
55 class ModelX;
56 #endif
57 
58 class BaseObject : public BaseScriptHolder {
59 protected:
60 	bool _autoSoundPanning;
61 	uint32 _sFXStart;
62 	bool setSFXTime(uint32 time);
63 	bool setSFXVolume(int volume);
64 	bool resumeSFX();
65 	bool pauseSFX();
66 	bool stopSFX(bool deleteSound = true);
67 	bool playSFX(const char *filename, bool looping = false, bool playNow = true, const char *eventName = nullptr, uint32 loopStart = 0);
68 	BaseSound *_sFX;
69 	TSFXType _sFXType;
70 	float _sFXParam1;
71 	float _sFXParam2;
72 	float _sFXParam3;
73 	float _sFXParam4;
74 	float _relativeRotate;
75 	bool _rotateValid;
76 	float _rotate;
77 	void setSoundEvent(const char *eventName);
78 	bool _rotatable;
79 	float _scaleX;
80 	float _scaleY;
81 	float _relativeScale;
82 	bool _editorSelected;
83 	bool _editorAlwaysRegister;
84 	bool _ready;
85 	Rect32 _rect;
86 	bool _rectSet;
87 	int32 _iD;
88 	char *_soundEvent;
89 public:
90 	Graphics::TSpriteBlendMode _blendMode;
91 	virtual bool afterMove();
92 	float _scale;
93 	uint32 _alphaColor;
94 	virtual bool isReady();
95 	virtual bool getExtendedFlag(const char *flagName);
96 	virtual bool resetSoundPan();
97 	virtual bool updateSounds();
98 	bool updateOneSound(BaseSound *sound);
99 	int32 _sFXVolume;
100 
101 	virtual bool handleMouseWheel(int32 delta);
102 	virtual bool handleMouse(TMouseEvent event, TMouseButton button);
103 	virtual bool handleKeypress(Common::Event *event, bool printable = false);
104 	virtual int32 getHeight();
105 	bool setCursor(const char *filename);
106 	bool setActiveCursor(const char *filename);
107 	bool cleanup();
108 	const char *getCaption(int caseVal = 1);
109 	void setCaption(const char *caption, int caseVal = 1);
110 
111 	bool _editorOnly;
112 	bool _is3D;
113 
114 	DECLARE_PERSISTENT(BaseObject, BaseScriptHolder)
115 	virtual bool showCursor();
116 	BaseSprite *_cursor;
117 	bool _sharedCursors;
118 	BaseSprite *_activeCursor;
119 	bool saveAsText(BaseDynamicBuffer *buffer, int indent) override;
120 	bool listen(BaseScriptHolder *param1, uint32 param2) override;
121 
122 	bool _movable;
123 	bool _zoomable;
124 	bool _shadowable;
125 	int32 _posY;
126 	int32 _posX;
127 	bool _registrable;
128 	char *_caption[7];
129 	bool _saveState;
130 
131 	BaseObject(BaseGame *inGame);
132 	~BaseObject() override;
133 	// base
update()134 	virtual bool update()  {
135 		return STATUS_FAILED;
136 	};
display()137 	virtual bool display() {
138 		return STATUS_FAILED;
139 	};
invalidateDeviceObjects()140 	virtual bool invalidateDeviceObjects()  {
141 		return STATUS_OK;
142 	};
restoreDeviceObjects()143 	virtual bool restoreDeviceObjects()     {
144 		return STATUS_OK;
145 	};
146 	bool _nonIntMouseEvents;
147 
148 #ifdef ENABLE_WME3D
149 	Math::Angle _angle;
150 	ModelX *_modelX;
151 	ModelX *_shadowModel;
152 	Math::Matrix4 _worldMatrix;
153 	Math::Vector3d _posVector;
154 	bool getMatrix(Math::Matrix4 *modelMatrix, Math::Vector3d *posVect = nullptr);
155 	uint32 _shadowColor;
156 	BaseSurface *_shadowImage;
157 	float _shadowSize;
158 	float _scale3D;
159 	Math::Vector3d _shadowLightPos;
160 	bool _drawBackfaces;
161 	TShadowType _shadowType;
162 
getAnimTransitionTime(char * from,char * to)163 	virtual uint32 getAnimTransitionTime(char *from, char *to) {
164 		return 0;
165 	};
166 #endif
167 
168 public:
169 	// scripting interface
170 	ScValue *scGetProperty(const Common::String &name) override;
171 	bool scSetProperty(const char *name, ScValue *value) override;
172 	bool scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *name) override;
173 	const char *scToString() override;
174 };
175 
176 } // End of namespace Wintermute
177 
178 #endif
179