TWP: Add hotspot marker

This commit is contained in:
scemino 2024-01-14 17:30:49 +01:00 committed by Eugene Sandulenko
parent 16ef14aaeb
commit 4f88b8e026
6 changed files with 51 additions and 2 deletions

View File

@ -40,7 +40,8 @@ enum TwpAction {
kSelectChoice6,
kSelectPreviousActor,
kSelectNextActor,
kSkipText
kSkipText,
kShowHotspots
};
}

View File

@ -187,6 +187,7 @@ Common::Array<Common::Keymap *> TwpMetaEngine::initKeymaps(const char *target) c
{"SELECTNEXTACTOR", _("Select Next Actor"), Twp::kSelectNextActor, "0"},
{"SELECTPREVACTOR", _("Select Previous Actor"), Twp::kSelectPreviousActor, "9"},
{"SKIPTEXT", _("Skip Text"), Twp::kSkipText, "."},
{"SHOWHOTSPOTS", _("Show hotspots"), Twp::kShowHotspots, "TAB"},
};
for (int i = 0; i < ARRAYSIZE(actions); i++) {

View File

@ -718,4 +718,36 @@ bool NoOverrideNode::update(float elapsed) {
return true;
}
HotspotMarkerNode::HotspotMarkerNode() : Node("HotspotMarker") {
_zOrder = -1000;
_visible = false;
}
HotspotMarkerNode::~HotspotMarkerNode() {}
void HotspotMarkerNode::drawSprite(const SpriteSheetFrame &sf, Texture *texture, Color color, Math::Matrix4 trsf) {
Math::Vector3d pos(sf.spriteSourceSize.left - sf.sourceSize.getX() / 2.f, -sf.spriteSourceSize.height() - sf.spriteSourceSize.top + sf.sourceSize.getY() / 2.f, 0.f);
trsf.translate(pos);
g_engine->getGfx().drawSprite(sf.frame, *texture, color, trsf);
}
void HotspotMarkerNode::drawCore(Math::Matrix4 trsf) {
SpriteSheet *gameSheet = g_engine->_resManager.spriteSheet("GameSheet");
Texture *texture = g_engine->_resManager.texture(gameSheet->meta.image);
SpriteSheetFrame *frame = &gameSheet->frameTable["hotspot_marker"];
Color color = Color::create(255, 165, 0);
for (int i = 0; i < g_engine->_room->_layers.size(); i++) {
Layer *layer = g_engine->_room->_layers[i];
for (int j = 0; j < layer->_objects.size(); j++) {
Object *obj = layer->_objects[j];
if (isObject(obj->getId()) && (obj->_objType == otNone) && obj->isTouchable()) {
Math::Vector2d pos = g_engine->roomToScreen(obj->_node->getAbsPos());
Math::Matrix4 t;
t.translate(Math::Vector3d(pos.getX(), pos.getY(), 0.f));
drawSprite(*frame, texture, color, t);
}
}
}
}
} // namespace Twp

View File

@ -353,6 +353,16 @@ private:
float _elapsed = 0.f;
};
class HotspotMarkerNode: public Node {
public:
HotspotMarkerNode();
virtual ~HotspotMarkerNode();
private:
void drawSprite(const SpriteSheetFrame& sf, Texture* texture, Color color, Math::Matrix4 trsf);
void drawCore(Math::Matrix4 trsf) override final;
};
} // End of namespace Twp
#endif

View File

@ -63,6 +63,7 @@ TwpEngine::TwpEngine(OSystem *syst, const ADGameDescription *gameDesc)
_screenScene.setName("Screen");
// _scene.addChild(&_walkboxNode);
// _screenScene.addChild(&_pathNode);
_screenScene.addChild(&_hotspotMarker);
_screenScene.addChild(&_inputState);
_screenScene.addChild(&_sentence);
_screenScene.addChild(&_dialog);
@ -735,9 +736,12 @@ Common::Error TwpEngine::run() {
case TwpAction::kSelectChoice6:
if (_dialog.getState() == DialogState::None) {
int index = (TwpAction)e.customType - kSelectChoice1;
g_engine->_dialog.choose(index);
_dialog.choose(index);
}
break;
case TwpAction::kShowHotspots:
_hotspotMarker.setVisible(!_hotspotMarker.isVisible());
break;
}
break;
} break;

View File

@ -215,6 +215,7 @@ public:
AudioSystem _audio;
SaveGameManager _saveGameManager;
ShaderParams _shaderParams;
HotspotMarkerNode _hotspotMarker;
private:
Gfx _gfx;