//todo: use events private void TradeSuccess() { if (ShakeDown) { Buyer.Attitude += CurrentArt.Value; CurrentComment = "I knew you would understand."; } else { Buyer.Attitude++; CurrentComment = "That's a deal!"; } Player.ArtWorks.Remove(CurrentArt); SelectionWheel.DestroySaleObject(); Player.Food += CurrentOffer.GetFoodValue(); Player.Security += CurrentOffer.GetSecurityValue(); //TODO: remove items from inventory Debug.Log($"You just sold {CurrentArt} for {CurrentOffer.AsText()}!"); CurrentTradeState = TradeState.Success; OnUpdate.Invoke(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> public void UpdateSelectionWheelItemCounters() { // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } // Update each item counter in the selection wheel based off the current building queue List <AbstractionCounter> absCounter = new List <AbstractionCounter>(); absCounter = GetAmountOfEachUnits(); for (int i = 0; i < selectionWheel._WheelButtons.Count; i++) { SelectionWheelUnitRef wheelUnitRef = selectionWheel._WheelButtons[i].GetComponent <SelectionWheelUnitRef>(); if (absCounter != null) { if (absCounter.Count > 0) { // Button item has a valid abstraction reference Abstraction absRef = wheelUnitRef.AbstractRef; if (absRef != null) { for (int k = 0; k < absCounter.Count; k++) { // Button item abstraction type matches the building queue abstraction type if (absRef.GetType() == absCounter[k]._Abstraction.GetType()) { // Update button item counter wheelUnitRef.SetQueueCounter(absCounter[k]._AbsCount); break; } // Reached the end of the absCounter array if (k == absCounter.Count - 1) { // Button item abstraction counter is 0 wheelUnitRef.SetQueueCounter(0); } } } else { continue; } } else { wheelUnitRef.SetQueueCounter(0); } } } }
//------------------------------------------------- private void AttachedToHand(Hand attachedHand) { _hand = attachedHand; _selection = _hand.GetComponentInChildren <SelectionWheel>(); SetSelection(); FindBow(); }
public void Submit() { Debug.Log("Selected " + ArtWork); FindObjectOfType <TradeSystem>().SelectArt(ArtWork); SelectionWheel.CloseWheel(); Holder.gameObject.SetActive(false); }
private void TradeFailure() { Debug.Log($"{CurrentArt} not sold. Last offer: {CurrentOffer.AsText()}"); SelectionWheel.DestroySaleObject(); CurrentTradeState = TradeState.Collapse; OnUpdate.Invoke(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> void Update() { if (_Player != null) { if (_SupplyGenerators > 0) { // Keep generating supplies for the player if (_SupplyTimer < SupplyGenerator.GeneratorTickDelay / _SupplyGenerators) { _SupplyTimer += Time.deltaTime; } else { if ((_Player.SuppliesCount < _Player.MaxSupplyCount) && _SupplyGenerators >= 1) { _Player.SuppliesCount += 1; } // Reset timer _SupplyTimer = 0f; } } if (_PowerGenerators > 0) { // Keep generating power for the player if (_PowerTimer < PowerStation.GeneratorTickDelay / _PowerGenerators) { _PowerTimer += Time.deltaTime; } else { if ((_Player.PowerCount < _Player.MaxSupplyCount) && _PowerGenerators >= 1) { _Player.PowerCount += 1; } // Reset timer _PowerTimer = 0f; } } // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.UpdateButtonStates(); } }
private void Start() { TradeSystem.OnUpdate.AddListener(UpdateUI); NextDay.onClick.AddListener(Player.NextDay); Player.OnDayChange.AddListener(UpdateUI); AcceptTradeButton.onClick.AddListener(TradeSystem.AcceptOffer); DenyTradeButton.onClick.AddListener(TradeSystem.DeclineOffer); SellingArgumentButton.onClick.AddListener(SetupArgumentButtons); RumourButton.onClick.AddListener(AskForRumour); SelectArtButton.onClick.AddListener(() => SelectionWheel.OpenWheel(Player.ArtWorks)); GetOutButton.onClick.AddListener(GetOut); UpdateUI(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> private void Update() { // Update menu type if (!GameManager.Instance._IsRadialMenu) { SelectionWheel = SelectionWindow; } // Check for pause screen input UpdatePauseScreen(); UpdateTextComponents(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called when the object is "clicked on" and the selection wheel appears. /// </summary> public override void OnSelectionWheel() { base.OnSelectionWheel(); // Show building slot wheel if (_Player) { // There ISNT a building on the slot if (_BuildingOnSlot == null) { // Cast object List <Abstraction> selectables = new List <Abstraction>(); foreach (var item in Buildings) { selectables.Add(item); } // Update list on the selection wheel _Player._HUD.SelectionWheel.UpdateListWithBuildings(selectables, this); // Reset selection wheel highlight _Player._HUD.SelectionWheel.DetailedHighlightTitle.text = ""; _Player._HUD.SelectionWheel.DetailedHighlightDescriptionLong.text = ""; // Show selection wheel GameManager.Instance.SelectionWheel.SetActive(true); // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.SetDefaultAbstraction(this); selectionWheel.HideItemPurchaseInfoPanel(); _IsCurrentlySelected = true; } // There IS already a building on the slot else { _BuildingOnSlot.OnSelectionWheel(); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called when the object is "clicked on" and the selection wheel appears. /// </summary> public virtual void OnSelectionWheel() { // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> /// <param name="eventData"></param> public void OnPointerExit(PointerEventData eventData) { if (SelectionWheel != null && _ObjectRefComponent != null && _ButtonComponent != null) { // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.HideItemPurchaseInfoPanel(); } }
//****************************************************************************************************************************** // // FUNCTIONS // //****************************************************************************************************************************** /// <summary> // Called when the gameObject is created. /// </summary> private void Start() { _ReticleObject = ReticleImage.gameObject; _Gamepad = GamepadManager.Instance.GetGamepad(1); _SelectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); // Get component references _PlayerAttached = GetComponent <Player>(); _KeyboardInputManager = GetComponent <KeyboardInput>(); // Initialize center point for LookAt() function RaycastHit hit; Physics.Raycast(_PlayerAttached.PlayerCamera.transform.position, _PlayerAttached.PlayerCamera.transform.forward * 1000, out hit); _LookPoint = hit.point; IsPrimaryController = false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> private void Update() { // Update slider progress value if (SliderBar != null) { SliderBar.value = _CurrentBuildProgress; } // Update queue counter text string if (_UnitCounter > 0 && QueueCounterTextComponent != null) { QueueCounterTextComponent.gameObject.SetActive(true); QueueCounterTextComponent.text = _UnitCounter.ToString(); } else if (QueueCounterTextComponent != null) { QueueCounterTextComponent.gameObject.SetActive(false); } // PC hotkey visibility if (_Player == null) { _Player = GameManager.Instance.Players[0]; } if (_Player != null && PCHotkeyObject != null) { // Set active based on whether the keyboard is the primary controller or not PCHotkeyObject.SetActive(_Player._KeyboardInputManager.IsPrimaryController); } // PC hotkey input for this button if (Input.GetKeyDown(PCShortcutKey)) { // Check whether the button should be interactable or not Button button = GetComponent <Button>(); Player player = GameManager.Instance.Players[0]; bool unlock = player.Level >= AbstractRef.CostTechLevel; bool purchasable = player.SuppliesCount >= AbstractRef.CostSupplies && player.PowerCount >= AbstractRef.CostPower && (player.MaxPopulation - player.PopulationCount) >= AbstractRef.CostPopulation; button.interactable = unlock && purchasable; // 'Buy' the item if the button is interactable if (button.IsInteractable()) { button.onClick.Invoke(); } // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.UpdateButtonStates(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called when the object is "clicked on" and the selection wheel appears. /// </summary> public override void OnSelectionWheel() { base.OnSelectionWheel(); // Show the building's options if its active in the world if (_ObjectState == WorldObjectStates.Active) { // Show building slot wheel if (_Player && Selectables.Count > 0) { // Update list then display on screen _Player._HUD.SelectionWheel.UpdateListWithBuildables(Selectables, AttachedBuildingSlot); // Get reference to the recycle building option if (Selectables[5] != null) { _RecycleOption = Selectables[5].GetComponent <RecycleBuilding>(); } // Update radial wheel building queue item counters if (_BuildingQueueUI != null) { _BuildingQueueUI.UpdateSelectionWheelItemCounters(); } // Show selection wheel if (ShowSelectionGUI) { GameManager.Instance.SelectionWheel.SetActive(true); } // Update center panels SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.SetDefaultAbstraction(this); selectionWheel.HideItemPurchaseInfoPanel(); } _IsCurrentlySelected = true; } // Show a wheel with recycle only as the selection (so you can cancel building the world object) else if (_ObjectState == WorldObjectStates.Building || _ObjectState == WorldObjectStates.InQueue) { if (_Player) { List <Abstraction> wheelOptions = new List <Abstraction>(); for (int i = 0; i < 10; i++) { // Recycle option if (i == 5) { if (_RecycleOption == null) { _RecycleOption = ObjectPooling.Spawn(GameManager.Instance.RecycleBuilding).GetComponent <RecycleBuilding>(); } _RecycleOption.SetBuildingToRecycle(this); _RecycleOption.SetToBeDestroyed(true); wheelOptions.Add(_RecycleOption); } // Empty option else { wheelOptions.Add(null); } } // Update list then display on screen _Player._HUD.SelectionWheel.UpdateListWithBuildables(wheelOptions, AttachedBuildingSlot); // Show selection wheel if (ShowSelectionGUI) { GameManager.Instance.SelectionWheel.SetActive(true); } // Update center panels SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.SetDefaultAbstraction(this); selectionWheel.HideItemPurchaseInfoPanel(); } _IsCurrentlySelected = true; } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> protected override void Update() { base.Update(); // Force the building to skip the deployable state and go straight to being active in the world if (_ObjectState == WorldObjectStates.Deployable) { _ObjectState = WorldObjectStates.Active; OnActiveState(); } // Update building queue if (_BuildingQueue != null) { if (_BuildingQueue.Count > 0) { // Check if current building is complete _BuildingQueue[0]._ObjectState = WorldObjectStates.Building; if (_BuildingQueue[0].GetCurrentBuildTimeRemaining() <= 0f) { // Play "on selectable built" particle effect if neccessary if (EffectPlayedOnBuiltSelectable != null) { // Assign internal effect & play _SelectableBuiltEffect = ObjectPooling.Spawn(EffectPlayedOnBuiltSelectable.gameObject, BuiltSelectableEffectPosition.position, transform.rotation).GetComponent <ParticleSystem>(); _SelectableBuiltEffect.Play(); // Despawn particle effect when it has finished its cycle ************************************************************************************************************* float duration = _SelectableBuiltEffect.duration + _SelectableBuiltEffect.startLifetime; StartCoroutine(ParticleDespawn(_SelectableBuiltEffect, duration)); } // Remove from queue _BuildingQueue.RemoveAt(0); // Start building next item if (_BuildingQueue.Count > 0) { _BuildingQueue[0].StartBuildingObject(AttachedBuildingSlot); _IsBuildingSomething = true; } else { _IsBuildingSomething = false; } // Update building queue UI _BuildingQueueUI.UpdateQueueItemList(); } // Currently building something else { _IsBuildingSomething = true; _BuildingStarted = false; // Play "on building selectable" particle effect if neccessary if (EffectPlayedWhenBuildingSelectable != null && _SelectableBuildingEffect == null) { // Assign internal effect & play _SelectableBuildingEffect = ObjectPooling.Spawn(EffectPlayedWhenBuildingSelectable.gameObject, BuiltSelectableEffectPosition.position, transform.rotation).GetComponent <ParticleSystem>(); _SelectableBuildingEffect.Play(); // Despawn particle effect when it has finished its cycle ************************************************************************************************************* float duration = _BuildingQueue[0].BuildingTime; StartCoroutine(ParticleDespawn(_SelectableBuildingEffect, duration)); } if (_SelectableBuildingEffect != null) { // Building particle is complete so null the reference (so next time its used - it repools a new instance) if (!_SelectableBuildingEffect.isPlaying) { _SelectableBuildingEffect = null; } } // Update radial wheel building queue item counters if (_BuildingQueueUI != null) { // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } // Only update the selection wheel item counters if the UI widget is currently being displayed if (selectionWheel.gameObject.activeInHierarchy) { _BuildingQueueUI.UpdateSelectionWheelItemCounters(); selectionWheel.UpdateLogoSliders(_BuildingQueue[0]); } } } } else { _BuildingStarted = false; } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> /// <param name="eventdata"></param> public void OnPointerEnter(PointerEventData eventdata) { if (SelectionWheel != null && _ObjectRefComponent != null && _ButtonComponent != null) { // Update the highlight text in the selection wheel if (_ObjectRefComponent.AbstractRef != null) { // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.ShowItemPurchaseInfoPanel(); // Detail window SelectionWheel.DetailedHighlightTitle.text = _ObjectRefComponent.AbstractRef.ObjectName.ToUpper(); SelectionWheel.DetailedHighlightDescriptionShort.text = _ObjectRefComponent.AbstractRef.ObjectDescriptionShort.ToUpper(); SelectionWheel.DetailedHighlightDescriptionLong.text = _ObjectRefComponent.AbstractRef.ObjectDescriptionLong; // Center panel SelectionWheel.CenterHighlightTitle.text = _ObjectRefComponent.AbstractRef.ObjectName; SelectionWheel.CenterTechLevelText.text = _ObjectRefComponent.AbstractRef.CostTechLevel.ToString(); SelectionWheel.CenterSupplyText.text = _ObjectRefComponent.AbstractRef.CostSupplies.ToString(); SelectionWheel.CenterPowerText.text = _ObjectRefComponent.AbstractRef.CostPower.ToString(); SelectionWheel.CenterPopulationText.text = _ObjectRefComponent.AbstractRef.CostPopulation.ToString(); Player player = GameManager.Instance.Players[0]; SelectionWheelUnitRef unitRef = GetComponent <SelectionWheelUnitRef>(); Abstraction item = unitRef.AbstractRef; bool unlock = player.Level >= item.CostTechLevel; bool purchasable = player.SuppliesCount >= item.CostSupplies && player.PowerCount >= item.CostPower && (player.MaxPopulation - player.PopulationCount) >= item.CostPopulation; // Update selection marker colours if (selectionWheel.SelectionMarkerImage) { if (!unlock) { selectionWheel.SelectionMarkerImage.color = Color.red; } if (!purchasable) { selectionWheel.SelectionMarkerImage.color = Color.red; } else if (unlock) { selectionWheel.SelectionMarkerImage.color = Color.green; } else { selectionWheel.SelectionMarkerImage.color = Color.grey; } } // Update cost texts colour based on state /// Tech level if (player.Level >= item.CostTechLevel) { selectionWheel.CenterTechLevelText.color = Color.black; } else { selectionWheel.CenterTechLevelText.color = Color.red; } /// Population if ((player.MaxPopulation - player.PopulationCount) >= item.CostPopulation) { selectionWheel.CenterPopulationText.color = Color.black; } else { selectionWheel.CenterPopulationText.color = Color.red; } /// Supplies if (player.SuppliesCount >= item.CostSupplies) { selectionWheel.CenterSupplyText.color = Color.black; } else { selectionWheel.CenterSupplyText.color = Color.red; } /// Power if (player.PowerCount >= item.CostPower) { selectionWheel.CenterPowerText.color = Color.black; } else { selectionWheel.CenterPowerText.color = Color.red; } // Play hover button sound SoundManager.Instance.PlaySound("SFX/_SFX_Back_Alt", 1f, 1f, false); } else { // Get selection wheel reference SelectionWheel selectionWheel = null; if (GameManager.Instance._IsRadialMenu) { selectionWheel = GameManager.Instance.SelectionWheel.GetComponentInChildren <SelectionWheel>(); } else { selectionWheel = GameManager.Instance.selectionWindow.GetComponentInChildren <SelectionWheel>(); } selectionWheel.ShowItemPurchaseInfoPanel(); // Detail window SelectionWheel.DetailedHighlightTitle.text = SelectionWheel.GetBuildingSlotInstigator().ObjectName.ToUpper(); SelectionWheel.DetailedHighlightDescriptionShort.text = SelectionWheel.GetBuildingSlotInstigator().ObjectDescriptionShort.ToUpper(); SelectionWheel.DetailedHighlightDescriptionLong.text = SelectionWheel.GetBuildingSlotInstigator().ObjectDescriptionLong; // Center panel SelectionWheel.CenterHighlightTitle.text = SelectionWheel.GetBuildingSlotInstigator().ObjectName; SelectionWheel.CenterTechLevelText.text = "1"; SelectionWheel.CenterSupplyText.text = "0"; SelectionWheel.CenterPowerText.text = "0"; SelectionWheel.CenterPopulationText.text = "0"; // Update selection marker colour selectionWheel.SelectionMarkerImage.color = Color.grey; } } }