aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/pet_control/pet_remote_glyphs.cpp
blob: e0334fef31215b04a0264213f6ae993990359830 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "titanic/pet_control/pet_remote_glyphs.h"
#include "titanic/pet_control/pet_remote.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/messages/pet_messages.h"

namespace Titanic {

CPetRemote *CPetRemoteGlyphs::getOwner() const {
	return static_cast<CPetRemote *>(_owner);
}

void CPetRemoteGlyphs::generateMessage(RemoteMessage msgNum, const CString &name, int num) {
	getOwner()->generateMessage(msgNum, name, num);
}

/*------------------------------------------------------------------------*/

void CPetRemoteGlyph::setDefaults(const CString &name, CPetControl *petControl) {
	_gfxElement->setBounds(Rect(0, 0, 52, 52));
	_gfxElement->setup(MODE_UNSELECTED, name, petControl);
}

CPetRemoteGlyphs *CPetRemoteGlyph::getOwner() const {
	return static_cast<CPetRemoteGlyphs *>(_owner);
}

CPetGfxElement *CPetRemoteGlyph::getElement(uint id) const {
	CPetRemote *remote = static_cast<CPetRemote *>(_owner->getOwner());
	return remote->getElement(id);
}

/*------------------------------------------------------------------------*/

bool CBasicRemoteGlyph::setup(CPetControl *petControl, CPetGlyphs *owner) {
	CPetRemoteGlyph::setup(petControl, owner);
	setDefaults(_gfxName, petControl);
	if (owner)
		_gfxElement = getElement(18);
	return true;
}

void CBasicRemoteGlyph::draw2(CScreenManager *screenManager) {
	if (_gfxElement)
		_gfxElement->draw(screenManager);
}

bool CBasicRemoteGlyph::MouseButtonDownMsg(const Point &pt) {
	return _gfxElement && _gfxElement->MouseButtonDownMsg(pt); 
}

bool CBasicRemoteGlyph::MouseButtonUpMsg(const Point &pt) {
	if (_gfxElement && _gfxElement->MouseButtonUpMsg(pt)) {
		getOwner()->generateMessage(RMSG_ACTIVATE, "Lift");
		return true;
	}

	return false;
}

void CBasicRemoteGlyph::getTooltip(CPetText *text) {
	text->setText(_tooltip);
}

/*------------------------------------------------------------------------*/

bool CToggleRemoteGlyph::setup(CPetControl *petControl, CPetGlyphs *owner) {
	CPetGlyph::setup(petControl, owner);
	if (owner)
		_gfxElement = getElement(0);
	return true;
}

void CToggleRemoteGlyph::draw2(CScreenManager *screenManager) {
	_gfxElement->setMode(_flag ? MODE_SELECTED : MODE_UNSELECTED);
	_gfxElement->draw(screenManager);
}

bool CToggleRemoteGlyph::elementMouseButtonDownMsg(const Point &pt) {
	return _gfxElement->MouseButtonDownMsg(pt);
}

bool CToggleRemoteGlyph::elementMouseButtonUpMsg(const Point &pt) {
	if (!_gfxElement->MouseButtonUpMsg(pt))
		return false;

	CTreeItem *target = getPetControl()->_remoteTarget;
	if (target) {
		CPETActivateMsg msg("SGTSelector", -1);
		msg.execute(target);
		_flag = !_flag;
		_gfxElement->setMode(_flag ? MODE_SELECTED : MODE_UNSELECTED);
	}

	return true;
}

/*------------------------------------------------------------------------*/

bool CTelevisionControlGlyph::setup(CPetControl *petControl, CPetGlyphs *owner) {
	CPetRemoteGlyph::setup(petControl, owner);
	setDefaults("3PetTV", petControl);
	if (owner) {
		_up = getElement(1);
		_down = getElement(2);
		_onOff = getElement(4);
	}
	
	return true;
}

void CTelevisionControlGlyph::draw2(CScreenManager *screenManager) {
	_onOff->setSelected(_flag);
	_onOff->draw(screenManager);
	_up->draw(screenManager);
	_down->draw(screenManager);
}

bool CTelevisionControlGlyph::MouseButtonDownMsg(const Point &pt) {
	if (_onOff && _onOff->MouseButtonDownMsg(pt))
		return true;
	if (_up && _up->MouseButtonDownMsg(pt))
		return true;
	if (_down && _down->MouseButtonDownMsg(pt))
		return true;

	return false;
}

bool CTelevisionControlGlyph::MouseButtonUpMsg(const Point &pt) {
	if (_onOff && _onOff->MouseButtonUpMsg(pt)) {
		_flag = !_flag;
		getOwner()->generateMessage(RMSG_ACTIVATE, "Television");
		return true;
	}

	if (_up && _up->MouseButtonUpMsg(pt)) {
		getOwner()->generateMessage(RMSG_UP, "Television");
		return true;
	}

	if (_down && _down->MouseButtonUpMsg(pt)) {
		getOwner()->generateMessage(RMSG_DOWN, "Television");
		return true;
	}

	return false;
}

void CTelevisionControlGlyph::getTooltip(CPetText *text) {
	text->setText("Television control");
}

/*------------------------------------------------------------------------*/

bool CEntertainmentDeviceGlyph::setup(CPetControl *petControl, CPetGlyphs *owner) {
	CPetRemoteGlyph::setup(petControl, owner);
	if (owner) {
		_gfxElement2 = getElement(1);
		_gfxElement3 = getElement(2);
	}

	return true;
}

void CEntertainmentDeviceGlyph::draw2(CScreenManager *screenManager) {
	CString viewName = getPetControl()->getFullViewName();
	if (viewName == "SGTState.Node 1.S") {
		_gfxElement->setSelected(_flag);
		_gfxElement->draw(screenManager);
	} else if (viewName == "SGTState.Node 4.E") {
		_gfxElement->setSelected(_flag2);
		_gfxElement->draw(screenManager);
		_gfxElement2->draw(screenManager);
		_gfxElement3->draw(screenManager);
	}
}

bool CEntertainmentDeviceGlyph::MouseButtonDownMsg(const Point &pt) {
	CString viewName = getPetControl()->getFullViewName();
	if (viewName == "SGTState.Node 1.S") {
		return elementMouseButtonDownMsg(pt);
	} else if (viewName == "SGTState.Node 4.E") {
		return _gfxElement->MouseButtonDownMsg(pt)
			|| _gfxElement2->MouseButtonDownMsg(pt)
			|| _gfxElement3->MouseButtonDownMsg(pt);
	}

	return false;
}

bool CEntertainmentDeviceGlyph::MouseButtonUpMsg(const Point &pt) {
	CString viewName = getPetControl()->getFullViewName();
	if (viewName == "SGTState.Node 1.S") {
		return elementMouseButtonUpMsg(pt);
	} else if (viewName == "SGTState.Node 4.E") {
		if (_gfxElement->MouseButtonUpMsg(pt)) {
			_flag2 = !_flag2;
			getOwner()->generateMessage(RMSG_ACTIVATE, "Television");
			return true;
		} else if (_gfxElement2->MouseButtonUpMsg(pt)) {
			getOwner()->generateMessage(RMSG_UP, "Television");
			return true;
		}
		else if (_gfxElement3->MouseButtonUpMsg(pt)) {
			getOwner()->generateMessage(RMSG_DOWN, "Television");
			return true;
		}
	}

	return false;
}

void CEntertainmentDeviceGlyph::getTooltip(CPetText *text) {
	text->setText("Operate visual entertainment device");
}

} // End of namespace Titanic