add get_text, set_text, get_pos, set_pos
This commit is contained in:
parent
d74b530a83
commit
501f1b568d
@ -1,6 +1,8 @@
|
|||||||
local DROP_FORCE = 8
|
local DROP_FORCE = 8
|
||||||
local DROP_INIT_VEL = {0, 3, 0}
|
local DROP_INIT_VEL = {0, 3, 0}
|
||||||
|
|
||||||
|
local textid
|
||||||
|
|
||||||
function on_hud_open()
|
function on_hud_open()
|
||||||
input.add_callback("player.drop", function ()
|
input.add_callback("player.drop", function ()
|
||||||
if hud.is_paused() or hud.is_inventory_open() then
|
if hud.is_paused() or hud.is_inventory_open() then
|
||||||
@ -25,9 +27,14 @@ function on_hud_open()
|
|||||||
drop.rigidbody:set_vel(velocity)
|
drop.rigidbody:set_vel(velocity)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
gfx.text3d.show({0.5, 99.5, 0.0015}, "Segmentation fault", {
|
textid = gfx.text3d.show({0.5, 99.5, 0.0015}, "Segmentation fault", {
|
||||||
scale=0.005,
|
scale=0.005,
|
||||||
color={0, 0, 0, 1},
|
color={0, 0, 0, 1},
|
||||||
displayMode="static_billboard"
|
displayMode="static_billboard"
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function on_hud_render()
|
||||||
|
local pos = gfx.text3d.get_pos(textid)
|
||||||
|
gfx.text3d.set_pos(textid, {pos[1], pos[2]+time.delta(), pos[3]})
|
||||||
|
end
|
||||||
|
|||||||
@ -6,6 +6,10 @@ TextNote::TextNote(std::wstring text, NotePreset preset, glm::vec3 position)
|
|||||||
position(std::move(position)) {
|
position(std::move(position)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextNote::setText(std::wstring_view text) {
|
||||||
|
this->text = text;
|
||||||
|
}
|
||||||
|
|
||||||
const std::wstring& TextNote::getText() const {
|
const std::wstring& TextNote::getText() const {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -14,6 +18,10 @@ const NotePreset& TextNote::getPreset() const {
|
|||||||
return preset;
|
return preset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextNote::setPosition(const glm::vec3& position) {
|
||||||
|
this->position = position;
|
||||||
|
}
|
||||||
|
|
||||||
const glm::vec3& TextNote::getPosition() const {
|
const glm::vec3& TextNote::getPosition() const {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,9 +10,13 @@ class TextNote {
|
|||||||
public:
|
public:
|
||||||
TextNote(std::wstring text, NotePreset preset, glm::vec3 position);
|
TextNote(std::wstring text, NotePreset preset, glm::vec3 position);
|
||||||
|
|
||||||
|
void setText(std::wstring_view text);
|
||||||
|
|
||||||
const std::wstring& getText() const;
|
const std::wstring& getText() const;
|
||||||
|
|
||||||
const NotePreset& getPreset() const;
|
const NotePreset& getPreset() const;
|
||||||
|
|
||||||
|
void setPosition(const glm::vec3& position);
|
||||||
|
|
||||||
const glm::vec3& getPosition() const;
|
const glm::vec3& getPosition() const;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -96,6 +96,14 @@ u64id_t TextsRenderer::add(std::unique_ptr<TextNote> note) {
|
|||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextNote* TextsRenderer::get(u64id_t id) const {
|
||||||
|
const auto& found = notes.find(id);
|
||||||
|
if (found == notes.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return found->second.get();
|
||||||
|
}
|
||||||
|
|
||||||
void TextsRenderer::remove(u64id_t id) {
|
void TextsRenderer::remove(u64id_t id) {
|
||||||
notes.erase(id);
|
notes.erase(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,5 +41,7 @@ public:
|
|||||||
|
|
||||||
u64id_t add(std::unique_ptr<TextNote> note);
|
u64id_t add(std::unique_ptr<TextNote> note);
|
||||||
|
|
||||||
|
TextNote* get(u64id_t id) const;
|
||||||
|
|
||||||
void remove(u64id_t id);
|
void remove(u64id_t id);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,8 +28,40 @@ static int l_hide(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_get_text(lua::State* L) {
|
||||||
|
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
|
||||||
|
return lua::pushwstring(L, note->getText());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_set_text(lua::State* L) {
|
||||||
|
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
|
||||||
|
note->setText(lua::require_wstring(L, 2));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_get_pos(lua::State* L) {
|
||||||
|
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
|
||||||
|
return lua::pushvec(L, note->getPosition());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int l_set_pos(lua::State* L) {
|
||||||
|
if (auto note = renderer->texts->get(lua::tointeger(L, 1))) {
|
||||||
|
note->setPosition(lua::tovec3(L, 2));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg text3dlib[] = {
|
const luaL_Reg text3dlib[] = {
|
||||||
{"show", lua::wrap<l_show>},
|
{"show", lua::wrap<l_show>},
|
||||||
{"hide", lua::wrap<l_hide>},
|
{"hide", lua::wrap<l_hide>},
|
||||||
|
{"get_text", lua::wrap<l_get_text>},
|
||||||
|
{"set_text", lua::wrap<l_set_text>},
|
||||||
|
{"get_pos", lua::wrap<l_get_pos>},
|
||||||
|
{"set_pos", lua::wrap<l_set_pos>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user