mirror of
https://github.com/RaindropViewer/RaindropViewer.git
synced 2026-07-31 03:22:14 +00:00
Landmark page viewer
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.Assets;
|
||||
using Raindrop;
|
||||
using Raindrop.Netcom;
|
||||
using Raindrop.ServiceLocator;
|
||||
using Raindrop.Services.Bootstrap;
|
||||
|
||||
public class LandmarkController : IDisposable
|
||||
{
|
||||
// public Image image;
|
||||
public string parcelName;
|
||||
public string simName;
|
||||
public string localCoords;
|
||||
public string parcelDesc;
|
||||
|
||||
private LandmarkView view;
|
||||
|
||||
#region shared data
|
||||
public object mutex;
|
||||
public bool DataReadyToRender; //if true, we should update the view. if it is false, we are not yet ready to update view.
|
||||
|
||||
// first layer of peeling asset data
|
||||
private InventoryLandmark landmark;
|
||||
private AssetLandmark decodedLandmark;
|
||||
private UUID localRegionID;
|
||||
private Vector3 localPosition;
|
||||
|
||||
private UUID parcelID;
|
||||
private ParcelInfo parcel;
|
||||
private bool parcelLocation = false;
|
||||
|
||||
// public AssetLandmark Landmark
|
||||
// {
|
||||
// set
|
||||
// {
|
||||
// this.modified = true;
|
||||
// this.decodedLandmark = value; //currently empty, will be filled by network request later.
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
|
||||
#region globalrefs
|
||||
private RaindropInstance instance { get { return ServiceLocator.Instance.Get<RaindropInstance>(); } }
|
||||
private RaindropNetcom netcom { get { return instance.Netcom; } }
|
||||
private GridClient client { get { return instance.Client; } }
|
||||
bool Active => instance.Client.Network.Connected;
|
||||
#endregion
|
||||
|
||||
public LandmarkController(LandmarkView landmarkView)
|
||||
{
|
||||
view = landmarkView;
|
||||
|
||||
client.Grid.RegionHandleReply += new EventHandler<RegionHandleReplyEventArgs>(Grid_RegionHandleReply);
|
||||
client.Parcels.ParcelInfoReply += new EventHandler<ParcelInfoReplyEventArgs>(Parcels_ParcelInfoReply);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Landmark_Disposed();
|
||||
}
|
||||
|
||||
void Landmark_Disposed()
|
||||
{
|
||||
client.Grid.RegionHandleReply -= new EventHandler<RegionHandleReplyEventArgs>(Grid_RegionHandleReply);
|
||||
client.Parcels.ParcelInfoReply -= new EventHandler<ParcelInfoReplyEventArgs>(Parcels_ParcelInfoReply);
|
||||
}
|
||||
|
||||
|
||||
//set the landmark to be shown
|
||||
public void SetLandmark(InventoryLandmark inventoryLandmark)
|
||||
{
|
||||
view.InitialiseView();
|
||||
this.DataReadyToRender = false;
|
||||
|
||||
RequestLandmarkFromServer(inventoryLandmark);
|
||||
// RenderLandmark
|
||||
}
|
||||
|
||||
public void SetLandmark(UUID parcelID)
|
||||
{
|
||||
this.parcelID = parcelID;
|
||||
|
||||
parcelLocation = true;
|
||||
client.Parcels.RequestParcelInfo(parcelID);
|
||||
}
|
||||
|
||||
#region Async and sync soubroutines to get the data to show to user.
|
||||
|
||||
private void RequestLandmarkFromServer(InventoryLandmark landmarkModel)
|
||||
{
|
||||
client.Assets.RequestAsset(
|
||||
landmarkModel.AssetUUID,
|
||||
landmarkModel.AssetType,
|
||||
true,
|
||||
Assets_OnAssetReceived);
|
||||
}
|
||||
|
||||
// when the landmark object is ready, we will render the textual parts to the view.
|
||||
void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
|
||||
{
|
||||
if (transfer.Success && asset.AssetType == AssetType.Landmark)
|
||||
{
|
||||
decodedLandmark = (AssetLandmark)asset;
|
||||
decodedLandmark.Decode();
|
||||
localPosition = decodedLandmark.Position;
|
||||
localRegionID = decodedLandmark.RegionID;
|
||||
// next step: Get image.
|
||||
// next step: Get Regionname.
|
||||
// next step: Get Regiondescription.
|
||||
client.Grid.RequestRegionHandle(decodedLandmark.RegionID);
|
||||
// client.Grid.RequestMapItems(decodedLandmark.RegionID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Grid_RegionHandleReply(object sender, RegionHandleReplyEventArgs e)
|
||||
{
|
||||
if (decodedLandmark == null || decodedLandmark.RegionID != e.RegionID) return;
|
||||
|
||||
parcelID = client.Parcels.RequestRemoteParcelID(decodedLandmark.Position, e.RegionHandle, e.RegionID);
|
||||
if (parcelID != UUID.Zero)
|
||||
{
|
||||
client.Parcels.RequestParcelInfo(parcelID);
|
||||
}
|
||||
}
|
||||
|
||||
// finally, we can haz datas.
|
||||
void Parcels_ParcelInfoReply(object sender, ParcelInfoReplyEventArgs e)
|
||||
{
|
||||
if (e.Parcel.ID != parcelID) return;
|
||||
|
||||
if (! Globals.isOnMainThread())
|
||||
{
|
||||
UnityMainThreadDispatcher.Instance().Enqueue(
|
||||
() => Parcels_ParcelInfoReply(sender,e)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
parcel = e.Parcel;
|
||||
|
||||
// pnlDetail.Visible = true;
|
||||
// if (parcel.SnapshotID != UUID.Zero)
|
||||
// {
|
||||
// SLImageHandler img = new SLImageHandler(instance, parcel.SnapshotID, "") {Dock = DockStyle.Fill};
|
||||
// pnlDetail.Controls.Add(img);
|
||||
// pnlDetail.Disposed += (senderx, ex) =>
|
||||
// {
|
||||
// img.Dispose();
|
||||
// };
|
||||
// img.BringToFront();
|
||||
// }
|
||||
//
|
||||
// btnTeleport.Enabled = true;
|
||||
// btnShowOnMap.Enabled = true;
|
||||
|
||||
if (parcelLocation)
|
||||
{
|
||||
localPosition = new Vector3
|
||||
{
|
||||
X = parcel.GlobalX % 256,
|
||||
Y = parcel.GlobalY % 256,
|
||||
Z = parcel.GlobalZ
|
||||
};
|
||||
}
|
||||
|
||||
// txtParcelName.Text = decodedLandmark == null
|
||||
// ? $"{parcel.Name} - {parcel.SimName} "
|
||||
// : $"{parcel.Name} - {parcel.SimName} ({(int) decodedLandmark.Position.X}, {(int) decodedLandmark.Position.Y}, {(int) decodedLandmark.Position.Z}) ";
|
||||
//
|
||||
// txtParcelDescription.Text = parcel.Description;
|
||||
//
|
||||
// view.RenderView(parcelLocation, parcelName, parcelDesc, teleportBool, showOnMapBool, );
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
private void UpdateInternalData(AssetLandmark lm)
|
||||
{
|
||||
lock (mutex)
|
||||
{
|
||||
this.parcelName = lm.RegionID.ToString();
|
||||
|
||||
DataReadyToRender = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
public class LandmarkModel
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60f91248461a4b8190dc9fe5e818d380
|
||||
timeCreated: 1641492294
|
||||
@@ -1,86 +0,0 @@
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.Assets;
|
||||
using Raindrop;
|
||||
using Raindrop.Netcom;
|
||||
using Raindrop.ServiceLocator;
|
||||
|
||||
public class LandmarkPresenter
|
||||
{
|
||||
// public Image image;
|
||||
public string parcelName;
|
||||
public string simName;
|
||||
public string localCoords;
|
||||
public string parcelDesc;
|
||||
|
||||
private LandmarkView view;
|
||||
private LandmarkModel model;
|
||||
|
||||
|
||||
#region shared data
|
||||
|
||||
public object mutex;
|
||||
|
||||
public bool modified; //if modified is true, we should update the view.
|
||||
|
||||
private InventoryLandmark landmark;
|
||||
private AssetLandmark decodedLandmark; //currently empty, will be filled by network request later.
|
||||
private UUID parcelID;
|
||||
private ParcelInfo parcel;
|
||||
private Vector3 localPosition;
|
||||
private bool parcelLocation = false;
|
||||
|
||||
// public AssetLandmark Landmark
|
||||
// {
|
||||
// set
|
||||
// {
|
||||
// this.modified = true;
|
||||
// this.decodedLandmark = value; //currently empty, will be filled by network request later.
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
|
||||
#region globalrefs
|
||||
private RaindropInstance instance { get { return ServiceLocator.Instance.Get<RaindropInstance>(); } }
|
||||
private RaindropNetcom netcom { get { return instance.Netcom; } }
|
||||
private GridClient client { get { return instance.Client; } }
|
||||
bool Active => instance.Client.Network.Connected;
|
||||
#endregion
|
||||
|
||||
|
||||
// todo: someone needs to pass the inventory landmark to me! :)
|
||||
public LandmarkPresenter(LandmarkView landmarkView, InventoryLandmark invLandmark)
|
||||
{
|
||||
view = landmarkView;
|
||||
// model = new LandmarkModel();
|
||||
|
||||
RequestLandmarkFromServer(invLandmark);
|
||||
|
||||
}
|
||||
|
||||
private void RequestLandmarkFromServer(InventoryLandmark landmarkModel)
|
||||
{
|
||||
client.Assets.RequestAsset(landmarkModel.AssetUUID, landmarkModel.AssetType, true, Assets_OnAssetReceived);
|
||||
}
|
||||
|
||||
void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
|
||||
{
|
||||
if (transfer.Success && asset.AssetType == AssetType.Landmark)
|
||||
{
|
||||
decodedLandmark = (AssetLandmark)asset;
|
||||
decodedLandmark.Decode();
|
||||
localPosition = decodedLandmark.Position;
|
||||
client.Grid.RequestRegionHandle(decodedLandmark.RegionID);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateInternalData(AssetLandmark lm)
|
||||
{
|
||||
lock (mutex)
|
||||
{
|
||||
this.parcelName = lm.RegionID.ToString();
|
||||
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,51 +1,84 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using OpenMetaverse;
|
||||
using Raindrop.Services.Bootstrap;
|
||||
using Raindrop.UI.views;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Debug = UnityEngine.Debug;
|
||||
using Logger = UnityEngine.Logger;
|
||||
using Vector3 = OpenMetaverse.Vector3;
|
||||
|
||||
//MVC style of fetch and drawing the contents.
|
||||
public class LandmarkView : MonoBehaviour
|
||||
{
|
||||
public Image image;
|
||||
private const string LoadingString = "Loading...";
|
||||
public ImageDisplayView imageView; //composite view :)
|
||||
public TMP_Text parcelName;
|
||||
public TMP_Text simName;
|
||||
public TMP_Text localCoords;
|
||||
public TMP_Text parcelDesc;
|
||||
|
||||
private LandmarkPresenter presenter;
|
||||
private LandmarkController _controller;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Debug.LogError("landmarkclasses: this class is not ready for use!");
|
||||
|
||||
//todo : specify uuid.
|
||||
var invLMrequested= new InventoryLandmark(UUID.Zero);
|
||||
LandmarkPresenter presenter = new LandmarkPresenter(this, invLMrequested);
|
||||
|
||||
LandmarkController controller = new LandmarkController(this);
|
||||
if (imageView == null)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
PollPresenterAndUpdate();
|
||||
// PollPresenterAndUpdate();
|
||||
}
|
||||
|
||||
// access the modified bool in presenter, if it is true, we need to update ourselves.
|
||||
private void PollPresenterAndUpdate()
|
||||
public void RenderView(Vector3 pos)
|
||||
{
|
||||
lock (presenter.mutex)
|
||||
if (! Globals.isOnMainThread())
|
||||
{
|
||||
if (presenter.modified == false)
|
||||
UnityMainThreadDispatcher.Instance().Enqueue(() =>
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//update ui.
|
||||
parcelName.text = presenter.parcelName;
|
||||
presenter.modified = false;
|
||||
RenderView(pos);
|
||||
} );
|
||||
}
|
||||
|
||||
RenderLocalPos(pos);
|
||||
|
||||
// lock (_controller.mutex)
|
||||
// {
|
||||
// if (_controller.data_modified == false)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// //update ui.
|
||||
// parcelName.text = _controller.parcelName;
|
||||
// _controller.data_modified = false;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private void RenderLocalPos(Vector3 pos)
|
||||
{
|
||||
this.localCoords.text = pos.ToString();
|
||||
}
|
||||
|
||||
// clear the text and image to nulls.
|
||||
public void InitialiseView()
|
||||
{
|
||||
parcelDesc.text = LoadingString;
|
||||
parcelName.text = LoadingString;
|
||||
simName.text = LoadingString;
|
||||
localCoords.text = LoadingString;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user