From f428a24a1666f097490f8a29c7b5a1d48cc661a1 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 6 Mar 2024 10:05:58 +0300 Subject: [PATCH] UINode.coord renamed to UINode.pos --- src/frontend/InventoryView.cpp | 46 ++++++++++----------- src/frontend/InventoryView.h | 4 +- src/frontend/debug_panel.cpp | 2 +- src/frontend/gui/GUI.cpp | 2 +- src/frontend/gui/UINode.cpp | 28 ++++++------- src/frontend/gui/UINode.h | 10 ++--- src/frontend/gui/containers.cpp | 16 ++++---- src/frontend/gui/containers.h | 2 +- src/frontend/gui/controls.cpp | 64 +++++++++++++++--------------- src/frontend/gui/gui_xml.cpp | 2 +- src/frontend/hud.cpp | 20 +++++----- src/logic/scripting/lua/libgui.cpp | 4 +- 12 files changed, 101 insertions(+), 99 deletions(-) diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index 7dd9179a..12665300 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -47,7 +47,7 @@ InventoryBuilder::InventoryBuilder() { /** Add slots grid to inventory view * @param cols grid columns * @param count total number of grid slots - * @param coord position of the first slot of the grid + * @param pos position of the first slot of the grid * @param padding additional space around the grid * @param addpanel automatically create panel behind the grid * with size including padding @@ -55,7 +55,7 @@ InventoryBuilder::InventoryBuilder() { */ void InventoryBuilder::addGrid( int cols, int count, - glm::vec2 coord, + glm::vec2 pos, int padding, bool addpanel, SlotLayout slotLayout) @@ -69,18 +69,18 @@ void InventoryBuilder::addGrid( uint height = rows * (slotSize + interval) - interval + padding*2; glm::vec2 vsize = view->getSize(); - if (coord.x + width > vsize.x) { - vsize.x = coord.x + width; + if (pos.x + width > vsize.x) { + vsize.x = pos.x + width; } - if (coord.y + height > vsize.y) { - vsize.y = coord.y + height; + if (pos.y + height > vsize.y) { + vsize.y = pos.y + height; } view->setSize(vsize); if (addpanel) { auto panel = std::make_shared(glm::vec2(width, height)); view->setColor(glm::vec4(0.122f, 0.122f, 0.122f, 0.878f)); - view->add(panel, coord); + view->add(panel, pos); } for (int row = 0; row < rows; row++) { @@ -121,7 +121,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) { ItemStack& stack = *bound; - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); int slotSize = InventoryView::SLOT_SIZE; @@ -137,9 +137,9 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) { if (color.a > 0.0) { batch->texture(nullptr); if (highlighted) { - batch->rect(coord.x-4, coord.y-4, slotSize+8, slotSize+8); + batch->rect(pos.x-4, pos.y-4, slotSize+8, slotSize+8); } else { - batch->rect(coord.x, coord.y, slotSize, slotSize); + batch->rect(pos.x, pos.y, slotSize, slotSize); } } @@ -158,7 +158,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) { UVRegion region = previews->get(cblock.name); batch->rect( - coord.x, coord.y, slotSize, slotSize, + pos.x, pos.y, slotSize, slotSize, 0, 0, 0, region, false, true, tint); break; } @@ -177,7 +177,7 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) { } } batch->rect( - coord.x, coord.y, slotSize, slotSize, + pos.x, pos.y, slotSize, slotSize, 0, 0, 0, region, false, true, tint); break; } @@ -187,8 +187,8 @@ void SlotView::draw(const GfxContext* pctx, Assets* assets) { auto font = assets->getFont("normal"); std::wstring text = std::to_wstring(stack.getCount()); - int x = coord.x+slotSize-text.length()*8; - int y = coord.y+slotSize-16; + int x = pos.x+slotSize-text.length()*8; + int y = pos.y+slotSize-16; batch->setColor(glm::vec4(0, 0, 0, 1.0f)); font->draw(batch, text, x+1, y+1); @@ -291,13 +291,13 @@ std::shared_ptr InventoryView::addSlot(SlotLayout layout) { uint width = InventoryView::SLOT_SIZE + layout.padding; uint height = InventoryView::SLOT_SIZE + layout.padding; - auto coord = layout.position; + auto pos = layout.position; auto vsize = getSize(); - if (coord.x + width > vsize.x) { - vsize.x = coord.x + width; + if (pos.x + width > vsize.x) { + vsize.x = pos.x + width; } - if (coord.y + height > vsize.y) { - vsize.y = coord.y + height; + if (pos.y + height > vsize.y) { + vsize.y = pos.y + height; } setSize(vsize); @@ -344,8 +344,8 @@ void InventoryView::setSelected(int index) { } } -void InventoryView::setCoord(glm::vec2 coord) { - Container::setCoord(coord - origin); +void InventoryView::setPos(glm::vec2 pos) { + Container::setPos(pos - origin); } void InventoryView::setOrigin(glm::vec2 origin) { @@ -378,8 +378,8 @@ static void readSlot(InventoryView* view, gui::UiXmlReader& reader, xml::xmlelem int index = element->attr("index", "0").asInt(); bool itemSource = element->attr("item-source", "false").asBool(); SlotLayout layout(index, glm::vec2(), true, itemSource, nullptr, nullptr); - if (element->has("coord")) { - layout.position = element->attr("coord").asVec2(); + if (element->has("pos")) { + layout.position = element->attr("pos").asVec2(); } if (element->has("sharefunc")) { layout.shareFunc = readSlotFunc(view, reader, element, "sharefunc"); diff --git a/src/frontend/InventoryView.h b/src/frontend/InventoryView.h index c33f0823..7cab1131 100644 --- a/src/frontend/InventoryView.h +++ b/src/frontend/InventoryView.h @@ -101,7 +101,7 @@ public: void setInventory(std::shared_ptr inventory); - virtual void setCoord(glm::vec2 coord) override; + virtual void setPos(glm::vec2 pos) override; void setOrigin(glm::vec2 origin); glm::vec2 getOrigin() const; @@ -133,7 +133,7 @@ public: void addGrid( int cols, int count, - glm::vec2 coord, + glm::vec2 pos, int padding, bool addpanel, SlotLayout slotLayout diff --git a/src/frontend/debug_panel.cpp b/src/frontend/debug_panel.cpp index 88763ecb..0fb20427 100644 --- a/src/frontend/debug_panel.cpp +++ b/src/frontend/debug_panel.cpp @@ -29,7 +29,7 @@ std::shared_ptr create_debug_panel( Player* player ) { auto panel = std::make_shared(glm::vec2(250, 200), glm::vec4(5.0f), 2.0f); - panel->setCoord(glm::vec2(10, 10)); + panel->setPos(glm::vec2(10, 10)); static int fps = 0; static int fpsMin = fps; diff --git a/src/frontend/gui/GUI.cpp b/src/frontend/gui/GUI.cpp index 3214bcf2..a55ce768 100644 --- a/src/frontend/gui/GUI.cpp +++ b/src/frontend/gui/GUI.cpp @@ -126,7 +126,7 @@ void GUI::draw(const GfxContext* pctx, Assets* assets) { auto& viewport = pctx->getViewport(); glm::vec2 wsize = viewport.size(); - menu->setCoord((wsize - menu->getSize()) / 2.0f); + menu->setPos((wsize - menu->getSize()) / 2.0f); uicamera->setFov(wsize.y); Shader* uishader = assets->getShader("ui"); diff --git a/src/frontend/gui/UINode.cpp b/src/frontend/gui/UINode.cpp index 79e13f06..d8a51f68 100644 --- a/src/frontend/gui/UINode.cpp +++ b/src/frontend/gui/UINode.cpp @@ -63,18 +63,18 @@ bool UINode::isFocused() const { return focused; } -bool UINode::isInside(glm::vec2 pos) { - glm::vec2 coord = calcCoord(); +bool UINode::isInside(glm::vec2 point) { + glm::vec2 pos = calcPos(); glm::vec2 size = getSize(); - return (pos.x >= coord.x && pos.y >= coord.y && - pos.x < coord.x + size.x && pos.y < coord.y + size.y); + return (point.x >= pos.x && point.y >= pos.y && + point.x < pos.x + size.x && point.y < pos.y + size.y); } -std::shared_ptr UINode::getAt(glm::vec2 pos, std::shared_ptr self) { +std::shared_ptr UINode::getAt(glm::vec2 point, std::shared_ptr self) { if (!interactive) { return nullptr; } - return isInside(pos) ? self : nullptr; + return isInside(point) ? self : nullptr; } bool UINode::isInteractive() const { @@ -93,11 +93,11 @@ bool UINode::isResizing() const { return resizing; } -glm::vec2 UINode::calcCoord() const { +glm::vec2 UINode::calcPos() const { if (parent) { - return coord + parent->calcCoord() + parent->contentOffset(); + return pos + parent->calcPos() + parent->contentOffset(); } - return coord; + return pos; } void UINode::scrolled(int value) { @@ -106,12 +106,12 @@ void UINode::scrolled(int value) { } } -void UINode::setCoord(glm::vec2 coord) { - this->coord = coord; +void UINode::setPos(glm::vec2 pos) { + this->pos = pos; } -glm::vec2 UINode::getCoord() const { - return coord; +glm::vec2 UINode::getPos() const { + return pos; } glm::vec2 UINode::getSize() const { @@ -187,6 +187,6 @@ const std::string& UINode::getId() const { void UINode::reposition() { if (positionfunc) { - setCoord(positionfunc()); + setPos(positionfunc()); } } diff --git a/src/frontend/gui/UINode.h b/src/frontend/gui/UINode.h index 205505c2..a79717cf 100644 --- a/src/frontend/gui/UINode.h +++ b/src/frontend/gui/UINode.h @@ -30,7 +30,7 @@ namespace gui { */ std::string id = ""; protected: - glm::vec2 coord {0.0f}; + glm::vec2 pos {0.0f}; glm::vec2 size; glm::vec2 minSize {1.0f}; glm::vec4 color {1.0f}; @@ -123,9 +123,9 @@ namespace gui { /* Get inner content offset. Used for scroll */ virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);}; /* Calculate screen position of the element */ - virtual glm::vec2 calcCoord() const; - virtual void setCoord(glm::vec2 coord); - virtual glm::vec2 getCoord() const; + virtual glm::vec2 calcPos() const; + virtual void setPos(glm::vec2 pos); + virtual glm::vec2 getPos() const; virtual glm::vec2 getSize() const; virtual void setSize(glm::vec2 size); virtual glm::vec2 getMinSize() const; @@ -140,7 +140,7 @@ namespace gui { void setId(const std::string& id); const std::string& getId() const; - /* Fetch coord from positionfunc if assigned */ + /* Fetch pos from positionfunc if assigned */ void reposition(); }; } diff --git a/src/frontend/gui/containers.cpp b/src/frontend/gui/containers.cpp index 4cbdeaf2..f908dc85 100644 --- a/src/frontend/gui/containers.cpp +++ b/src/frontend/gui/containers.cpp @@ -79,7 +79,7 @@ void Container::setScrollable(bool flag) { } void Container::draw(const GfxContext* pctx, Assets* assets) { - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); glm::vec2 size = getSize(); drawBackground(pctx, assets); @@ -88,7 +88,7 @@ void Container::draw(const GfxContext* pctx, Assets* assets) { batch->flush(); { GfxContext ctx = pctx->sub(); - ctx.scissors(glm::vec4(coord.x, coord.y, size.x, size.y)); + ctx.scissors(glm::vec4(pos.x, pos.y, size.x, size.y)); for (auto node : nodes) { if (node->isVisible()) node->draw(pctx, assets); @@ -100,12 +100,12 @@ void Container::draw(const GfxContext* pctx, Assets* assets) { void Container::drawBackground(const GfxContext* pctx, Assets* assets) { if (color.a <= 0.0f) return; - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); auto batch = pctx->getBatch2D(); batch->texture(nullptr); batch->setColor(color); - batch->rect(coord.x, coord.y, size.x, size.y); + batch->rect(pos.x, pos.y, size.x, size.y); } void Container::add(std::shared_ptr node) { @@ -115,8 +115,8 @@ void Container::add(std::shared_ptr node) { refresh(); } -void Container::add(std::shared_ptr node, glm::vec2 coord) { - node->setCoord(coord); +void Container::add(std::shared_ptr node, glm::vec2 pos) { + node->setPos(pos); add(node); } @@ -211,7 +211,7 @@ void Panel::refresh() { y += margin.y; float ex = x + margin.x; - node->setCoord(glm::vec2(ex, y)); + node->setPos(glm::vec2(ex, y)); y += nodesize.y + margin.w + interval; float width = size.x - padding.x - padding.z - margin.x - margin.z; @@ -228,7 +228,7 @@ void Panel::refresh() { glm::vec2 nodesize = node->getSize(); const glm::vec4 margin = node->getMargin(); x += margin.x; - node->setCoord(glm::vec2(x, y+margin.y)); + node->setPos(glm::vec2(x, y+margin.y)); x += nodesize.x + margin.z + interval; node->refresh(); diff --git a/src/frontend/gui/containers.h b/src/frontend/gui/containers.h index 80b3b17a..3dcf80c8 100644 --- a/src/frontend/gui/containers.h +++ b/src/frontend/gui/containers.h @@ -40,7 +40,7 @@ namespace gui { virtual void draw(const GfxContext* pctx, Assets* assets) override; virtual std::shared_ptr getAt(glm::vec2 pos, std::shared_ptr self) override; virtual void add(std::shared_ptr node); - virtual void add(std::shared_ptr node, glm::vec2 coord); + virtual void add(std::shared_ptr node, glm::vec2 pos); virtual void remove(std::shared_ptr node); virtual void scrolled(int value) override; virtual void setScrollable(bool flag); diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index b4b72c26..a7165662 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -139,28 +139,28 @@ void Label::draw(const GfxContext* pctx, Assets* assets) { (lines == 1 ? lineHeight : lineHeight*lineInterval)*lines + font->getYOffset() ); - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); switch (align) { case Align::left: break; case Align::center: - coord.x += (size.x-newsize.x)*0.5f; + pos.x += (size.x-newsize.x)*0.5f; break; case Align::right: - coord.x += size.x-newsize.x; + pos.x += size.x-newsize.x; break; } switch (valign) { case Align::top: break; case Align::center: - coord.y += (size.y-newsize.y)*0.5f; + pos.y += (size.y-newsize.y)*0.5f; break; case Align::bottom: - coord.y += size.y-newsize.y; + pos.y += size.y-newsize.y; break; } - textYOffset = coord.y-calcCoord().y; + textYOffset = pos.y-calcPos().y; totalLineHeight = lineHeight * lineInterval; if (multiline) { @@ -172,10 +172,10 @@ void Label::draw(const GfxContext* pctx, Assets* assets) { view = std::wstring_view(text.c_str()+offset, end); offset += end + 1; } - font->draw(batch, view, coord.x, coord.y + i * totalLineHeight, FontStyle::none); + font->draw(batch, view, pos.x, pos.y + i * totalLineHeight, FontStyle::none); } } else { - font->draw(batch, text, coord.x, coord.y, FontStyle::none); + font->draw(batch, text, pos.x, pos.y, FontStyle::none); } } @@ -198,7 +198,7 @@ Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(textur } void Image::draw(const GfxContext* pctx, Assets* assets) { - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); glm::vec4 color = getColor(); auto batch = pctx->getBatch2D(); @@ -208,7 +208,7 @@ void Image::draw(const GfxContext* pctx, Assets* assets) { } batch->texture(texture); batch->setColor(color); - batch->rect(coord.x, coord.y, size.x, size.y, + batch->rect(pos.x, pos.y, size.x, size.y, 0, 0, 0, UVRegion(), false, true, color); } @@ -296,11 +296,11 @@ void Button::refresh() { } void Button::drawBackground(const GfxContext* pctx, Assets* assets) { - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); auto batch = pctx->getBatch2D(); batch->texture(nullptr); batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color)); - batch->rect(coord.x, coord.y, size.x, size.y); + batch->rect(pos.x, pos.y, size.x, size.y); } void Button::mouseRelease(GUI* gui, int x, int y) { @@ -351,11 +351,11 @@ RichButton* RichButton::listenAction(onaction action) { } void RichButton::drawBackground(const GfxContext* pctx, Assets* assets) { - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); auto batch = pctx->getBatch2D(); batch->texture(nullptr); batch->setColor(isPressed() ? pressedColor : (hover ? hoverColor : color)); - batch->rect(coord.x, coord.y, size.x, size.y); + batch->rect(pos.x, pos.y, size.x, size.y); } // ================================ TextBox =================================== @@ -368,7 +368,7 @@ TextBox::TextBox(std::wstring placeholder, glm::vec4 padding) add(label); setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f)); - textInitX = label->getCoord().x; + textInitX = label->getPos().x; } void TextBox::draw(const GfxContext* pctx, Assets* assets) { @@ -379,14 +379,14 @@ void TextBox::draw(const GfxContext* pctx, Assets* assets) { if (!isFocused()) return; - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); glm::vec2 size = getSize(); auto subctx = pctx->sub(); - subctx.scissors(glm::vec4(coord.x, coord.y, size.x, size.y)); + subctx.scissors(glm::vec4(pos.x, pos.y, size.x, size.y)); const int lineHeight = font->getLineHeight() * label->getLineInterval(); - glm::vec2 lcoord = label->calcCoord(); + glm::vec2 lcoord = label->calcPos(); lcoord.y -= 2; auto batch = pctx->getBatch2D(); batch->texture(nullptr); @@ -422,7 +422,7 @@ void TextBox::draw(const GfxContext* pctx, Assets* assets) { } void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) { - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); auto batch = pctx->getBatch2D(); batch->texture(nullptr); @@ -439,14 +439,14 @@ void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) { batch->setColor(invalidColor); } - batch->rect(coord.x, coord.y, size.x, size.y); + batch->rect(pos.x, pos.y, size.x, size.y); if (!isFocused() && supplier) { input = supplier(); } if (isFocused() && multiline) { batch->setColor(glm::vec4(1, 1, 1, 0.1f)); - glm::vec2 lcoord = label->calcCoord(); + glm::vec2 lcoord = label->calcPos(); lcoord.y -= 2; uint line = label->getLineByTextIndex(caret); int lineY = label->getLineYOffset(line); @@ -538,7 +538,7 @@ size_t TextBox::getSelectionLength() const { /// @brief Set scroll offset /// @param x scroll offset void TextBox::setTextOffset(uint x) { - label->setCoord(glm::vec2(textInitX - int(x), label->getCoord().y)); + label->setPos(glm::vec2(textInitX - int(x), label->getPos().y)); textOffset = x; } @@ -613,7 +613,7 @@ size_t TextBox::normalizeIndex(int index) { int TextBox::calcIndexAt(int x, int y) const { if (font == nullptr) return 0; - glm::vec2 lcoord = label->calcCoord(); + glm::vec2 lcoord = label->calcPos(); uint line = label->getLineByYOffset(y-lcoord.y); line = std::min(line, label->getLinesNumber()-1); size_t lineLength = getLineLength(line); @@ -885,11 +885,11 @@ InputBindBox::InputBindBox(Binding& binding, glm::vec4 padding) } void InputBindBox::drawBackground(const GfxContext* pctx, Assets* assets) { - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); auto batch = pctx->getBatch2D(); batch->texture(nullptr); batch->setColor(isFocused() ? focusedColor : (hover ? hoverColor : color)); - batch->rect(coord.x, coord.y, size.x, size.y); + batch->rect(pos.x, pos.y, size.x, size.y); label->setText(util::str2wstr_utf8(binding.text())); } @@ -927,18 +927,18 @@ void TrackBar::draw(const GfxContext* pctx, Assets* assets) { if (supplier) { value = supplier(); } - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); auto batch = pctx->getBatch2D(); batch->texture(nullptr); batch->setColor(hover ? hoverColor : color); - batch->rect(coord.x, coord.y, size.x, size.y); + batch->rect(pos.x, pos.y, size.x, size.y); float width = size.x; float t = (value - min) / (max-min+trackWidth*step); batch->setColor(trackColor); int actualWidth = size.x * (trackWidth / (max-min+trackWidth*step) * step); - batch->rect(coord.x + width * t, coord.y, actualWidth, size.y); + batch->rect(pos.x + width * t, pos.y, actualWidth, size.y); } void TrackBar::setSupplier(doublesupplier supplier) { @@ -950,9 +950,9 @@ void TrackBar::setConsumer(doubleconsumer consumer) { } void TrackBar::mouseMove(GUI*, int x, int y) { - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); value = x; - value -= coord.x; + value -= pos.x; value = (value)/size.x * (max-min+trackWidth*step); value += min; value = (value > max) ? max : value; @@ -1021,11 +1021,11 @@ void CheckBox::draw(const GfxContext* pctx, Assets* assets) { if (supplier) { checked = supplier(); } - glm::vec2 coord = calcCoord(); + glm::vec2 pos = calcPos(); auto batch = pctx->getBatch2D(); batch->texture(nullptr); batch->setColor(checked ? checkColor : (hover ? hoverColor : color)); - batch->rect(coord.x, coord.y, size.x, size.y); + batch->rect(pos.x, pos.y, size.x, size.y); } void CheckBox::mouseRelease(GUI*, int x, int y) { diff --git a/src/frontend/gui/gui_xml.cpp b/src/frontend/gui/gui_xml.cpp index 25a35b28..224133c3 100644 --- a/src/frontend/gui/gui_xml.cpp +++ b/src/frontend/gui/gui_xml.cpp @@ -28,7 +28,7 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no node.setId(element->attr("id").getText()); } if (element->has("pos")) { - node.setCoord(element->attr("pos").asVec2()); + node.setPos(element->attr("pos").asVec2()); } if (element->has("size")) { node.setSize(element->attr("size").asVec2()); diff --git a/src/frontend/hud.cpp b/src/frontend/hud.cpp index 49305281..63f27b5e 100644 --- a/src/frontend/hud.cpp +++ b/src/frontend/hud.cpp @@ -351,8 +351,6 @@ void Hud::showOverlay(UiDocument* doc, bool playerInventory) { add(HudElement(hud_element_mode::inventory_bound, doc, secondUI, false)); } -/// @brief Add element as permanent overlay -/// @param doc element layout document void Hud::openPermanent(UiDocument* doc) { auto root = doc->getRoot(); remove(root); @@ -365,7 +363,6 @@ void Hud::openPermanent(UiDocument* doc) { add(HudElement(hud_element_mode::permanent, doc, doc->getRoot(), false)); } -/// @brief Hide inventory and turn off inventory mode void Hud::closeInventory() { auto level = frontend->getLevel(); @@ -431,6 +428,11 @@ void Hud::remove(std::shared_ptr node) { cleanup(); } +class DeltaGrapher : gui::UINode { + +public: +}; + void Hud::draw(const GfxContext& ctx){ const Viewport& viewport = ctx.getViewport(); const uint width = viewport.getWidth(); @@ -445,7 +447,7 @@ void Hud::draw(const GfxContext& ctx){ uishader->use(); uishader->uniformMatrix("u_projview", uicamera->getProjView()); - hotbarView->setCoord(glm::vec2(width/2, height-65)); + hotbarView->setPos(glm::vec2(width/2, height-65)); hotbarView->setSelected(player->getChosenSlot()); // Crosshair @@ -485,12 +487,12 @@ void Hud::draw(const GfxContext& ctx){ if (inventoryOpen) { float caWidth = inventoryView ? contentAccess->getSize().x : 0.0f; - contentAccessPanel->setCoord(glm::vec2(width-caWidth, 0)); + contentAccessPanel->setPos(glm::vec2(width-caWidth, 0)); glm::vec2 invSize = inventoryView ? inventoryView->getSize() : glm::vec2(); if (secondUI == nullptr) { if (inventoryView) { - inventoryView->setCoord(glm::vec2( + inventoryView->setPos(glm::vec2( glm::min(width/2-invSize.x/2, width-caWidth-10-invSize.x), height/2-invSize.y/2 )); @@ -501,18 +503,18 @@ void Hud::draw(const GfxContext& ctx){ int interval = invSize.y > 0.0 ? 5 : 0; float totalHeight = invSize.y + blockInvSize.y + interval; if (inventoryView) { - inventoryView->setCoord(glm::vec2( + inventoryView->setPos(glm::vec2( glm::min(width/2-invwidth/2, width-caWidth-10-invwidth), height/2+totalHeight/2-invSize.y )); } - secondUI->setCoord(glm::vec2( + secondUI->setPos(glm::vec2( glm::min(width/2-invwidth/2, width-caWidth-10-invwidth), height/2-totalHeight/2 )); } } - grabbedItemView->setCoord(glm::vec2(Events::cursor)); + grabbedItemView->setPos(glm::vec2(Events::cursor)); batch->flush(); } diff --git a/src/logic/scripting/lua/libgui.cpp b/src/logic/scripting/lua/libgui.cpp index 11d563af..e25e6af8 100644 --- a/src/logic/scripting/lua/libgui.cpp +++ b/src/logic/scripting/lua/libgui.cpp @@ -171,7 +171,7 @@ static int l_gui_getattr(lua_State* L) { if (attr == "color") { return lua::pushcolor_arr(L, node->getColor()); } else if (attr == "pos") { - return lua::pushvec2_arr(L, node->getCoord()); + return lua::pushvec2_arr(L, node->getPos()); } else if (attr == "size") { return lua::pushvec2_arr(L, node->getSize()); } else if (attr == "hoverColor") { @@ -210,7 +210,7 @@ static int l_gui_setattr(lua_State* L) { auto node = getDocumentNode(L, docname, element); if (attr == "pos") { - node->setCoord(lua::tovec2(L, 4)); + node->setPos(lua::tovec2(L, 4)); } else if (attr == "size") { node->setSize(lua::tovec2(L, 4)); } else if (attr == "color") {