reformatted hud.h, hud.cpp
This commit is contained in:
+10
-20
@@ -322,9 +322,7 @@ void Hud::drawDebug(int fps){
|
|||||||
fpsMax = max(fps, fpsMax);
|
fpsMax = max(fps, fpsMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// @brief Remove all elements marked as removed
|
||||||
* Remove all elements marked as removed
|
|
||||||
*/
|
|
||||||
void Hud::cleanup() {
|
void Hud::cleanup() {
|
||||||
auto it = std::remove_if(elements.begin(), elements.end(), [](const HudElement& e) {
|
auto it = std::remove_if(elements.begin(), elements.end(), [](const HudElement& e) {
|
||||||
return e.isRemoved();
|
return e.isRemoved();
|
||||||
@@ -414,9 +412,7 @@ void Hud::update(bool visible) {
|
|||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// @brief Show inventory on the screen and turn on inventory mode blocking movement
|
||||||
* Show inventory on the screen and turn on inventory mode blocking movement
|
|
||||||
*/
|
|
||||||
void Hud::openInventory() {
|
void Hud::openInventory() {
|
||||||
auto inventory = player->getInventory();
|
auto inventory = player->getInventory();
|
||||||
|
|
||||||
@@ -428,13 +424,11 @@ void Hud::openInventory() {
|
|||||||
add(HudElement(hud_element_mode::inventory_bound, inventoryDocument, inventoryView, false));
|
add(HudElement(hud_element_mode::inventory_bound, inventoryDocument, inventoryView, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// @brief Show player inventory + block UI
|
||||||
* Show player inventory + block UI
|
/// @param block world position of the open block
|
||||||
* @param block world position of the open block
|
/// @param doc block UI document (root element must be an InventoryView)
|
||||||
* @param doc block UI document (root element must be an InventoryView)
|
/// @param blockinv block inventory.
|
||||||
* @param blockinv block inventory.
|
/// If blockinv is nullptr a new virtual inventory will be created
|
||||||
* In case of nullptr a new virtual inventory will be created
|
|
||||||
*/
|
|
||||||
void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockinv, bool playerInventory) {
|
void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockinv, bool playerInventory) {
|
||||||
if (isInventoryOpen()) {
|
if (isInventoryOpen()) {
|
||||||
closeInventory();
|
closeInventory();
|
||||||
@@ -459,10 +453,8 @@ void Hud::openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inven
|
|||||||
add(HudElement(hud_element_mode::inventory_bound, doc, blockUI, false));
|
add(HudElement(hud_element_mode::inventory_bound, doc, blockUI, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// @brief Add element as permanent overlay
|
||||||
* Add element as permanent overlay
|
/// @param doc element layout document
|
||||||
* @param doc element layout document
|
|
||||||
*/
|
|
||||||
void Hud::openPermanent(UiDocument* doc) {
|
void Hud::openPermanent(UiDocument* doc) {
|
||||||
auto root = doc->getRoot();
|
auto root = doc->getRoot();
|
||||||
remove(root);
|
remove(root);
|
||||||
@@ -475,9 +467,7 @@ void Hud::openPermanent(UiDocument* doc) {
|
|||||||
add(HudElement(hud_element_mode::permanent, doc, doc->getRoot(), false));
|
add(HudElement(hud_element_mode::permanent, doc, doc->getRoot(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/// @brief Hide inventory and turn off inventory mode
|
||||||
* Hide inventory and turn off inventory mode
|
|
||||||
*/
|
|
||||||
void Hud::closeInventory() {
|
void Hud::closeInventory() {
|
||||||
auto level = frontend->getLevel();
|
auto level = frontend->getLevel();
|
||||||
|
|
||||||
|
|||||||
+46
-46
@@ -23,75 +23,75 @@ class UiDocument;
|
|||||||
class InventoryInteraction;
|
class InventoryInteraction;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class GUI;
|
class GUI;
|
||||||
class UINode;
|
class UINode;
|
||||||
class Panel;
|
class Panel;
|
||||||
class Container;
|
class Container;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class hud_element_mode {
|
enum class hud_element_mode {
|
||||||
// element is hidden if menu or inventory open
|
// element is hidden if menu or inventory open
|
||||||
ingame,
|
ingame,
|
||||||
// element is visible if hud is visible
|
// element is visible if hud is visible
|
||||||
permanent,
|
permanent,
|
||||||
// element is visible in inventory mode
|
// element is visible in inventory mode
|
||||||
inventory_any,
|
inventory_any,
|
||||||
// element will be removed on inventory close
|
// element will be removed on inventory close
|
||||||
inventory_bound
|
inventory_bound
|
||||||
};
|
};
|
||||||
|
|
||||||
class HudElement {
|
class HudElement {
|
||||||
hud_element_mode mode;
|
hud_element_mode mode;
|
||||||
UiDocument* document;
|
UiDocument* document;
|
||||||
std::shared_ptr<gui::UINode> node;
|
std::shared_ptr<gui::UINode> node;
|
||||||
|
|
||||||
bool debug;
|
bool debug;
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
public:
|
public:
|
||||||
HudElement(hud_element_mode mode, UiDocument* document, std::shared_ptr<gui::UINode> node, bool debug);
|
HudElement(hud_element_mode mode, UiDocument* document, std::shared_ptr<gui::UINode> node, bool debug);
|
||||||
|
|
||||||
void update(bool pause, bool inventoryOpen, bool debug);
|
void update(bool pause, bool inventoryOpen, bool debug);
|
||||||
|
|
||||||
UiDocument* getDocument() const;
|
UiDocument* getDocument() const;
|
||||||
std::shared_ptr<gui::UINode> getNode() const;
|
std::shared_ptr<gui::UINode> getNode() const;
|
||||||
|
|
||||||
void setRemoved() {
|
void setRemoved() {
|
||||||
removed = true;
|
removed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isRemoved() const {
|
bool isRemoved() const {
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Hud {
|
class Hud {
|
||||||
Engine* engine;
|
Engine* engine;
|
||||||
Assets* assets;
|
Assets* assets;
|
||||||
std::unique_ptr<Camera> uicamera;
|
std::unique_ptr<Camera> uicamera;
|
||||||
|
|
||||||
int fps = 60;
|
int fps = 60;
|
||||||
int fpsMin = 60;
|
int fpsMin = 60;
|
||||||
int fpsMax = 60;
|
int fpsMax = 60;
|
||||||
std::wstring fpsString;
|
std::wstring fpsString;
|
||||||
bool inventoryOpen = false;
|
bool inventoryOpen = false;
|
||||||
bool pause = false;
|
bool pause = false;
|
||||||
|
|
||||||
std::shared_ptr<gui::Container> contentAccessPanel;
|
std::shared_ptr<gui::Container> contentAccessPanel;
|
||||||
std::shared_ptr<InventoryView> contentAccess;
|
std::shared_ptr<InventoryView> contentAccess;
|
||||||
std::shared_ptr<InventoryView> hotbarView;
|
std::shared_ptr<InventoryView> hotbarView;
|
||||||
std::shared_ptr<gui::UINode> debugPanel;
|
std::shared_ptr<gui::UINode> debugPanel;
|
||||||
std::shared_ptr<gui::Panel> darkOverlay;
|
std::shared_ptr<gui::Panel> darkOverlay;
|
||||||
std::unique_ptr<InventoryInteraction> interaction;
|
std::unique_ptr<InventoryInteraction> interaction;
|
||||||
std::shared_ptr<SlotView> grabbedItemView;
|
std::shared_ptr<SlotView> grabbedItemView;
|
||||||
gui::GUI* gui;
|
gui::GUI* gui;
|
||||||
LevelFrontend* frontend;
|
LevelFrontend* frontend;
|
||||||
Player* player;
|
Player* player;
|
||||||
|
|
||||||
std::vector<HudElement> elements;
|
std::vector<HudElement> elements;
|
||||||
|
|
||||||
std::shared_ptr<InventoryView> inventoryView = nullptr;
|
std::shared_ptr<InventoryView> inventoryView = nullptr;
|
||||||
std::shared_ptr<InventoryView> blockUI = nullptr;
|
std::shared_ptr<InventoryView> blockUI = nullptr;
|
||||||
glm::ivec3 currentblock {};
|
glm::ivec3 currentblock {};
|
||||||
blockid_t currentblockid = 0;
|
blockid_t currentblockid = 0;
|
||||||
|
|
||||||
std::shared_ptr<gui::UINode> createDebugPanel(Engine* engine);
|
std::shared_ptr<gui::UINode> createDebugPanel(Engine* engine);
|
||||||
@@ -100,24 +100,24 @@ class Hud {
|
|||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
public:
|
public:
|
||||||
Hud(Engine* engine, LevelFrontend* frontend, Player* player);
|
Hud(Engine* engine, LevelFrontend* frontend, Player* player);
|
||||||
~Hud();
|
~Hud();
|
||||||
|
|
||||||
void update(bool hudVisible);
|
void update(bool hudVisible);
|
||||||
void draw(const GfxContext& context);
|
void draw(const GfxContext& context);
|
||||||
void drawDebug(int fps);
|
void drawDebug(int fps);
|
||||||
|
|
||||||
bool isInventoryOpen() const;
|
bool isInventoryOpen() const;
|
||||||
bool isPause() const;
|
bool isPause() const;
|
||||||
void setPause(bool pause);
|
void setPause(bool pause);
|
||||||
|
|
||||||
void openInventory();
|
void openInventory();
|
||||||
void openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockInv, bool playerInventory);
|
void openInventory(glm::ivec3 block, UiDocument* doc, std::shared_ptr<Inventory> blockInv, bool playerInventory);
|
||||||
void closeInventory();
|
void closeInventory();
|
||||||
void openPermanent(UiDocument* doc);
|
void openPermanent(UiDocument* doc);
|
||||||
|
|
||||||
void add(HudElement element);
|
void add(HudElement element);
|
||||||
void remove(HudElement& element);
|
void remove(HudElement& element);
|
||||||
void remove(std::shared_ptr<gui::UINode> node);
|
void remove(std::shared_ptr<gui::UINode> node);
|
||||||
|
|
||||||
Player* getPlayer() const;
|
Player* getPlayer() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user