Various Improvements & Fixes

Map icons now have a constant size independent of zoom level
Galaxy Map now displays zone properties when clicking on a zone
Zone generator now uses half of nebula density, means smaller and more varied zones
Stations will refuse docking to entities with insufficient clearance
This commit is contained in:
Reinier Vens 2021-05-12 00:15:11 +01:00
commit 122e929214
25 changed files with 801 additions and 621 deletions

View file

@ -20,8 +20,7 @@ public class InventoryMenu : MonoBehaviour
public ActionGameManager GameManager;
public RectTransform DragParent;
public ConfirmationDialog Dialog;
public ObservablePointerEnterTrigger BackgroundEntered;
public ObservablePointerExitTrigger BackgroundExited;
// public ClickCatcher Background;
private int _currentPanel = -1;
@ -29,36 +28,37 @@ public class InventoryMenu : MonoBehaviour
private InventoryPanel _selectedPanel;
private ItemInstance _selectedItem;
private ItemData _selectedItemData;
// private List<IDisposable> _backgroundSubscriptions;
private ItemInstance _dragItem;
private Transform[] _dragCells;
private Vector2[] _dragOffsets;
private int2 _dragCellOffset;
private ItemRotation _originalRotation;
//private Shape _previousFakeOccupancy;
private Shape _originalOccupancy;
private EquippedItem _originalEquippedItem;
private InventoryPanel _originalPanel;
private InventoryPanel _dragTargetPanel;
private int2 _dragTargetPosition;
private int2 _lastDragPosition;
private bool _dragTargetValid;
private bool _destroyItem;
// private ItemInstance _dragItem;
// private Transform[] _dragCells;
// private Vector2[] _dragOffsets;
// private int2 _dragCellOffset;
// private ItemRotation _originalRotation;
// //private Shape _previousFakeOccupancy;
// private Shape _originalOccupancy;
// private EquippedItem _originalEquippedItem;
// private InventoryPanel _originalPanel;
//
// private InventoryPanel _dragTargetPanel;
// private int2 _dragTargetPosition;
// private int2 _lastDragPosition;
// private bool _dragTargetValid;
// private bool _destroyItem;
private void OnEnable()
{
AkSoundEngine.RegisterGameObj(gameObject);
BackgroundEntered.gameObject.SetActive(true);
// Background.gameObject.SetActive(true);
BackgroundEntered.OnPointerEnterAsObservable().Subscribe(enter =>
{
_destroyItem = true;
});
BackgroundExited.OnPointerExitAsObservable().Subscribe(enter =>
{
_destroyItem = false;
});
// 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);
@ -71,7 +71,7 @@ public class InventoryMenu : MonoBehaviour
private void OnDisable()
{
AkSoundEngine.UnregisterGameObj(gameObject);
BackgroundEntered.gameObject.SetActive(false);
// Background.gameObject.SetActive(false);
}
void Start()
@ -198,13 +198,13 @@ public class InventoryMenu : MonoBehaviour
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);
}
// 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);
// }
}
}

View file

@ -26,6 +26,7 @@ public class MapRenderer : MonoBehaviour
public Image InfluenceDisplay;
public float Scale;
public float2 Position;
public float IconSize = 1f/128;
private RectTransform _rect;
private RenderTexture _mapTexture;
@ -117,5 +118,7 @@ public class MapRenderer : MonoBehaviour
InfluenceCamera.transform.position = pos;
InfluenceCamera.orthographicSize = _size.y * Scale * .5f;
GameManager.ZoneRenderer.SetIconSize(IconSize * Scale);
}
}

View file

