diff --git a/include/client/Typer.hpp b/include/client/Typer.hpp index 9282ea9..ca557e4 100644 --- a/include/client/Typer.hpp +++ b/include/client/Typer.hpp @@ -26,7 +26,7 @@ struct TypingCharacter { class Typer { private: - float scale = 0.3; + float scale = 1.0f; Shader shader; std::map Characters; unsigned int VAO, VBO; diff --git a/include/client/menus/Menu.hpp b/include/client/menus/Menu.hpp index 5e5d280..3cc6559 100644 --- a/include/client/menus/Menu.hpp +++ b/include/client/menus/Menu.hpp @@ -56,7 +56,6 @@ class Menu { int menuWidth = 0; int menuHeight = 0; float menuScale = 0; - float textScale = 1.0f; Typer textRenderer; Typer titleRenderer; diff --git a/src/client/App.cpp b/src/client/App.cpp index 34312b3..3946d70 100644 --- a/src/client/App.cpp +++ b/src/client/App.cpp @@ -78,7 +78,7 @@ void App::init(const std::string& serverIp) { audio.reset(); } - glfwSetFramebufferSizeCallback(window, [](GLFWwindow* w, const int width, const int height) { + glfwSetFramebufferSizeCallback(window, [](GLFWwindow* w, int width, int height) { App* app = static_cast(glfwGetWindowUserPointer(w)); // Skip resize if window is minimized (0x0) if (width == 0 || height == 0) diff --git a/src/client/menus/Chat.cpp b/src/client/menus/Chat.cpp index 1953e55..6f288d3 100644 --- a/src/client/menus/Chat.cpp +++ b/src/client/menus/Chat.cpp @@ -5,8 +5,12 @@ Chat::Chat(float width, float height) : Menu(width, height) { + DESIGN_WIDTH = 3840; + DESIGN_HEIGHT = 2160; build(); chatColor = glm::vec4(0,0,0,0.6f); + + resize(width, height); } Chat::~Chat() @@ -45,12 +49,12 @@ void Chat::goThroughChatLog(const int key) void Chat::onRender() { drawSimpleQuad(x, y, w, h, chatColor); - float offset = 10.0f * menuScale; - float charHeight = (48+10)*textScale*menuScale; //48 cause font is 48 and 10 is height offset + float offset = 10.0f * textRenderer.getScale(); + float charHeight = 48 * textRenderer.getScale(); textRenderer.renderText(currMsg, x + offset, y + offset, glm::vec3(0.5, 0.8f, 0.2f)); - int currHeight = offset + charHeight; + float currHeight = offset + charHeight; for (auto it = chatLog.rbegin(); it != chatLog.rend() && currHeight < (h - charHeight); ++it) { textRenderer.renderText(it->message.c_str(), x+offset, y+currHeight, glm::vec3(1.0f)); @@ -64,9 +68,9 @@ void Chat::renderRecentMessages() auto nowMs = std::chrono::duration_cast(timepoint.time_since_epoch()).count(); auto nowS = std::chrono::duration_cast(timepoint.time_since_epoch()).count(); - float offset = 10.0f * menuScale; - float charHeight = (48+10)*textScale; //48 cause font is 48 and 10 is height offset - int currHeight = offset + charHeight; + float offset = 10.0f * textRenderer.getScale(); + float charHeight = 48 * textRenderer.getScale(); + float currHeight = offset + charHeight; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -82,12 +86,12 @@ void Chat::renderRecentMessages() std::clamp(1.0 - age / (MESSAGE_LIFETIME * 1000), 0.0, 1.0) ); - drawSimpleQuad(x + offset, y + (currHeight - 4) * menuScale, textRenderer.getPixelSizeOfString(msg->message) + 2, charHeight, glm::vec4(0,0,0,alpha/2.0f)); + drawSimpleQuad(x + offset, y + currHeight - offset / 2.0f - 4, textRenderer.getPixelSizeOfString(msg->message) + 2, charHeight, glm::vec4(0,0,0,alpha/2.0f)); textRenderer.renderText( msg->message.c_str(), x + offset, - y + currHeight * menuScale, + y + currHeight, glm::vec3(1.0f), alpha ); diff --git a/src/client/menus/DebugHUD.cpp b/src/client/menus/DebugHUD.cpp index c13fb08..82bf40f 100644 --- a/src/client/menus/DebugHUD.cpp +++ b/src/client/menus/DebugHUD.cpp @@ -4,7 +4,11 @@ DebugHUD::DebugHUD(float width, float height) : Menu(width, height) { + DESIGN_WIDTH = 3840; + DESIGN_HEIGHT = 2160; build(); + + resize(width, height); } void DebugHUD::update(const DebugStats& stats) @@ -19,20 +23,21 @@ void DebugHUD::build() void DebugHUD::onRender() { - const float pad = 8.0f * menuScale; - const float lineH = 18.0f * menuScale * textScale * 3; - const float bgPadX = 2.0f * menuScale; // horizontal inset inside each bg + float scale = textRenderer.getScale() * 2.5f; + const float pad = 8.0f * scale; + const float lineH = 18.0f * scale; + const float bgPadX = 2.0f * scale; // horizontal inset inside each bg const glm::vec4 bgColor{ 0.0f, 0.0f, 0.0f, 0.0f }; const glm::vec3 white{ 1.0f, 1.0f, 1.0f }; const float textX = pad; - float textY = static_cast(fullscreenHeight) - pad - 4.0f * menuScale * textScale * 5; + float textY = static_cast(fullscreenHeight) - pad - 8.0f * scale; char buf[64]; auto drawLine = [&](const char* text) { float w = static_cast(textRenderer.getPixelSizeOfString(text)); - drawSimpleQuad(textX - bgPadX, textY - 3.0f * menuScale, w + bgPadX * 2.0f, lineH - 2.0f * menuScale, bgColor); + drawSimpleQuad(textX - bgPadX, textY - 3.0f * scale, w + bgPadX * 2.0f, lineH - 2.0f * scale, bgColor); textRenderer.renderText(text, textX, textY, white); textY -= lineH; }; diff --git a/src/client/menus/Menu.cpp b/src/client/menus/Menu.cpp index a143de4..3e593bb 100644 --- a/src/client/menus/Menu.cpp +++ b/src/client/menus/Menu.cpp @@ -400,11 +400,10 @@ void Menu::resize(float width, float height) float scale = std::min(scaleX, scaleY); menuScale = scale; - this->menuWidth = DESIGN_WIDTH * scale; this->menuHeight = DESIGN_HEIGHT * scale; - textRenderer.setScale(textScale * scale); + textRenderer.setScale(scale); build(); } diff --git a/src/client/menus/PlayerListHUD.cpp b/src/client/menus/PlayerListHUD.cpp index 23ac242..f9550d3 100644 --- a/src/client/menus/PlayerListHUD.cpp +++ b/src/client/menus/PlayerListHUD.cpp @@ -27,7 +27,11 @@ glm::vec3 PlayerListHUD::idToColor(uint32_t id) PlayerListHUD::PlayerListHUD(float width, float height) : Menu(width, height) { + DESIGN_WIDTH = 3840; + DESIGN_HEIGHT = 2160; build(); + + resize(width, height); } void PlayerListHUD::update(const std::vector& players) @@ -44,11 +48,12 @@ void PlayerListHUD::onRender() { if (m_players.empty()) return; - const float s = menuScale; - const float panelW = 300.0f * s * textScale * 3; + float scale = textRenderer.getScale() * 2.5f; + const float s = scale; + const float panelW = 300.0f * s; const float padX = 10.0f * s; - const float padY = 8.0f * s * textScale * 3; - const float lineH = 20.0f * s * textScale * 3; + const float padY = 8.0f * s; + const float lineH = 20.0f * s; const float iconSize = 12.0f * s; const float topGap = 10.0f * s; diff --git a/src/server/Server.cpp b/src/server/Server.cpp index c1dfe8d..10d413c 100644 --- a/src/server/Server.cpp +++ b/src/server/Server.cpp @@ -770,9 +770,14 @@ void Server::receiveMessage(NetMessage &pkt, const sockaddr_in &cliaddr) std::istringstream iss(pkt.message.substr(strlen("tp "))); float x, y, z; if (iss >> x >> y >> z) { - player->movement->setPosition(glm::vec3(x, y, z)); - player->movement->setVelocity(glm::vec3(0.0f)); - player->movement->accumulatedFallDistance = 0.0f; + if (abs(x) < 100000000 && abs(y) < 100000000 && abs(z) < 2000) + { + player->movement->setPosition(glm::vec3(x, y, z)); + player->movement->setVelocity(glm::vec3(0.0f)); + player->movement->accumulatedFallDistance = 0.0f; + } + else + player->targetedMessages.push_back("You can't tp that far!"); } else { player->targetedMessages.push_back("[server] Usage: /tp "); }