Skip to content

Commit

Permalink
Various fixes plus progress bars are now green
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AxelDominatoR authored and Xottab-DUTY committed Dec 16, 2017
1 parent 218dacf commit 801239f
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ bool CInventory::Eat(PIItem pIItem)
if (IsGameTypeSingle() && Actor()->m_inventory == this)
Actor()->callback(GameObject::eUseObject)((smart_cast<CGameObject*>(pIItem))->lua_game_object());

if (pItemToEat->CanDelete())
if (pItemToEat->Empty())
{
if (!pItemToEat->CanDelete())
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/eatable_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "EntityCondition.h"
#include "InventoryOwner.h"
#include "UIGameCustom.h"
#include "ui/UIActorMenu.h"

CEatableItem::CEatableItem()
{
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/xrGame/eatable_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};
5 changes: 5 additions & 0 deletions src/xrGame/ui/UIActorMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
37 changes: 36 additions & 1 deletion src/xrGame/ui/UIActorMenuInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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*>((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);
}
}
8 changes: 6 additions & 2 deletions src/xrGame/ui/UICellItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/xrGame/ui/UIProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CUIProgressBar::CUIProgressBar(void)

m_bBackgroundPresent = false;
m_bUseColor = false;
m_bUseGradient = true;
m_bNoLerp = false; //Alundaio

AttachChild(&m_UIBackgroundItem);
Expand Down Expand Up @@ -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());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/xrGame/ui/UIProgressBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 801239f

Please sign in to comment.