Skip to content

Commit

Permalink
Added support for the Added/Removed money text
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon committed Apr 26, 2021
1 parent 4ed0dfb commit 6a0c244
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
44 changes: 33 additions & 11 deletions PlayerCompanion/Companion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ public class Companion : Script
private static int nextWeaponUpdate = 0;
private static int nextWeaponSave = 0;

internal static readonly ScaledText moneyText = new ScaledText(PointF.Empty, "$0", 0.65f, GTA.UI.Font.Pricedown)
internal static readonly ScaledText moneyTotal = new ScaledText(PointF.Empty, "$0", 0.65f, GTA.UI.Font.Pricedown)
{
Alignment = Alignment.Right,
Outline = true
};
internal static readonly ScaledText moneyChange = new ScaledText(PointF.Empty, "$0", 0.5f, GTA.UI.Font.Pricedown)
{
Alignment = Alignment.Right,
Outline = true
};
internal static int drawUntil = 0;

internal static readonly ObjectPool pool = new ObjectPool();
internal static readonly InventoryMenu menu = new InventoryMenu();
Expand Down Expand Up @@ -113,7 +119,7 @@ public Companion()
Inventories.ItemAdded += Inventories_ItemAdded;
Inventories.ItemRemoved += Inventories_ItemRemoved;
// And set the money text
moneyText.Text = $"${Wallet.Money}";
moneyTotal.Text = $"${Wallet.Money}";
}

#endregion
Expand All @@ -140,21 +146,37 @@ private void Companion_Tick(object sender, EventArgs e)
menu.Visible = !menu.Visible;
}

// if the notification feed is paused and the user has the character wheel button pressed
// Draw the current money that the user has
if (Function.Call<bool>(Hash.THEFEED_IS_PAUSED) && Game.IsControlPressed(Control.CharacterWheel))
// Hide the vanilla Money text
Hud.HideComponentThisFrame(HudComponent.Cash);
Hud.HideComponentThisFrame(HudComponent.CashChange);
Hud.HideComponentThisFrame(HudComponent.WantedStars);
Function.Call(Hash.DISPLAY_CASH, false);

bool switchOpen = Function.Call<bool>(Hash.THEFEED_IS_PAUSED) && Game.IsControlPressed(Control.CharacterWheel);
// If the player is pressing alt, draw the total money
if (switchOpen)
{
Hud.HideComponentThisFrame(HudComponent.Cash);
Hud.HideComponentThisFrame(HudComponent.CashChange);
Hud.HideComponentThisFrame(HudComponent.WantedStars);
Function.Call(Hash.DISPLAY_CASH, false);
Screen.SetElementAlignment(GFXAlignment.Right, GFXAlignment.Top);
PointF position = Screen.GetRealPosition(0, 0);
Screen.ResetElementAlignment();

moneyTotal.Position = position;
moneyTotal.Draw();
}
// If the player has received or got money removed
if (drawUntil >= Game.GameTime)
{
Screen.SetElementAlignment(GFXAlignment.Right, GFXAlignment.Top);
PointF position = Screen.GetRealPosition(0, 0);
Screen.ResetElementAlignment();

moneyText.Position = position;
moneyText.Draw();
if (switchOpen)
{
position.Y += 40;
}

moneyChange.Position = position;
moneyChange.Draw();
}

// If the Player Ped Model has been changed, make the required updates
Expand Down
11 changes: 9 additions & 2 deletions PlayerCompanion/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;

namespace PlayerCompanion
Expand Down Expand Up @@ -53,6 +54,14 @@ public int this[Model model]
throw new ArgumentOutOfRangeException(nameof(value), "Money can't be under Zero.");
}

int difference = value - this[model];
bool positive = difference > 0;
string sign = positive ? "+" : "-";
Companion.moneyChange.Text = $"{sign}${Math.Abs(difference)}";
Companion.moneyChange.Color = positive ? Color.LightGreen : Color.Red;
Companion.drawUntil = Game.GameTime + 5000;
Companion.moneyTotal.Text = $"${value}";

if (model == PedHash.Michael || model == PedHash.Franklin || model == PedHash.Franklin)
{
Game.Player.Money = value;
Expand All @@ -62,8 +71,6 @@ public int this[Model model]
moneyValues[model] = value;
Save();
}

Companion.moneyText.Text = $"${value}";
}
}

Expand Down

0 comments on commit 6a0c244

Please sign in to comment.