update gui.create_frame return value

This commit is contained in:
MihailRis 2026-02-06 17:31:07 +03:00
parent 8468ab184d
commit 8ee2edef5c
5 changed files with 37 additions and 21 deletions

View file

@ -128,11 +128,13 @@ function on_hud_open()
hud.default_hand_controller = update_hand
local name = "misc/moon"
gui.create_frame(name, name, {128, 128})
local frame = gui.create_frame(name, name, {128, 128})
frame:add("<button>Hello, World</button>")
frame.color = {255, 0, 0, 255}
local document = Document.new(name)
document.root:add("<button>Hello, World</button>")
document.root.color = {255, 0, 0, 255}
input.add_callback('key:y', function ()
gui.set_active_frame(name)
end)
end
function on_hud_render()

View file

@ -234,6 +234,14 @@ menu = _MENU
gui.root = _GUI_ROOT
gui.main_frame_id = "core:main"
local __gui_create_frame = gui.create_frame
function gui.create_frame(id, output, size)
__gui_create_frame(id, output, size)
local document = Document.new(id)
return document.root, document
end
do
local status, err = pcall(function()
local default_styles = toml.parse(file.read(
@ -440,6 +448,8 @@ function __vc_on_hud_open()
end
elseif hud.is_inventory_open() then
hud.close_inventory()
elseif gui.get_active_frame() then
gui.set_active_frame("")
else
hud.pause()
end

View file

@ -240,7 +240,7 @@ void LevelScreen::update(float delta) {
auto menu = gui.getMenu();
bool inputLocked =
menu->hasOpenPage() || hud->isInventoryOpen() || gui.isFocusCaught();
gui.getActiveFrame() || hud->isInventoryOpen() || gui.isFocusCaught();
bool paused = hud->isPause();
if (!paused) {
world.updateTimers(delta);

View file

@ -129,7 +129,7 @@ void GUI::actMouse(Frame& frame, float delta, const CursorState& cursor) {
doubleClicked = false;
doubleClickTimer += delta + mouseDelta * 0.1f;
auto hover = container->getAt(cursor.pos);
auto hover = frame.getAt(cursor.pos);
if (this->hover && this->hover != hover) {
this->hover->setMouseEnter(false);
}
@ -289,8 +289,8 @@ void GUI::draw(const DrawContext& pctx, Assets& assets) {
uicamera->setAspectRatio(viewport.x / static_cast<float>(viewport.y));
auto uishader = assets.get<Shader>("ui");
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjView());
uishader->use();
batch2D->begin();
for (auto& [outputTexture, frame] : frames) {

View file

@ -3,6 +3,7 @@
#include <algorithm>
#include <cmath>
#include <glm/gtc/constants.hpp>
#include "BlocksController.hpp"
#include "content/Content.hpp"
@ -28,17 +29,19 @@
#include "window/input.hpp"
#include "world/Level.hpp"
const float INTERACTION_RELOAD = 0.160f;
const float STEPS_SPEED = 2.2f;
const float CAM_SHAKE_OFFSET = 0.0075f;
const float CAM_SHAKE_OFFSET_Y = 0.031f;
const float CAM_SHAKE_SPEED = STEPS_SPEED;
const float CAM_SHAKE_DELTA_K = 10.0f;
const float ZOOM_SPEED = 16.0f;
const float CROUCH_ZOOM = 0.9f;
const float RUN_ZOOM = 1.1f;
const float C_ZOOM = 0.1f;
const float CROUCH_SHIFT_Y = -0.2f;
namespace {
const float INTERACTION_RELOAD = 0.160f;
const float STEPS_SPEED = 2.2f;
const float CAM_SHAKE_OFFSET = 0.0075f;
const float CAM_SHAKE_OFFSET_Y = 0.031f;
const float CAM_SHAKE_SPEED = STEPS_SPEED;
const float CAM_SHAKE_DELTA_K = 10.0f;
const float ZOOM_SPEED = 16.0f;
const float CROUCH_ZOOM = 0.9f;
const float RUN_ZOOM = 1.1f;
const float C_ZOOM = 0.1f;
const float CROUCH_SHIFT_Y = -0.2f;
}
CameraControl::CameraControl(Player& player, const CameraSettings& settings)
: player(player),
@ -249,17 +252,18 @@ void PlayerController::onFootstep(const Hitbox& hitbox) {
}
void PlayerController::updateFootsteps(float delta) {
const float pi = glm::pi<float>();
auto hitbox = player.getHitbox();
if (hitbox && hitbox->grounded) {
const glm::vec3& vel = hitbox->velocity;
float f = glm::length(glm::vec2(vel.x, vel.z));
stepsTimer += delta * f * STEPS_SPEED;
if (stepsTimer >= M_PI) {
stepsTimer = fmod(stepsTimer, M_PI);
if (stepsTimer >= pi) {
stepsTimer = fmod(stepsTimer, pi);
onFootstep(*hitbox);
}
} else {
stepsTimer = M_PI;
stepsTimer = pi;
}
}