Aetheria/Assets/Scripts/UI/Menu/InventoryMenu.cs

193 lines
8.3 KiB
C#
Raw Normal View History

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UniRx;
using UniRx.Triggers;
using CultMath;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class InventoryMenu : MonoBehaviour
{
public InventoryPanel[] InventoryPanels;
public PropertiesPanel PropertiesPanel;
public ActionGameManager GameManager;
public RectTransform DragParent;
public ConfirmationDialog Dialog;
// public ClickCatcher Background;
private int _currentPanel = -1;
private int2 _selectedPosition;
private InventoryPanel _selectedPanel;
private ItemInstance _selectedItem;
private ItemData _selectedItemData;
private void OnEnable()
{
// Background.gameObject.SetActive(true);
// Background.OnEnter.Subscribe(enter =>
// {
// _destroyItem = true;
// });
// BackgroundExited.OnPointerExitAsObservable().Subscribe(enter =>
// {
// _destroyItem = false;
// });
var cargo = GameManager.DockingBay ?? GameManager.CurrentEntity.CargoBays.FirstOrDefault();
if (cargo!=null)
InventoryPanels[0].Display(cargo);
else InventoryPanels[0].Clear();
if(GameManager.CurrentEntity != null)
InventoryPanels[1].Display(GameManager.CurrentEntity);
else InventoryPanels[1].Clear();
}
private void OnDisable()
{
// Background.gameObject.SetActive(false);
}
void Start()
{
PropertiesPanel.GameManager = GameManager;
foreach (var panel in InventoryPanels)
{
panel.OnClickAsObservable().Subscribe(e =>
{
if (e.data is InventoryCargoEventData cargoEvent)
{
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
if(item!=null)
{
if (e.clickCount == 2)
{
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
if (otherPanel.CanDropItem(item))
{
otherPanel.DropItem(item);
// TODO: SFX: Equip
cargoEvent.CargoBay.Remove(item);
panel.RefreshCells();
otherPanel.RefreshCells();
}
// else
// TODO: SFX: Fail
}
else
{
if (_selectedPanel != null)
{
if (_selectedPanel.CellInstances.ContainsKey(_selectedPosition))
{
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
}
}
}
_selectedPanel = panel;
_selectedPosition = cargoEvent.Position;
PropertiesPanel.Inspect(item);
_selectedPanel = panel;
_selectedPosition = cargoEvent.CargoBay.Cargo[item];
_selectedItem = item;
Replace the Database Tools with the Studio and cut Unity over Cut 8b. The Unity project compiles with 0 errors in 6000.3.24f1 batchmode. Packages: manifest.json pins org.gamecult.cultlib at cultlib-unity-v1.0.57 and org.gamecult.caching.unity at caching-unity-v1.2.0, next to the 8a CultMath tag. Aetheria.Shared.Unity references GameCult.CultLib and keeps noEngineReferences. The Database Tools (Assets/Scripts/CultCache/Editor) are deleted in this commit, alongside their five ported drawers in Assets/Scripts/Editor/CultCacheDrawers.cs, each an [CultInspectorDrawer] ICultInspectorDrawer: - InspectableType: popup of the attribute type's [Union] member names, writing the string. - InspectableColor: float3 and float4 through ColorField. - InspectableAnimationCurve: float4[] and BezierCurve through CurveField. - InspectableTemperature: Kelvin, Celsius and Fahrenheit fields over one value. - InspectableSchematicShape: size and cell toggles. The old drawer also drew the item's schematic texture and tinted hull hardpoints, which need the parent document. The tagged Studio hands a drawer only the value, so those wait on the Studio exposing the open record. Unity call sites: - ActionGameManager opens the catalog through AetheriaStores; Cut 10 adds the run and player stores. - Refs resolve through ItemManager.GetData or Get(ref); orbit, planet and belt maps key by CultRecordKey; identity is compared by reference or key. - The PlayerSettings.msgpack reader and writer, which Cut 10 deletes, pass CultDocumentMessagePackSerialization.OptionsFor, since the embedded run reaches CultMath values and refs. Keyboard layouts need no resolver and keep MessagePack's defaults until Cut 10. - The input map uses the nested action to binding shape. - PropertiesPanel reads CultInspectorRangeAttribute. - NameTools loses its legacy name-file writer. - Slime compares serialized settings instead of the deleted SHA1 helper. - FieldDriver drops InspectorHeader. - .gitignore covers the test project's build output. Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6), Unity batchmode (0 errors). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:15:20 +02:00
_selectedItemData = GameManager.ItemManager.GetData(item);
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
}
// TODO: SFX: Success
}
}
}
else if (e.data is InventoryEntityEventData entityEvent)
{
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
if (item != null)
{
if (e.clickCount == 2)
{
var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0];
if (otherPanel.CanDropItem(item.EquippableItem))
{
if (!entityEvent.Entity.Active)
{
if (entityEvent.Entity.TryUnequip(item) != null)
{
otherPanel.DropItem(item.EquippableItem);
// TODO: SFX: Unequip
panel.RefreshCells();
otherPanel.RefreshCells();
}
// else
// TODO: SFX: Fail
}
// else
// TODO: SFX: Fail
}
}
else
{
if (_selectedPanel != null)
{
if (_selectedPanel.CellInstances.ContainsKey(_selectedPosition))
{
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
}
}
}
PropertiesPanel.Inspect(item);
_selectedPanel = panel;
_selectedPosition = item.Position;
_selectedItem = item.EquippableItem;
_selectedItemData = GameManager.ItemManager.GetData(item.EquippableItem);
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = _selectedItemData.Shape.Rotate(v, _selectedItem.Rotation) + _selectedPosition;
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
}
// TODO: SFX: Success
}
}
}
});
panel.OnBackgroundClick.Subscribe(data =>
{
if (GameManager.CurrentEntity == null) return; // Only show ship settings if there's a ship, duh!
PropertiesPanel.Clear();
PropertiesPanel.AddField("Shutdown Threshold",
() => GameManager.CurrentEntity.Settings.ShutdownPerformance,
f => GameManager.CurrentEntity.Settings.ShutdownPerformance = f,
0,
1);
});
}
}
void Update()
{
// if (Keyboard.current.qKey.wasPressedThisFrame && _dragItem != null)
// {
// _dragItem.Rotation = (ItemRotation) (((int) _dragItem.Rotation + 1) % 4);
// }
// if (Keyboard.current.eKey.wasPressedThisFrame && _dragItem != null)
// {
// _dragItem.Rotation = (ItemRotation) (((int) _dragItem.Rotation + 3) % 4);
// }
}
}