Refactor and fixes

This commit is contained in:
MihailRis 2023-11-16 11:11:52 +03:00
parent a62fc5c4e0
commit 3527e9d8e7
2 changed files with 22 additions and 12 deletions

View File

@ -97,7 +97,7 @@ void Panel::refresh() {
vec2 size = this->size();
if (orientation_ == Orientation::vertical) {
float maxw = size.x;
for (auto node : nodes) {
for (auto& node : nodes) {
vec2 nodesize = node->size();
const vec4 margin = node->margin();
y += margin.y;
@ -116,25 +116,29 @@ void Panel::refresh() {
}
node->setCoord(vec2(ex, y));
y += nodesize.y + margin.w + interval;
node->size(vec2(size.x - padding.x - padding.z - margin.x - margin.z, nodesize.y));
float width = size.x - padding.x - padding.z - margin.x - margin.z;
node->size(vec2(width, nodesize.y));
maxw = fmax(maxw, ex+node->size().x+margin.z+padding.z);
}
if (resizing_)
this->size(vec2(maxw, y+padding.w));
this->size(vec2(size.x, y+padding.w));
} else {
float maxh = size.y;
for (auto node : nodes) {
for (auto& node : nodes) {
vec2 nodesize = node->size();
const vec4 margin = node->margin();
x += margin.x;
node->setCoord(vec2(x, y+margin.y));
x += nodesize.x + margin.z + interval;
node->size(vec2(nodesize.x, size.y - padding.y - padding.w - margin.y - margin.w));
float height = size.y - padding.y - padding.w - margin.y - margin.w;
node->size(vec2(nodesize.x, height));
maxh = fmax(maxh, y+margin.y+node->size().y+margin.w+padding.w);
}
bool increased = maxh > size.y;
if (resizing_)
this->size(vec2(x+padding.z, maxh));
this->size(vec2(x+padding.z, size.y));
if (increased)
refresh();
}

View File

@ -29,6 +29,7 @@ using std::wstring;
using glm::vec3;
using glm::vec4;
using std::shared_ptr;
using std::filesystem::path;
using std::filesystem::directory_iterator;
using namespace gui;
@ -38,11 +39,12 @@ MenuScreen::MenuScreen(Engine* engine_) : Screen(engine_) {
panel->setCoord(vec2(10, 10));
{
Button* button = new Button(L"Continue", vec4(12.0f, 10.0f, 12.0f, 10.0f));
auto button = new Button(L"Continue", vec4(12.0f, 10.0f, 12.0f, 10.0f));
button->listenAction([this, panel](GUI*) {
std::cout << "-- loading world" << std::endl;
EngineSettings& settings = engine->getSettings();
World* world = new World("world", enginefs::get_worlds_folder()/"world", 42, settings);
path folder = enginefs::get_worlds_folder()/"world";
World* world = new World("world", folder, 42, settings);
auto screen = new LevelScreen(engine, world->loadLevel(settings));
engine->setScreen(shared_ptr<Screen>(screen));
@ -90,7 +92,9 @@ void MenuScreen::draw(float delta) {
Window::setBgColor(vec3(0.2f, 0.2f, 0.2f));
}
LevelScreen::LevelScreen(Engine* engine, Level* level) : Screen(engine), level(level) {
LevelScreen::LevelScreen(Engine* engine, Level* level)
: Screen(engine),
level(level) {
worldRenderer = new WorldRenderer(level, engine->getAssets());
hud = new HudRenderer(engine, level);
}
@ -128,7 +132,9 @@ void LevelScreen::update(float delta) {
gui::GUI* gui = engine->getGUI();
EngineSettings& settings = engine->getSettings();
bool inputLocked = hud->isPause() || hud->isInventoryOpen() || gui->isFocusCaught();
bool inputLocked = hud->isPause() ||
hud->isInventoryOpen() ||
gui->isFocusCaught();
if (!inputLocked) {
updateHotkeys();
}
@ -141,8 +147,8 @@ void LevelScreen::draw(float delta) {
EngineSettings& settings = engine->getSettings();
Camera* camera = level->player->camera;
float fovFactor = 18.0f / (float)settings.chunks.loadDistance;
worldRenderer->draw(camera, occlusion, fovFactor, settings.graphics.fogCurve);
float fogFactor = 18.0f / (float)settings.chunks.loadDistance;
worldRenderer->draw(camera, occlusion, fogFactor, settings.graphics.fogCurve);
hud->draw();
if (level->player->debug) {
hud->drawDebug( 1 / delta, occlusion);