Skip to content

Commit

Permalink
implement unboxing and a scary button
Browse files Browse the repository at this point in the history
fix a half-second stutter whenever an inventory action occurs (for any player who donated or won a mapping competition, caused by the inventory schema being written to disk)
  • Loading branch information
BenLubar committed May 8, 2024
1 parent ff62851 commit 3b58777
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 44 deletions.
21 changes: 12 additions & 9 deletions reactivedrop/resource/ui/CollectionPanelInventoryUnboxChoice.res
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,22 @@
"command" "PreviousSelection"
"enabledImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_left"
"color" "224 224 224 255"
}
"mouseOverImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_left"
"color" "255 255 255 255"
}
"pressedImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_left"
"color" "255 255 255 255"
}
"disabledImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_left"
"color" "96 96 96 255"
}
}
Expand All @@ -131,22 +131,22 @@
"command" "NextSelection"
"enabledImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_right"
"color" "224 224 224 255"
}
"mouseOverImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_right"
"color" "255 255 255 255"
}
"pressedImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_right"
"color" "255 255 255 255"
}
"disabledImage"
{
"material" "vgui/TODO"
"material" "vgui/swarm/big_arrow_right"
"color" "96 96 96 255"
}
}
Expand All @@ -161,13 +161,14 @@
}
"BtnConfirm"
{
"ControlName" "CNB_Button"
"ControlName" "CNB_Button_Hold"
"fieldName" "BtnConfirm"
"xpos" "250"
"ypos" "385"
"wide" "150"
"tall" "23"
"font" "DefaultMedium"
"labelText" "#rd_unbox_strange_confirm"
"textAlignment" "center"
}
"BtnCancel"
Expand All @@ -179,6 +180,8 @@
"wide" "150"
"tall" "23"
"font" "DefaultMedium"
"labelText" "#rd_unbox_strange_cancel"
"textAlignment" "center"
"command" "CancelSelection"
}
}
1 change: 1 addition & 0 deletions src/game/client/swarm/gameui/swarm/vitemshowcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void ItemShowcase::OnThink()
case MODE_ITEM_DROP:
case MODE_ITEM_CLAIMED:
case MODE_ITEM_UPGRADED:
case MODE_ITEM_CRAFTED:
{
const ReactiveDropInventory::ItemDef_t *pDef = ReactiveDropInventory::GetItemDef( m_Queue[0]->ItemDefID );

Expand Down
62 changes: 54 additions & 8 deletions src/game/client/swarm/rd_collections_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "rd_collections.h"
#include "rd_inventory_shared.h"
#include "rd_crafting_defs.h"
#include <vgui/IInput.h>
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <vgui_controls/ImagePanel.h>
Expand All @@ -15,7 +16,8 @@
#include "asw_equipment_list.h"
#include "asw_weapon_shared.h"
#include "vgui_bitmapbutton.h"
#include "nb_button.h"
#include "nb_button_hold.h"
#include "gameui/swarm/vgenericconfirmation.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand All @@ -24,6 +26,28 @@
ConVar rd_briefing_item_details_displaytype( "rd_briefing_item_details_displaytype", "170 170 170 255" );
extern ConVar rd_equipped_medal[RD_STEAM_INVENTORY_NUM_MEDAL_SLOTS];

static SteamItemDef_t s_iDeferredCraftingRecipe = 0;
static CUtlVector<SteamItemInstanceID_t> s_DeferredCraftingIngredients;
static CUtlVector<uint32> s_DeferredCraftingQuantities;

static void DeferredCraftingConfirm()
{
if ( !s_iDeferredCraftingRecipe )
return;

ReactiveDropInventory::PerformCraftingAction( s_iDeferredCraftingRecipe, std::initializer_list<SteamItemInstanceID_t>( &s_DeferredCraftingIngredients.Head(), &s_DeferredCraftingIngredients.Tail() ), std::initializer_list<uint32>( &s_DeferredCraftingQuantities.Head(), &s_DeferredCraftingQuantities.Tail() ) );

s_iDeferredCraftingRecipe = 0;
s_DeferredCraftingIngredients.Purge();
s_DeferredCraftingQuantities.Purge();
}
static void DeferredCraftingCancel()
{
s_iDeferredCraftingRecipe = 0;
s_DeferredCraftingIngredients.Purge();
s_DeferredCraftingQuantities.Purge();
}

CRD_Collection_Tab_Inventory::CRD_Collection_Tab_Inventory( TabbedGridDetails *parent, const char *szLabel, const char *szSlot )
: BaseClass( parent, szLabel )
{
Expand Down Expand Up @@ -412,7 +436,7 @@ class CRD_Collection_Panel_Inventory_Unbox_Choice : public vgui::EditablePanel
m_pBtnNext = new CBitmapButton( this, "BtnNext", " " );
m_pBtnNext->AddActionSignalTarget( this );
m_pBtnNext->SetCommand( "NextSelection" );
m_pBtnConfirm = new CNB_Button( this, "BtnConfirm", "#rd_unbox_strange_confirm", this, "ConfirmSelection" );
m_pBtnConfirm = new CNB_Button_Hold( this, "BtnConfirm", "#rd_unbox_strange_confirm", this, "ConfirmSelection" );
m_pBtnConfirm->SetControllerButton( KEY_XBUTTON_X );
m_pBtnCancel = new CNB_Button( this, "BtnCancel", "#rd_unbox_strange_cancel", this, "CancelSelection" );
m_pBtnCancel->SetControllerButton( KEY_XBUTTON_B );
Expand Down Expand Up @@ -656,14 +680,36 @@ class CRD_Collection_Panel_Inventory_Unbox_Choice : public vgui::EditablePanel

if ( m_Warnings.Count() )
{
// "#rd_unbox_strange_warnings_title"
// "#rd_unbox_strange_warnings_desc"

DebuggerBreakIfDebugging(); // TODO!
Assert( s_iDeferredCraftingRecipe == 0 );
Assert( s_DeferredCraftingIngredients.Count() == 0 );
Assert( s_DeferredCraftingQuantities.Count() == 0 );
s_iDeferredCraftingRecipe = m_Choices[m_iChoice];
s_DeferredCraftingIngredients.Purge();
s_DeferredCraftingIngredients.AddToTail( m_pEntry->m_Details.ItemID );
s_DeferredCraftingQuantities.Purge();
s_DeferredCraftingQuantities.AddToTail( 1 );

BaseModUI::GenericConfirmation::Data_t data;
data.pWindowTitle = "#rd_unbox_strange_warnings_title";
data.pMessageText = "#rd_unbox_strange_warnings_desc";
data.bOkButtonEnabled = true;
data.bCancelButtonEnabled = true;
data.pfnOkCallback = DeferredCraftingConfirm;
data.pfnCancelCallback = DeferredCraftingCancel;

BaseModUI::CBaseModPanel::GetSingleton().OpenFrontScreen();

BaseModUI::GenericConfirmation *pConfirm = assert_cast< BaseModUI::GenericConfirmation * >( BaseModUI::CBaseModPanel::GetSingleton().OpenWindow( BaseModUI::WT_GENERICCONFIRMATION, BaseModUI::CBaseModPanel::GetSingleton().GetWindow( BaseModUI::WT_MAINMENU ) ) );
pConfirm->SetUsageData( data );
}
else
{
DebuggerBreakIfDebugging(); // TODO!
SteamItemDef_t iRecipe = m_Choices[m_iChoice];
SteamItemInstanceID_t iIngredient = m_pEntry->m_Details.ItemID;

BaseModUI::CBaseModPanel::GetSingleton().OpenFrontScreen();

ReactiveDropInventory::PerformCraftingAction( iRecipe, { iIngredient }, { 1 } );
}
}
else if ( FStrEq( command, "CancelSelection" ) )
Expand Down Expand Up @@ -773,7 +819,7 @@ class CRD_Collection_Panel_Inventory_Unbox_Choice : public vgui::EditablePanel
vgui::Panel *m_pPnlDetails;
CBitmapButton *m_pBtnPrevious;
CBitmapButton *m_pBtnNext;
CNB_Button *m_pBtnConfirm;
CNB_Button_Hold *m_pBtnConfirm;
CNB_Button *m_pBtnCancel;
CUtlVector<vgui::Label *> m_Warnings;
struct ItemIconSection_t
Expand Down
17 changes: 11 additions & 6 deletions src/game/client/swarm/vgui/nb_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CNB_Button::CNB_Button( Panel *parent, const char *panelName, const char *text,

m_hButtonFont = INVALID_FONT;
m_szControllerButton = NULL;
m_iControllerButton = KEY_NONE;
}
CNB_Button::CNB_Button( Panel *parent, const char *panelName, const wchar_t *text, Panel *pActionSignalTarget, const char *pCmd, bool bSuppressAddToFocusList )
: BaseClass( parent, panelName, text, pActionSignalTarget, pCmd )
Expand All @@ -35,6 +36,7 @@ CNB_Button::CNB_Button( Panel *parent, const char *panelName, const wchar_t *tex

m_hButtonFont = INVALID_FONT;
m_szControllerButton = NULL;
m_iControllerButton = KEY_NONE;
}

CNB_Button::~CNB_Button()
Expand Down Expand Up @@ -89,6 +91,12 @@ void CNB_Button::PaintBackground()
{
DrawRoundedBox( nBorder, nBorder, wide - nBorder * 2, tall - nBorder * 2, m_DisabledColor, m_DisabledHighlightColor );
}

if ( m_szControllerButton && g_RD_Steam_Input.GetJoystickCount() )
{
int padding = ( tall - nBorder * 2 - surface()->GetFontTall( m_hButtonFont ) ) / 2;
g_RD_Steam_Input.DrawLegacyControllerGlyph( m_szControllerButton, nBorder + padding, nBorder + padding, false, false, m_hButtonFont );
}
}

