fix
This commit is contained in:
@@ -150,6 +150,14 @@ std::wstring Button::getText() const {
|
||||
return L"";
|
||||
}
|
||||
|
||||
glm::vec4 Button::getPressedColor() const {
|
||||
return pressedColor;
|
||||
}
|
||||
|
||||
void Button::setPressedColor(glm::vec4 color) {
|
||||
pressedColor = color;
|
||||
}
|
||||
|
||||
Button* Button::textSupplier(wstringsupplier supplier) {
|
||||
if (label) {
|
||||
label->textSupplier(supplier);
|
||||
@@ -402,6 +410,7 @@ TrackBar::TrackBar(double min,
|
||||
step(step),
|
||||
trackWidth(trackWidth) {
|
||||
setColor(glm::vec4(0.f, 0.f, 0.f, 0.4f));
|
||||
setHoverColor(glm::vec4(0.01f, 0.02f, 0.03f, 0.5f));
|
||||
}
|
||||
|
||||
void TrackBar::draw(const GfxContext* pctx, Assets* assets) {
|
||||
@@ -444,6 +453,55 @@ void TrackBar::mouseMove(GUI*, int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double TrackBar::getValue() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
double TrackBar::getMin() const {
|
||||
return min;
|
||||
}
|
||||
|
||||
double TrackBar::getMax() const {
|
||||
return max;
|
||||
}
|
||||
|
||||
double TrackBar::getStep() const {
|
||||
return step;
|
||||
}
|
||||
|
||||
int TrackBar::getTrackWidth() const {
|
||||
return trackWidth;
|
||||
}
|
||||
|
||||
glm::vec4 TrackBar::getTrackColor() const {
|
||||
return trackColor;
|
||||
}
|
||||
|
||||
void TrackBar::setValue(double x) {
|
||||
value = x;
|
||||
}
|
||||
|
||||
void TrackBar::setMin(double x) {
|
||||
min = x;
|
||||
}
|
||||
|
||||
void TrackBar::setMax(double x) {
|
||||
max = x;
|
||||
}
|
||||
|
||||
void TrackBar::setStep(double x) {
|
||||
step = x;
|
||||
}
|
||||
|
||||
void TrackBar::setTrackWidth(int width) {
|
||||
trackWidth = width;
|
||||
}
|
||||
|
||||
void TrackBar::setTrackColor(glm::vec4 color) {
|
||||
trackColor = color;
|
||||
}
|
||||
|
||||
// ================================ CheckBox ==================================
|
||||
CheckBox::CheckBox(bool checked) : UINode(glm::vec2(), glm::vec2(32.0f)), checked(checked) {
|
||||
setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
|
||||
@@ -72,6 +72,9 @@ namespace gui {
|
||||
virtual void setText(std::wstring text);
|
||||
virtual std::wstring getText() const;
|
||||
|
||||
virtual glm::vec4 getPressedColor() const;
|
||||
virtual void setPressedColor(glm::vec4 color);
|
||||
|
||||
virtual Button* textSupplier(wstringsupplier supplier);
|
||||
|
||||
virtual void refresh() override;
|
||||
@@ -144,7 +147,6 @@ namespace gui {
|
||||
|
||||
class TrackBar : public UINode {
|
||||
protected:
|
||||
glm::vec4 hoverColor {0.01f, 0.02f, 0.03f, 0.5f};
|
||||
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||
doublesupplier supplier = nullptr;
|
||||
doubleconsumer consumer = nullptr;
|
||||
@@ -165,6 +167,20 @@ namespace gui {
|
||||
virtual void setConsumer(doubleconsumer consumer);
|
||||
|
||||
virtual void mouseMove(GUI*, int x, int y) override;
|
||||
|
||||
virtual double getValue() const;
|
||||
virtual double getMin() const;
|
||||
virtual double getMax() const;
|
||||
virtual double getStep() const;
|
||||
virtual int getTrackWidth() const;
|
||||
virtual glm::vec4 getTrackColor() const;
|
||||
|
||||
virtual void setValue(double);
|
||||
virtual void setMin(double);
|
||||
virtual void setMax(double);
|
||||
virtual void setStep(double);
|
||||
virtual void setTrackWidth(int);
|
||||
virtual void setTrackColor(glm::vec4);
|
||||
};
|
||||
|
||||
class CheckBox : public UINode {
|
||||
|
||||
@@ -32,7 +32,13 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
||||
node.setSize(element->attr("size").asVec2());
|
||||
}
|
||||
if (element->has("color")) {
|
||||
node.setColor(element->attr("color").asColor());
|
||||
glm::vec4 color = element->attr("color").asColor();
|
||||
glm::vec4 hoverColor = color;
|
||||
if (element->has("hover-color")) {
|
||||
hoverColor = node.getHoverColor();
|
||||
}
|
||||
node.setColor(color);
|
||||
node.setHoverColor(hoverColor);
|
||||
}
|
||||
if (element->has("margin")) {
|
||||
node.setMargin(element->attr("margin").asVec4());
|
||||
@@ -54,6 +60,9 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
||||
);
|
||||
node.setPositionFunc(supplier);
|
||||
}
|
||||
if (element->has("hover-color")) {
|
||||
node.setHoverColor(element->attr("hover-color").asColor());
|
||||
}
|
||||
std::string alignName = element->attr("align", "").getText();
|
||||
node.setAlign(align_from_string(alignName, node.getAlign()));
|
||||
}
|
||||
@@ -163,9 +172,38 @@ static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement e
|
||||
if (element->has("text-align")) {
|
||||
button->setTextAlign(align_from_string(element->attr("text-align").getText(), button->getTextAlign()));
|
||||
}
|
||||
if (element->has("pressed-color")) {
|
||||
button->setPressedColor(element->attr("pressed-color").asColor());
|
||||
}
|
||||
return button;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readCheckBox(UiXmlReader& reader, xml::xmlelement element) {
|
||||
auto text = readAndProcessInnerText(element);
|
||||
bool checked = element->attr("checked", "false").asBool();
|
||||
auto checkbox = std::make_shared<FullCheckBox>(text, glm::vec2(), checked);
|
||||
_readPanel(reader, element, *checkbox);
|
||||
|
||||
if (element->has("consumer")) {
|
||||
auto consumer = scripting::create_bool_consumer(
|
||||
reader.getEnvironment().getId(),
|
||||
element->attr("consumer").getText(),
|
||||
reader.getFilename()+".lua"
|
||||
);
|
||||
checkbox->setConsumer(consumer);
|
||||
}
|
||||
|
||||
if (element->has("supplier")) {
|
||||
auto supplier = scripting::create_bool_supplier(
|
||||
reader.getEnvironment().getId(),
|
||||
element->attr("supplier").getText(),
|
||||
reader.getFilename()+".lua"
|
||||
);
|
||||
checkbox->setSupplier(supplier);
|
||||
}
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement element) {
|
||||
auto placeholder = util::str2wstr_utf8(element->attr("placeholder", "").getText());
|
||||
auto text = readAndProcessInnerText(element);
|
||||
@@ -181,6 +219,15 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
||||
);
|
||||
textbox->setTextConsumer(consumer);
|
||||
}
|
||||
|
||||
if (element->has("supplier")) {
|
||||
auto supplier = scripting::create_wstring_supplier(
|
||||
reader.getEnvironment().getId(),
|
||||
element->attr("consumer").getText(),
|
||||
reader.getFilename()+".lua"
|
||||
);
|
||||
textbox->setTextSupplier(supplier);
|
||||
}
|
||||
return textbox;
|
||||
}
|
||||
|
||||
@@ -216,6 +263,9 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
||||
);
|
||||
bar->setSupplier(supplier);
|
||||
}
|
||||
if (element->has("track-color")) {
|
||||
bar->setTrackColor(element->attr("track-color").asColor());
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
|
||||
@@ -227,6 +277,7 @@ UiXmlReader::UiXmlReader(const scripting::Environment& env, AssetsLoader& assets
|
||||
add("panel", readPanel);
|
||||
add("button", readButton);
|
||||
add("textbox", readTextBox);
|
||||
add("chackbox", readCheckBox);
|
||||
add("trackbar", readTrackBar);
|
||||
add("container", readContainer);
|
||||
}
|
||||
|
||||
+23
-7
@@ -1,5 +1,7 @@
|
||||
#include "hud.h"
|
||||
|
||||
// TODO: refactor this garbage
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
@@ -27,6 +29,7 @@
|
||||
#include "../window/input.h"
|
||||
#include "../voxels/Chunks.h"
|
||||
#include "../voxels/Block.h"
|
||||
#include "../voxels/Chunk.h"
|
||||
#include "../world/World.h"
|
||||
#include "../world/Level.h"
|
||||
#include "../objects/Player.h"
|
||||
@@ -365,11 +368,22 @@ void Hud::update(bool visible) {
|
||||
Events::toggleCursor();
|
||||
}
|
||||
|
||||
if (blockUI) {
|
||||
voxel* vox = level->chunks->get(currentblock.x, currentblock.y, currentblock.z);
|
||||
if (vox == nullptr || vox->id != currentblockid) {
|
||||
closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& element : elements) {
|
||||
element.getNode()->setVisible(visible);
|
||||
}
|
||||
|
||||
glm::vec2 invSize = contentAccessPanel->getSize();
|
||||
contentAccessPanel->setVisible(inventoryOpen);
|
||||
contentAccessPanel->setSize(glm::vec2(invSize.x, Window::height));
|
||||
contentAccess->setMinSize(glm::vec2(1, Window::height));
|
||||
// hotbarView->setVisible(visible && !inventoryOpen);
|
||||
hotbarView->setVisible(visible);
|
||||
|
||||
for (int i = keycode::NUM_1; i <= keycode::NUM_9; i++) {
|
||||
if (Events::jpressed(i)) {
|
||||
@@ -388,10 +402,12 @@ void Hud::update(bool visible) {
|
||||
player->setChosenSlot(slot);
|
||||
}
|
||||
|
||||
for (auto& element : elements) {
|
||||
element.update(pause, inventoryOpen, player->debug);
|
||||
if (element.isRemoved()) {
|
||||
remove(element);
|
||||
if (visible) {
|
||||
for (auto& element : elements) {
|
||||
element.update(pause, inventoryOpen, player->debug);
|
||||
if (element.isRemoved()) {
|
||||
remove(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
cleanup();
|
||||
@@ -431,12 +447,12 @@ void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inven
|
||||
}
|
||||
openInventory();
|
||||
if (blockinv == nullptr) {
|
||||
Events::toggleCursor();
|
||||
abort();
|
||||
blockinv = level->inventories->createVirtual(blockUI->getSlotsCount());
|
||||
}
|
||||
level->chunks->getChunkByVoxel(block.x, block.y, block.z)->setUnsaved(true);
|
||||
blockUI->bind(blockinv, frontend, interaction.get());
|
||||
currentblock = block;
|
||||
currentblockid = level->chunks->get(block.x, block.y, block.z)->id;
|
||||
add(HudElement(hud_element_mode::inventory_bound, doc, blockUI, false));
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ class Hud {
|
||||
std::shared_ptr<InventoryView> inventoryView = nullptr;
|
||||
std::shared_ptr<InventoryView> blockUI = nullptr;
|
||||
glm::ivec3 currentblock {};
|
||||
blockid_t currentblockid = 0;
|
||||
|
||||
std::shared_ptr<gui::UINode> createDebugPanel(Engine* engine);
|
||||
std::shared_ptr<InventoryView> createContentAccess();
|
||||
|
||||
Reference in New Issue
Block a user