From 801239f39af10650306e329c03f40b4ae44726ba Mon Sep 17 00:00:00 2001 From: Axel DominatoR Date: Sat, 22 Aug 2015 21:00:16 +0100 Subject: [PATCH] Various fixes plus progress bars are now green Fixed various issues with the multiple item uses and now the progress bars are green. Also fixed a few issues with the hotbar and progressbar background --- src/xrGame/Inventory.cpp | 2 +- src/xrGame/eatable_item.cpp | 2 ++ src/xrGame/eatable_item.h | 2 +- src/xrGame/ui/UIActorMenu.h | 5 ++++ src/xrGame/ui/UIActorMenuInventory.cpp | 37 +++++++++++++++++++++++++- src/xrGame/ui/UICellItem.cpp | 8 ++++-- src/xrGame/ui/UIProgressBar.cpp | 12 ++++++--- src/xrGame/ui/UIProgressBar.h | 1 + 8 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/xrGame/Inventory.cpp b/src/xrGame/Inventory.cpp index b2b946cf9a6..c6bd7ec18f3 100644 --- a/src/xrGame/Inventory.cpp +++ b/src/xrGame/Inventory.cpp @@ -1073,7 +1073,7 @@ bool CInventory::Eat(PIItem pIItem) if (IsGameTypeSingle() && Actor()->m_inventory == this) Actor()->callback(GameObject::eUseObject)((smart_cast(pIItem))->lua_game_object()); - if (pItemToEat->CanDelete()) + if (pItemToEat->Empty()) { if (!pItemToEat->CanDelete()) return false; diff --git a/src/xrGame/eatable_item.cpp b/src/xrGame/eatable_item.cpp index 5c45ad5c6b4..83eac0469d2 100644 --- a/src/xrGame/eatable_item.cpp +++ b/src/xrGame/eatable_item.cpp @@ -15,6 +15,7 @@ #include "EntityCondition.h" #include "InventoryOwner.h" #include "UIGameCustom.h" +#include "ui/UIActorMenu.h" CEatableItem::CEatableItem() { @@ -137,6 +138,7 @@ bool CEatableItem::UseBy(CEntityAlive* entity_alive) m_iRemainingUses = 0; SetCondition((float)m_iRemainingUses / (float)m_iMaxUses); + CurrentGameUI()->GetActorMenu().RefreshConsumableCells(); return true; } diff --git a/src/xrGame/eatable_item.h b/src/xrGame/eatable_item.h index 56e7cb7a4fe..4161abf684a 100644 --- a/src/xrGame/eatable_item.h +++ b/src/xrGame/eatable_item.h @@ -33,7 +33,7 @@ class CEatableItem : public CInventoryItem virtual void OnH_A_Independent(); virtual bool UseBy(CEntityAlive* npc); virtual bool Empty() const { return m_iRemainingUses == 0; } - bool CanDelete() const { return Empty() && m_bRemoveAfterUse == true; } + bool CanDelete() const { return m_bRemoveAfterUse == true; } virtual u16 GetMaxUses() const { return m_iMaxUses; } virtual u16 GetRemainingUses() const { return m_iRemainingUses; } }; diff --git a/src/xrGame/ui/UIActorMenu.h b/src/xrGame/ui/UIActorMenu.h index cf26dad6559..e694ec6917f 100644 --- a/src/xrGame/ui/UIActorMenu.h +++ b/src/xrGame/ui/UIActorMenu.h @@ -88,6 +88,7 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback CUICellItem* m_InfoCellItem; u32 m_InfoCellItem_timer; CUICellItem* m_pCurrentCellItem; + CUICellItem* m_pCurrentConsumable; CUICellItem* m_upgrade_selected; CUIPropertiesBox* m_UIPropertiesBox; @@ -354,4 +355,8 @@ class CUIActorMenu : public CUIDialogWnd, public CUIWndCallback void UpdateConditionProgressBars(); IC UIHint* get_hint_wnd() { return m_hint_wnd; } + + CUICellItem* GetCurrentConsumable() { return m_pCurrentConsumable; }; + void SetCurrentConsumable(CUICellItem* ci) { m_pCurrentConsumable = ci; }; + void RefreshConsumableCells(); }; // class CUIActorMenu diff --git a/src/xrGame/ui/UIActorMenuInventory.cpp b/src/xrGame/ui/UIActorMenuInventory.cpp index 0d10edcd6ce..53076da504a 100644 --- a/src/xrGame/ui/UIActorMenuInventory.cpp +++ b/src/xrGame/ui/UIActorMenuInventory.cpp @@ -1129,7 +1129,12 @@ void CUIActorMenu::ProcessPropertiesBoxClicked(CUIWindow* w, void* d) case INVENTORY_TO_SLOT_ACTION: ToSlot(cell_item, true, item->BaseSlot()); break; case INVENTORY_TO_BELT_ACTION: ToBelt(cell_item, false); break; case INVENTORY_TO_BAG_ACTION: ToBag(cell_item, false); break; - case INVENTORY_EAT_ACTION: TryUseItem(cell_item); break; + + case INVENTORY_EAT_ACTION: + CurrentGameUI()->GetActorMenu().SetCurrentConsumable(cell_item); + TryUseItem(cell_item); + break; + case INVENTORY_DROP_ACTION: { void* d = m_UIPropertiesBox->GetClickedItem()->GetData(); @@ -1291,3 +1296,33 @@ void CUIActorMenu::MoveArtefactsToBag() } // for i m_pInventoryBeltList->ClearAll(true); } + +void CUIActorMenu::RefreshConsumableCells() +{ + CUICellItem* ci = GetCurrentConsumable(); + if (ci) + { + CEatableItem* eitm = smart_cast((CEatableItem*)ci->m_pData); + if (eitm) + { + Fvector2 cp = GetUICursor().GetCursorPosition(); // XXX: This is unused + CUIDragDropListEx* invlist = GetListByType(iActorBag); + + CUICellItem* parent = invlist->RemoveItem(ci, true); + const u32 c = parent->ChildsCount(); + if (c > 0) + { + while (parent->ChildsCount()) + { + CUICellItem* child = parent->PopChild(nullptr); + invlist->SetItem(child); + } + + invlist->SetItem(parent); + } + else + invlist->SetItem(parent); + } + SetCurrentConsumable(nullptr); + } +} diff --git a/src/xrGame/ui/UICellItem.cpp b/src/xrGame/ui/UICellItem.cpp index 257581016ff..5ff2a30f639 100644 --- a/src/xrGame/ui/UICellItem.cpp +++ b/src/xrGame/ui/UICellItem.cpp @@ -13,6 +13,8 @@ #include "Weapon.h" #include "CustomOutfit.h" #include "ActorHelmet.h" +#include "UIGameCustom.h" +#include "UIActorMenu.h" CUICellItem* CUICellItem::m_mouse_selected_item = NULL; @@ -145,6 +147,7 @@ bool CUICellItem::OnMouseAction(float x, float y, EUIMessages mouse_action) else if (mouse_action == WINDOW_LBUTTON_DB_CLICK) { GetMessageTarget()->SendMessage(this, DRAG_DROP_ITEM_DB_CLICK, NULL); + CurrentGameUI()->GetActorMenu().SetCurrentConsumable(this); return true; } else if (mouse_action == WINDOW_RBUTTON_DOWN) @@ -222,12 +225,13 @@ void CUICellItem::UpdateConditionProgressBar() else if (max_uses > 8) cond = (float)remaining_uses / (float)max_uses; else - { cond = (float)remaining_uses * 0.125f - 0.0625f; + + if (max_uses < 8) m_pConditionState->ShowBackground(false); - } m_pConditionState->m_bNoLerp = true; + m_pConditionState->m_bUseGradient = false; } } diff --git a/src/xrGame/ui/UIProgressBar.cpp b/src/xrGame/ui/UIProgressBar.cpp index 4139218387d..9ec276eff3b 100644 --- a/src/xrGame/ui/UIProgressBar.cpp +++ b/src/xrGame/ui/UIProgressBar.cpp @@ -10,6 +10,7 @@ CUIProgressBar::CUIProgressBar(void) m_bBackgroundPresent = false; m_bUseColor = false; + m_bUseGradient = true; m_bNoLerp = false; //Alundaio AttachChild(&m_UIBackgroundItem); @@ -60,9 +61,14 @@ void CUIProgressBar::UpdateProgressBar() return; } - Fcolor curr; - curr.lerp(m_minColor, m_middleColor, m_maxColor, fCurrentLength); - m_UIProgressItem.SetTextureColor(curr.get()); + if ( m_bUseGradient ) + { + Fcolor curr; + curr.lerp(m_minColor, m_middleColor, m_maxColor, fCurrentLength); + m_UIProgressItem.SetTextureColor(curr.get()); + } + else + m_UIProgressItem.SetTextureColor( m_maxColor.get()); } } diff --git a/src/xrGame/ui/UIProgressBar.h b/src/xrGame/ui/UIProgressBar.h index 630c139bef5..07579309571 100644 --- a/src/xrGame/ui/UIProgressBar.h +++ b/src/xrGame/ui/UIProgressBar.h @@ -32,6 +32,7 @@ class CUIProgressBar : public CUIWindow public: bool m_bUseColor; + bool m_bUseGradient; bool m_bNoLerp; //Alundaio: use only solid color with m_maxColor Fcolor m_minColor; Fcolor m_middleColor;