PETKA: implemented QObjectCase

This commit is contained in:
Andrei Prykhodko 2019-08-03 18:02:52 +03:00 committed by Eugene Sandulenko
parent 8bb12711cb
commit 7b7268acfb
4 changed files with 177 additions and 1 deletions

View File

@ -81,10 +81,12 @@ void InterfaceMain::loadRoom(int id, bool fromSave) {
const BGInfo *info = findBGInfo(id);
QSystem *sys = g_vm->getQSystem();
QObjectBG *room = (QObjectBG *)sys->findObject(id);
g_vm->getQSystem()->_room = room;
g_vm->resMgr()->loadBitmap(room->_resourceId);
_objs.push_back(room);
for (uint i = 0; i < info->attachedObjIds.size(); ++i) {
QMessageObject *obj = g_vm->getQSystem()->findObject(info->attachedObjIds[i]);
debug("Added sound id %d", obj->_resourceId);
obj->_sound = g_vm->soundMgr()->addSound(g_vm->resMgr()->findSoundName(obj->_resourceId), Audio::Mixer::kSFXSoundType);
obj->_hasSound = obj->_sound != nullptr;
obj->_startSound = false;
@ -157,4 +159,3 @@ void InterfaceMain::unloadRoom(bool fromSave) {
}
} // End of namespace Petka

View File

@ -20,9 +20,170 @@
*
*/
#include "petka/interfaces/main.h"
#include "petka/objects/object_case.h"
#include "petka/flc.h"
#include "petka/petka.h"
#include "petka/q_manager.h"
#include "petka/video.h"
#include "petka/objects/heroes.h"
#include "petka/q_system.h"
namespace Petka {
// Полоска в чемодане
const char *const kPoloska = "\xCF\xEE\xEB\xEE\xF1\xEA\xE0\x20\xE2\x20\xF7\xE5\xEC\xEE\xE4\xE0\xED\xE5";
const Common::Point itemsLocation[] = {{120, 145}, {240, 145}, {360, 145},
{100, 220}, {240, 220}, {380, 220}};
QObjectCase::QObjectCase() {
_itemIndex = 0;
_isShown = false;
_updateZ = false;
_id = 4099;
_resourceId = 6000;
_z = 980;
_clickedObjIndex = -1;
}
void QObjectCase::update(int time) {
if (!_isShown || _clickedObjIndex >= 6)
return;
_time += time;
FlicDecoder *flc = g_vm->resMgr()->loadFlic(6001 + _clickedObjIndex);
if (flc) {
while (_time >= flc->getDelay()) {
flc->setFrame(-1);
_time -= flc->getDelay();
g_vm->videoSystem()->addDirtyRectFromMsk(Common::Point(0, 0), *flc);
}
}
}
void QObjectCase::show(bool v) {
_x = 0; // sys->xOffset
QObject::show(v);
if (v) {
fillWithItems();
QMessageObject *obj = g_vm->getQSystem()->findObject(kPoloska);
obj->_z = _z + 2;
obj->_x = 0; // sys->xOffset
g_vm->getQSystem()->_mainInterface->_objs.push_back(obj);
} else {
Common::Array<QVisibleObject *> &objs = g_vm->getQSystem()->_mainInterface->_objs;
for (int i = 0; i < objs.size();) {
if (objs[i]->_z == _z + 1 || objs[i]->_z == _z + 2) {
objs.remove_at(i);
} else {
++i;
}
}
g_vm->getQSystem()->_currInterface->_startIndex = 0;
}
}
bool QObjectCase::isInPoint(int x, int y) {
return _isShown;
}
void QObjectCase::onMouseMove(int x, int y) {
FlicDecoder *flc = g_vm->resMgr()->loadFlic(6009);
if (*(byte *)flc->getCurrentFrame()->getBasePtr(x - _x, y - _y) != 0) {
if (_clickedObjIndex != 3 && _clickedObjIndex < 6 && _clickedObjIndex >= 0) {
FlicDecoder *flc = g_vm->resMgr()->loadFlic(6001 + _clickedObjIndex);
flc->setFrame(1);
g_vm->videoSystem()->addDirtyRectFromMsk(Common::Point(0, 0), *flc);
}
_clickedObjIndex = 3;
} else {
int i;
for (i = 0; i < 6; ++i) {
FlicDecoder *flc = g_vm->resMgr()->loadFlic(6001 + i);
if (flc->getMskRects()[i].contains(Common::Point(x - _x, y))) {
break;
}
}
if (_clickedObjIndex != i && _clickedObjIndex < 6 && _clickedObjIndex >= 0) {
FlicDecoder *flc = g_vm->resMgr()->loadFlic(6001 + _clickedObjIndex);
flc->setFrame(1);
g_vm->videoSystem()->addDirtyRectFromMsk(Common::Point(0, 0), *flc);
}
if (i == 6) {
if (_clickedObjIndex < 6 && _clickedObjIndex >= 0) {
_clickedObjIndex = -1;
}
} else if (i != _clickedObjIndex) {
if ((i || g_vm->getQSystem()->_chapayev->_isShown) && (i != 2 || g_vm->getQSystem()->_room->_showMap)) {
FlicDecoder *flc = g_vm->resMgr()->loadFlic(6001 + i);
g_vm->videoSystem()->addDirtyRectFromMsk(Common::Point(0, 0), *flc);
_clickedObjIndex = i;
} else {
_clickedObjIndex = -1;
}
}
}
}
void QObjectCase::onClick(int x, int y) {
switch (_clickedObjIndex) {
case 0:
// setChapayev()
break;
case 1:
// loadPanel()
break;
case 2:
// loadMap()
break;
case 3:
show(0);
break;
case 4:
if (_items.size() > _itemIndex + 6) {
_itemIndex += 6;
fillWithItems();
g_vm->videoSystem()->makeAllDirty();
}
break;
case 5:
if (_itemIndex > 0) {
_itemIndex = (_itemIndex - 6 <= 0) ? 0 : _itemIndex - 6;
fillWithItems();
g_vm->videoSystem()->makeAllDirty();
}
break;
default:
break;
}
}
void QObjectCase::fillWithItems() {
Common::Array<QVisibleObject *> &objs = g_vm->getQSystem()->_mainInterface->_objs;
for (int i = 0; i < objs.size();) {
if (objs[i]->_z == _z + 1) {
objs.remove_at(i);
} else {
++i;
}
}
for (int i = 0; i < objs.size();) {
if (objs[i]->_resourceId == 6000) {
g_vm->getQSystem()->_currInterface->_startIndex = i;
}
}
for (int i = _itemIndex; i < _itemIndex + 6 >= _items.size() ? _items.size() : _itemIndex + 6; ++i) {
QMessageObject *obj = g_vm->getQSystem()->findObject(_items[i]);
obj->_z = _z + 1;
objs.push_back(obj);
g_vm->resMgr()->loadFlic(obj->_resourceId);
_x = itemsLocation[i - _itemIndex].x;
_y = itemsLocation[i - _itemIndex].y;
}
}
}

View File

@ -28,7 +28,19 @@
namespace Petka {
class QObjectCase : public QObject {
public:
QObjectCase();
void update(int time) override;
void show(bool v) override;
bool isInPoint(int x, int y) override;
void onMouseMove(int x, int y) override;
void onClick(int x, int y) override;
void fillWithItems();
private:
Common::Array<int> _items;
uint _clickedObjIndex;
int _itemIndex;
};
} // End of namespace Petka

View File

@ -78,6 +78,8 @@ public:
int _isIniting;
int _fxId;
int _musicId;
QObjectBG *_room;
};
} // End of namespace Petka