| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using UnityEngine; |
| | 4 | | using Object = UnityEngine.Object; |
| | 5 | |
|
| | 6 | | namespace DCL.Builder |
| | 7 | | { |
| | 8 | | internal class SectionSceneGeneralSettingsController : SectionBase, ISelectSceneListener, ISectionUpdateSceneDataReq |
| | 9 | | { |
| | 10 | | public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionSceneGeneralSettingsView"; |
| | 11 | |
|
| | 12 | | internal const string PERMISSION_MOVE_PLAYER = "ALLOW_TO_MOVE_PLAYER_INSIDE_SCENE"; |
| | 13 | | internal const string PERMISSION_TRIGGER_EMOTES = "ALLOW_TO_TRIGGER_AVATAR_EMOTE"; |
| | 14 | |
|
| | 15 | | private ISceneData sceneData; |
| | 16 | |
|
| 3 | 17 | | private readonly SceneDataUpdatePayload sceneDataUpdatePayload = new SceneDataUpdatePayload(); |
| | 18 | | private readonly SectionSceneGeneralSettingsView view; |
| | 19 | |
|
| | 20 | | public event Action<string, SceneDataUpdatePayload> OnRequestUpdateSceneData; |
| | 21 | |
|
| 0 | 22 | | public SectionSceneGeneralSettingsController() : this( |
| | 23 | | Object.Instantiate(Resources.Load<SectionSceneGeneralSettingsView>(VIEW_PREFAB_PATH)) |
| 0 | 24 | | ) { } |
| | 25 | |
|
| 3 | 26 | | public SectionSceneGeneralSettingsController(SectionSceneGeneralSettingsView view) |
| | 27 | | { |
| 3 | 28 | | this.view = view; |
| 3 | 29 | | view.OnApplyChanges += OnApplyChanges; |
| 3 | 30 | | } |
| | 31 | |
|
| | 32 | | public override void Dispose() |
| | 33 | | { |
| 3 | 34 | | view.OnApplyChanges -= OnApplyChanges; |
| 3 | 35 | | Object.Destroy(view.gameObject); |
| 3 | 36 | | } |
| | 37 | |
|
| 0 | 38 | | public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); } |
| | 39 | |
|
| | 40 | | public void SetSceneData(ISceneData sceneData) |
| | 41 | | { |
| 3 | 42 | | this.sceneData = sceneData; |
| | 43 | |
|
| 3 | 44 | | view.SetName(sceneData.name); |
| 3 | 45 | | view.SetDescription(sceneData.description); |
| 3 | 46 | | view.SetConfigurationActive(sceneData.isDeployed); |
| 3 | 47 | | view.SetPermissionsActive(sceneData.isDeployed); |
| | 48 | |
|
| 3 | 49 | | if (sceneData.isDeployed) |
| | 50 | | { |
| 2 | 51 | | view.SetAllowMovePlayer(sceneData.requiredPermissions != null && sceneData.requiredPermissions.Contains( |
| 2 | 52 | | view.SetAllowTriggerEmotes(sceneData.requiredPermissions != null && sceneData.requiredPermissions.Contai |
| 2 | 53 | | view.SetAllowVoiceChat(sceneData.allowVoiceChat); |
| 2 | 54 | | view.SetMatureContent(sceneData.isMatureContent); |
| | 55 | | } |
| 3 | 56 | | } |
| | 57 | |
|
| 0 | 58 | | protected override void OnShow() { view.SetActive(true); } |
| | 59 | |
|
| 0 | 60 | | protected override void OnHide() { view.SetActive(false); } |
| 0 | 61 | | void ISelectSceneListener.OnSelectScene(ISceneCardView sceneCardView) { SetSceneData(sceneCardView.SceneData); } |
| | 62 | |
|
| | 63 | | void OnApplyChanges() |
| | 64 | | { |
| 0 | 65 | | sceneDataUpdatePayload.name = view.GetName(); |
| 0 | 66 | | sceneDataUpdatePayload.description = view.GetDescription(); |
| 0 | 67 | | sceneDataUpdatePayload.allowVoiceChat = view.GetAllowVoiceChat(); |
| 0 | 68 | | sceneDataUpdatePayload.isMatureContent = view.GetMatureContent(); |
| | 69 | |
|
| 0 | 70 | | string[] permissions = null; |
| 0 | 71 | | if (view.GetAllowMovePlayer() && view.GetAllowTriggerEmotes()) |
| | 72 | | { |
| 0 | 73 | | permissions = new [] { PERMISSION_MOVE_PLAYER, PERMISSION_TRIGGER_EMOTES }; |
| 0 | 74 | | } |
| 0 | 75 | | else if (view.GetAllowMovePlayer()) |
| | 76 | | { |
| 0 | 77 | | permissions = new [] { PERMISSION_MOVE_PLAYER }; |
| 0 | 78 | | } |
| 0 | 79 | | else if (view.GetAllowTriggerEmotes()) |
| | 80 | | { |
| 0 | 81 | | permissions = new [] { PERMISSION_TRIGGER_EMOTES }; |
| | 82 | | } |
| 0 | 83 | | sceneDataUpdatePayload.requiredPermissions = permissions; |
| 0 | 84 | | OnRequestUpdateSceneData?.Invoke(sceneData.id, sceneDataUpdatePayload); |
| 0 | 85 | | } |
| | 86 | | } |
| | 87 | | } |