Skip to content

Commit

Permalink
PRINCE: Inventory - left mouse button handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Jun 22, 2014
1 parent 3bf8d86 commit 98525c1
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 50 deletions.
4 changes: 0 additions & 4 deletions engines/prince/mob.h
Expand Up @@ -66,10 +66,6 @@ class Mob {

bool _visible;
uint16 _type;
uint16 _x1; // initialize this?
uint16 _y1;
uint16 _x2;
uint16 _y2;
uint16 _mask;
Common::Rect _rect;

Expand Down
146 changes: 102 additions & 44 deletions engines/prince/prince.cpp
Expand Up @@ -82,7 +82,8 @@ PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc)
_invLineX(134), _invLineY(176), _invLine(5), _invLines(3), _invLineW(70), _invLineH(76), _maxInvW(72), _maxInvH(76),
_invLineSkipX(2), _invLineSkipY(3), _showInventoryFlag(false), _inventoryBackgroundRemember(false),
_mst_shadow(0), _mst_shadow2(0), _candleCounter(0), _invX1(53), _invY1(18), _invWidth(536), _invHeight(438),
_invCurInside(false) {
_invCurInside(false), _optionsFlag(false), _currentMob(0), _optionEnabled(0), _invOptionsNumber(5),
_invExamY(120) {

// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
Expand Down Expand Up @@ -685,7 +686,7 @@ void PrinceEngine::keyHandler(Common::Event event) {
}
}

void PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobList) {
int PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobList) {
Common::Point mousepos = _system->getEventManager()->getMousePos();
Common::Point mousePosCamera(mousepos.x + _picWindowX, mousepos.y);

Expand All @@ -700,7 +701,7 @@ void PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobLis
textW += _font->getCharWidth(mob._name[i]);
}

uint16 x = mousepos.x - textW/2;
uint16 x = mousepos.x - textW / 2;
if (x > screen->w) {
x = 0;
}
Expand All @@ -715,9 +716,10 @@ void PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobLis
}

_font->drawString(screen, mob._name, x, y, screen->w, 216);
break;
return mob._mask;
}
}
return 0;
}

