[Text] Now able to display multiple lines.
This commit is contained in:
parent
c7e23e61a0
commit
e8f0198c3c
@ -34,21 +34,37 @@ void Text::updateTextSprites() {
|
||||
m_textSprites.clear();
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int maxX = 0;
|
||||
gk::Color color = gk::Color{70, 70, 70, 255};
|
||||
for(char c : m_text) {
|
||||
if (c == '\n') {
|
||||
y += 9;
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
gk::Sprite sprite{"texture-font", 8, 8};
|
||||
sprite.setCurrentFrame(c);
|
||||
sprite.setPosition(x + 1, 1, 0);
|
||||
sprite.setPosition(x + 1, y + 1, 0);
|
||||
sprite.setColor(color);
|
||||
m_textSprites.emplace_back(std::move(sprite));
|
||||
x += m_charWidth[(u8)c];
|
||||
}
|
||||
x = 0;
|
||||
y = 0;
|
||||
color = m_color;
|
||||
for(char c : m_text) {
|
||||
if (c == '\n') {
|
||||
maxX = std::max(x, maxX);
|
||||
y += 9;
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
gk::Sprite sprite{"texture-font", 8, 8};
|
||||
sprite.setCurrentFrame(c);
|
||||
sprite.setPosition(x, 0, 0);
|
||||
sprite.setPosition(x, y, 0);
|
||||
if (c == '[')
|
||||
color = Color::Blue;
|
||||
sprite.setColor(color);
|
||||
@ -56,8 +72,8 @@ void Text::updateTextSprites() {
|
||||
x += m_charWidth[(u8)c];
|
||||
}
|
||||
|
||||
m_size.x = x;
|
||||
m_size.y = 8;
|
||||
m_size.x = std::max(x, maxX);
|
||||
m_size.y = 8 + y * 9;
|
||||
}
|
||||
|
||||
// FIXME: Since I use the font from Minecraft assets, I needed to use
|
||||
|
@ -32,6 +32,10 @@ void DebugOverlay::update() {
|
||||
stream << "x: " << floorf(m_player.x()) << " | ";
|
||||
stream << "y: " << floorf(m_player.y()) << " | ";
|
||||
stream << "z: " << floorf(m_player.z());
|
||||
stream << '\n';
|
||||
stream << "cx: " << floorf(m_player.x() / CHUNK_WIDTH) << " | ";
|
||||
stream << "cy: " << floorf(m_player.y() / CHUNK_HEIGHT) << " | ";
|
||||
stream << "cz: " << floorf(m_player.z() / CHUNK_DEPTH);
|
||||
|
||||
m_positionText.setText(stream.str());
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
ClientPlayer *ClientPlayer::s_instance = nullptr;
|
||||
|
||||
ClientPlayer::ClientPlayer(gk::Camera &camera) : m_camera(camera) {
|
||||
// FIXME: Warning: Duplicated in ServerCommandHandler.hpp
|
||||
m_x = 0;
|
||||
m_y = 22;
|
||||
m_z = 20;
|
||||
|
@ -55,8 +55,8 @@ class Chunk : public gk::NonCopyable {
|
||||
s32 y() const { return m_y; }
|
||||
s32 z() const { return m_z; }
|
||||
|
||||
Chunk *getSurroundingChunk(u8 i) { return (i > 5) ? nullptr : ((!m_surroundingChunks[i] || !m_surroundingChunks[i]->isInitialized()) ? nullptr : m_surroundingChunks[i]); }
|
||||
const Chunk *getSurroundingChunk(u8 i) const { return (i > 5) ? nullptr : ((!m_surroundingChunks[i] || !m_surroundingChunks[i]->isInitialized()) ? nullptr : m_surroundingChunks[i]); }
|
||||
Chunk *getSurroundingChunk(u8 i);
|
||||
const Chunk *getSurroundingChunk(u8 i) const;
|
||||
void setSurroundingChunk(u8 i, Chunk *chunk) { if (i < 6) m_surroundingChunks[i] = chunk; }
|
||||
|
||||
bool hasChanged() const { return m_hasChanged; }
|
||||
|
@ -167,6 +167,16 @@ BlockData *Chunk::getBlockData(int x, int y, int z) {
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
Chunk *Chunk::getSurroundingChunk(u8 i) {
|
||||
return (i > 5 || !m_surroundingChunks[i] || !m_surroundingChunks[i]->isInitialized())
|
||||
? nullptr : m_surroundingChunks[i];
|
||||
}
|
||||
|
||||
const Chunk *Chunk::getSurroundingChunk(u8 i) const {
|
||||
return (i > 5 || !m_surroundingChunks[i] || !m_surroundingChunks[i]->isInitialized())
|
||||
? nullptr : m_surroundingChunks[i];
|
||||
}
|
||||
|
||||
// FIXME
|
||||
// void Chunk::updateNeighbours(int x, int y, int z) {
|
||||
// int neighbours[7][3] = {
|
||||
|
@ -40,6 +40,7 @@ class ServerCommandHandler {
|
||||
|
||||
Registry &m_registry;
|
||||
|
||||
// FIXME: Warning: Duplicated in ClientPlayer.cpp
|
||||
gk::Vector3<s32> m_spawnPosition{0, 22, 20};
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@ void ServerCommandHandler::setupCallbacks() {
|
||||
m_registry.serialize(packet);
|
||||
client.tcpSocket->send(packet);
|
||||
|
||||
// FIXME: Duplicated below, why?
|
||||
for (auto &it : m_players) {
|
||||
sf::Packet spawnPacket;
|
||||
spawnPacket << Network::Command::PlayerSpawn << it.first;
|
||||
@ -45,6 +46,7 @@ void ServerCommandHandler::setupCallbacks() {
|
||||
invPacket << m_players.at(client.id).inventory();
|
||||
client.tcpSocket->send(invPacket);
|
||||
|
||||
// FIXME: Duplicated above, why?
|
||||
sf::Packet spawnPacket;
|
||||
spawnPacket << Network::Command::PlayerSpawn << client.id;
|
||||
spawnPacket << m_spawnPosition.x << m_spawnPosition.y << m_spawnPosition.z;
|
||||
|
Loading…
x
Reference in New Issue
Block a user