void CNB_Button::OnCursorEntered()
Expand Down Expand Up @@ -150,16 +158,12 @@ void CNB_Button::DrawRoundedBox( int x, int y, int wide, int tall, Color color,
surface()->DrawFilledRectFade( x + cornerWide, y, x + wide * 0.5f, y + tall, 0, 255, true );
surface()->DrawFilledRectFade( x + wide * 0.5f, y, x + wide - cornerWide, y + tall, 255, 0, true );
}

if ( m_szControllerButton && g_RD_Steam_Input.GetJoystickCount() )
{
int padding = ( tall - surface()->GetFontTall( m_hButtonFont ) ) / 2;
g_RD_Steam_Input.DrawLegacyControllerGlyph( m_szControllerButton, x + padding, y + padding, false, false, m_hButtonFont );
}
}

void CNB_Button::SetControllerButton( KeyCode code )
{
m_iControllerButton = code;

switch ( code )
{
case KEY_XBUTTON_A:
Expand Down Expand Up @@ -213,6 +217,7 @@ void CNB_Button::SetControllerButton( KeyCode code )
default:
Warning( "CNB_Button: Unhandled controller button code %d\n", code );
m_szControllerButton = NULL;
m_iControllerButton = KEY_NONE;
break;
}
}
13 changes: 7 additions & 6 deletions src/game/client/swarm/vgui/nb_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class CNB_Button : public vgui::Button
CNB_Button( Panel *parent, const char *panelName, const char *text, Panel *pActionSignalTarget = NULL, const char *pCmd = NULL, bool bSuppressAddToFocusList = false );
CNB_Button( Panel *parent, const char *panelName, const wchar_t *text, Panel *pActionSignalTarget = NULL, const char *pCmd = NULL, bool bSuppressAddToFocusList = false );
virtual ~CNB_Button();
virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
virtual void Paint();
virtual void PaintBackground();
virtual void OnCursorEntered();
virtual void NavigateTo();

void ApplySchemeSettings( vgui::IScheme *pScheme ) override;
void Paint() override;
void PaintBackground() override;
void OnCursorEntered() override;
void NavigateTo() override;

void DrawRoundedBox( int x, int y, int wide, int tall, Color color, Color highlightCenterColor );
void SetControllerButton( vgui::KeyCode code );
Expand All @@ -32,6 +32,7 @@ class CNB_Button : public vgui::Button

vgui::HFont m_hButtonFont;
const char *m_szControllerButton;
vgui::KeyCode m_iControllerButton;
bool m_bAddedToControllerFocus;

CPanelAnimationVar( bool, m_bAutoFocus, "autoFocus", "0" );
Expand Down
Loading

0 comments on commit 3b58777

Please sign in to comment.