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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
/* 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_rooms_glyphs.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/pet_control/pet_section.h"
#include "titanic/support/screen_manager.h"
#include "titanic/room_flags.h"
#include "titanic/titanic.h"
namespace Titanic {
CPetRoomsGlyph::CPetRoomsGlyph() : CPetGlyph(),
_roomFlags(0), _field38(0), _mode(RGM_UNASSIGNED),
_object0(nullptr), _object1(nullptr), _object2(nullptr), _object3(nullptr),
_object4(nullptr), _object5(nullptr), _object6(nullptr), _object7(nullptr) {
}
CPetRoomsGlyph::CPetRoomsGlyph(uint flags) : CPetGlyph(),
_roomFlags(flags), _field38(0), _mode(RGM_UNASSIGNED),
_object0(nullptr), _object1(nullptr), _object2(nullptr), _object3(nullptr),
_object4(nullptr), _object5(nullptr), _object6(nullptr), _object7(nullptr) {
}
bool CPetRoomsGlyph::setup(CPetControl *petControl, CPetGlyphs *owner) {
if (!CPetGlyph::setup(petControl, owner))
return false;
CPetSection *section = owner->getOwner();
_object0 = section->getBackground(9);
_object1 = section->getBackground(12);
_object4 = section->getBackground(13);
_object5 = section->getBackground(10);
_object2 = section->getBackground(11);
_object3 = section->getBackground(14);
_object6 = section->getBackground(15);
_object7 = _object6;
return true;
}
void CPetRoomsGlyph::drawAt(CScreenManager *screenManager, const Point &pt, bool isHighlighted_) {
// Clear background
Rect rect(pt.x, pt.y, pt.x + 52, pt.y + 52);
screenManager->fillRect(SURFACE_BACKBUFFER, &rect, 0, 0, 0);
CRoomFlags roomFlags(_roomFlags);
uint elevBits = roomFlags.getElevatorBits();
uint classBits = roomFlags.getPassengerClassBits();
uint floorBits = roomFlags.getFloorBits();
uint roomBits = roomFlags.getRoomBits();
// Save a copy of object pointers that may be modified
CGameObject *obj0 = _object0;
CGameObject *obj1 = _object1;
CGameObject *obj4 = _object4;
CGameObject *obj5 = _object5;
if (_field38 == 1 || isHighlighted_) {
_object0 = _object2;
_object1 = _object3;
_object4 = _object6;
_object5 = _object7;
}
// Draw the images
Point destPt = pt;
drawObjects(classBits + elevBits * 4, destPt, screenManager);
destPt.y += 10;
drawObjects((floorBits >> 4) & 15, destPt, screenManager);
destPt.y += 10;
drawObjects(floorBits & 15, destPt, screenManager);
destPt.y += 10;
drawObjects(roomBits >> 3, destPt, screenManager);
destPt.y += 7;
drawObjects(((roomBits & 7) << 1) + (roomFlags.getBit0() ? 1 : 0),
destPt, screenManager);
// Restore original object pointers
_object0 = obj0;
_object1 = obj1;
_object4 = obj4;
_object5 = obj5;
}
void CPetRoomsGlyph::selectGlyph(const Point &topLeft, const Point &pt) {
if (isAssigned()) {
bool isShiftPressed = g_vm->_window->getSpecialButtons() & MK_SHIFT;
if (isShiftPressed) {
int selection = getSelection(topLeft, pt);
if (selection >= 0)
_roomFlags |= 1 << selection;
}
updateTooltip();
}
}
bool CPetRoomsGlyph::dragGlyph(const Point &topLeft, CMouseDragStartMsg *msg) {
bool isShiftPressed = g_vm->_window->getSpecialButtons() & MK_SHIFT;
CPetControl *petControl = getPetControl();
if (!isShiftPressed && petControl) {
CGameObject *chevron = petControl->getHiddenObject("3PetChevron");
if (chevron) {
chevron->_id = _roomFlags;
chevron->_isMail = _field38;
petControl->removeFromInventory(chevron, false, false);
chevron->loadSurface();
chevron->dragMove(msg->_mousePos);
msg->_handled = true;
if (msg->execute(chevron))
return true;
}
}
return false;
}
void CPetRoomsGlyph::getTooltip(CPetText *text) {
CRoomFlags roomFlags(_roomFlags);
CPetRooms *owner = static_cast<CPetRooms *>(getPetSection());
CString msg;
if (isCurrentlyAssigned()) {
msg = "Your assigned room: ";
} else if (isPreviouslyAssigned()) {
msg = "A previously assigned room: ";
} else if (!_field38) {
msg = "Saved Chevron: ";
} else if (_field38 == 1 && owner->getRoomFlags() == _roomFlags) {
msg = "Current location: ";
}
// Get the room description
CString roomStr = roomFlags.getRoomDesc();
if (roomStr == "The Elevator") {
int elevNum = owner->getElevatorNum();
roomStr = CString::format("Elevator %d", elevNum);
}
roomStr += " (shift-click edits)";
text->setText(roomStr);
}
void CPetRoomsGlyph::saveGlyph(SimpleFile *file, int indent) {
file->writeNumberLine(_roomFlags, indent);
file->writeNumberLine(_mode, indent);
}
bool CPetRoomsGlyph::proc33(CPetGlyph *glyph) {
CPetRoomsGlyph *roomGlyph = static_cast<CPetRoomsGlyph *>(glyph);
return CPetGlyph::proc33(glyph) && _roomFlags == roomGlyph->_roomFlags;
}
void CPetRoomsGlyph::loadFlags(SimpleFile *file, int val) {
if (!val) {
_roomFlags = file->readNumber();
}
}
void CPetRoomsGlyph::changeLocation(int newClassNum) {
CRoomFlags roomFlags(_roomFlags);
roomFlags.changeLocation(newClassNum);
_roomFlags = roomFlags.get();
}
int CPetRoomsGlyph::getSelection(const Point &topLeft, const Point &pt) {
Rect rects[4] = {
Rect(topLeft.x, topLeft.y, topLeft.x + 13, topLeft.y + 10),
Rect(topLeft.x + 13, topLeft.y, topLeft.x + 26, topLeft.y + 10),
Rect(topLeft.x + 26, topLeft.y, topLeft.x + 39, topLeft.y + 10),
Rect(topLeft.x + 39, topLeft.y, topLeft.x + 52, topLeft.y + 10)
};
for (int idx = 0, btnIndex = 19; idx < 5; ++idx, btnIndex -= 4) {
// Iterate through each of the four rects, seeing if there's a match.
// If not, move it down to the next row for the next loop iteration
for (int i = 0; i < 4; ++i) {
if (rects[i].contains(pt))
return btnIndex - i;
rects[i].translate(0, 10);
}
}
return -1;
}
void CPetRoomsGlyph::drawObjects(uint flags, const Point &pt, CScreenManager *screenManager) {
if (_object0 && _object1 && _object4 && _object5) {
Point destPos = pt;
((flags & 8) ? _object0 : _object5)->draw(screenManager, destPos);
destPos.x += 13;
((flags & 4) ? _object4 : _object5)->draw(screenManager, destPos);
destPos.x += 13;
((flags & 2) ? _object0 : _object1)->draw(screenManager, destPos);
destPos.x += 13;
((flags & 1) ? _object4 : _object5)->draw(screenManager, destPos);
}
}
/*------------------------------------------------------------------------*/
void CPetRoomsGlyphs::saveGlyphs(SimpleFile *file, int indent) {
file->writeNumberLine(size(), indent);
for (const_iterator i = begin(); i != end(); ++i)
(*i)->saveGlyph(file, indent);
}
CPetRoomsGlyph *CPetRoomsGlyphs::findAssignedRoom() const {
for (const_iterator i = begin(); i != end(); ++i) {
CPetRoomsGlyph *glyph = static_cast<CPetRoomsGlyph *>(*i);
if (glyph->isCurrentlyAssigned())
return glyph;
}
return nullptr;
}
CPetRoomsGlyph *CPetRoomsGlyphs::findGlyphByFlags(uint flags) const {
for (const_iterator i = begin(); i != end(); ++i) {
CPetRoomsGlyph *glyph = static_cast<CPetRoomsGlyph *>(*i);
if (glyph->getRoomFlags() == flags)
return glyph;
}
return nullptr;
}
} // End of namespace Titanic
|