Skip to content

Commit

Permalink
Feat: added simple image retrieve UI object
Browse files Browse the repository at this point in the history
  • Loading branch information
davidejensen committed Dec 27, 2023
1 parent 2d2c3f7 commit f5d8db5
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 14 deletions.
17 changes: 16 additions & 1 deletion Explorer/Assets/DCL/Navmap/Assets/FloatingPanel.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ MonoBehaviour:
descriptionContent: {fileID: 4673463797054126884}
rectTransform: {fileID: 25544740848074249}
<CategoriesContainer>k__BackingField: {fileID: 2627153927686046327}
placeImage: {fileID: 3532656630585342090}
placeImage: {fileID: 3544030107733454522}
closeButton: {fileID: 336449712889304881}
backButton: {fileID: 846060297463590866}
jumpInButton: {fileID: 7544780555329989278}
Expand Down Expand Up @@ -4173,6 +4173,7 @@ GameObject:
- component: {fileID: 5639355638059818371}
- component: {fileID: 8281347120207082334}
- component: {fileID: 3532656630585342090}
- component: {fileID: 3544030107733454522}
m_Layer: 5
m_Name: PlaceImage
m_TagString: Untagged
Expand Down Expand Up @@ -4238,6 +4239,20 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &3544030107733454522
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7900764672589405173}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e79e296834574c5d9138852d94c8998, type: 3}
m_Name:
m_EditorClassIdentifier:
<LoadingObject>k__BackingField: {fileID: 0}
<Image>k__BackingField: {fileID: 3532656630585342090}
--- !u!1 &8312802546809659174
GameObject:
m_ObjectHideFlags: 0
Expand Down
8 changes: 6 additions & 2 deletions Explorer/Assets/DCL/Navmap/FloatingPanelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DCL.ParcelsService;
using DCL.PlacesAPIService;
using DCL.UI;
using DCL.WebRequests;
using DG.Tweening;
using System;
using System.Collections.Generic;
Expand All @@ -26,8 +27,9 @@ public class FloatingPanelController : IDisposable

private readonly Vector2 rectTransformLocalPosition = new Vector3(1702, 480);
private readonly Vector2 rectTransformLocalPositionOutside = new Vector3(2100, 480);
private readonly ImageController placeImageController;