void PrinceEngine::printAt(uint32 slot, uint8 color, const char *s, uint16 x, uint16 y) {
Expand All @@ -740,7 +742,7 @@ uint32 PrinceEngine::getTextWidth(const char *s) {
return textW;
}

void PrinceEngine::showTexts() {
void PrinceEngine::showTexts(Graphics::Surface *screen) {
for (uint32 slot = 0; slot < MAXTEXTS; ++slot) {
Text& text = _textSlots[slot];
if (!text._str && !text._time)
Expand All @@ -751,11 +753,11 @@ void PrinceEngine::showTexts() {

for (uint8 i = 0; i < lines.size(); ++i) {
_font->drawString(
_graph->_frontScreen,
screen,
lines[i],
text._x - getTextWidth(lines[i].c_str())/2,
text._y - (lines.size() - i) * (_font->getFontHeight()),
_graph->_frontScreen->w,
screen->w,
text._color
);
}
Expand Down Expand Up @@ -1249,8 +1251,8 @@ void PrinceEngine::drawScreen() {
playNextFrame();

if (!_inventoryBackgroundRemember) {
hotspot(_graph->_frontScreen, _mobList);
showTexts();
_currentMob = hotspot(_graph->_frontScreen, _mobList);
showTexts(_graph->_frontScreen);
} else {
_inventoryBackgroundRemember = false;
}
Expand Down Expand Up @@ -1372,18 +1374,13 @@ void PrinceEngine::prepareInventoryToView() {
for (int j = 0; j < _invLine; j++) {
Mob tempMobItem;
if (item < _mainHero->_inventory.size()) {
int itemNr = _mainHero->_inventory[item];
int itemNr = _mainHero->_inventory[item];
tempMobItem._visible = 0;
tempMobItem._mask = itemNr; // itemNr - 1??
tempMobItem._x1 = currInvX + _picWindowX; //picWindowX2 ?
tempMobItem._x2 = currInvX + _picWindowX + _invLineW - 1; // picWindowX2 ?
tempMobItem._y1 = currInvY;
tempMobItem._y2 = currInvY + _invLineH - 1;

tempMobItem._rect.left = tempMobItem._x1;
tempMobItem._rect.right = tempMobItem._x2;
tempMobItem._rect.top = tempMobItem._y1;
tempMobItem._rect.bottom = tempMobItem._y2;
tempMobItem._rect.left = currInvX + _picWindowX; //picWindowX2 ?
tempMobItem._rect.right = currInvX + _picWindowX + _invLineW - 1; // picWindowX2 ?
tempMobItem._rect.top = currInvY;
tempMobItem._rect.bottom = currInvY + _invLineH - 1;

tempMobItem._name = "";
tempMobItem._examText = "";
Expand Down Expand Up @@ -1466,6 +1463,59 @@ void PrinceEngine::drawInvItems() {
}
}

void PrinceEngine::inventoryLeftButton() {
if (_optionsFlag == 1) {
//check_opt
if (_currentMob != 0) {
if (_optionEnabled < _invOptionsNumber) {
_optionsFlag = 0;
// ebp = _currentMob;
} else {
return;
}
} else {
// test bx, RMBMask 7996 ?
}
} else {
if (_currentMob != 0) {
//if (_currentPointerNumber != 2) {
if (_currentMob != 29) {
_optionEnabled = 0;
} else {
_optionEnabled = 1;
}
//do_option
//} else {
//use_item_on_item
//}
}
}
//do_option
int selectedMob = _currentMob; // no _currentMob just selectedMob as global for _currentMob.mask ?
if (_optionEnabled == 0) {
int invObjExamEvent = _script->scanInvObjExamEvents(selectedMob); // test this
if (invObjExamEvent == -1) {
// do_standard
printAt(0, 216, _invMobList[selectedMob]._examText.c_str(), kNormalWidth / 2, _invExamY);
showTexts(_graph->_screenForInventory); // here?
// setSpecVoice();
} else {
//store_new_pc
// storeNewPC();
_flags->setFlagValue(Flags::CURRMOB, selectedMob);
_currentMob = 0;
//_optionsMob = 0;
}
} else {
// not_examine

}
}

void PrinceEngine::inventoryRightButton() {

}

void PrinceEngine::displayInventory() {
// temp:
_mainHero->_inventory.clear();
Expand All @@ -1475,10 +1525,41 @@ void PrinceEngine::displayInventory() {
_mainHero->_inventory.push_back(4);
_mainHero->_inventory.push_back(68);

_mainHero->_inventory.push_back(29);
_mainHero->_inventory.push_back(13);
_mainHero->_inventory.push_back(44);
_mainHero->_inventory.push_back(67);

prepareInventoryToView();

while (!shouldQuit()) {

rememberScreenInv();

Graphics::Surface *suitcase = _suitcaseBmp->getSurface();
_graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);

drawInvItems();

Common::Rect _inventoryRect;
_inventoryRect.left = _invX1;
_inventoryRect.top = _invY1;
_inventoryRect.right = _invX1 + _invWidth;
_inventoryRect.bottom = _invY1 + _invHeight;
Common::Point mousePos = _system->getEventManager()->getMousePos();

if (!_invCurInside && _inventoryRect.contains(mousePos)) {
_invCurInside = true;
}

if (_invCurInside && !_inventoryRect.contains(mousePos)) {
inventoryFlagChange(false);
_invCurInside = false;
break;
}

_currentMob = hotspot(_graph->_screenForInventory, _invMobList);

Common::Event event;
Common::EventManager *eventMan = _system->getEventManager();
while (eventMan->pollEvent(event)) {
Expand All @@ -1491,6 +1572,8 @@ void PrinceEngine::displayInventory() {
case Common::EVENT_MOUSEMOVE:
break;
case Common::EVENT_LBUTTONDOWN:
inventoryLeftButton();
break;
case Common::EVENT_RBUTTONDOWN:
break;
case Common::EVENT_LBUTTONUP:
Expand All @@ -1506,31 +1589,6 @@ void PrinceEngine::displayInventory() {
if (shouldQuit())
return;

rememberScreenInv();

Graphics::Surface *suitcase = _suitcaseBmp->getSurface();
_graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);

drawInvItems();

Common::Rect _inventoryRect;
_inventoryRect.left = _invX1;
_inventoryRect.top = _invY1;
_inventoryRect.right = _invX1 + _invWidth;
_inventoryRect.bottom = _invY1 + _invHeight;
Common::Point mousePos = _system->getEventManager()->getMousePos();

if (!_invCurInside && _inventoryRect.contains(mousePos)) {
_invCurInside = true;
}

if (_invCurInside && !_inventoryRect.contains(mousePos)) {
inventoryFlagChange(false);
_invCurInside = false;
break;
}

hotspot(_graph->_screenForInventory, _invMobList);
getDebugger()->onFrame();
_graph->update(_graph->_screenForInventory);
pause();
Expand Down
12 changes: 10 additions & 2 deletions engines/prince/prince.h
Expand Up @@ -273,12 +273,18 @@ class PrinceEngine : public Engine {
void showMask(int maskNr, Graphics::Surface *originalRoomSurface);
void clsMasks();

int _currentMob; // number of selected Mob / inventory item

static const int16 kMaxInv = 90; // max amount of inventory items in whole game

uint32 _invTxtSize;
byte *_invTxt;

bool _showInventoryFlag;
bool _optionsFlag;
int _optionEnabled;
int _invOptionsNumber;
int _invExamY;
bool _inventoryBackgroundRemember;
int _invLineX;
int _invLineY;
Expand Down Expand Up @@ -307,16 +313,18 @@ class PrinceEngine : public Engine {
void displayInventory();
void addInvObj();
void makeInvCursor();
void inventoryLeftButton();
void inventoryRightButton();

int testAnimNr;
int testAnimFrame;

private:
bool playNextFrame();
void keyHandler(Common::Event event);
void hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobList);
int hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobList);
void drawScreen();
void showTexts();
void showTexts(Graphics::Surface *screen);
void init();
void showLogo();
void showBackAnims();
Expand Down
21 changes: 21 additions & 0 deletions engines/prince/script.cpp
Expand Up @@ -205,6 +205,27 @@ uint8 *Script::getRoomOffset(int locationNr) {
return &_data[_scriptInfo.rooms + locationNr * 64];
}

struct RE {
int16 _mob; // number of Mob, -1 for end of list
int32 _code; // offset of code in script
};

int Script::scanInvObjExamEvents(int mobMask) {
RE tempRE;
int i = 0;
do {
tempRE._mob = (int)READ_UINT16(&_data[_scriptInfo.invObjExam + i * 6]);
debug("mob: %d", tempRE._mob);
tempRE._code = (int)READ_UINT32(&_data[_scriptInfo.invObjExam + i * 6 + 2]);
debug("code: %d", tempRE._code);
if (tempRE._mob == mobMask) {
return tempRE._code;
}
i++;
} while (tempRE._mob != -1); //?? || i <= 1 or without this (no items there)
return -1; // or sth else?
}

void Script::installSingleBackAnim(Common::Array<BackgroundAnim> &_backanimList, int offset) {

BackgroundAnim newBackgroundAnim;
Expand Down
2 changes: 2 additions & 0 deletions engines/prince/script.h
Expand Up @@ -137,6 +137,8 @@ class Script {
void installSingleBackAnim(Common::Array<BackgroundAnim> &_backanimList, int offset);
bool loadAllMasks(Common::Array<Mask> &maskList, int offset);

int scanInvObjExamEvents(int mobMask);

const char *getString(uint32 offset) {
return (const char *)(&_data[offset]);
}
Expand Down

0 comments on commit 98525c1

Please sign in to comment.