/* 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 3 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, see .
*
*/
#include "common/config-manager.h"
#include "twp/twp.h"
#include "twp/motor.h"
#include "twp/hud.h"
#include "twp/resmanager.h"
namespace Twp {
class ShakeVerb : public Motor {
public:
virtual ~ShakeVerb() {}
ShakeVerb(VerbSlot *slot, float amount) : _slot(slot), _amount(amount) {}
private:
virtual void onUpdate(float elapsed) override {
_shakeTime += 40.f * elapsed;
_elapsed += elapsed;
_slot->_shakeOffset = Math::Vector2d(_amount * cos(_shakeTime + 0.3f), _amount * sin(_shakeTime));
}
private:
VerbSlot *_slot = nullptr;
float _amount = 0.f;
float _shakeTime = 0.f;
float _elapsed = 0.f;
};
Verb::Verb() = default;
Verb::Verb(VerbId verbId, const Common::String &img, const Common::String &f, const Common::String &t, const Common::String &k, int fl)
: id(verbId), image(img), fun(f), text(t), key(k), flags(fl) {
}
VerbUiColors::VerbUiColors() = default;
VerbUiColors::VerbUiColors(const Color &s, const Color &vbNormal, const Color &vbNormalTint, const Color &vbHiglight, const Color &vbHiglightTint, const Color &dlgNormal, const Color &dlgHighlt, const Color &invFrame, const Color &inventoryBack, const Color &retroNml, const Color &retroHighlt)
: sentence(s), verbNormal(vbNormal), verbNormalTint(vbNormalTint), verbHighlight(vbHiglight), verbHighlightTint(vbHiglightTint), dialogNormal(dlgNormal), dialogHighlight(dlgHighlt), inventoryFrame(invFrame), inventoryBackground(inventoryBack), retroNormal(retroNml), retroHighlight(retroHighlt) {
}
ActorSlot::ActorSlot() = default;
HudShader::HudShader() = default;
void HudShader::init() {
const char *v_source = R"(
attribute vec2 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoords;
uniform vec4 u_shadowColor;
uniform vec4 u_normalColor;
uniform vec4 u_highlightColor;
uniform vec2 u_ranges;
uniform mat4 u_transform;
varying vec4 v_color;
varying vec2 v_texCoords;
varying vec4 v_shadowColor;
varying vec4 v_normalColor;
varying vec4 v_highlightColor;
varying vec2 v_ranges;
void main() {
gl_Position = u_transform * vec4(a_position, 0.0, 1.0);
v_color = a_color;
v_texCoords = a_texCoords;
v_shadowColor = u_shadowColor;
v_normalColor = u_normalColor;
v_highlightColor = u_highlightColor;
v_ranges = u_ranges;
})";
const char *f_source = R"(
varying vec4 v_color;
varying vec2 v_texCoords;
varying vec4 v_shadowColor;
varying vec4 v_normalColor;
varying vec4 v_highlightColor;
varying vec2 v_ranges;
uniform sampler2D u_texture;
void main() {
float shadows = v_ranges.x;
float highlights = v_ranges.y;
vec4 texColor = texture2D(u_texture, v_texCoords);
if (texColor.g <= shadows) {
texColor *= v_shadowColor;
} else if (texColor.g >= highlights) {
texColor *= v_highlightColor;
} else {
texColor *= v_normalColor;
}
texColor *= v_color;
gl_FragColor = texColor;
})";
Shader::init("hud", v_source, f_source);
}
HudShader::~HudShader() = default;
void HudShader::applyUniforms() {
setUniform("u_ranges", Math::Vector2d(0.8f, 0.8f));
setUniform4("u_shadowColor", _shadowColor);
setUniform4("u_normalColor", _normalColor);
setUniform4("u_highlightColor", _highlightColor);
}
Hud::Hud() : Node("hud") {
_zOrder = 100;
_visible = false;
for (auto &_actorSlot : _actorSlots) {
ActorSlot *slot = &_actorSlot;
slot->actor = nullptr;
}
}
void Hud::init() {
_shader.init();
}
ActorSlot *Hud::actorSlot(Common::SharedPtr