public FloatingPanelController(FloatingPanelView view, IPlacesAPIService placesAPIService, ITeleportController teleportController)
public FloatingPanelController(FloatingPanelView view, IPlacesAPIService placesAPIService, ITeleportController teleportController, IWebRequestController webRequestController)
{
this.view = view;
this.placesAPIService = placesAPIService;
Expand All @@ -36,7 +38,7 @@ public FloatingPanelController(FloatingPanelView view, IPlacesAPIService placesA
view.closeButton.onClick.RemoveAllListeners();
view.closeButton.onClick.AddListener(HidePanel);
view.gameObject.SetActive(false);

placeImageController = new ImageController(view.placeImage, webRequestController);
categoriesDictionary = new Dictionary<string, GameObject>();

for (var i = 0; i < view.categories.Length; i++)
Expand Down Expand Up @@ -118,6 +120,7 @@ private void SetEmptyParcelInfo(Vector2Int parcel)

private void SetFloatingPanelInfo(PlacesData.PlaceInfo placeInfo)
{
placeImageController.RequestImage(placeInfo.image);
view.placeName.text = placeInfo.title;
view.placeCreator.text = $"created by <b>{placeInfo.contact_name}</b>";

Expand All @@ -128,6 +131,7 @@ private void SetFloatingPanelInfo(PlacesData.PlaceInfo placeInfo)
view.location.text = placeInfo.base_position;
view.visits.SetText("{0:0}", placeInfo.user_visits);
view.parcelsCount.SetText("{0:0}", placeInfo.Positions.Length);

SetUpVotes(placeInfo);

if (placeInfo.categories.Length == 0)
Expand Down
2 changes: 1 addition & 1 deletion Explorer/Assets/DCL/Navmap/FloatingPanelView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class FloatingPanelView : MonoBehaviour
public RectTransform CategoriesContainer { get; private set; }

[field: SerializeField]
public Image placeImage;
public ImageView placeImage;

[field: SerializeField]
public Button closeButton;
Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/Navmap/Navmap.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"GUID:006c0e0a70294dbba8a4cbcfb77e1f7d",
"GUID:9e314663ce958b746873cb22d57ede55",
"GUID:9e24947de15b9834991c9d8411ea37cf",
"GUID:fb9aef3113f3505428c3576d8c32f8c4"
"GUID:fb9aef3113f3505428c3576d8c32f8c4",
"GUID:4a12c0b1b77ec6b418a8d7bd5c925be3"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
6 changes: 4 additions & 2 deletions Explorer/Assets/DCL/Navmap/NavmapController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using DCL.ParcelsService;
using DCL.PlacesAPIService;
using DCL.UI;
using DCL.WebRequests;
using System;
using System.Collections.Generic;
using System.Threading;
Expand Down Expand Up @@ -41,15 +42,16 @@ public NavmapController(
NavmapView navmapView,
IMapRenderer mapRenderer,
IPlacesAPIService placesAPIService,
ITeleportController teleportController)
ITeleportController teleportController,
IWebRequestController webRequestController)
{
this.navmapView = navmapView;
this.mapRenderer = mapRenderer;

rectTransform = this.navmapView.transform.parent.GetComponent<RectTransform>();

zoomController = new NavmapZoomController(navmapView.zoomView);
floatingPanelController = new FloatingPanelController(navmapView.floatingPanelView, placesAPIService, teleportController);
floatingPanelController = new FloatingPanelController(navmapView.floatingPanelView, placesAPIService, teleportController, webRequestController);
filterController = new NavmapFilterController(this.navmapView.filterView);
searchBarController = new NavmapSearchBarController(navmapView.SearchBarView, navmapView.SearchBarResultPanel, placesAPIService, navmapView.floatingPanelView);
searchBarController.OnResultClicked += OnResultClicked;
Expand Down
8 changes: 6 additions & 2 deletions Explorer/Assets/DCL/PluginSystem/Global/ExplorePanelPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using DCL.ParcelsService;
using DCL.PlacesAPIService;
using DCL.Settings;
using DCL.WebRequests;
using Global.Dynamic;
using MVC;
using System.Threading;
Expand All @@ -23,6 +24,7 @@ public class ExplorePanelPlugin : IDCLGlobalPlugin<ExplorePanelPlugin.ExplorePan
private readonly IPlacesAPIService placesAPIService;
private readonly ITeleportController teleportController;
private readonly BackpackSettings backpackSettings;
private readonly IWebRequestController webRequestController;
private NavmapController navmapController;

public ExplorePanelPlugin(
Expand All @@ -31,22 +33,24 @@ public ExplorePanelPlugin(
MapRendererContainer mapRendererContainer,
IPlacesAPIService placesAPIService,
ITeleportController teleportController,
BackpackSettings backpackSettings)
BackpackSettings backpackSettings,
IWebRequestController webRequestController)
{
this.assetsProvisioner = assetsProvisioner;
this.mvcManager = mvcManager;
this.mapRendererContainer = mapRendererContainer;
this.placesAPIService = placesAPIService;
this.teleportController = teleportController;
this.backpackSettings = backpackSettings;
this.webRequestController = webRequestController;
}

public async UniTask InitializeAsync(ExplorePanelSettings settings, CancellationToken ct)
{
ExplorePanelView panelView = (await assetsProvisioner.ProvideMainAssetAsync(settings.ExplorePanelPrefab, ct: ct)).Value.GetComponent<ExplorePanelView>();
ControllerBase<ExplorePanelView, ExplorePanelParameter>.ViewFactoryMethod viewFactoryMethod = ExplorePanelController.Preallocate(panelView, null, out ExplorePanelView explorePanelView);

navmapController = new NavmapController(navmapView: explorePanelView.GetComponentInChildren<NavmapView>(), mapRendererContainer.MapRenderer, placesAPIService, teleportController);
navmapController = new NavmapController(navmapView: explorePanelView.GetComponentInChildren<NavmapView>(), mapRendererContainer.MapRenderer, placesAPIService, teleportController, webRequestController);
await navmapController.InitialiseAssetsAsync(assetsProvisioner, ct);

(ProvidedAsset<NFTColorsSO> rarityColorMappings, ProvidedAsset<NftTypeIconSO> categoryIconsMapping, ProvidedAsset<NftTypeIconSO> rarityBackgroundsMapping) = await UniTask.WhenAll(
Expand Down
93 changes: 93 additions & 0 deletions Explorer/Assets/DCL/UI/Assets/Image.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7225474628005434785
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6521834947971461802}
- component: {fileID: 3735591345964488943}
- component: {fileID: 5031392240167187892}
- component: {fileID: 6280177048631039952}
m_Layer: 5
m_Name: Image
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &6521834947971461802
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7225474628005434785}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -16, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3735591345964488943
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7225474628005434785}
m_CullTransparentMesh: 1
--- !u!114 &5031392240167187892
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7225474628005434785}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &6280177048631039952
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7225474628005434785}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1e79e296834574c5d9138852d94c8998, type: 3}
m_Name:
m_EditorClassIdentifier:
<LoadingObject>k__BackingField: {fileID: 0}
<Image>k__BackingField: {fileID: 5031392240167187892}
7 changes: 7 additions & 0 deletions Explorer/Assets/DCL/UI/Assets/Image.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Explorer/Assets/DCL/UI/Assets/PageSelector.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ RectTransform:
m_Father: {fileID: 5955730194940385775}
m_RootOrder: -2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 40.55, y: -13}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 40.55, y: 0}
m_SizeDelta: {x: 0, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2705436137430404885
Expand Down
38 changes: 38 additions & 0 deletions Explorer/Assets/DCL/UI/ImageController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using CommunicationData.URLHelpers;
using Cysharp.Threading.Tasks;
using DCL.WebRequests;
using Utility;
using System.Threading;
using UnityEngine;

namespace DCL.UI
{
public class ImageController
{
private const int PIXELS_PER_UNIT = 50;
private readonly ImageView view;
private readonly IWebRequestController webRequestController;
private CancellationTokenSource cts;

public ImageController(ImageView view, IWebRequestController webRequestController)
{
this.view = view;
this.webRequestController = webRequestController;
}

public void RequestImage(string uri)
{
cts.SafeCancelAndDispose();
cts = new CancellationTokenSource();
RequestImageAsync(uri, cts.Token).Forget();
}

private async UniTaskVoid RequestImageAsync(string uri, CancellationToken ct)
{
view.LoadingObject.SetActive(true);
Texture2D texture = (await webRequestController.GetTextureAsync(new CommonArguments(URLAddress.FromString(uri)), new GetTextureArguments(false), ct)).CreateTexture(TextureWrapMode.Clamp);
view.Image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), VectorUtilities.OneHalf, PIXELS_PER_UNIT, 0, SpriteMeshType.FullRect, Vector4.one, false);
view.LoadingObject.SetActive(false);
}
}
}
11 changes: 11 additions & 0 deletions Explorer/Assets/DCL/UI/ImageController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Explorer/Assets/DCL/UI/ImageView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using UnityEngine;
using UnityEngine.UI;