@ -1,42 +0,0 @@
/* 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.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Unity.Mathematics.math;
public class MapViewDragHandler : MonoBehaviour
{
public Camera Camera;
public float Scaling;
public ClickCatcher Background;
private Vector2 _previousPosition;
private bool _isDragging;
void Update()
{
var newPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
if (!Input.GetMouseButton(0)) _isDragging = false;
if (_isDragging) Camera.transform.position -= (Vector3) ((Vector2) newPosition - _previousPosition);
if (Background.PointerIsInside)
{
if (Input.GetMouseButtonDown(0))
{
_previousPosition = newPosition;
_isDragging = true;
}
if (abs(Input.mouseScrollDelta.y) > .01f)
{
var previousPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
Camera.orthographicSize *= 1 + Input.mouseScrollDelta.y * Scaling;
Camera.transform.position -= Camera.ScreenToWorldPoint(Input.mousePosition) - previousPosition;
}
}
}
}

View file

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

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using MessagePack;
using TMPro;
using UniRx;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
@ -41,6 +42,8 @@ public class SectorMap : MonoBehaviour
public Color PlayerLocationLabelColor;
public float PlayerLocationIconSize = 1.25f;
public Subject<SectorZone> ZoneClicked = new Subject<SectorZone>();
private SectorZone _currentPlayerLocation;
private HashSet<SectorZone> _revealedZones = new HashSet<SectorZone>();
private HashSet<(SectorZone, SectorZone)> _revealedLinks = new HashSet<(SectorZone, SectorZone)>();
@ -98,6 +101,7 @@ public class SectorMap : MonoBehaviour
if (!_revealedZones.Contains(zone))
{
var zoneInstance = ZonePrototype.Instantiate<SectorZoneUI>();
zoneInstance.Clickable.OnClick += (clickableCollider, data) => ZoneClicked.OnNext(zone);
if(zone == _currentPlayerLocation)
MarkPlayerLocation(zoneInstance);
_zoneInstances[zone] = zoneInstance;

View file

@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UniRx;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
@ -10,10 +11,11 @@ using float2 = Unity.Mathematics.float2;
public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IScrollHandler
{
public ClickRaycaster Raycaster;
public PropertiesPanel Properties;
public Canvas Canvas;
public SectorMap Map;
public ActionGameManager GameManager;
public Camera MainCamera;
public Camera SectorCamera;
public MeshRenderer SectorBackgroundRenderer;
public float ZoomSpeed;
@ -49,6 +51,61 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS
_sectorBackgroundDepth = _sectorBackgroundTransform.position.z;
_sectorCameraTransform = SectorCamera.transform;
_sectorCameraDepth = _sectorCameraTransform.position.z;
Raycaster.OnClickMiss += data =>
{
Properties.gameObject.SetActive(false);
};
Map.ZoneClicked.Subscribe(zone =>
{
Properties.gameObject.SetActive(true);
Properties.Clear();
Properties.Title.text = zone.Name;
Properties.AddProperty("Owner", () => zone.Owner?.Name ?? "None");
var otherFactions = zone.Factions
.Where(f => f.ID != zone.Owner?.ID)
.Select(f=>f.Name).ToArray();
if (otherFactions.Length > 0)
Properties.AddProperty("Factions Present", () => string.Join(", ", otherFactions));
var density = saturate(ActionGameManager.CurrentSector.Background.CloudDensity(zone.Position)/2);
var radius = GameManager.Settings.ZoneSettings.ZoneRadius.Evaluate(density);
var mass = GameManager.Settings.ZoneSettings.ZoneMass.Evaluate(density);
Properties.AddProperty("Mass", () => ActionGameManager.PlayerSettings.Format(mass));
Properties.AddProperty("Radius", () => ActionGameManager.PlayerSettings.Format(radius));
if (zone.PackedContents == null)
{
Properties.AddProperty(() => "Has not been visited");
}
else
{
var planetCount = zone.PackedContents.Planets.Count(body => body is PlanetData).ToString();
Properties.AddProperty("Planets", () => planetCount);
var beltCount = zone.PackedContents.Planets.Count(body => body is AsteroidBeltData).ToString();
Properties.AddProperty("Asteroid Belts", () => beltCount);
var giantCount = zone.PackedContents.Planets.Count(body => body is GasGiantData && !(body is SunData)).ToString();
Properties.AddProperty("Gas Giants", () => giantCount);
var starCount = zone.PackedContents.Planets.Count(body => body is SunData).ToString();
Properties.AddProperty("Stars", () => starCount);
var stationCount = zone.PackedContents.Entities
.Count(entity => ((HullData) entity.Hull.Data.Value).HullType == HullType.Ship)
.ToString();
Properties.AddProperty("Stations", () => stationCount);
var turretCount = zone.PackedContents.Entities
.Count(entity => ((HullData) entity.Hull.Data.Value).HullType == HullType.Ship)
.ToString();
Properties.AddProperty("Turrets", () => turretCount);
var shipCount = zone.PackedContents.Entities
.Count(entity => ((HullData) entity.Hull.Data.Value).HullType == HullType.Ship)
.ToString();
Properties.AddProperty("Ships", () => shipCount);
}
});
// PathAnimationButton.onClick.AddListener(() =>
// {
// Map.StartCoroutine(AnimatePath());

View file

@ -11,4 +11,5 @@ public class SectorZoneUI : MonoBehaviour
public MeshRenderer Influence;
public TextMeshPro Label;
public Transform IconContainer;
public ClickableCollider Clickable;
}