Added interior marker / textlabel repositioning when changing enter / exit position
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using reallife_gamemode.Model;
|
||||
using GTANetworkAPI;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,6 +10,11 @@ namespace reallife_gamemode.Server.Managers
|
||||
{
|
||||
public class InteriorManager
|
||||
{
|
||||
public static Dictionary<int, NetHandle> _interiorEnterTextLabels = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitTextLabels = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorEnterMarkers = new Dictionary<int, NetHandle>();
|
||||
public static Dictionary<int, NetHandle> _interiorExitMarkers = new Dictionary<int, NetHandle>();
|
||||
|
||||
public static Interior GetInteriorByName(string name, DatabaseContext dbContext = null)
|
||||
{
|
||||
if(dbContext == null)
|
||||
@@ -23,5 +29,51 @@ namespace reallife_gamemode.Server.Managers
|
||||
return dbContext.Interiors.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadInteriors()
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
foreach (Interior interior in dbContext.Interiors)
|
||||
{
|
||||
TextLabel enT = GetInteriorEnterTextLabel(interior);
|
||||
TextLabel exT = GetInteriorExitTextLabel(interior);
|
||||
Marker enM = GetInteriorEnterMarker(interior);
|
||||
Marker exM = GetInteriorExitMarkers(interior);
|
||||
|
||||
if (enT != null) enT.Delete();
|
||||
if (exT != null) exT.Delete();
|
||||
if (enM != null) enM.Delete();
|
||||
if (exM != null) exM.Delete();
|
||||
if (interior.EnterPosition != null)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("enterposition not null");
|
||||
_interiorEnterTextLabels[interior.Id] = NAPI.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Eingang", interior.EnterPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorEnterMarkers[interior.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.EnterPosition.Subtract(new Vector3(0, 0, 1.5)), new Vector3(), new Vector3(), 1.0f, new Color(255, 255, 255));
|
||||
}
|
||||
|
||||
if(interior.ExitPosition != null)
|
||||
{
|
||||
NAPI.Util.ConsoleOutput("exitposition not null");
|
||||
_interiorExitTextLabels[interior.Id] = NAPI.TextLabel.CreateTextLabel("~y~" + interior.Name + "\n~s~Ausgang", interior.ExitPosition, 10f, 1f, 0, new Color(255, 255, 255));
|
||||
_interiorExitMarkers[interior.Id] = NAPI.Marker.CreateMarker(MarkerType.VerticalCylinder, interior.ExitPosition.Subtract(new Vector3(0, 0, 1.5)), new Vector3(), new Vector3(), 1.0f, new Color(255, 255, 255));
|
||||
}
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteInterior(Interior interior)
|
||||
{
|
||||
_interiorEnterTextLabels.Remove(interior.Id);
|
||||
_interiorExitTextLabels.Remove(interior.Id);
|
||||
_interiorEnterMarkers.Remove(interior.Id);
|
||||
_interiorExitMarkers.Remove(interior.Id);
|
||||
}
|
||||
|
||||
public static TextLabel GetInteriorEnterTextLabel(Interior interior) => NAPI.Pools.GetAllTextLabels().Find(t => t.Handle.Value == _interiorEnterTextLabels.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static TextLabel GetInteriorExitTextLabel(Interior interior) => NAPI.Pools.GetAllTextLabels().Find(t => t.Handle.Value == _interiorExitTextLabels.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static Marker GetInteriorEnterMarker(Interior interior) => NAPI.Pools.GetAllMarkers().Find(t => t.Handle.Value == _interiorEnterMarkers.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
public static Marker GetInteriorExitMarkers(Interior interior) => NAPI.Pools.GetAllMarkers().Find(t => t.Handle.Value == _interiorExitMarkers.FirstOrDefault(x => x.Key == interior.Id).Value.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user