[LuaGUI] Now provides SCREEN_WIDTH, SCREEN_HEIGHT and GUI_SCALE instead of them being hardcoded in init.lua.

This commit is contained in:
Quentin Bazin 2020-02-15 13:54:02 +09:00
parent 41a46ba13b
commit 857c7e4060
7 changed files with 16 additions and 16 deletions

View File

@ -38,11 +38,10 @@ namespace {
constexpr int SEALEVEL = 4;
}
// FIXME
// FIXME: These variables should be renamed
extern float SCREEN_WIDTH;
extern float SCREEN_HEIGHT;
// FIXME
extern int GUI_SCALE;
namespace Config {

View File

@ -22,11 +22,10 @@
*/
#include "Config.hpp"
// FIXME
// FIXME: These variables should be renamed
float SCREEN_WIDTH = 1600;
float SCREEN_HEIGHT = 1050;
// FIXME
int GUI_SCALE = 3;
// Gameplay

View File

@ -36,8 +36,8 @@ mod:block {
-- FIXME: Replace this by gui:set_size() and gui:set_centered()
local gui_pos = {
x = SCREEN_WIDTH / GUI_SCALE / 2.0 - 176 / 2.0,
y = SCREEN_HEIGHT / GUI_SCALE / 2.0 - 166 / 2.0
x = gui.SCREEN_WIDTH / gui.GUI_SCALE / 2.0 - 176 / 2.0,
y = gui.SCREEN_HEIGHT / gui.GUI_SCALE / 2.0 - 166 / 2.0
}
gui:furnace {

View File

@ -20,12 +20,6 @@
--
-- =====================================================================================
--
-- FIXME
SCREEN_WIDTH = 1600
SCREEN_HEIGHT = 1050
GUI_SCALE = 3
mod = LuaMod.new("default")
dofile("mods/default/blocks.lua")
@ -71,8 +65,8 @@ function show_inventory(client)
-- FIXME: Replace this by gui:set_size() and gui:set_centered()
local gui_pos = {
x = SCREEN_WIDTH / GUI_SCALE / 2.0 - 176 / 2.0,
y = SCREEN_HEIGHT / GUI_SCALE / 2.0 - 166 / 2.0
x = gui.SCREEN_WIDTH / gui.GUI_SCALE / 2.0 - 176 / 2.0,
y = gui.SCREEN_HEIGHT / gui.GUI_SCALE / 2.0 - 166 / 2.0
}
gui:player_inventory {

View File

@ -35,8 +35,8 @@ mod:block {
-- FIXME: Replace this by gui:set_size() and gui:set_centered()
local gui_pos = {
x = SCREEN_WIDTH / GUI_SCALE / 2.0 - 176 / 2.0,
y = SCREEN_HEIGHT / GUI_SCALE / 2.0 - 166 / 2.0
x = gui.SCREEN_WIDTH / gui.GUI_SCALE / 2.0 - 176 / 2.0,
y = gui.SCREEN_HEIGHT / gui.GUI_SCALE / 2.0 - 166 / 2.0
}
gui:button {

View File

@ -213,8 +213,15 @@ void LuaGUI::show(Client &client) {
client.tcpSocket->send(packet);
}
#include "Config.hpp" // FIXME
void LuaGUI::initUsertype(sol::state &lua) {
lua.new_usertype<LuaGUI>("LuaGUI",
// FIXME: These variables should be renamed and put somewhere else
"SCREEN_WIDTH", sol::var(std::ref(SCREEN_WIDTH)),
"SCREEN_HEIGHT", sol::var(std::ref(SCREEN_HEIGHT)),
"GUI_SCALE", sol::var(std::ref(GUI_SCALE)),
"image", &LuaGUI::addImage,
"button", &LuaGUI::addTextButton,
"inventory", &LuaGUI::addInventoryWidget,

View File

@ -83,6 +83,7 @@ void ServerCommandHandler::setupCallbacks() {
auto &player = m_players.at(client.id);
player.setPosition(m_spawnPosition.x, m_spawnPosition.y, m_spawnPosition.z);
// FIXME: Find a better way to give starting items
m_scriptEngine.lua()["init"](player);
sf::Packet invPacket;