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 258 259 260 261 262
|
/* 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/events.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/pet_control/pet_section.h"
#include "titanic/room_flags.h"
#include "titanic/support/screen_manager.h"
#include "titanic/support/simple_file.h"
#include "titanic/titanic.h"
#include "titanic/translation.h"
namespace Titanic {
CPetRoomsGlyph::CPetRoomsGlyph() : CPetGlyph(),
_roomFlags(0), _mailFlag(0), _mode(RGM_UNASSIGNED),
_chevLeftOnDim(nullptr), _chevLeftOffDim(nullptr), _chevLeftOnLit(nullptr), _chevLeftOffLit(nullptr),
_chevRightOnDim(nullptr), _chevRightOffDim(nullptr), _chevRightOnLit(nullptr), _chevRightOffLit(nullptr) {
}
CPetRoomsGlyph::CPetRoomsGlyph(uint flags) : CPetGlyph(),
_roomFlags(flags), _mailFlag(0), _mode(RGM_UNASSIGNED),
_chevLeftOnDim(nullptr), _chevLeftOffDim(nullptr), _chevLeftOnLit(nullptr), _chevLeftOffLit(nullptr),
_chevRightOnDim(nullptr), _chevRightOffDim(nullptr), _chevRightOnLit(nullptr), _chevRightOffLit(nullptr) {
}
bool CPetRoomsGlyph::setup(CPetControl *petControl, CPetGlyphs *owner) {
if (!CPetGlyph::setup(petControl, owner))
return false;
CPetSection *section = owner->getOwner();
_chevLeftOnDim = section->getBackground(8);
_chevLeftOffDim = section->getBackground(9);
_chevRightOnDim = section->getBackground(12);
_chevRightOffDim = section->getBackground(13);
_chevLeftOnLit = section->getBackground(10);
_chevLeftOffLit = section->getBackground(11);
_chevRightOnLit = section->getBackground(14);
_chevRightOffLit = section->getBackground(15);
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 *leftOnDim = _chevLeftOnDim;
CGameObject *leftOffDim = _chevLeftOffDim;
CGameObject *rightOnDim = _chevRightOnDim;
CGameObject *rightOffDim = _chevRightOffDim;
if (_mailFlag || isHighlighted_) {
_chevLeftOnDim = _chevLeftOnLit;
_chevLeftOffDim = _chevLeftOffLit;
_chevRightOnDim = _chevRightOnLit;
_chevRightOffDim = _chevRightOffLit;
}
// Draw the chevron fragments for each line
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 += 10;
drawObjects(((roomBits & 7) << 1) + (roomFlags.getBit0() ? 1 : 0),
destPt, screenManager);
// Restore original image pointers
_chevLeftOnDim = leftOnDim;
_chevLeftOffDim = leftOffDim;
_chevRightOnDim = rightOnDim;
_chevRightOffDim = rightOffDim;
}
void CPetRoomsGlyph::selectGlyph(const Point &topLeft, const Point &pt) {
if (!isAssigned()) {
bool isShiftPressed = g_vm->_events->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->_events->getSpecialButtons() & MK_SHIFT;
CPetControl *petControl = getPetControl();
if (!isShiftPressed && petControl) {
CGameObject *chevron = petControl->getHiddenObject("3PetChevron");
if (chevron) {
chevron->_destRoomFlags = _roomFlags;
chevron->_isPendingMail = _mailFlag != 0;
petControl->removeFromInventory(chevron, false, false);
chevron->loadSurface();
chevron->dragMove(msg->_mousePos);
msg->_handled = true;
if (msg->execute(chevron))
return true;
petControl->moveToHiddenRoom(chevron);
}
}
return false;
}
void CPetRoomsGlyph::getTooltip(CTextControl *text) {
CRoomFlags roomFlags(_roomFlags);
CPetRooms *owner = static_cast<CPetRooms *>(getPetSection());
CString prefix;
if (isCurrentlyAssigned()) {
prefix = g_vm->_strings[YOUR_ASSIGNED_ROOM];
} else if (isPreviouslyAssigned()) {
prefix = g_vm->_strings[PREVIOUSLY_ASSIGNED_ROOM];
} else if (!_mailFlag) {
prefix = g_vm->_strings[SAVED_CHEVRON];
} else if (_mailFlag == 1 && owner->getRoomFlags() == _roomFlags) {
prefix = g_vm->_strings[CURRENT_LOCATION];
}
// Get the room description
CString roomStr = roomFlags.getRoomDesc();
if (roomStr == TRANSLATE("The Elevator", "Der Aufzug")) {
int elevNum = owner->getElevatorNum();
roomStr = CString::format(g_vm->_strings[ELEVATOR_NUM].c_str(), elevNum);
}
roomStr += g_vm->_strings[SHIFT_CLICK_TO_EDIT];
text->setText(prefix + 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::changeClass(PassengerClass newClassNum) {
CRoomFlags roomFlags(_roomFlags);
roomFlags.changeClass(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 (_chevLeftOnDim && _chevLeftOffDim && _chevRightOnDim && _chevRightOffDim) {
Point destPos = pt;
((flags & 8) ? _chevLeftOnDim : _chevLeftOffDim)->draw(screenManager, destPos);
destPos.x += 13;
((flags & 4) ? _chevRightOnDim : _chevRightOffDim)->draw(screenManager, destPos);
destPos.x += 13;
((flags & 2) ? _chevLeftOnDim : _chevLeftOffDim)->draw(screenManager, destPos);
destPos.x += 13;
((flags & 1) ? _chevRightOnDim : _chevRightOffDim)->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 = dynamic_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
|