From 13708ba2bf9bb212adab2a06db7e9fff157d1d0e Mon Sep 17 00:00:00 2001 From: alexiscatnip Date: Sun, 6 Feb 2022 13:17:18 +0800 Subject: [PATCH] Landmark page viewer --- .../UI/map/Landmarks/LandmarkController.cs | 189 ++++++++++++++++++ ...ter.cs.meta => LandmarkController.cs.meta} | 0 .../UI/map/Landmarks/LandmarkModel.cs | 5 - .../UI/map/Landmarks/LandmarkModel.cs.meta | 3 - .../UI/map/Landmarks/LandmarkPresenter.cs | 86 -------- .../Raindrop/UI/map/Landmarks/LandmarkView.cs | 69 +++++-- 6 files changed, 240 insertions(+), 112 deletions(-) create mode 100644 Assets/Raindrop/UI/map/Landmarks/LandmarkController.cs rename Assets/Raindrop/UI/map/Landmarks/{LandmarkPresenter.cs.meta => LandmarkController.cs.meta} (100%) delete mode 100644 Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs delete mode 100644 Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs.meta delete mode 100644 Assets/Raindrop/UI/map/Landmarks/LandmarkPresenter.cs diff --git a/Assets/Raindrop/UI/map/Landmarks/LandmarkController.cs b/Assets/Raindrop/UI/map/Landmarks/LandmarkController.cs new file mode 100644 index 0000000..0b0444e --- /dev/null +++ b/Assets/Raindrop/UI/map/Landmarks/LandmarkController.cs @@ -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(); } } + 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(Grid_RegionHandleReply); + client.Parcels.ParcelInfoReply += new EventHandler(Parcels_ParcelInfoReply); + } + + public void Dispose() + { + Landmark_Disposed(); + } + + void Landmark_Disposed() + { + client.Grid.RegionHandleReply -= new EventHandler(Grid_RegionHandleReply); + client.Parcels.ParcelInfoReply -= new EventHandler(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; + } + } + +} \ No newline at end of file diff --git a/Assets/Raindrop/UI/map/Landmarks/LandmarkPresenter.cs.meta b/Assets/Raindrop/UI/map/Landmarks/LandmarkController.cs.meta similarity index 100% rename from Assets/Raindrop/UI/map/Landmarks/LandmarkPresenter.cs.meta rename to Assets/Raindrop/UI/map/Landmarks/LandmarkController.cs.meta diff --git a/Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs b/Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs deleted file mode 100644 index 9adb18c..0000000 --- a/Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs +++ /dev/null @@ -1,5 +0,0 @@ -public class LandmarkModel -{ - - -} \ No newline at end of file diff --git a/Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs.meta b/Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs.meta deleted file mode 100644 index 2b8eeab..0000000 --- a/Assets/Raindrop/UI/map/Landmarks/LandmarkModel.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 60f91248461a4b8190dc9fe5e818d380 -timeCreated: 1641492294 \ No newline at end of file diff --git a/Assets/Raindrop/UI/map/Landmarks/LandmarkPresenter.cs b/Assets/Raindrop/UI/map/Landmarks/LandmarkPresenter.cs deleted file mode 100644 index f4808b4..0000000 --- a/Assets/Raindrop/UI/map/Landmarks/LandmarkPresenter.cs +++ /dev/null @@ -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(); } } - 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; - } - } - -} \ No newline at end of file diff --git a/Assets/Raindrop/UI/map/Landmarks/LandmarkView.cs b/Assets/Raindrop/UI/map/Landmarks/LandmarkView.cs index ff04882..da7351a 100644 --- a/Assets/Raindrop/UI/map/Landmarks/LandmarkView.cs +++ b/Assets/Raindrop/UI/map/Landmarks/LandmarkView.cs @@ -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; } } \ No newline at end of file