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