1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-26 04:12:41 +01:00

Implement some text related opcodes

This commit is contained in:
Daniel Evans 2014-07-30 15:48:51 +01:00
parent 81712a12b1
commit 4214162ed0
3 changed files with 49 additions and 3 deletions

View File

@ -4,10 +4,21 @@
#include <glm/glm.hpp>
#include <string>
#include <map>
#include <vector>
class PlayerController;
class CutsceneData;
struct TextDisplayData
{
// This is set by the final display text command.
std::string text;
glm::vec2 position;
glm::vec4 colourFG;
glm::vec4 colourBG;
};
struct GameState
{
unsigned int maxProgress;
@ -50,6 +61,9 @@ struct GameState
std::map<unsigned short, std::string> specialCharacters;
std::map<unsigned short, std::string> specialModels;
TextDisplayData nextText;
std::vector<TextDisplayData> texts;
GameState() :
maxProgress(1),
numMissions(0),

View File

@ -624,14 +624,32 @@ SCMMicrocodeTable ops_game = {
OPC_UNIMPLEMENTED_MSG( 0x0336, "Set Player Visible", 2)
OPC_UNIMPLEMENTED_MSG( 0x033E, "Display Text", 3)
OPC( 0x033E, "Display Text", 3, {
glm::vec2 pos(p->at(0).real, p->at(1).real);
std::string str(p->at(2).string);
str = m->getWorld()->gameData.texts.text(str);
m->getWorld()->state.nextText.text = str;
m->getWorld()->state.nextText.position = pos;
m->getWorld()->state.texts.push_back(m->getWorld()->state.nextText);
})
OPC_UNIMPLEMENTED_MSG( 0x033F, "Set Text Scale", 2)
OPC_UNIMPLEMENTED_MSG( 0x0340, "Set Text Colour", 4)
OPC( 0x0340, "Set Text Colour", 4, {
m->getWorld()->state.nextText.colourFG.r = p->at(0).integer / 255.f;
m->getWorld()->state.nextText.colourFG.g = p->at(1).integer / 255.f;
m->getWorld()->state.nextText.colourFG.b = p->at(2).integer / 255.f;
m->getWorld()->state.nextText.colourFG.a = p->at(3).integer / 255.f;
})
OPC_UNIMPLEMENTED_MSG( 0x0341, "Set Text Justify", 1)
OPC_UNIMPLEMENTED_MSG( 0x0342, "Set Text Centered", 1)
OPC_UNIMPLEMENTED_MSG( 0x0344, "Set Center Text Size", 1)
OPC_UNIMPLEMENTED_MSG( 0x0345, "Set Text Background", 1)
OPC_UNIMPLEMENTED_MSG( 0x0346, "Set Text Background Colour", 4)
OPC( 0x0346, "Set Text Background Colour", 4,
{
m->getWorld()->state.nextText.colourBG.r = p->at(0).integer / 255.f;
m->getWorld()->state.nextText.colourBG.g = p->at(1).integer / 255.f;
m->getWorld()->state.nextText.colourBG.b = p->at(2).integer / 255.f;
m->getWorld()->state.nextText.colourBG.a = p->at(3).integer / 255.f;
})
OPC_UNIMPLEMENTED_MSG( 0x0348, "Set Text Size Proportional", 1)
OPC_UNIMPLEMENTED_MSG( 0x0349, "Set Text Font", 1)

View File

@ -253,6 +253,7 @@ void update(float dt)
}
gta->destroyQueuedObjects();
gta->state.texts.clear();
gta->dynamicsWorld->stepSimulation(dt, 2, dt);
@ -412,6 +413,19 @@ void render(float alpha)
messageText.setPosition(sz.x / 2.f - std::round(b.width / 2.f), lowerBar - std::round(b.height / 2.f));
window.draw(messageText);
}
for(auto& t : gta->state.texts) {
sf::Text messageText(t.text, font, 15);
glm::vec2 scpos(t.position.x, t.position.y);
auto s = window.getSize();
scpos /= glm::vec2(640.f, 480.f);
scpos *= glm::vec2(s.x, s.y);
messageText.setPosition(scpos.x, scpos.y);
window.draw(messageText);
}
}
std::string getGamePath()