Add Alot of stuff, Computer, repairStation, Whole game, Many things!

This commit is contained in:
2024-11-18 06:31:28 +01:00
parent 19b7964f83
commit a2091c3cf2
430 changed files with 55285 additions and 715 deletions

View File

@@ -0,0 +1,8 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class BankruptScreenController : MonoBehaviour {
public void Restart() {
SceneManager.LoadScene("MainMenu");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6c6cc9cdd84fd440aecd149413b6c97
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +1,6 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<ui:Template name="SellEntry" src="project://database/Assets/HUD/ComputerScreen/SellEntry.uxml?fileID=9197481963319205126&amp;guid=21f89b660ed43af43ae41053197365d0&amp;type=3#SellEntry" />
<ui:VisualElement style="flex-grow: 1; background-color: rgb(255, 255, 255); width: 75%; align-self: center; margin-top: 50px; margin-bottom: 50px; flex-direction: row;">
<ui:VisualElement name="Doeze" style="flex-grow: 1; background-color: rgb(255, 255, 255); width: 75%; align-self: center; margin-top: 50px; margin-bottom: 50px; flex-direction: row;">
<ui:Instance template="SellEntry" name="SellEntry" />
<ui:Instance template="SellEntry" name="SellEntry" />
<ui:Instance template="SellEntry" name="SellEntry" />

View File

@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;
public class ComputerScreenController : MonoBehaviour {
private UIDocument _uiDocument;
private void OnEnable() {
_uiDocument = GetComponent<UIDocument>();
var root = _uiDocument.rootVisualElement;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20f14f6fae9591d42ba3d72a6cdf91b1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,6 +2,7 @@
<ui:VisualElement name="VisualElement" style="flex-grow: 1; width: initial; margin-top: 30px; margin-right: 30px; margin-bottom: 30px; margin-left: 30px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px;">
<ui:Label tabindex="-1" text="ITEMNAME" parse-escape-sequences="true" display-tooltip-when-elided="true" name="ItemName" style="align-self: auto; -unity-text-align: upper-center; font-size: 70%; margin-top: 15px; margin-right: 15px; margin-bottom: 15px; margin-left: 15px;" />
<ui:VisualElement name="ItemImage" style="flex-grow: 1; width: auto; height: auto; background-image: url(&quot;project://database/Assets/HUD/ComputerScreen/prototype.png?fileID=2800000&amp;guid=ad0f7eac80567534ab59a2864d336793&amp;type=3#prototype&quot;); -unity-background-scale-mode: scale-to-fit;" />
<ui:Label tabindex="-1" text="Price: 2 barkie" parse-escape-sequences="true" display-tooltip-when-elided="true" name="PriceLabel" style="align-items: center; align-self: auto; -unity-text-align: upper-center; font-size: 43px;" />
<ui:Button text="Buy" parse-escape-sequences="true" display-tooltip-when-elided="true" name="BuyButton" style="margin-top: 50px; margin-bottom: 50px; padding-bottom: 20px; padding-top: 20px; margin-right: 25px; margin-left: 25px; font-size: 54px;" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,32 @@
using TMPro;
using UnityEngine;
public class DayEndHUDController : MonoBehaviour {
[SerializeField] private TextMeshProUGUI _gainsText;
[SerializeField] private TextMeshProUGUI _rentText;
[SerializeField] private TextMeshProUGUI _profitText;
[SerializeField] private TextMeshProUGUI _buttonText;
public void DayEnd(float gains, float rent, float profit) {
_gainsText.text = "Gains: " + gains + "$";
_rentText.text = "Rent: " + rent + "$";
_profitText.text = "Profit: " + profit + "$";
//Check if the user is bankrupt
if (GameController.Instance.Money < 0) {
_buttonText.text = "Game Over";
}
else {
_buttonText.text = "Next Day";
}
}
public void ConfirmEnd() {
GameController.Instance.Reset();
if (GameController.Instance.Money < 0) {
GameController.GameOver(GameController.LooseCondition.Bankrupt);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2f75c50d62e583241b94570f8ec67be8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

95
Assets/HUD/HUDManager.cs Normal file
View File

@@ -0,0 +1,95 @@
using UnityEngine;
public class HUDManager : MonoBehaviour {
public static HUDManager Instance { get; private set; }
[SerializeField] private GameObject _computerHUD;
[SerializeField] private GameObject _sellScreenHUD;
[SerializeField] private GameObject _miniGameHud;
[SerializeField] private GameObject _dayEndHUD;
[SerializeField] private GameObject _repairHUD;
private GameObject _currentHUD;
public bool IsUiOpen => _currentHUD != null;
private void Awake() {
if (Instance != null) {
Debug.LogError("What? 2 HudManagers crazy!!!");
}
Instance = this;
}
private void Update() {
CheckClose();
}
public void ShowComputerHUD() {
ShowHUD(_computerHUD);
}
public void ShowSellScreenHUD(SellCounter counter) {
ShowHUD(_sellScreenHUD);
}
public void ShowDayEndHUD() {
ShowHUD(_dayEndHUD);
}
private void ShowHUD(GameObject hud) {
if (_currentHUD != null) {
_currentHUD.SetActive(false);
}
_currentHUD = hud;
_currentHUD.SetActive(true);
}
public void HideCurrentHUD() {
if (_currentHUD != null) {
_currentHUD.SetActive(false);
_currentHUD = null;
}
}
private void CheckClose() {
if (!Input.GetKeyDown(KeyCode.Escape)) return;
if (_currentHUD == null) return;
HideCurrentHUD();
}
public void SellItem(SellCounter counter, Object sellingObject) {
Debug.Log(_sellScreenHUD.GetComponent<SellScreenController>());
this.ShowSellScreenHUD(counter);
_sellScreenHUD.GetComponent<SellScreenController>().SetItem(counter, sellingObject);
}
public void BuyItem(ComputerBehaviour computerBehaviour, ObjectSO objectSo, bool isBroken) {
this.ShowMinigameHUD();
this._miniGameHud.GetComponent<MinigameScreenController>().BuyItem(computerBehaviour, objectSo, isBroken);
}
private void ShowMinigameHUD() {
ShowHUD(_miniGameHud);
}
public DayEndHUDController GetDayEndController() {
return _dayEndHUD.GetComponent<DayEndHUDController>();
}
public void UpdateItem(ObjectSO objectToSell, bool isBroken) {
this._miniGameHud.GetComponent<MinigameScreenController>().UpdateItem(objectToSell, isBroken);
}
public void ShowRepairHUD() {
ShowHUD(_repairHUD);
}
public void SetRepairHudItem(RepairStationBehaviour repairStationBehaviour, Object @object, float timeToFix,
float costToFix) {
_repairHUD.GetComponent<RepairHudController>().SetObject(repairStationBehaviour, @object, timeToFix, costToFix);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91564f962996cde4ea12c2bdf6bb28f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3,9 +3,13 @@
<ui:VisualElement name="VisualElement" style="flex-grow: 1; width: 75%; align-self: center; margin-right: 0; margin-left: 0; padding-top: 0; padding-bottom: 0; background-color: rgb(255, 255, 255); padding-right: 0; padding-left: 0; height: auto; cursor: initial; margin-top: 50px; margin-bottom: 50px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); border-top-width: 10px; border-right-width: 10px; border-bottom-width: 10px; border-left-width: 10px;">
<ui:Label tabindex="-1" text="ITEMNAME" parse-escape-sequences="true" display-tooltip-when-elided="true" name="ItemName" style="font-size: 93px; height: auto; width: auto; -unity-text-align: upper-center; margin-top: 30px; justify-content: flex-start;" />
<ui:VisualElement style="flex-grow: 1; flex-direction: row; -unity-text-align: upper-center; align-items: center; justify-content: center; align-self: auto;">
<ui:Label tabindex="-1" text="Paid Price:" parse-escape-sequences="true" display-tooltip-when-elided="true" style="font-size: 50px; height: auto; width: auto; -unity-text-align: middle-center; margin-top: 0; justify-content: flex-start; white-space: nowrap;" />
<ui:Label tabindex="-1" text="Avg selling price: " parse-escape-sequences="true" display-tooltip-when-elided="true" style="font-size: 50px; height: auto; width: auto; -unity-text-align: middle-center; margin-top: 0; justify-content: flex-start; white-space: nowrap;" />
<ui:Label tabindex="-1" text="100 Barkie" parse-escape-sequences="true" display-tooltip-when-elided="true" name="PriceLabel" style="font-size: 50px;" />
</ui:VisualElement>
<ui:VisualElement style="flex-grow: 1; flex-direction: row; -unity-text-align: upper-center; align-items: center; justify-content: center; align-self: auto;">
<ui:Label tabindex="-1" text="You paid: " parse-escape-sequences="true" display-tooltip-when-elided="true" style="font-size: 50px; height: auto; width: auto; -unity-text-align: middle-center; margin-top: 0; justify-content: flex-start; white-space: nowrap;" />
<ui:Label tabindex="-1" text="100 Barkie" parse-escape-sequences="true" display-tooltip-when-elided="true" name="YouPaid" style="font-size: 50px;" />
</ui:VisualElement>
<ui:TextField picking-mode="Ignore" label="Your Price" value="20" name="YourPriceInputfield" password="false" keyboard-type="DecimalPad" style="flex-direction: column; margin-right: 150px; margin-left: 150px; font-size: 48px; -unity-text-align: upper-center; margin-top: 100px; align-self: auto;" />
<ui:Button text="Place for Sale" parse-escape-sequences="true" display-tooltip-when-elided="true" name="SellButton" style="margin-right: 150px; margin-left: 150px; padding-bottom: 50px; padding-top: 50px; margin-top: 105px; -unity-text-align: middle-center; justify-content: flex-start; align-items: stretch; align-self: auto; font-size: 72px; margin-bottom: 105px;" />
</ui:VisualElement>

View File

@@ -1,7 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using Button = UnityEngine.UIElements.Button;
@@ -10,41 +7,57 @@ public class SellScreenController : MonoBehaviour {
private UIDocument _document;
private Label _itemNameLabel;
private Label _avgPriceLabel;
private Label _paidPriceLabel;
private TextField _YourPriceInputfield;
private TextField _yourPriceInputfield;
private SellCounter _counter;
private Object _sellingObject;
//Becase we set the gameobject to active false, we need to use Awake
private void Awake() {
//Because we set the gameobject to active false, we need to use OnEnable
private void OnEnable() {
_document = GetComponent<UIDocument>();
_itemNameLabel = _document.rootVisualElement.Q<Label>("ItemName");
_document.rootVisualElement.Q<Button>("SellButton").clicked += SellItem;
_paidPriceLabel = _document.rootVisualElement.Q<Label>("PriceLabel");
_YourPriceInputfield = _document.rootVisualElement.Q<TextField>("YourPrice");
_avgPriceLabel = _document.rootVisualElement.Q<Label>("PriceLabel");
_paidPriceLabel = _document.rootVisualElement.Q<Label>("YouPaid");
_yourPriceInputfield = _document.rootVisualElement.Q<TextField>("YourPriceInputfield");
if (_itemNameLabel == null) {
Debug.LogError("Item name not found");
}
}
//on sleep
private void OnDisable() {
// _document.rootVisualElement.Q<Button>("SellButton").clicked -= SellItem;
_counter = null;
_sellingObject = null;
_itemNameLabel.text = "";
_paidPriceLabel.text = "";
_avgPriceLabel.text = "";
_yourPriceInputfield.value = "";
}
//TODO: ask how to do this, since the gameobjec that renders the ui is not active
public void SetItem(SellCounter counter, Object @object) {
_counter = counter;
_sellingObject = @object;
_paidPriceLabel.text = @object.ObjectSo.basePrice.ToString();
_paidPriceLabel.text = @object.PaidPrice.ToString();
_avgPriceLabel.text = @object.ObjectSo.basePrice.ToString();
_itemNameLabel.text = @object.ObjectSo.objectName;
}
public void SellItem() {
_counter.ConfirmSell(_sellingObject);
HUDManager.Instance.HideCurrentHUD();
//Sell the item
//Trigger an event that the item was sold
private void SellItem() {
Debug.Log("Selling: " + _itemNameLabel.text);
Debug.Log("Selling for: " + _yourPriceInputfield.text);
_counter.ConfirmSell(_sellingObject, float.Parse(_yourPriceInputfield.text));
HUDManager.Instance.HideCurrentHUD();
}
}

View File

@@ -0,0 +1,23 @@
using TMPro;
using UnityEngine;
using Slider = UnityEngine.UI.Slider;
public class MainHUDController : MonoBehaviour {
[SerializeField] private TextMeshProUGUI _moneyText;
[SerializeField] private TextMeshProUGUI _timeText;
[SerializeField] private Slider _charismaSlider;
public void SetMoneyText(float money) {
_moneyText.text = money + "$";
}
public void SetTime(int hour) {
_timeText.text = "Current Time: " + hour.ToString() + ":00";
}
public void SetCharisma(int charisma) {
//map 0-100 to 0-1
_charismaSlider.value = charisma / 100f;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6cbc0ae6227299a40ab875242b8f8307
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using UnityEngine;
public class MainMenuController : MonoBehaviour {
public void StartGame() {
// Load the game scene
UnityEngine.SceneManagement.SceneManager.LoadScene("Main");
}
public void QuitGame() {
// Quit the game
Application.Quit();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 753db37796583c54090ffda93c3ad74b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,192 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Random = UnityEngine.Random;
public class MinigameScreenController : MonoBehaviour {
[SerializeField] private Button _raiseButton;
[SerializeField] private Slider _currentBetSlider;
[SerializeField] private TextMeshProUGUI _currentBetText;
[SerializeField] private List<TextMeshProUGUI> _otherBidders;
[SerializeField] private List<string> _otherBiddersNames;
[SerializeField] private TextMeshProUGUI _currentItemLabel;
[SerializeField] private TextMeshProUGUI _basePriceLabel;
[SerializeField] private TextMeshProUGUI _buyInPriceLabel;
[SerializeField] private TextMeshProUGUI _brokenLabel;
[SerializeField] private float _buyInPrice = 5; //The price it costs to buy in to the auction
[SerializeField] private float _raiseSpeed = 10;
private bool _isRunning = false;
private bool _didRun = false;
private float _currentBet = 0;
private float _maxBet = 50;
private const float MinBet = 0;
[SerializeField] private ObjectSO _currentObject;
private bool _isBroken = false;
private readonly List<float> _otherBiddersPrices = new List<float>();
//This is the computer that the player is interacting with
private ComputerBehaviour _computerBehaviour;
private void Start() {
_currentBetSlider.minValue = MinBet;
_maxBet = _currentObject.basePrice * 2;
_currentBetSlider.maxValue = _maxBet;
_buyInPriceLabel.text = _buyInPrice.ToString() + "$";
foreach (TextMeshProUGUI textMeshProUGUI in _otherBidders) {
textMeshProUGUI.text = "0$";
}
_currentBetText.text = _currentBet.ToString() + "$";
}
private void OnEnable() {
_raiseButton.onClick.AddListener(StartRaise);
}
private void OnDisable() {
_raiseButton.onClick.RemoveListener(StartRaise);
_computerBehaviour = null;
}
private void StartRaise() {
if (_didRun == false) {
if (_isRunning == false) {
GameController.Instance.Money -= _buyInPrice;
_isRunning = true;
StartCoroutine(RaiseBet());
}
else {
_isRunning = false;
StopCoroutine(RaiseBet());
StopRaise();
Debug.Log("Current bet: " + _currentBet);
}
}
else {
Debug.Log("already ran for this item");
}
}
private void StopRaise() {
_isRunning = false;
//Calculate the other bidders
//check if ur the highest bidder
//if not, check if the other bidders are higher than the current bet
_didRun = true;
foreach (var textMeshProUGUI in _otherBidders) {
float basePrice = _currentObject.basePrice;
if (_isBroken) {
basePrice *= 0.5f;
}
float randomPrice = Random.Range(-12.0f, -2.0f);
randomPrice = Mathf.Round(randomPrice * 100) / 100;
float finalPrice = basePrice + randomPrice;
finalPrice = Mathf.Round(finalPrice * 100) / 100;
finalPrice = Mathf.Max(finalPrice, 0);
_otherBiddersPrices.Add(finalPrice);
textMeshProUGUI.text = finalPrice.ToString() + "$";
}
//Check if the player is the highest bidder
bool playerIsHighest = true;
foreach(var price in _otherBiddersPrices) {
if (price > _currentBet) {
playerIsHighest = false;
}
}
if (playerIsHighest) {
Debug.Log("Player is the highest bidder");
_currentBetText.color = Color.green;
GameController.Instance.Money += _buyInPrice;
_computerBehaviour.ConfirmBuy(_currentObject, _currentBet, _isBroken);
SoundFXController.Instance.PlayItemBoughtFX();
}
else {
Debug.Log("Player is not the highest bidder");
_currentBetText.color = Color.red;
}
}
public void Reset() {
_didRun = false;
_currentBet = 0;
_currentBetText.color = Color.white;
_currentBetText.text = _currentBet.ToString() + "$";
_currentBetSlider.value = _currentBet;
foreach (var textMeshProUGUI in _otherBidders) {
textMeshProUGUI.text = "0$";
}
_otherBiddersPrices.Clear();
}
private IEnumerator RaiseBet() {
while (_isRunning) {
//Round to 2 decimals
_currentBet += _raiseSpeed * Time.deltaTime;
_currentBet = Mathf.Round(_currentBet * 100) / 100;
_currentBetSlider.value = _currentBet;
_currentBetText.text = _currentBet.ToString() + "$";
if (_currentBet >= _maxBet) {
StopRaise();
}
yield return null;
}
}
public void BuyItem(ComputerBehaviour computerBehaviour, ObjectSO objectSo, bool isBroken) {
this.UpdateItem(objectSo, isBroken);
_computerBehaviour = computerBehaviour;
}
public void UpdateItem(ObjectSO objectToSell, bool isBroken) {
_currentObject = objectToSell;
Reset();
float actualBasePrice = objectToSell.basePrice;
_brokenLabel.text = isBroken ? "Broken" : "Not Broken";
_isBroken = isBroken;
if (isBroken) {
actualBasePrice *= 0.5f;
_maxBet = actualBasePrice * 2;
}
_currentItemLabel.text = objectToSell.objectName;
float playerMoney = GameController.Instance.Money;
_maxBet = Mathf.Min(_maxBet, playerMoney);
_maxBet = objectToSell.basePrice * 2;
_currentBetSlider.maxValue = _maxBet;
//Here we lower the price if the item is broken
_currentBetSlider.maxValue = _maxBet;
_basePriceLabel.text = actualBasePrice.ToString() + "$";
_basePriceLabel.color = isBroken ? Color.red : Color.black;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4729fcd4b5f563f4986ece77d16c7f0f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: