diff --git a/res/textures/gui/menubg.png b/res/textures/gui/menubg.png index e3342a02..54135f36 100644 Binary files a/res/textures/gui/menubg.png and b/res/textures/gui/menubg.png differ diff --git a/src/engine.cpp b/src/engine.cpp index 3f717c98..e0cef498 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -128,7 +128,7 @@ void Engine::mainloop() { updateHotkeys(); audio::update(delta); - gui->act(delta); + gui->act(delta, Viewport(Window::width, Window::height)); screen->update(delta); if (!Window::isIconified()) { diff --git a/src/frontend/screens/LevelScreen.cpp b/src/frontend/screens/LevelScreen.cpp index 47a68fa8..87c8963c 100644 --- a/src/frontend/screens/LevelScreen.cpp +++ b/src/frontend/screens/LevelScreen.cpp @@ -72,13 +72,15 @@ void LevelScreen::saveWorldPreview() { logger.info() << "saving world preview"; auto paths = engine->getPaths(); auto player = controller->getPlayer(); + auto& settings = engine->getSettings(); + int previewSize = settings.ui.worldPreviewSize.get(); + // camera special copy for world preview Camera camera = *player->camera; camera.setFov(glm::radians(70.0f)); - auto& settings = engine->getSettings(); - int previewSize = settings.ui.worldPreviewSize.get(); Viewport viewport(previewSize * 1.5, previewSize); GfxContext ctx(nullptr, viewport, batch.get()); + worldRenderer->draw(ctx, &camera, false, postProcessing.get()); auto image = postProcessing->toImage(); image->flipY(); diff --git a/src/frontend/screens/MenuScreen.cpp b/src/frontend/screens/MenuScreen.cpp index 8d4ca80b..1ddc317d 100644 --- a/src/frontend/screens/MenuScreen.cpp +++ b/src/frontend/screens/MenuScreen.cpp @@ -4,6 +4,7 @@ #include "../../graphics/ui/elements/Menu.hpp" #include "../../graphics/core/Batch2D.hpp" #include "../../graphics/core/Shader.hpp" +#include "../../graphics/core/Texture.hpp" #include "../../window/Window.h" #include "../../window/Camera.h" #include "../../engine.h" @@ -16,7 +17,7 @@ MenuScreen::MenuScreen(Engine* engine) : Screen(engine) { menu->reset(); menu->setPage("main"); - uicamera.reset(new Camera(glm::vec3(), Window::height)); + uicamera = std::make_unique(glm::vec3(), Window::height); uicamera->perspective = false; uicamera->flipped = true; } @@ -28,23 +29,26 @@ void MenuScreen::update(float delta) { } void MenuScreen::draw(float delta) { + auto assets = engine->getAssets(); + Window::clear(); Window::setBgColor(glm::vec3(0.2f)); uicamera->setFov(Window::height); - Shader* uishader = engine->getAssets()->getShader("ui"); + Shader* uishader = assets->getShader("ui"); uishader->use(); uishader->uniformMatrix("u_projview", uicamera->getProjView()); uint width = Window::width; uint height = Window::height; + auto bg = assets->getTexture("gui/menubg"); batch->begin(); - batch->texture(engine->getAssets()->getTexture("gui/menubg")); + batch->texture(bg); batch->rect( 0, 0, width, height, 0, 0, 0, - UVRegion(0, 0, width/64, height/64), + UVRegion(0, 0, width/bg->getWidth(), height/bg->getHeight()), false, false, glm::vec4(1.0f) ); batch->flush(); diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp index 60350a1f..a8b291a8 100644 --- a/src/graphics/ui/GUI.cpp +++ b/src/graphics/ui/GUI.cpp @@ -113,16 +113,14 @@ void GUI::actFocused() { } } -/// @brief Processing user input and UI logic -/// @param delta delta time -void GUI::act(float delta) { +void GUI::act(float delta, const Viewport& vp) { while (!postRunnables.empty()) { runnable callback = postRunnables.back(); postRunnables.pop(); callback(); } - container->setSize(glm::vec2(Window::width, Window::height)); + container->setSize(vp.size()); container->act(delta); auto prevfocus = focus; diff --git a/src/graphics/ui/GUI.hpp b/src/graphics/ui/GUI.hpp index 85bdcdd8..d18972e2 100644 --- a/src/graphics/ui/GUI.hpp +++ b/src/graphics/ui/GUI.hpp @@ -11,6 +11,7 @@ #include "../../delegates.h" +class Viewport; class GfxContext; class Assets; class Camera; @@ -80,7 +81,8 @@ namespace gui { /// @brief Main input handling and logic update method /// @param delta delta time - void act(float delta); + /// @param viewport window size + void act(float delta, const Viewport& viewport); /// @brief Draw all visible elements on main container /// @param pctx parent graphics context diff --git a/src/logic/scripting/lua/libblock.cpp b/src/logic/scripting/lua/libblock.cpp index 2f0c18a8..85c56240 100644 --- a/src/logic/scripting/lua/libblock.cpp +++ b/src/logic/scripting/lua/libblock.cpp @@ -22,6 +22,18 @@ int l_block_name(lua_State* L) { return 1; } + +int l_block_material(lua_State* L) { + auto indices = scripting::content->getIndices(); + lua::luaint id = lua_tointeger(L, 1); + if (id < 0 || size_t(id) >= indices->countBlockDefs()) { + return 0; + } + auto def = indices->getBlockDef(id); + lua_pushstring(L, def->material.c_str()); + return 1; +} + int l_is_solid_at(lua_State* L) { lua::luaint x = lua_tointeger(L, 1); lua::luaint y = lua_tointeger(L, 2); @@ -218,6 +230,7 @@ int l_is_replaceable_at(lua_State* L) { const luaL_Reg blocklib [] = { {"index", lua_wrap_errors}, {"name", lua_wrap_errors}, + {"material", lua_wrap_errors}, {"defs_count", lua_wrap_errors}, {"is_solid_at", lua_wrap_errors}, {"is_replaceable_at", lua_wrap_errors}, diff --git a/src/util/platform.cpp b/src/util/platform.cpp index 0ffc884f..9de3f4d4 100644 --- a/src/util/platform.cpp +++ b/src/util/platform.cpp @@ -7,7 +7,7 @@ #include "../typedefs.h" -#ifdef WIN32 +#ifdef _WIN32 #include #include "./stringutil.h" @@ -41,4 +41,4 @@ std::string platform::detect_locale() { return preferredLocaleName.substr(0, 5); } -#endif \ No newline at end of file +#endif diff --git a/src/voxels/DefaultWorldGenerator.cpp b/src/voxels/DefaultWorldGenerator.cpp index f453d94f..77bf8ad8 100644 --- a/src/voxels/DefaultWorldGenerator.cpp +++ b/src/voxels/DefaultWorldGenerator.cpp @@ -18,7 +18,7 @@ #include "../maths/util.h" #include "../core_defs.h" -// TODO: do something with long conditions + move magic numbers to constants +// will be refactored in generators update const int SEA_LEVEL = 55; @@ -204,4 +204,4 @@ void DefaultWorldGenerator::generate(voxel* voxels, int cx, int cz, int seed){ } } } -} \ No newline at end of file +}