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