2020-05-31 17:07:22 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using SanAndreasUnity.Behaviours;
|
2019-10-21 01:55:38 +00:00
|
|
|
|
using SanAndreasUnity.Behaviours.World;
|
2019-10-21 00:28:10 +00:00
|
|
|
|
using SanAndreasUnity.Utilities;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.UI {
|
|
|
|
|
|
|
|
|
|
public class TeleportWindow : PauseMenuWindow {
|
|
|
|
|
|
|
|
|
|
// spawn locations
|
2019-10-21 00:28:10 +00:00
|
|
|
|
private List<TransformDataStruct> _spawns = new List<TransformDataStruct>();
|
|
|
|
|
public List<TransformDataStruct> Spawns { get { return this._spawns; } }
|
|
|
|
|
private List<string> _spawnNames = new List<string>();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TeleportWindow() {
|
|
|
|
|
|
|
|
|
|
// set default parameters
|
|
|
|
|
|
|
|
|
|
this.windowName = "Teleport";
|
|
|
|
|
this.useScrollView = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnSceneChanged (SceneChangedMessage msg) {
|
|
|
|
|
|
|
|
|
|
_spawns.Clear ();
|
2019-10-21 00:28:10 +00:00
|
|
|
|
_spawnNames.Clear();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
if (!GameManager.IsInStartupScene)
|
2019-10-21 00:28:10 +00:00
|
|
|
|
FindSpawnPlacesInternal();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
this.AdjustWindowRect ();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start () {
|
|
|
|
|
|
|
|
|
|
this.RegisterButtonInPauseMenu ();
|
|
|
|
|
|
|
|
|
|
this.AdjustWindowRect ();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 01:55:38 +00:00
|
|
|
|
protected override void OnLoaderFinished()
|
|
|
|
|
{
|
|
|
|
|
base.OnLoaderFinished();
|
|
|
|
|
|
|
|
|
|
if (_spawns.Count < 1)
|
|
|
|
|
{
|
|
|
|
|
this.FindSpawnPlacesInternal();
|
|
|
|
|
this.AdjustWindowRect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
2019-10-21 00:28:10 +00:00
|
|
|
|
private void FindSpawnPlacesInternal()
|
|
|
|
|
{
|
2019-10-21 01:55:38 +00:00
|
|
|
|
_spawns.Clear();
|
|
|
|
|
_spawnNames.Clear();
|
|
|
|
|
|
|
|
|
|
// if exterior is not loaded, then use enexes from loaded interiors
|
2021-07-18 04:03:43 +00:00
|
|
|
|
if (Cell.Instance != null && ! Cell.Instance.HasMainExterior)
|
2019-10-21 01:55:38 +00:00
|
|
|
|
{
|
2019-10-23 01:46:51 +00:00
|
|
|
|
foreach(var enex in Cell.Instance.GetEnexesFromLoadedInteriors())
|
2019-10-21 01:55:38 +00:00
|
|
|
|
{
|
2021-07-18 04:03:43 +00:00
|
|
|
|
_spawns.Add(Cell.Instance.GetEnexExitTransform(enex));
|
2019-10-21 01:55:38 +00:00
|
|
|
|
_spawnNames.Add(enex.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var spawnPlaces = FindSpawnPlaces ();
|
|
|
|
|
_spawns = spawnPlaces.Select(tr => new TransformDataStruct(tr)).ToList();
|
|
|
|
|
_spawnNames = spawnPlaces.Select(tr => tr.name).ToList();
|
|
|
|
|
}
|
2019-10-21 00:28:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
public static Transform[] FindSpawnPlaces ()
|
|
|
|
|
{
|
2019-07-05 22:16:44 +00:00
|
|
|
|
var obj = GameObject.Find("Player Spawns");
|
|
|
|
|
if (obj)
|
2019-10-26 16:05:35 +00:00
|
|
|
|
return obj.transform.GetFirstLevelChildren().ToArray();
|
2020-05-31 17:07:22 +00:00
|
|
|
|
return new Transform[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void AdjustWindowRect ()
|
|
|
|
|
{
|
|
|
|
|
float width = 260;
|
|
|
|
|
float height = Mathf.Min( 0.7f * Screen.height, 10 + 25 * _spawns.Count );
|
|
|
|
|
this.windowRect = new Rect(Screen.width - width - 10, 10, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnWindowGUI ()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (null == Ped.Instance) {
|
2019-07-05 22:16:44 +00:00
|
|
|
|
GUILayout.Label ("No local ped");
|
2020-05-31 17:07:22 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-10-26 16:05:35 +00:00
|
|
|
|
for (int i = 0; i < _spawns.Count; i++)
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
|
|
|
|
var spawnLocation = _spawns [i];
|
2019-10-21 00:28:10 +00:00
|
|
|
|
|
|
|
|
|
if (GUILayout.Button (_spawnNames[i]))
|
2020-05-31 17:07:22 +00:00
|
|
|
|
{
|
2021-02-22 18:43:17 +00:00
|
|
|
|
Vector3 pos = spawnLocation.position;
|
|
|
|
|
Vector3 eulers = spawnLocation.rotation.eulerAngles;
|
2021-02-27 16:03:06 +00:00
|
|
|
|
SendCommand($"/teleport {pos.x} {pos.y} {pos.z} {eulers.y}");
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 18:43:17 +00:00
|
|
|
|
void SendCommand(string command)
|
|
|
|
|
{
|
|
|
|
|
Chat.ChatManager.SendChatMessageToAllPlayersAsLocalPlayer(command);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|