namespace DCL.UI
{
public class ImageView : MonoBehaviour
{
[field: SerializeField]
internal GameObject LoadingObject { get; private set; }

[field: SerializeField]
internal Image Image { get; private set; }
}
}
11 changes: 11 additions & 0 deletions Explorer/Assets/DCL/UI/ImageView.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Explorer/Assets/DCL/UI/UI.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"GUID:029c1c1b674aaae47a6841a0b89ad80e",
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:006c0e0a70294dbba8a4cbcfb77e1f7d",
"GUID:fa7b3fdbb04d67549916da7bd2af58ab"
"GUID:fa7b3fdbb04d67549916da7bd2af58ab",
"GUID:4a12c0b1b77ec6b418a8d7bd5c925be3",
"GUID:8322ea9340a544c59ddc56d4793eac74",
"GUID:166b65e6dfc848bb9fb075f53c293a38"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void Dispose()
staticContainer.SingletonSharedDependencies.FrameTimeBudgetProvider, staticContainer.SingletonSharedDependencies.MemoryBudgetProvider, realmData, debugBuilder, staticContainer.CacheCleaner),
new MapRendererPlugin(mapRendererContainer.MapRenderer),
new MinimapPlugin(staticContainer.AssetsProvisioner, mvcManager, mapRendererContainer, placesAPIService),
new ExplorePanelPlugin(staticContainer.AssetsProvisioner, mvcManager, mapRendererContainer, placesAPIService, parcelServiceContainer.TeleportController, dynamicSettings.BackpackSettings),
new ExplorePanelPlugin(staticContainer.AssetsProvisioner, mvcManager, mapRendererContainer, placesAPIService, parcelServiceContainer.TeleportController, dynamicSettings.BackpackSettings, staticContainer.WebRequestsContainer.WebRequestController),
new WebRequestsPlugin(staticContainer.WebRequestsContainer.AnalyticsContainer, debugBuilder),
};

Expand Down

0 comments on commit f5d8db5

Please sign in to comment.