diff --git a/Assets/Scripts/Common b/Assets/Scripts/Common deleted file mode 160000 index df6e2fe..0000000 --- a/Assets/Scripts/Common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit df6e2fe0699e4c1347d1bbddb4e3a44fc60a8aa8 diff --git a/Assets/Scripts/Common/SceneParams.cs b/Assets/Scripts/Common/SceneParams.cs new file mode 100644 index 0000000..295d156 --- /dev/null +++ b/Assets/Scripts/Common/SceneParams.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +class SceneParams +{ + static private SceneParams _instance; + static public SceneParams Instance + { + get + { + if (_instance == null) + { + _instance = new SceneParams(); + } + return _instance; + } + } + + public class CameraSettings + { + private bool isBlockMove = true; + private bool isBlockZoom = true; + + // Запретить переход + public bool IsBlockMove { + get => isBlockMove; + set + { + if (Instance.IsDataHistoryLoadged) + isBlockMove = value; + } + } + public bool IsBlockZoom { + get => isBlockZoom; + set + { + if (Instance.IsDataHistoryLoaded) + isBlockZoom = value; + } + } + + public Transform DefaultTransform = null; + public bool IsStartPos { get; set; } = true; + } + + public class SpawnMovePoint + { + private bool isSpawnMTEPoint = false; + private bool isSpawnRTLSPoint = false; + + public bool IsSpawnMTEPoint { get => isSpawnMTEPoint; set => isSpawnMTEPoint = value; } + public bool IsSpawnRTLSPoint { get => isSpawnRTLSPoint; set => isSpawnRTLSPoint = value; } + } + + public class Person + { + private Vector3 startPosition; + + public Vector3 StartPosition { get => startPosition; set => startPosition = value; } + } + + public CameraSettings cameraSettings = new CameraSettings(); + public SpawnMovePoint spawnMovePoint = new SpawnMovePoint(); + public Person person = new Person(); + + public bool IsDataHistoryLoaded { get; set; } = false; +} diff --git a/Assets/UI.meta b/Assets/UI.meta new file mode 100644 index 0000000..f7401c5 --- /dev/null +++ b/Assets/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: aee62a1cbad12f040afd0542e625c849 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker.meta b/Assets/UI/DatePicker.meta new file mode 100644 index 0000000..3b47a11 --- /dev/null +++ b/Assets/UI/DatePicker.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f0eb457bbed30d14ba2f845dc53612bc +folderAsset: yes +timeCreated: 1467636598 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/Animation.meta b/Assets/UI/DatePicker/Animation.meta new file mode 100644 index 0000000..38f3a26 --- /dev/null +++ b/Assets/UI/DatePicker/Animation.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 3467a7c36069e414f9a7fb67503aaf21 +folderAsset: yes +timeCreated: 1469019442 +licenseType: Store +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/Animation/DatePickerAnimationController.controller b/Assets/UI/DatePicker/Animation/DatePickerAnimationController.controller new file mode 100644 index 0000000..c8abaa0 --- /dev/null +++ b/Assets/UI/DatePicker/Animation/DatePickerAnimationController.controller @@ -0,0 +1,265 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!91 &9100000 +AnimatorController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: DatePickerAnimationController + serializedVersion: 5 + m_AnimatorParameters: [] + m_AnimatorLayers: + - serializedVersion: 5 + m_Name: Base Layer + m_StateMachine: {fileID: 110777036} + m_Mask: {fileID: 0} + m_Motions: [] + m_Behaviours: [] + m_BlendingMode: 0 + m_SyncedLayerIndex: -1 + m_DefaultWeight: 0 + m_IKPass: 0 + m_SyncedLayerAffectsTiming: 0 + m_Controller: {fileID: 9100000} +--- !u!1102 &110207658 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Show_Slide_Below + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 3e29f803e4198334b90aacf11d1a41ac, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &110209270 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Show_Slide_Above + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 3e29f803e4198334b90aacf11d1a41ac, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &110212962 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Default + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 0} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &110231856 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: SlideIn_Left + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: a1fa32b1afb362844897299b7a0f3437, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &110232760 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Hide_Slide_Above + m_Speed: -1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 3e29f803e4198334b90aacf11d1a41ac, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &110236750 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Hide_Slide_Below + m_Speed: -1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 3e29f803e4198334b90aacf11d1a41ac, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &110251916 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: SlideDown + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 3e29f803e4198334b90aacf11d1a41ac, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1102 &110281700 +AnimatorState: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: SlideIn_Right + m_Speed: -1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 7400000, guid: 3fd038a8db8f02246b50a68bbb66ad1c, type: 2} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: +--- !u!1107 &110777036 +AnimatorStateMachine: + serializedVersion: 5 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Base Layer + m_ChildStates: + - serializedVersion: 1 + m_State: {fileID: 110212962} + m_Position: {x: 216, y: 732, z: 0} + - serializedVersion: 1 + m_State: {fileID: 110231856} + m_Position: {x: 48, y: -48, z: 0} + - serializedVersion: 1 + m_State: {fileID: 110281700} + m_Position: {x: 348, y: -48, z: 0} + - serializedVersion: 1 + m_State: {fileID: 110251916} + m_Position: {x: 383, y: 17, z: 0} + - serializedVersion: 1 + m_State: {fileID: 110207658} + m_Position: {x: 60, y: 492, z: 0} + - serializedVersion: 1 + m_State: {fileID: 110236750} + m_Position: {x: 60, y: 540, z: 0} + - serializedVersion: 1 + m_State: {fileID: 110209270} + m_Position: {x: 408, y: 492, z: 0} + - serializedVersion: 1 + m_State: {fileID: 110232760} + m_Position: {x: 408, y: 540, z: 0} + m_ChildStateMachines: [] + m_AnyStateTransitions: [] + m_EntryTransitions: [] + m_StateMachineTransitions: {} + m_StateMachineBehaviours: [] + m_AnyStatePosition: {x: 228, y: -144, z: 0} + m_EntryPosition: {x: 240, y: 648, z: 0} + m_ExitPosition: {x: 800, y: 120, z: 0} + m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} + m_DefaultState: {fileID: 110212962} diff --git a/Assets/UI/DatePicker/Animation/DatePickerAnimationController.controller.meta b/Assets/UI/DatePicker/Animation/DatePickerAnimationController.controller.meta new file mode 100644 index 0000000..2044208 --- /dev/null +++ b/Assets/UI/DatePicker/Animation/DatePickerAnimationController.controller.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7007f7b85352a5c41bc151217c657528 +timeCreated: 1469020952 +licenseType: Store +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/Animation/Slide_Below.anim b/Assets/UI/DatePicker/Animation/Slide_Below.anim new file mode 100644 index 0000000..5e5c29e --- /dev/null +++ b/Assets/UI/DatePicker/Animation/Slide_Below.anim @@ -0,0 +1,232 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!74 &7400000 +AnimationClip: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Slide_Below + serializedVersion: 6 + m_Legacy: 0 + m_Compressed: 0 + m_UseHighQualityCurve: 1 + m_RotationCurves: [] + m_CompressedRotationCurves: [] + m_EulerCurves: [] + m_PositionCurves: [] + m_ScaleCurves: + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: {x: 1, y: 0, z: 1} + inSlope: {x: 0, y: 4, z: 0} + outSlope: {x: 0, y: 4, z: 0} + tangentMode: 0 + weightedMode: 0 + inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} + outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} + - serializedVersion: 3 + time: 0.25 + value: {x: 1, y: 1, z: 1} + inSlope: {x: 0, y: 4, z: 0} + outSlope: {x: 0, y: 4, z: 0} + tangentMode: 0 + weightedMode: 0 + inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} + outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334} + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + path: + m_FloatCurves: + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 4 + outSlope: 4 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.25 + value: 1 + inSlope: 4 + outSlope: 4 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_Alpha + path: + classID: 225 + script: {fileID: 0} + m_PPtrCurves: [] + m_SampleRate: 120 + m_WrapMode: 0 + m_Bounds: + m_Center: {x: 0, y: 0, z: 0} + m_Extent: {x: 0, y: 0, z: 0} + m_ClipBindingConstant: + genericBindings: + - serializedVersion: 2 + path: 0 + attribute: 3 + script: {fileID: 0} + typeID: 4 + customType: 0 + isPPtrCurve: 0 + - serializedVersion: 2 + path: 0 + attribute: 1574349066 + script: {fileID: 0} + typeID: 225 + customType: 0 + isPPtrCurve: 0 + pptrCurveMapping: [] + m_AnimationClipSettings: + serializedVersion: 2 + m_AdditiveReferencePoseClip: {fileID: 0} + m_AdditiveReferencePoseTime: 0 + m_StartTime: 0 + m_StopTime: 0.25 + m_OrientationOffsetY: 0 + m_Level: 0 + m_CycleOffset: 0 + m_HasAdditiveReferencePose: 0 + m_LoopTime: 0 + m_LoopBlend: 0 + m_LoopBlendOrientation: 0 + m_LoopBlendPositionY: 0 + m_LoopBlendPositionXZ: 0 + m_KeepOriginalOrientation: 0 + m_KeepOriginalPositionY: 1 + m_KeepOriginalPositionXZ: 0 + m_HeightFromFeet: 0 + m_Mirror: 0 + m_EditorCurves: + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.25 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_LocalScale.x + path: + classID: 224 + script: {fileID: 0} + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 4 + outSlope: 4 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.25 + value: 1 + inSlope: 4 + outSlope: 4 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_LocalScale.y + path: + classID: 224 + script: {fileID: 0} + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.25 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_LocalScale.z + path: + classID: 224 + script: {fileID: 0} + - curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 4 + outSlope: 4 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 0.25 + value: 1 + inSlope: 4 + outSlope: 4 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + attribute: m_Alpha + path: + classID: 225 + script: {fileID: 0} + m_EulerEditorCurves: [] + m_HasGenericRootTransform: 0 + m_HasMotionFloatCurves: 0 + m_GenerateMotionCurves: 0 + m_Events: [] diff --git a/Assets/UI/DatePicker/Animation/Slide_Below.anim.meta b/Assets/UI/DatePicker/Animation/Slide_Below.anim.meta new file mode 100644 index 0000000..513c3ce --- /dev/null +++ b/Assets/UI/DatePicker/Animation/Slide_Below.anim.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3e29f803e4198334b90aacf11d1a41ac +timeCreated: 1469104120 +licenseType: Store +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker.cs b/Assets/UI/DatePicker/DatePicker.cs new file mode 100644 index 0000000..9ebac34 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker.cs @@ -0,0 +1,1059 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using UnityEngine; +using UnityEngine.UI; +using UI.Tables; +using UnityEngine.Events; + +namespace UI.Dates +{ + [ExecuteInEditMode] + public class DatePicker : MonoBehaviour + { + #region Dates + [SerializeField] + private DateSelectionMode m_DateSelectionMode = DateSelectionMode.SingleDate; + public DateSelectionMode DateSelectionMode + { + get { return m_DateSelectionMode; } + set + { + SetProperty(ref m_DateSelectionMode, value); + } + } + + [SerializeField] + private SerializableDate m_SelectedDate; + public SerializableDate SelectedDate + { + get { return m_SelectedDate; } + set + { + SetProperty(ref m_SelectedDate, value); + + // This will update the VisibleDate field to match the selected date, ensuring that the currently visible month always matches the selected date + // (when the date is selected) + // This is only relevant when selecting dates that don't fall within the current month + if (Config.Misc.SwitchToSelectedMonthWhenDateSelected) + { + VisibleDate = value; + } + + UpdateInputFieldText(); + if (Config.Misc.CloseWhenDateSelected) Hide(); + } + } + + [SerializeField] + private List m_SelectedDates = new List(); + public List SelectedDates + { + get { return m_SelectedDates; } + set + { + SetProperty(ref m_SelectedDates, value); + } + } + + [SerializeField] + private SerializableDate m_VisibleDate; + public SerializableDate VisibleDate + { + get + { + if (!m_VisibleDate.HasValue) + { + if (SelectedDate.HasValue) + { + m_VisibleDate = new SerializableDate(SelectedDate.Date); + } + else + { + m_VisibleDate = new SerializableDate(DateTime.Today); + } + } + + return m_VisibleDate; + } + set { SetProperty(ref m_VisibleDate, value); } + } + + [Tooltip("Defines how 'VisibleDate' is calculated, if at all. Only used if Selected Date has no value.")] + public VisibleDateDefaultBehaviour VisibleDateDefaultBehaviour = VisibleDateDefaultBehaviour.UseTodaysDate; + + public bool IsSharedCalendar { get; set; } + #endregion + + #region Config + public DatePickerConfig Config; + #endregion + + #region References + [Header("References")] + public RectTransform Ref_DatePickerTransform; + public DatePicker_Header Ref_Header; + + public TableLayout Ref_DayTable; + public DatePicker_Animator Ref_DayTableAnimator; + public TableCell Ref_DayTableContainer; + + public DatePicker_DayHeader Ref_Template_DayName; + public DatePicker_DayButton Ref_Template_Day_CurrentMonth; + public DatePicker_DayButton Ref_Template_Day_OtherMonths; + public DatePicker_DayButton Ref_Template_Day_Today; + public DatePicker_DayButton Ref_Template_Day_SelectedDay; + + public Image Ref_Border; + public DatePicker_ContentLayout Ref_ContentLayout; + + public Image Ref_ScreenOverlay; + public DatePicker_Animator Ref_ScreenOverlayAnimator; + + public DatePicker_Animator Ref_Animator; + + private GameObject Panel_BlockRaycasts; + + // Optional +#pragma warning disable + [SerializeField, UnityEngine.Serialization.FormerlySerializedAs("Ref_InputField"), HideInInspector] + private InputField Ref_OldInputField; +#pragma warning restore + + [SerializeField] + private TMPro.TMP_InputField m_Ref_InputField; + public TMPro.TMP_InputField Ref_InputField + { + get + { + if (m_Ref_InputField == null && Ref_OldInputField != null) + { + m_Ref_InputField = DatePicker_TextMeshProUtilities.ReplaceInputFieldWithTextMeshPro(Ref_OldInputField); + } + + return m_Ref_InputField; + } + set + { + m_Ref_InputField = value; + } + } + + + public TableLayout Ref_InputFieldContainer; + public TableCell Ref_InputFieldToggleButtonCell; + + public DatePicker_DateRange Ref_DatePicker_DateRange; + #endregion + + [SerializeField] + private DatePicker_DayButton_Pool _buttonPool; + private DatePicker_DayButton_Pool buttonPool + { + get + { + if (_buttonPool == null) _buttonPool = GetComponent(); + if (_buttonPool == null) _buttonPool = gameObject.AddComponent(); + + return _buttonPool; + } + } + + public RectTransform Ref_Viewport = null; + + public bool IsVisible + { + get + { + return Ref_DatePickerTransform.gameObject.activeInHierarchy; + } + } + + private bool m_initialized = false; + private bool m_updateScheduled = false; + + void Awake() + { +#if UNITY_EDITOR && UNITY_2019_2_OR_NEWER + if (UnityEditor.PrefabUtility.IsOutermostPrefabInstanceRoot(this.gameObject)) + { + UnityEditor.PrefabUtility.UnpackPrefabInstance(this.gameObject, UnityEditor.PrefabUnpackMode.Completely, UnityEditor.InteractionMode.AutomatedAction); + } +#endif + + ClearWeekDayHeaders(); + buttonPool.InvalidateAll(); + + foreach (var row in Ref_DayTable.Rows) + { + DestroyImmediate(row.gameObject); + } + + // If any buttons already exist (most likely created in edit mode) + // Then add them to our pool rather than creating new ones unnecessarily + var existingDayButtons = Ref_DatePickerTransform.GetComponentsInChildren(); + foreach (var button in existingDayButtons) + { + buttonPool.AddExistingButton(button); + } + + if (!SelectedDate.HasValue) + { + if (VisibleDateDefaultBehaviour == Dates.VisibleDateDefaultBehaviour.UseTodaysDate) + { + VisibleDate = DateTime.Today; + } + } + } + + void Start() + { + //UpdateDisplay(); + //DatePickerTimer.DelayedCall(0, UpdateDisplay, this); + SetupHoldButtons(); + } + + void SetupHoldButtons() + { + if (!Application.isPlaying) return; + + var buttons = new DatePicker_Button[] { Ref_Header.NextMonthButton, Ref_Header.PreviousMonthButton, Ref_Header.NextYearButton, Ref_Header.PreviousYearButton }; + + foreach (var button in buttons) + { + button.gameObject.AddComponent(); + } + } + + /// + /// Enable the DatePicker if it has been disabled via Disable() + /// + public void Enable() + { + if (Panel_BlockRaycasts != null) Panel_BlockRaycasts.SetActive(false); + } + + /// + /// Disable (but not hide) the DatePicker + /// + public void Disable() + { + if (Panel_BlockRaycasts == null) + { + Panel_BlockRaycasts = new GameObject("Panel - Block Raycasts", typeof(RectTransform), typeof(Image)); + Panel_BlockRaycasts.transform.SetParent(this.transform); + Panel_BlockRaycasts.transform.SetAsLastSibling(); + + var rt = Panel_BlockRaycasts.GetComponent(); + rt.anchorMax = Vector2.one; + rt.anchorMin = Vector2.zero; + rt.anchoredPosition3D = Vector3.zero; + rt.offsetMin = Vector2.zero; + rt.offsetMax = Vector2.zero; + rt.localScale = Vector3.one; + rt.localRotation = Quaternion.identity; + + var image = Panel_BlockRaycasts.GetComponent(); + image.color = Color.clear; + image.raycastTarget = true; + } + + Panel_BlockRaycasts.SetActive(true); + } + + void OnEnable() + { + if (!m_initialized) DatePickerTimer.AtEndOfFrame(UpdateDisplay, this); + } + + public void ShowPreviousMonth() + { + VisibleDate = VisibleDate.Date.AddMonths(-1); + MonthChangedUpdateDisplay(); + } + + public void ShowNextMonth() + { + VisibleDate = VisibleDate.Date.AddMonths(1); + MonthChangedUpdateDisplay(); + } + + public void ShowPreviousYear() + { + VisibleDate = VisibleDate.Date.AddYears(-1); + MonthChangedUpdateDisplay(); + } + + public void ShowNextYear() + { + VisibleDate = VisibleDate.Date.AddYears(1); + MonthChangedUpdateDisplay(); + } + + void MonthChangedUpdateDisplay() + { + if (Config.Animation.MonthChangedAnimation == Animation.None) + { + UpdateDisplay(); + return; + } + + Ref_DayTableAnimator.PlayAnimation(Config.Animation.MonthChangedAnimation, + AnimationType.Hide, + () => + { + UpdateDisplay(); + + Ref_DayTableAnimator.PlayAnimation(Config.Animation.MonthChangedAnimation, AnimationType.Show); + }); + } + + private void Update() + { + if (m_updateScheduled) _UpdateDisplay(); + } + + public void UpdateDisplay() + { + m_updateScheduled = true; + } + + private void _UpdateDisplay() + { + // don't do anything if we aren't actually active in the hierarchy + // (basically, we're either inactive or a prefab) + if (!this.gameObject.activeInHierarchy) return; + if (!m_updateScheduled) return; + + m_updateScheduled = false; + + m_initialized = true; + + if (Config.Sizing.OverrideTransformHeight) + { + Ref_DatePickerTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Config.Sizing.PreferredHeight); + } + + UpdateBorder(); + UpdateHeader(); + UpdateWeekDayHeaders(); + UpdateDaySection(); + + // Free all buttons in the pool + buttonPool.FreeAll(); + + // Clear existing data + // No longer applicable; re-using existing table structure where possible + //Ref_DayTable.ClearRows(); + + List rows = Ref_DayTable.Rows; + + Ref_DayTable.ColumnWidths = new List() { 0 }; + + bool dateRangeValid = Config.DateRange.Validate(); + + // Day Names + var dayNames = DatePickerUtilities.GetAbbreviatedDayNames().ToList(); + var dayNameRow = Ref_DayTable.Rows.Count != 0 ? Ref_DayTable.Rows[0] : Ref_DayTable.AddRow(0); + dayNameRow.dontUseTableRowBackground = true; + + int columnIndex = 0; + + if (Config.WeekDays.ShowWeekNumbers) + { + dayNames.Insert(0, ""); + } + + var dayNameCells = dayNameRow.Cells; + foreach (var dayName in dayNames) + { + DatePicker_DayHeader header = null; + + if (dayNameCells.Count > columnIndex) + { + header = dayNameCells[columnIndex].GetComponent(); + } + + if (header == null) + { + header = Instantiate(Ref_Template_DayName); + header.transform.localScale = Vector3.one; + dayNameRow.AddCell(header.Cell); + } + + header.HeaderText.text = dayName; + + columnIndex++; + } + + while (dayNameRow.CellCount > dayNames.Count) + { + DestroyImmediate(dayNameRow.Cells[dayNameRow.CellCount - 1].gameObject); + } + + columnIndex = 0; + + var days = DatePickerUtilities.GetDateRangeForDisplay(VisibleDate.Date); + TableRow row = null; + int rowIndex = 1; + + foreach (var day in days) + { + if (day.DayOfWeek == DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek) + { + row = rows.Count > rowIndex ? rows[rowIndex] : Ref_DayTable.AddRow(0); + rowIndex++; + columnIndex = 0; + } + + var dayType = GetDayTypeForDate(day); + var dayItem = buttonPool.GetButton(dayType); + + row.AddCell(dayItem.Cell); + dayItem.transform.SetSiblingIndex(columnIndex); + dayItem.name = day.ToDateString(); + + dayItem.Text.text = day.Day.ToString(); + dayItem.DatePicker = this; + dayItem.Date = day; + dayItem.name = day.ToDateString(); + dayItem.IsTemplate = false; + dayItem.Button.interactable = true; + dayItem.Type = dayType; + dayItem.transform.localScale = Vector3.one; + + if (dateRangeValid) // if the date range is not valid, then don't attempt to use it + { + if ((Config.DateRange.RestrictFromDate && day.CompareTo(Config.DateRange.FromDate) < 0) + || (Config.DateRange.RestrictToDate && day.CompareTo(Config.DateRange.ToDate) > 0)) + { + dayItem.Button.interactable = false; + } + } + + if (Config.DateRange.ProhibitedDates != null && Config.DateRange.ProhibitedDates.Count != 0) + { + if (Config.DateRange.ProhibitedDates.Any(pd => pd.HasValue && pd.Date == day.Date)) + { + dayItem.Button.interactable = false; + } + } + + if ((dayItem.Date.DayOfWeek == DayOfWeek.Monday && !Config.DateRange.PermittedWeekDays.Monday) + || (dayItem.Date.DayOfWeek == DayOfWeek.Tuesday && !Config.DateRange.PermittedWeekDays.Tuesday) + || (dayItem.Date.DayOfWeek == DayOfWeek.Wednesday && !Config.DateRange.PermittedWeekDays.Wednesday) + || (dayItem.Date.DayOfWeek == DayOfWeek.Thursday && !Config.DateRange.PermittedWeekDays.Thursday) + || (dayItem.Date.DayOfWeek == DayOfWeek.Friday && !Config.DateRange.PermittedWeekDays.Friday) + || (dayItem.Date.DayOfWeek == DayOfWeek.Saturday && !Config.DateRange.PermittedWeekDays.Saturday) + || (dayItem.Date.DayOfWeek == DayOfWeek.Sunday && !Config.DateRange.PermittedWeekDays.Sunday) + ) + { + dayItem.Button.interactable = false; + } + + // Optionally hide dates from other months + if (dayType == DatePickerDayButtonType.OtherMonths) + { + if (!Config.Misc.ShowDatesInOtherMonths) + { + dayItem.Button.gameObject.SetActive(false); + } + else + { + dayItem.Button.gameObject.SetActive(true); + } + } + + columnIndex++; + } + + UpdateWeekNumbers(ref days); + Ref_DayTable.UpdateLayout(); + + DatePickerTimer.AtEndOfFrame(() => + { + var _rows = Ref_DayTable.Rows; + + foreach (var _row in _rows) + { + var cells = _row.Cells; + int cIndex = 0; + + foreach (var cell in cells) + { + if (cell.transform.childCount == 0 || cIndex >= dayNames.Count) + { + DestroyImmediate(cell.gameObject); + } + + cIndex++; + } + } + + }, this); + + + DatePickerTimer.DelayedCall(0.01f, () => Ref_DayTable.UpdateLayout(), this); + + UpdateInputField(); + } + void UpdateWeekNumbers(ref List days) + { + DateTimeFormatInfo currentDateTimeFormatInfo = DateTimeFormatInfo.CurrentInfo; + + var rows = Ref_DayTable.Rows; + for (int rowIndex = 1; rowIndex < rows.Count; rowIndex++) + { + DatePicker_DayHeader weekNumberElement = rows[rowIndex].GetComponentInChildren(true); + + if (Config.WeekDays.ShowWeekNumbers) + { + int weekNumber = rowIndex; + + if (Config.WeekDays.WeekNumberMode == WeekNumberMode.WeekOfYear) + { + weekNumber = currentDateTimeFormatInfo.Calendar.GetWeekOfYear(days[7 * (rowIndex - 1)], Config.WeekDays.CalendarWeekRule, currentDateTimeFormatInfo.FirstDayOfWeek); + } + + if (weekNumberElement == null) + { + weekNumberElement = Instantiate(Ref_Template_DayName); + } + + rows[rowIndex].AddCell(weekNumberElement.Cell); + weekNumberElement.transform.SetAsFirstSibling(); + + weekNumberElement.HeaderText.text = weekNumber.ToString(); + weekNumberElement.transform.localScale = Vector3.one; + + weekNumberElement.gameObject.SetActive(true); + } + else + { + if (weekNumberElement != null) + { + weekNumberElement.gameObject.SetActive(false); + } + } + } + } + + void UpdateInputField() + { + if (Ref_InputField != null && Ref_InputFieldContainer != null && Ref_InputFieldToggleButtonCell != null) + { + Ref_InputField.text = SelectedDate.HasValue ? SelectedDate.Date.ToString(Config.Format.DateFormat) : ""; + if (Ref_ScreenOverlay != null) Ref_ScreenOverlay.color = Config.Modal.ScreenOverlayColor; + + var valueBefore = Ref_InputFieldContainer.ColumnWidths.ToList(); + + if (Config.InputField.ShowToggleButton) + { + Ref_InputFieldContainer.ColumnWidths = new List { 0, Config.InputField.ToggleButtonWidth }; + Ref_InputFieldToggleButtonCell.gameObject.SetActive(true); + } + else + { + Ref_InputFieldContainer.ColumnWidths = new List { 0 }; + Ref_InputFieldToggleButtonCell.gameObject.SetActive(false); + } + + if (!valueBefore.SequenceEqual(Ref_InputFieldContainer.ColumnWidths)) Ref_InputFieldContainer.UpdateLayout(); + } + } + + void UpdateBorder() + { + // Border size / color + Ref_ContentLayout.SetBorderSize(Config.Border.Size); + Ref_Border.color = Config.Border.Color; + } + + void UpdateHeader() + { + // Update month name + Ref_Header.HeaderText.text = VisibleDate.Date.ToString("MMM yyyy"); + + Config.Header.Apply(Ref_Header); + + var dateRangeValid = Config.DateRange.Validate(true); + + if (dateRangeValid && Config.DateRange.RestrictFromDate) + { + var lastDayOfPreviousMonth = VisibleDate.Date.AddMonths(-1); + lastDayOfPreviousMonth = new DateTime(lastDayOfPreviousMonth.Year, lastDayOfPreviousMonth.Month, DateTime.DaysInMonth(lastDayOfPreviousMonth.Year, lastDayOfPreviousMonth.Month)).AddDays(1).AddTicks(-1); + + Ref_Header.PreviousMonthButton.Button.interactable = (lastDayOfPreviousMonth.CompareTo(Config.DateRange.FromDate) >= 0); + + var lastDayOfMonthInPreviousYear = VisibleDate.Date.AddYears(-1); + lastDayOfMonthInPreviousYear = new DateTime(lastDayOfMonthInPreviousYear.Year, lastDayOfMonthInPreviousYear.Month, DateTime.DaysInMonth(lastDayOfMonthInPreviousYear.Year, lastDayOfMonthInPreviousYear.Month)); + + Ref_Header.PreviousYearButton.Button.interactable = (lastDayOfMonthInPreviousYear.CompareTo(Config.DateRange.FromDate) >= 0); + } + else + { + Ref_Header.PreviousMonthButton.Button.interactable = true; + } + + if (dateRangeValid && Config.DateRange.RestrictToDate) + { + var firstDayOfNextMonth = VisibleDate.Date.AddMonths(1); + firstDayOfNextMonth = new DateTime(firstDayOfNextMonth.Year, firstDayOfNextMonth.Month, 1); + + Ref_Header.NextMonthButton.Button.interactable = (firstDayOfNextMonth.CompareTo(Config.DateRange.ToDate) <= 0); + + var firstDayOfMonthInNextYear = VisibleDate.Date.AddYears(1); + firstDayOfMonthInNextYear = new DateTime(firstDayOfMonthInNextYear.Year, firstDayOfMonthInNextYear.Month, 1); + + Ref_Header.NextYearButton.Button.interactable = (firstDayOfMonthInNextYear.CompareTo(Config.DateRange.ToDate) <= 0); + } + else + { + Ref_Header.NextMonthButton.Button.interactable = true; + } + } + + void UpdateWeekDayHeaders() + { + Config.WeekDays.ApplyConfig(Ref_Template_DayName); + } + + void UpdateDaySection() + { + var templateList = new List() + { + Ref_Template_Day_Today, + Ref_Template_Day_SelectedDay, + Ref_Template_Day_CurrentMonth, + Ref_Template_Day_OtherMonths + }; + + Config.Days.Validate(); + + foreach (var template in templateList) + { + template.IsTemplate = true; // just in case + template.Text.font = Config.Days.Font; + + if (Config.Days.FontSize > 0) template.Text.fontSize = Config.Days.FontSize; + + template.Text.fontSizeMin = Config.Days.FontSizeMin; + template.Text.fontSizeMax = Config.Days.FontSizeMax; + template.Text.enableAutoSizing = Config.Days.FontAutoSize; + } + + Config.Days.Today.ApplyConfig(Ref_Template_Day_Today); + Config.Days.SelectedDay.ApplyConfig(Ref_Template_Day_SelectedDay); + Config.Days.OtherMonths.ApplyConfig(Ref_Template_Day_OtherMonths); + Config.Days.CurrentMonth.ApplyConfig(Ref_Template_Day_CurrentMonth); + + Ref_DayTable.RowBackgroundColor = Config.Days.BackgroundColor; + Ref_DayTableContainer.image.color = Config.Days.BackgroundColor; + + /*Ref_DayTable.transform.rotation = new Quaternion(0, 0, 0, 0); + Ref_DayTableContainer.transform.rotation = new Quaternion(0, 0, 0, 0); + Ref_DayTableContainer.NotifyTableCellPropertiesChanged();*/ + } + + public void InvalidateAllDayButtonTemplates() + { + buttonPool.InvalidateAll(); + UpdateDisplay(); + } + + public void InvalidateDayButtonTemplate(DatePickerDayButtonType type) + { + buttonPool.InvalidateType(type); + UpdateDisplay(); + } + + public void ClearWeekDayHeaders() + { + var weekDayHeaders = Ref_DayTable.GetComponentsInChildren(); + foreach (var header in weekDayHeaders) + { + DestroyImmediate(header.gameObject); + } + } + + private DatePickerDayButtonType GetDayTypeForDate(DateTime date) + { + DatePickerDayButtonType type; + + if ((DateSelectionMode == Dates.DateSelectionMode.SingleDate && SelectedDate.HasValue && date.Equals(SelectedDate.Date)) + || (DateSelectionMode == Dates.DateSelectionMode.MultipleDates && SelectedDates.Contains(date))) + { + type = DatePickerDayButtonType.SelectedDay; + } + else if (date.Equals(DateTime.Today)) + { + type = DatePickerDayButtonType.Today; + } + else if (date.Month == VisibleDate.Date.Month) + { + type = DatePickerDayButtonType.CurrentMonth; + } + else + { + type = DatePickerDayButtonType.OtherMonths; + } + + return type; + } + + /// + /// Called by DayButton + /// + /// + /// + //public UnityEvent DateTimeClicked = new UnityEvent(); + public void DayButtonClicked(DateTime date) + { + if (DateSelectionMode == Dates.DateSelectionMode.SingleDate) + { + SelectedDate = date; + } + else + { + if (SelectedDates.Any(d => d == date)) + { + SelectedDates.Remove(date); + } + else + { + SelectedDates.Add(date); + } + } + + if (Ref_DatePicker_DateRange != null) + { + Ref_DatePicker_DateRange.DateSelected(date); + } + + if (Config.Events.OnDaySelected != null) + { + Config.Events.OnDaySelected.Invoke(date); + } + + UpdateDisplay(); + + // I would have preferred to have this react automatically to changes, + // but that would mean setting up an observable list, which is an added + // complication we don't need right now + // UpdateInputFieldText(); + } + + public void UpdateInputFieldText() + { + if (Ref_InputField != null) + { + switch (DateSelectionMode) + { + case Dates.DateSelectionMode.SingleDate: + Ref_InputField.text = (SelectedDate.HasValue) ? SelectedDate.Date.ToString(Config.Format.DateFormat) : ""; + break; + case Dates.DateSelectionMode.MultipleDates: + var valueCount = SelectedDates.Count(s => s.HasValue); + Ref_InputField.text = ((valueCount == 1) ? SelectedDates.First(s => s.HasValue).Date.ToString(Config.Format.DateFormat) + : (valueCount > 1 ? "Multiple Dates" : "")); + break; + } + } + } + + /// + /// Called by DayButton + /// + /// + public void DayButtonMouseOver(DateTime date) + { + if (Config.Events.OnDayMouseOver != null) + { + Config.Events.OnDayMouseOver.Invoke(date); + } + } + + /// + /// Called by the screen overlay when it is clicked + /// + public void ModalOverlayClicked() + { + if (Ref_DatePicker_DateRange != null) + { + Ref_DatePicker_DateRange.ModalOverlayClicked(); + } + else + { + if (Config.Modal.CloseWhenModalOverlayClicked) Hide(); + } + } + + public void InputFieldClicked() + { + if (Config.InputField.ToggleDisplayWhenInputFieldClicked) ToggleDisplay(); + } + + public void ToggleDisplay() + { + if (Ref_DatePickerTransform.gameObject.activeInHierarchy) + { + Hide(); + } + else + { + Show(); + } + } + + public void Show(bool setPositionIfNecessary = true) + { + if (Ref_Viewport == null) + { + var canvas = FindParentOfType(this.gameObject); + Ref_Viewport = canvas.transform as RectTransform; + } + + + if (setPositionIfNecessary && Ref_InputField != null) + { + // Position tablelayout relative to InputField + SetPositionAdjacentToInputFieldContainer(); + // Wait till the end of the frame, then complete Show() (this ensures that the DatePicker only becomes visible after being resized) + DatePickerTimer.DelayedCall(0, () => Show(false), this, true); + return; + } + + Ref_DatePickerTransform.gameObject.SetActive(true); + + if (Config.Modal.IsModal && Ref_ScreenOverlay != null) + { + if (Ref_Viewport != null) + { + Ref_ScreenOverlay.transform.SetParent(Ref_Viewport); + Ref_ScreenOverlay.transform.SetAsLastSibling(); + } + + Ref_ScreenOverlay.gameObject.SetActive(true); + + Ref_ScreenOverlayAnimator.PlayAnimation(Animation.Fade, AnimationType.Show); + } + + if (Ref_Viewport != null) + { + Ref_DatePickerTransform.SetParent(Ref_Viewport); + Ref_DatePickerTransform.SetAsLastSibling(); + } + + if (Config.Animation.ShowAnimation != Animation.None) + { + PlayAnimation(Config.Animation.ShowAnimation, AnimationType.Show); + } + } + + private void PlayAnimation(Animation animation, AnimationType animationType, Action onComplete = null) + { + Ref_Animator.PlayAnimation(animation, animationType, onComplete); + } + + public void Hide() + { + if (Config.Animation.HideAnimation != Animation.None) + { + PlayAnimation(Config.Animation.HideAnimation, AnimationType.Hide, _Hide); + } + else + { + _Hide(); + } + } + + private void _Hide() + { + if (Config.Modal.IsModal) + { + if (Ref_ScreenOverlay != null) Ref_ScreenOverlayAnimator.PlayAnimation(Animation.Fade, AnimationType.Hide, HideScreenOverlay_Complete); + } + + if (this.transform != Ref_DatePickerTransform) + { + Ref_DatePickerTransform.SetParent(this.transform); + } + + Ref_DatePickerTransform.gameObject.SetActive(false); + } + + private void HideScreenOverlay_Complete() + { + Ref_ScreenOverlay.transform.SetParent(this.transform); + Ref_ScreenOverlay.gameObject.SetActive(false); + } + + private void SetPositionAdjacentToInputFieldContainer() + { + if (Ref_InputFieldContainer == null) return; + + var rectTransform = Ref_DatePickerTransform; + var inputFieldRectTransform = Ref_InputFieldContainer.transform as RectTransform; + var inputFieldWidth = inputFieldRectTransform.rect.width; + + if (IsSharedCalendar) + { + rectTransform.SetParent(inputFieldRectTransform.parent); + } + + // Fix anchors: + rectTransform.anchorMin = new Vector2(0, 1); + rectTransform.anchorMax = new Vector2(1, 1); + + var widthBefore = rectTransform.rect.width; + if (Config.Sizing.UsePreferredWidthInsteadOfInputFieldWidth) + { + rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Config.Sizing.PreferredWidth); + } + else + { + rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inputFieldWidth); + } + + if (widthBefore != rectTransform.rect.width) + { + ((RectTransform)Ref_DayTable.transform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectTransform.rect.width); + } + + var pivotX = 0.5f; + switch (Config.InputField.DatePickerAlignmentRelativeToInputField) + { + case Alignment.Left: + { + pivotX = 0f; + } + break; + case Alignment.Right: + { + pivotX = 1f; + } + break; + } + + if (Ref_Viewport == null) + { + var canvas = GetComponentInParent(); + Ref_Viewport = ((RectTransform)canvas.transform); + } + + rectTransform.pivot = new Vector2(pivotX, 0.5f); + rectTransform.anchoredPosition = inputFieldRectTransform.anchoredPosition; + rectTransform.SetParent(Ref_Viewport); + + rectTransform.pivot = new Vector2(pivotX, 1); + rectTransform.anchoredPosition -= new Vector2(0, inputFieldRectTransform.rect.height); + + var spaceBelow = Ref_Viewport.rect.height + rectTransform.anchoredPosition.y; + + if (spaceBelow < rectTransform.rect.height) + { + rectTransform.pivot = new Vector2(pivotX, 0); + rectTransform.anchoredPosition += new Vector2(0, inputFieldRectTransform.rect.height); + + var spaceAbove = -(rectTransform.anchoredPosition.y + rectTransform.rect.height); + if (spaceAbove < 0) + { + rectTransform.anchoredPosition += new Vector2(0, spaceAbove); + } + } + + DatePickerTimer.DelayedCall(0.05f, () => { Ref_DayTableContainer.GetRow().NotifyTableRowPropertiesChanged(); }, this); + } + + private static T FindParentOfType(GameObject childObject) + where T : UnityEngine.Object + { + Transform t = childObject.transform; + while (t.parent != null) + { + var component = t.parent.GetComponent(); + + if (component != null) return component; + + t = t.parent.transform; + } + + // We didn't find anything + return null; + } + + #region SetProperty + protected void SetProperty(ref T currentValue, T newValue) + { + if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue))) + return; + + currentValue = newValue; + + UpdateDisplay(); + } + + void OnRectTransformDimensionsChange() + { + //UpdateDisplay(); + //DatePickerTimer.DelayedCall(0f, UpdateDisplay, this); + } + #endregion + + /// + /// Get all Day buttons of the specified type + /// + /// + /// + public List GetDayButtons(DatePickerDayButtonType type) + { + var dayButtons = GetComponentsInChildren(); + + return dayButtons.Where(d => d.Type == type).ToList(); + } + + /// + /// Get all day buttons regardless of type + /// + /// + private List GetDayButtons() + { + return GetComponentsInChildren().ToList(); + } + + /// + /// Get the day button for the specified date + /// + /// + /// + public DatePicker_DayButton GetDayButton(DateTime date) + { + var dateString = date.ToDateString(); + var dayButtons = GetComponentsInChildren(); + + return dayButtons.FirstOrDefault(d => d.name == dateString); + } + + /// + /// Get a serialized string representing the configuration of this DatePicker + /// + /// + public string GetSerializedConfiguration() + { + return JsonUtility.ToJson(Config); + } + + /// + /// Set the configuration of this DatePicker based on a Json string + /// (output from GetSerializedConfiguration) + /// + /// + public void SetConfigFromJsonString(string json) + { + Config = JsonUtility.FromJson(json); + UpdateDisplay(); + } + } +} diff --git a/Assets/UI/DatePicker/DatePicker.cs.meta b/Assets/UI/DatePicker/DatePicker.cs.meta new file mode 100644 index 0000000..1ab92c0 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 53ad93d5d824d8f4f98ae5c68f09a2bc +timeCreated: 1467637034 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePickerCache.cs b/Assets/UI/DatePicker/DatePickerCache.cs new file mode 100644 index 0000000..0287df4 --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerCache.cs @@ -0,0 +1,13 @@ +using UnityEngine; +using System; +using System.Collections; +using System.Globalization; +using System.Collections.Generic; + +namespace UI.Dates +{ + public static class DatePickerCache + { + internal static Dictionary _DateFallsWithinMonthResults = new Dictionary(); + } +} diff --git a/Assets/UI/DatePicker/DatePickerCache.cs.meta b/Assets/UI/DatePicker/DatePickerCache.cs.meta new file mode 100644 index 0000000..9e0a780 --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerCache.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 32d47812cd9d1e241a278efb2e170282 +timeCreated: 1468330494 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePickerExtensions.cs b/Assets/UI/DatePicker/DatePickerExtensions.cs new file mode 100644 index 0000000..527e538 --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerExtensions.cs @@ -0,0 +1,22 @@ +using UnityEngine; +using System; +using System.Collections; +using System.Globalization; +using System.Collections.Generic; +using UnityEngine.UI; + +namespace UI.Dates +{ + public static class DatePickerExtensions + { + public static void Apply(this ColorBlock colors, ColorBlock newColors) + { + colors.colorMultiplier = newColors.colorMultiplier; + colors.disabledColor = newColors.disabledColor; + colors.fadeDuration = newColors.fadeDuration; + colors.highlightedColor = newColors.highlightedColor; + colors.normalColor = newColors.normalColor; + colors.pressedColor = newColors.pressedColor; + } + } +} diff --git a/Assets/UI/DatePicker/DatePickerExtensions.cs.meta b/Assets/UI/DatePicker/DatePickerExtensions.cs.meta new file mode 100644 index 0000000..37831b5 --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerExtensions.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 44987c61f7f0b134db5efb0dca34fa1e +timeCreated: 1487928166 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePickerTimer.cs b/Assets/UI/DatePicker/DatePickerTimer.cs new file mode 100644 index 0000000..faf314d --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerTimer.cs @@ -0,0 +1,147 @@ +using UnityEngine; +using System; +using System.Collections; +using System.Linq; +using System.Globalization; +using System.Collections.Generic; + +namespace UI.Dates +{ + internal class DelayedEditorAction + { + internal double TimeToExecute; + internal Action Action; + internal MonoBehaviour ActionTarget; + internal bool ForceEvenIfTargetIsGone; + + public DelayedEditorAction(double timeToExecute, Action action, MonoBehaviour actionTarget, bool forceEvenIfTargetIsGone = false) + { + TimeToExecute = timeToExecute; + Action = action; + ActionTarget = actionTarget; + ForceEvenIfTargetIsGone = forceEvenIfTargetIsGone; + } + } + + public static class DatePickerTimer + { + private static DatePickerTimerComponent _timerComponent; + private static DatePickerTimerComponent timerComponent + { + get + { + if (_timerComponent == null) + { + _timerComponent = GameObject.FindObjectOfType(); + + if (_timerComponent == null && !IsQuitting) + { + var timerGO = new GameObject("DatePickerTimer"); + _timerComponent = timerGO.AddComponent(); + + GameObject.DontDestroyOnLoad(timerGO); + } + } + + return _timerComponent; + } + } + + public static bool IsFirstFrame + { + /*get { return timerComponent.IsFirstFrame; } */ + get { return Time.frameCount <= 1; } + } + + private static bool IsQuitting { get; set; } + + public static void StartCoroutine(IEnumerator coroutine) + { + if (Application.isPlaying) timerComponent.StartCoroutine(coroutine); + } + +#if UNITY_2018_1_OR_NEWER + [RuntimeInitializeOnLoadMethod()] + public static void OnLoad() + { + Application.quitting += () => IsQuitting = true; + } +#endif + +#if UNITY_EDITOR + static List delayedEditorActions = new List(); + + static DatePickerTimer() + { + UnityEditor.EditorApplication.update += EditorUpdate; + } +#endif + + public static WaitForSecondsRealtime GetWaitForSecondsRealtimeInstruction(float seconds) + { + return new WaitForSecondsRealtime(seconds); + } + + public static WaitForSeconds GetWaitForSecondsInstruction(float seconds) + { + return new WaitForSeconds(seconds); + } + + static void EditorUpdate() + { +#if UNITY_EDITOR + if (Application.isPlaying) return; + + var actionsToExecute = delayedEditorActions.Where(dea => UnityEditor.EditorApplication.timeSinceStartup >= dea.TimeToExecute).ToList(); + + if (actionsToExecute.Count == 0) return; + + foreach (var actionToExecute in actionsToExecute) + { + try + { + if (actionToExecute.ActionTarget != null || actionToExecute.ForceEvenIfTargetIsGone) // don't execute if the target is gone + { + actionToExecute.Action.Invoke(); + } + } + finally + { + delayedEditorActions.Remove(actionToExecute); + } + } +#endif + } + + /// + /// Call Action 'action' after the specified delay, provided the 'actionTarget' is still present and active in the scene at that time. + /// Can be used in both edit and play modes. + /// + /// + /// + /// + public static void DelayedCall(float delay, Action action, MonoBehaviour actionTarget, bool forceEvenIfObjectIsInactive = false) + { + if (Application.isPlaying) + { + if (timerComponent != null) timerComponent.DelayedCall(delay, action, actionTarget, forceEvenIfObjectIsInactive); + } +#if UNITY_EDITOR + else + { + delayedEditorActions.Add(new DelayedEditorAction(UnityEditor.EditorApplication.timeSinceStartup + delay, action, actionTarget, forceEvenIfObjectIsInactive)); + } +#endif + } + + /// + /// Shorthand for DelayedCall(0, action, actionTarget) + /// + /// + /// + public static void AtEndOfFrame(Action action, MonoBehaviour actionTarget, bool forceEvenIfObjectIsInactive = false) + { + DelayedCall(0, action, actionTarget, forceEvenIfObjectIsInactive); + } + } +} diff --git a/Assets/UI/DatePicker/DatePickerTimer.cs.meta b/Assets/UI/DatePicker/DatePickerTimer.cs.meta new file mode 100644 index 0000000..dccab71 --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerTimer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1c9ccb654fb05db4cb6f1a89feb3e042 +timeCreated: 1468243048 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePickerTimerComponent.cs b/Assets/UI/DatePicker/DatePickerTimerComponent.cs new file mode 100644 index 0000000..6f4c7fd --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerTimerComponent.cs @@ -0,0 +1,64 @@ +using System; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using UI.Tables; +using System.Collections.Generic; +using System.Linq; + +namespace UI.Dates +{ + public class DatePickerTimerComponent : MonoBehaviour + { + public List delayedActions = new List(); + + public void DelayedCall(float delay, Action action, MonoBehaviour target, bool forceEvenIfTargetIsInactive) + { + this.enabled = true; + + delayedActions.Add(new DelayedAction { timeToExecute = Time.unscaledTime + delay, action = action, target = target, forceEvenIfTargetIsInactive = forceEvenIfTargetIsInactive }); + } + + private void Update() + { + List actionsToExecute = null; + foreach (var action in delayedActions) + { + if (Time.unscaledTime >= action.timeToExecute) + { + if (actionsToExecute == null) actionsToExecute = new List(); + actionsToExecute.Add(action); + } + } + + if (actionsToExecute == null || actionsToExecute.Count == 0) return; + + foreach (var action in actionsToExecute) + { + try + { + if ((action.forceEvenIfTargetIsInactive) + || (action.target != null && action.target.gameObject.activeInHierarchy)) + { + action.action.Invoke(); + } + } + finally + { + delayedActions.Remove(action); + } + } + + // stop calling update if we have nothing scheduled (DelayedCall will re-enable this) + if (delayedActions.Count == 0) this.enabled = false; + } + } + + public class DelayedAction + { + public float timeToExecute; + public Action action; + public MonoBehaviour target; + public bool forceEvenIfTargetIsInactive; + } +} diff --git a/Assets/UI/DatePicker/DatePickerTimerComponent.cs.meta b/Assets/UI/DatePicker/DatePickerTimerComponent.cs.meta new file mode 100644 index 0000000..518597c --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerTimerComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eacc0f717a736fe409e8e7ff365401d9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePickerUtilities.cs b/Assets/UI/DatePicker/DatePickerUtilities.cs new file mode 100644 index 0000000..cfa7b32 --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerUtilities.cs @@ -0,0 +1,76 @@ +using UnityEngine; +using System; +using System.Collections; +using System.Globalization; +using System.Collections.Generic; +using System.Linq; + +namespace UI.Dates +{ + public static class DatePickerUtilities + { + public static string DateFormat = "yyyy-MM-dd"; + + public static string ToDateString(this SerializableDate date) + { + return date.HasValue ? date.Date.ToDateString() : null; + } + + public static string ToDateString(this DateTime date) + { + return date.ToString(DateFormat); + } + + public static string[] GetAbbreviatedDayNames() + { + //return Shift(DateTimeFormatInfo.CurrentInfo.AbbreviatedDayNames, (int)DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek); + return Shift(DateTimeFormatInfo.CurrentInfo.AbbreviatedDayNames.Where(d => d != "").ToArray(), (int)DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek); + } + + public static List GetDateRangeForDisplay(DateTime date) + { + var list = new List(); + + var firstDayOfMonth = new DateTime(date.Year, date.Month, 1); + var firstDayOfWeekInCulture = DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek; + + var day = firstDayOfMonth; + while (day.DayOfWeek != firstDayOfWeekInCulture) + { + day = day.AddDays(-1); + } + + for (var x = 0; x < 42; x++) + { + list.Add(day); + + day = day.AddDays(1); + } + + return list; + } + + public static bool DateFallsWithinMonth(DateTime date, DateTime month) + { + // We cache the results of this check because it will be performed often + var key = date.ToDateString() + "|" + month.ToDateString(); + if (!DatePickerCache._DateFallsWithinMonthResults.ContainsKey(key)) + { + var firstDay = new DateTime(month.Year, month.Month, 1); + var lastDay = new DateTime(month.Year, month.Month, DateTime.DaysInMonth(month.Year, month.Month)).AddDays(1).AddTicks(-1); + + DatePickerCache._DateFallsWithinMonthResults.Add(key, date.CompareTo(firstDay) >= 0 && date.CompareTo(lastDay) <= 0); + } + + return DatePickerCache._DateFallsWithinMonthResults[key]; + } + + internal static T[] Shift(T[] array, int positions) + { + T[] copy = new T[array.Length]; + Array.Copy(array, 0, copy, array.Length - positions, positions); + Array.Copy(array, positions, copy, 0, array.Length - positions); + return copy; + } + } +} diff --git a/Assets/UI/DatePicker/DatePickerUtilities.cs.meta b/Assets/UI/DatePicker/DatePickerUtilities.cs.meta new file mode 100644 index 0000000..260040a --- /dev/null +++ b/Assets/UI/DatePicker/DatePickerUtilities.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 70300bc161a3bcd409f1d47f6071b16d +timeCreated: 1467647761 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_Animator.cs b/Assets/UI/DatePicker/DatePicker_Animator.cs new file mode 100644 index 0000000..f69308c --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Animator.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace UI.Dates +{ + // Was having some positioning issues with the default Animator component, so I wrote a simple animator here + // It turned out that the Animator component wasn't responsible, but I've decided to leave the simpler implementation in place for now + [RequireComponent(typeof(RectTransform)), RequireComponent(typeof(CanvasGroup))] + public class DatePicker_Animator : MonoBehaviour + { + protected List animations = new List(); + + private CanvasGroup m_canvasGroup = null; + protected CanvasGroup canvasGroup + { + get + { + if (m_canvasGroup == null) m_canvasGroup = GetComponent(); + return m_canvasGroup; + } + } + + private RectTransform m_rectTransform = null; + protected RectTransform rectTransform + { + get + { + if (m_rectTransform == null) m_rectTransform = GetComponent(); + return m_rectTransform; + } + } + + public bool ResetWhenAnimationComplete = true; + public float AnimationDuration = 0.25f; + + public void PlayAnimation(Animation animation, AnimationType animationType, Action onComplete = null) + { + if (animationType == AnimationType.Show) + { + switch (animation) + { + case Animation.Slide: + { + // Start off by setting our Y scale to zero; + SetPropertyValue(DatePicker_Animation_Property.ScaleY, 0); + // Then animate to full size + Animate(DatePicker_Animation_Property.ScaleY, 1, AnimationDuration, onComplete); + } + break; + case Animation.Fade: + { + SetPropertyValue(DatePicker_Animation_Property.Alpha, 0); + Animate(DatePicker_Animation_Property.Alpha, 1, AnimationDuration, onComplete); + } + break; + } + } + else + { + switch (animation) + { + case Animation.Slide: + { + Animate(DatePicker_Animation_Property.ScaleY, 0f, AnimationDuration, onComplete); + } + break; + + case Animation.Fade: + { + Animate(DatePicker_Animation_Property.Alpha, 0f, AnimationDuration, onComplete); + } + break; + } + } + } + + public void Animate(DatePicker_Animation_Property property, float desiredValue, float duration, Action onComplete = null) + { + if (!Application.isPlaying) + { + SetPropertyValue(property, desiredValue); + if (onComplete != null) onComplete.Invoke(); + return; + } + + var animation = animations.FirstOrDefault(a => a.property == property); + + if (animation == null) + { + animation = new DatePicker_Animation + { + property = property + }; + + animations.Add(animation); + } + + animation.initialValue = GetPropertyValue(animation.property); + animation.desiredValue = desiredValue; + animation.percentageComplete = 0; + animation.startTime = Time.time; + animation.duration = duration; + animation.onComplete = onComplete; + } + + void Update() + { + if (!animations.Any()) return; + + foreach (var animation in animations) + { + animation.percentageComplete = (Time.time - animation.startTime) / animation.duration; + SetPropertyValue(animation.property, animation.currentValue); + + if (animation.percentageComplete >= 1) + { + if (animation.onComplete != null) animation.onComplete.Invoke(); + } + } + + animations.RemoveAll(a => a.percentageComplete >= 1); + + if (ResetWhenAnimationComplete && !animations.Any()) + { + SetPropertyValue(DatePicker_Animation_Property.Alpha, 1); + SetPropertyValue(DatePicker_Animation_Property.ScaleX, 1); + SetPropertyValue(DatePicker_Animation_Property.ScaleY, 1); + } + } + + float GetPropertyValue(DatePicker_Animation_Property property) + { + switch (property) + { + case DatePicker_Animation_Property.Alpha: + return canvasGroup.alpha; + case DatePicker_Animation_Property.ScaleX: + return rectTransform.localScale.x; + case DatePicker_Animation_Property.ScaleY: + return rectTransform.localScale.y; + } + + return 0f; + } + + void SetPropertyValue(DatePicker_Animation_Property property, float newValue) + { + switch (property) + { + case DatePicker_Animation_Property.Alpha: + canvasGroup.alpha = newValue; + break; + case DatePicker_Animation_Property.ScaleX: + rectTransform.localScale = new Vector3(newValue, rectTransform.localScale.y, rectTransform.localScale.z); + break; + case DatePicker_Animation_Property.ScaleY: + rectTransform.localScale = new Vector3(rectTransform.localScale.x, newValue, rectTransform.localScale.z); + break; + } + } + + protected class DatePicker_Animation + { + public DatePicker_Animation_Property property; + public float initialValue; + public float desiredValue; + public float startTime; + public float percentageComplete; + public float duration; + + public Action onComplete; + + public float currentValue + { + get + { + return Mathf.Lerp(initialValue, desiredValue, percentageComplete); + } + } + } + + public enum DatePicker_Animation_Property + { + Alpha, + ScaleX, + ScaleY + } + } +} diff --git a/Assets/UI/DatePicker/DatePicker_Animator.cs.meta b/Assets/UI/DatePicker/DatePicker_Animator.cs.meta new file mode 100644 index 0000000..46ce8af --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Animator.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ecbabc5a850c4304dadacf1b49b0ef88 +timeCreated: 1469109423 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_Button.cs b/Assets/UI/DatePicker/DatePicker_Button.cs new file mode 100644 index 0000000..9512a68 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Button.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.UI; +using UI.Tables; +using UnityEngine.Serialization; +using TMPro; + +namespace UI.Dates +{ + public class DatePicker_Button : MonoBehaviour + { + public Button Button; + + #pragma warning disable + [SerializeField, FormerlySerializedAs("Text"), HideInInspector] + private Text oldText; + #pragma warning restore + + [SerializeField] + private TextMeshProUGUI m_Text; + + public TextMeshProUGUI Text + { + get + { + if (m_Text == null) + { + if (oldText == null) + { + Debug.LogError("[DatePicker] An error ocurred while upgrading to TextMesh Pro - unable to locate original text element for a button."); + return null; + } + + m_Text = DatePicker_TextMeshProUtilities.ReplaceTextElementWithTextMeshPro(oldText); + } + + return m_Text; + } + } + + + public bool IsTemplate = true; + + [SerializeField] + private TableCell m_Cell = null; + public TableCell Cell + { + get + { + if (m_Cell == null) m_Cell = GetComponent(); // as used by DayButton + if (m_Cell == null) m_Cell = GetComponentInParent(); // as used by header buttons + + return m_Cell; + } + } + } +} diff --git a/Assets/UI/DatePicker/DatePicker_Button.cs.meta b/Assets/UI/DatePicker/DatePicker_Button.cs.meta new file mode 100644 index 0000000..c3d36f3 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Button.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: aca775cb21cc5c84b8002986bfa21acb +timeCreated: 1467803686 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_Config.cs b/Assets/UI/DatePicker/DatePicker_Config.cs new file mode 100644 index 0000000..91b2807 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Config.cs @@ -0,0 +1,478 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using UnityEngine; +using UnityEngine.Serialization; +using UnityEngine.UI; +using UnityEngine.Events; +using System.Linq; +using TMPro; + +namespace UI.Dates +{ + [Serializable] + public class DatePickerEvent : UnityEvent { } + + [Serializable] + public struct DatePickerConfig + { + public DatePickerMiscConfig Misc; + [Space] + public DatePickerSizeConfig Sizing; + [Space] + public DatePickerModalConfig Modal; + [Space] + public DatePickerDateRangeConfig DateRange; + [Space] + public DatePickerFormatConfig Format; + [Space] + public DatePickerBorderConfig Border; + [Space] + public DatePickerHeaderConfig Header; + [Space] + public DatePickerWeekDaysConfig WeekDays; + [Space] + public DatePickerDayConfig Days; + [Space] + public DatePickerAnimationConfig Animation; + [Space] + public DatePickerInputFieldConfig InputField; + [Space] + public DatePickerEventConfig Events; + } + + [Serializable] + public class DatePickerSizeConfig + { + public bool OverrideTransformHeight = false; + public float PreferredHeight = 256f; + + public bool UsePreferredWidthInsteadOfInputFieldWidth = false; + public float PreferredWidth = 256f; + } + + [Serializable] + public class DatePickerDayConfig + { + public Color BackgroundColor; + + #pragma warning disable + [SerializeField, FormerlySerializedAs("Font"), HideInInspector] + private Font oldFont; + #pragma warning restore + public TMP_FontAsset Font; + + public int FontSize; + public bool FontAutoSize = true; + public int FontSizeMin = 2; + public int FontSizeMax = 16; + + public DatePickerDayButtonConfig CurrentMonth; + public DatePickerDayButtonConfig OtherMonths; + public DatePickerDayButtonConfig Today; + public DatePickerDayButtonConfig SelectedDay; + + public void Validate() + { + if (Font == null && oldFont != null) + { + Font = DatePicker_TextMeshProUtilities.GetTMPFontFromOldFont(oldFont); + } + } + } + + [Serializable] + public class DatePickerBorderConfig + { + public RectOffset Size = null; + public Color Color; + } + + [Serializable] + public class DatePickerDayButtonConfig + { + [Tooltip("If this value is set, then the values provided here will override the values of the template. If you wish to modify the template directly, this value should be cleared.")] + public bool OverrideTemplate = true; + + [Header("Text")] + public Color TextColor; + + [Header("Background")] + public Sprite BackgroundImage; + public ColorBlock BackgroundColors; + + public void ApplyConfig(DatePicker_Button button) + { + if (!OverrideTemplate) return; + + button.Text.color = TextColor; + button.Button.colors = BackgroundColors; + //button.Button.colors.Apply(BackgroundColors); + button.Button.image.sprite = BackgroundImage; + } + } + + [Serializable] + public class DatePickerWeekDaysConfig + { + [Header("Week Numbers")] + public bool ShowWeekNumbers = false; + public WeekNumberMode WeekNumberMode = WeekNumberMode.WeekOfYear; + public CalendarWeekRule CalendarWeekRule = CalendarWeekRule.FirstFullWeek; + [Tooltip("0 == Auto")] + public float WeekNumberColumnWidth = 0f; + + [Header("Appearance")] + [Tooltip("If this value is set, then the values provided here will override the values of the template. If you wish to modify the template directly, this value should be cleared.")] + public bool OverrideTemplate = true; + + [Header("Text")] + public Color TextColor; + #pragma warning disable + [SerializeField, FormerlySerializedAs("Font"), HideInInspector] + private Font oldFont; + #pragma warning restore + public TMP_FontAsset Font; + public int FontSize; + public bool FontAutoSize = true; + public int FontSizeMin = 2; + public int FontSizeMax = 16; + + [Header("Background")] + public Sprite BackgroundImage; + public Color BackgroundColor; + + public void ApplyConfig(DatePicker_DayHeader header) + { + if (!OverrideTemplate) return; + + header.HeaderText.color = TextColor; + + if (Font == null && oldFont != null) + { + Font = DatePicker_TextMeshProUtilities.GetTMPFontFromOldFont(oldFont); + } + + if (Font != null) header.HeaderText.font = Font; + + header.HeaderText.fontSize = FontSize; + header.HeaderText.fontSizeMin = FontSizeMin; + header.HeaderText.fontSizeMax = FontSizeMax; + header.HeaderText.enableAutoSizing = FontAutoSize; + + header.Cell.image.sprite = BackgroundImage; + header.Cell.image.color = BackgroundColor; + } + } + + [Serializable] + public class DatePickerButtonConfig + { + public Sprite Image; + public ColorBlock Colors; + public bool PreserveAspect = true; + + public void ApplyConfig(DatePicker_Button button) + { + //button.Button.colors = Colors; + button.Button.colors.Apply(Colors); + button.Button.image.sprite = Image; + button.Button.image.preserveAspect = PreserveAspect; + } + } + + [Serializable] + public class DatePickerHeaderConfig + { + public bool ShowHeader = true; + + [Header("Background")] + public Color BackgroundColor; + + [Header("Text")] + public Color TextColor; + #pragma warning disable + [SerializeField, FormerlySerializedAs("Font"), HideInInspector] + private Font oldFont; + #pragma warning restore + public TMP_FontAsset Font; + + public int FontSize = 22; + public bool FontAutoSize = true; + public int FontSizeMin = 2; + public int FontSizeMax = 24; + + [Header("Height")] + public float Height = 48f; + + [Header("Buttons")] + public bool ShowNextAndPreviousMonthButtons = true; + public bool ShowNextAndPreviousYearButtons = true; + + [Space] + public float MonthButtonCellWidth = 48f; + public RectOffset MonthButtonCellPadding = null; + [Space] + public float YearButtonCellWidth = 48f; + public RectOffset YearButtonCellPadding = null; + + [Space] + public DatePickerButtonConfig PreviousMonthButton; + public DatePickerButtonConfig NextMonthButton; + public DatePickerButtonConfig PreviousYearButton; + public DatePickerButtonConfig NextYearButton; + + [SerializeField, HideInInspector] + private bool m_newPaddingValuesApplied = false; + + public void Apply(DatePicker_Header header) + { + if (header == null) return; + + if (ShowHeader) + { + header.gameObject.SetActive(true); + } + else + { + header.gameObject.SetActive(false); + return; + } + + header.Background.color = BackgroundColor; + + header.HeaderText.color = TextColor; + + if (Font == null && oldFont != null) + { + Font = DatePicker_TextMeshProUtilities.GetTMPFontFromOldFont(oldFont); + } + + if (Font != null) header.HeaderText.font = Font; + + header.HeaderText.fontSize = FontSize; + header.HeaderText.fontSizeMin = FontSizeMin; + header.HeaderText.fontSizeMax = FontSizeMax; + header.HeaderText.enableAutoSizing = FontAutoSize; + + if (ShowNextAndPreviousMonthButtons) + { + header.NextMonthButton.gameObject.SetActive(true); + header.PreviousMonthButton.gameObject.SetActive(true); + + NextMonthButton.ApplyConfig(header.NextMonthButton); + PreviousMonthButton.ApplyConfig(header.PreviousMonthButton); + } + else + { + header.NextMonthButton.gameObject.SetActive(false); + header.PreviousMonthButton.gameObject.SetActive(false); + } + + if (ShowNextAndPreviousYearButtons) + { + header.NextYearButton.gameObject.SetActive(true); + header.PreviousYearButton.gameObject.SetActive(true); + + NextYearButton.ApplyConfig(header.NextYearButton); + PreviousYearButton.ApplyConfig(header.PreviousYearButton); + } + else + { + header.NextYearButton.gameObject.SetActive(false); + header.PreviousYearButton.gameObject.SetActive(false); + } + + if (header.Row.preferredHeight != Height) + { + header.Row.preferredHeight = Height; + header.Row.NotifyTableRowPropertiesChanged(); + } + + if (header.TableLayout == null) header.TableLayout = header.Row.GetTable(); + + header.TableLayout.ColumnWidths = new List() { YearButtonCellWidth, MonthButtonCellWidth, 0, MonthButtonCellWidth, YearButtonCellWidth }; + + if (!m_newPaddingValuesApplied) + { + MonthButtonCellPadding = new RectOffset(8, 8, 8, 8); + YearButtonCellPadding = new RectOffset(8, 8, 8, 8); + + m_newPaddingValuesApplied = true; + } + + + if (header.NextMonthButton.Cell != null) + { + header.NextMonthButton.Cell.padding = MonthButtonCellPadding; + LayoutRebuilder.MarkLayoutForRebuild(header.NextMonthButton.Cell.transform as RectTransform); + } + + if (header.NextYearButton.Cell != null) + { + header.NextYearButton.Cell.padding = YearButtonCellPadding; + LayoutRebuilder.MarkLayoutForRebuild(header.NextYearButton.Cell.transform as RectTransform); + } + + if (header.PreviousMonthButton.Cell != null) + { + header.PreviousMonthButton.Cell.padding = MonthButtonCellPadding; + LayoutRebuilder.MarkLayoutForRebuild(header.PreviousMonthButton.Cell.transform as RectTransform); + } + + if (header.PreviousYearButton.Cell != null) + { + header.PreviousYearButton.Cell.padding = YearButtonCellPadding; + LayoutRebuilder.MarkLayoutForRebuild(header.PreviousYearButton.Cell.transform as RectTransform); + } + + header.TableLayout.UpdateLayout(); + } + } + + [Serializable] + public struct DatePickerEventConfig + { + [SerializeField] + public DatePickerEvent OnDaySelected; + [SerializeField] + public DatePickerEvent OnDayMouseOver; + } + + [Serializable] + public class DatePickerMiscConfig + { + [Tooltip("If this is set, the DatePicker will always switch to the selected month when a new date is selected.")] + public bool SwitchToSelectedMonthWhenDateSelected = true; + + public bool ShowDatesInOtherMonths = true; + + [Tooltip("If this is set, then the DatePicker will be closed when a date is selected. Useful for popup datepicker dialogs.")] + public bool CloseWhenDateSelected = false; + + public DatePickerMiscConfig Clone() + { + return new DatePickerMiscConfig + { + SwitchToSelectedMonthWhenDateSelected = SwitchToSelectedMonthWhenDateSelected, + ShowDatesInOtherMonths = ShowDatesInOtherMonths, + CloseWhenDateSelected = CloseWhenDateSelected + }; + } + } + + [Serializable] + public class DatePickerFormatConfig + { + public string DateFormat = DatePickerUtilities.DateFormat; + } + + [Serializable] + public class DatePickerModalConfig + { + [Tooltip("If this is set to true, then the DatePicker will be the only thing on the screen which can be interacted with when it is active.")] + public bool IsModal = false; + + [Tooltip("If this is set to true, then the DatePicker will be closed when the screen overlay is clicked. Relevant to Modal DatePickers only.")] + public bool CloseWhenModalOverlayClicked = true; + + public Color ScreenOverlayColor; + } + + [Serializable] + public class DatePickerDateRangeConfig + { + public bool RestrictFromDate = false; + public SerializableDate FromDate; + public bool RestrictToDate = false; + public SerializableDate ToDate; + + public List ProhibitedDates = new List(); + + public DatePickerPermittedWeekDaysConfig PermittedWeekDays = new DatePickerPermittedWeekDaysConfig(); + + public bool Validate(bool silent = false) + { + if (RestrictFromDate && !FromDate.HasValue) + { + if (!silent) Debug.Log("[DatePicker] Restrict From Date requires a 'From Date' to be specified."); + return false; + } + + if (RestrictToDate && !ToDate.HasValue) + { + if (!silent) Debug.Log("[DatePicker] Restrict To Date requires a 'To Date' to be specified."); + return false; + } + + if (RestrictFromDate && RestrictToDate) + { + if (ToDate.Date.CompareTo(FromDate.Date) < 0) + { + if (!silent) Debug.Log("[DatePicker] Invalid Date range specified."); + return false; + } + } + + return true; + } + + public DatePickerDateRangeConfig Clone() + { + return new DatePickerDateRangeConfig + { + RestrictFromDate = RestrictFromDate, + RestrictToDate = RestrictToDate, + FromDate = new SerializableDate(FromDate), + ToDate = new SerializableDate(ToDate), + ProhibitedDates = ProhibitedDates.ToList(), + PermittedWeekDays = PermittedWeekDays.Clone() + }; + } + } + + [Serializable] + public class DatePickerPermittedWeekDaysConfig + { + public bool Monday = true; + public bool Tuesday = true; + public bool Wednesday = true; + public bool Thursday = true; + public bool Friday = true; + public bool Saturday = true; + public bool Sunday = true; + + public DatePickerPermittedWeekDaysConfig Clone() + { + return new DatePickerPermittedWeekDaysConfig() + { + Monday = Monday, + Tuesday = Tuesday, + Wednesday = Wednesday, + Thursday = Thursday, + Friday = Friday, + Saturday = Saturday, + Sunday = Sunday + }; + } + } + + [Serializable] + public class DatePickerInputFieldConfig + { + public bool ToggleDisplayWhenInputFieldClicked = true; + public bool ShowToggleButton = true; + public float ToggleButtonWidth = 64f; + + public Dates.Alignment DatePickerAlignmentRelativeToInputField = Dates.Alignment.Left; + } + + [Serializable] + public class DatePickerAnimationConfig + { + public Animation ShowAnimation = Animation.None; + public Animation HideAnimation = Animation.None; + + public Animation MonthChangedAnimation = Animation.None; + } +} diff --git a/Assets/UI/DatePicker/DatePicker_Config.cs.meta b/Assets/UI/DatePicker/DatePicker_Config.cs.meta new file mode 100644 index 0000000..e91b77d --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Config.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2a19bba98d87f014cb89bf2cb1067bae +timeCreated: 1467815858 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_ContentLayout.cs b/Assets/UI/DatePicker/DatePicker_ContentLayout.cs new file mode 100644 index 0000000..6c2f4c4 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_ContentLayout.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.UI; +using UI.Tables; + +namespace UI.Dates +{ + public class DatePicker_ContentLayout : MonoBehaviour + { + public DatePicker DatePicker; + + private RectTransform m_rectTransform = null; + protected RectTransform rectTransform + { + get + { + if (m_rectTransform == null) m_rectTransform = this.GetComponent(); + + return m_rectTransform; + } + } + + public void SetBorderSize(RectOffset borderSize) + { + rectTransform.offsetMin = new Vector2(borderSize.right, borderSize.bottom); + rectTransform.offsetMax = new Vector2(-borderSize.left, -borderSize.top); + } + + public void SetBorderSize(int borderSize) + { + SetBorderSize(new RectOffset(borderSize, borderSize, borderSize, borderSize)); + } + + void OnRectTransformDimensionsChanged() + { + DatePicker.UpdateDisplay(); + } + } +} diff --git a/Assets/UI/DatePicker/DatePicker_ContentLayout.cs.meta b/Assets/UI/DatePicker/DatePicker_ContentLayout.cs.meta new file mode 100644 index 0000000..9e36644 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_ContentLayout.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 225c28f22f54c8d44967529493e1caa2 +timeCreated: 1467809084 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_DateRange.cs b/Assets/UI/DatePicker/DatePicker_DateRange.cs new file mode 100644 index 0000000..2934ed2 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DateRange.cs @@ -0,0 +1,161 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.UI; +using UI.Tables; + +namespace UI.Dates +{ + [ExecuteInEditMode] + public class DatePicker_DateRange : MonoBehaviour + { + [SerializeField] + private SerializableDate m_FromDate; + public SerializableDate FromDate + { + get { return m_FromDate; } + set + { + SetProperty(ref m_FromDate, value); + + Ref_DatePicker_From.SelectedDate = new SerializableDate(value); + } + } + + [SerializeField] + private SerializableDate m_ToDate; + public SerializableDate ToDate + { + get { return m_ToDate; } + set + { + SetProperty(ref m_ToDate, value); + + Ref_DatePicker_To.SelectedDate = new SerializableDate(value); + } + } + + public DatePickerConfig Config; + + public DatePicker Ref_DatePicker_From; + public DatePicker Ref_DatePicker_To; + + public void UpdateDisplay() + { + if (!this.gameObject.activeInHierarchy) return; + + m_FromDate = FromDate; + m_ToDate = ToDate; + + ApplyConfig(Ref_DatePicker_From); + ApplyConfig(Ref_DatePicker_To); + + if (Ref_DatePicker_From.SelectedDate.HasValue) + { + Ref_DatePicker_To.Config.DateRange.FromDate = Ref_DatePicker_From.SelectedDate; + Ref_DatePicker_To.Config.DateRange.RestrictFromDate = true; + } + + if (Ref_DatePicker_To.SelectedDate.HasValue) + { + Ref_DatePicker_From.Config.DateRange.ToDate = Ref_DatePicker_To.SelectedDate; + Ref_DatePicker_From.Config.DateRange.RestrictToDate = true; + } + + Ref_DatePicker_From.UpdateDisplay(); + Ref_DatePicker_To.UpdateDisplay(); + } + + public void InputFieldClicked() + { + if (Config.InputField.ToggleDisplayWhenInputFieldClicked) ToggleDisplay(); + } + + public void ToggleDisplay() + { + if (Ref_DatePicker_From.IsVisible || Ref_DatePicker_To.IsVisible) + { + Hide(); + } + else + { + Show(); + } + } + + public void Show() + { + Ref_DatePicker_From.Show(); + Ref_DatePicker_To.Show(); + } + + public void Hide() + { + Ref_DatePicker_From.Hide(); + Ref_DatePicker_To.Hide(); + } + + void ApplyConfig(DatePicker datePicker) + { + datePicker.Config = Config; + + // we manipulate the DateRange configuration object afterwards, so we need to ensure that it is a unique instance or the changes will be applied to both DatePickers + datePicker.Config.DateRange = datePicker.Config.DateRange.Clone(); + + datePicker.Config.Misc = datePicker.Config.Misc.Clone(); + datePicker.Config.Misc.CloseWhenDateSelected = false; + } + + /// + /// Called by the DatePicker instances + /// + /// + public void DateSelected(DateTime date) + { + FromDate = new SerializableDate(Ref_DatePicker_From.SelectedDate); + ToDate = new SerializableDate(Ref_DatePicker_To.SelectedDate); + + this.UpdateDisplay(); + + DatePickerTimer.DelayedCall(0.1f, + () => + { + if (Config.Misc.CloseWhenDateSelected) + { + // Only close if we have both from and to dates selected + if (FromDate.HasValue && ToDate.HasValue) + { + Hide(); + } + } + }, + this); + } + + public void ModalOverlayClicked() + { + if (Config.Modal.CloseWhenModalOverlayClicked) Hide(); + } + + protected void SetProperty(ref T currentValue, T newValue) + { + if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue))) + return; + currentValue = newValue; + + UpdateDisplay(); + } + + /*void OnValidate() + { + if (!this.gameObject.activeInHierarchy) return; + + DatePickerTimer.DelayedCall(0f, () => + { + FromDate = m_FromDate; + ToDate = m_ToDate; + }, this, false); + }*/ + } +} diff --git a/Assets/UI/DatePicker/DatePicker_DateRange.cs.meta b/Assets/UI/DatePicker/DatePicker_DateRange.cs.meta new file mode 100644 index 0000000..5733fa6 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DateRange.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a14d9d0f3e6133f47971e80348738636 +timeCreated: 1469620780 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_DayButton.cs b/Assets/UI/DatePicker/DatePicker_DayButton.cs new file mode 100644 index 0000000..38fa8d7 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DayButton.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.UI; +using UI.Tables; + +namespace UI.Dates +{ + public class DatePicker_DayButton : DatePicker_Button + { + public DateTime Date; + public DatePickerDayButtonType Type; + + [HideInInspector] + public DatePicker DatePicker; + + public void Clicked() + { + if (!Button.interactable) return; + + DatePicker.DayButtonClicked(Date); + } + + public void MouseOver() + { + if (!Button.interactable) return; + + DatePicker.DayButtonMouseOver(Date); + } + } +} diff --git a/Assets/UI/DatePicker/DatePicker_DayButton.cs.meta b/Assets/UI/DatePicker/DatePicker_DayButton.cs.meta new file mode 100644 index 0000000..06608f2 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DayButton.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: cab375c3d71687b43bdfe322a109d817 +timeCreated: 1467814440 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_DayButton_Pool.cs b/Assets/UI/DatePicker/DatePicker_DayButton_Pool.cs new file mode 100644 index 0000000..25d4ffa --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DayButton_Pool.cs @@ -0,0 +1,205 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using System.Linq; + +namespace UI.Dates +{ + public class DatePicker_DayButton_Pool : MonoBehaviour + { + private DatePicker _datePicker; + private DatePicker datePicker + { + get + { + if (_datePicker == null) _datePicker = this.GetComponent(); + + return _datePicker; + } + } + + [SerializeField] + private RectTransform _poolRect; + private RectTransform poolRect + { + get + { + if (_poolRect == null) + { + _poolRect = (RectTransform)(new GameObject("Pool Rect", typeof(RectTransform)).transform); + _poolRect.SetParent(this.transform); + _poolRect.gameObject.SetActive(false); + } + + return _poolRect; + } + } + + private Dictionary pool = new Dictionary(); + + public void AddExistingButton(DatePicker_DayButton button) + { + GetPoolList(button.Type).AddExistingButtonToPool(button); + } + + public DatePicker_DayButton GetButton(DatePickerDayButtonType type) + { + return GetPoolList(type).GetButton(); + } + + private DatePicker_DayButton_Pool_List GetPoolList(DatePickerDayButtonType type) + { + DatePicker_DayButton_Pool_List poolList = null; + if (!pool.ContainsKey(type)) + { + poolList = new DatePicker_DayButton_Pool_List(type, poolRect); + pool.Add(type, poolList); + + var template = GetTemplate(type); + poolList.SetTemplate(template); + } + else + { + poolList = pool[type]; + } + + return poolList; + } + + public void FreeAll() + { + foreach (var kvp in pool) + { + kvp.Value.FreeAll(); + } + } + + public void InvalidateAll() + { + foreach (var kvp in pool) + { + kvp.Value.Invalidate(); + } + + + } + + public void InvalidateType(DatePickerDayButtonType type) + { + if (!pool.ContainsKey(type)) return; + + pool[type].Invalidate(); + } + + private DatePicker_DayButton GetTemplate(DatePickerDayButtonType type) + { + switch (type) + { + case DatePickerDayButtonType.Today: + return datePicker.Ref_Template_Day_Today; + + case DatePickerDayButtonType.SelectedDay: + return datePicker.Ref_Template_Day_SelectedDay; + + case DatePickerDayButtonType.CurrentMonth: + return datePicker.Ref_Template_Day_CurrentMonth; + + case DatePickerDayButtonType.OtherMonths: + return datePicker.Ref_Template_Day_OtherMonths; + } + + return null; + } + } + + public class DatePicker_DayButton_Pool_List + { + //private DatePickerDayButtonType type; + private DatePicker_DayButton template; + private RectTransform poolRect; + + private List pool = new List(); + + public DatePicker_DayButton_Pool_List(DatePickerDayButtonType type, RectTransform poolRect) + { + //this.type = type; + this.poolRect = poolRect; + } + + public void SetTemplate(DatePicker_DayButton template) + { + this.template = template; + } + + public void AddExistingButtonToPool(DatePicker_DayButton button) + { + if (pool.Any(p => p.button == button)) return; + + var buttonItem = new DatePicker_DayButton_Pool_List_Item() { button = button }; + + pool.Add(buttonItem); + } + + public DatePicker_DayButton GetButton() + { + var buttonItem = pool.FirstOrDefault(i => !i.inUse && i.button != null); + + if (buttonItem == null) + { + buttonItem = new DatePicker_DayButton_Pool_List_Item(template); + pool.Add(buttonItem); + } + + buttonItem.inUse = true; + + return buttonItem.button; + } + + public void FreeAll() + { + if (pool.Count == 0) return; + + pool.ForEach(p => + { + if (p == null) return; + + p.inUse = false; + p.button.transform.SetParent(poolRect); + }); + } + + public void Invalidate() + { + var items = pool.Select(p => p.button).ToList(); + + foreach (var i in items) + { + if (i == null) continue; + + if (Application.isPlaying) GameObject.Destroy(i.gameObject); + else GameObject.DestroyImmediate(i.gameObject); + } + + // if, for example, our template has changed, all of our pool items are invalid, so we should remove them + pool.Clear(); + } + } + + class DatePicker_DayButton_Pool_List_Item + { + public bool inUse = false; + public DatePicker_DayButton button = null; + + public DatePicker_DayButton_Pool_List_Item() + { + } + + public DatePicker_DayButton_Pool_List_Item(DatePicker_DayButton template) + { + button = GameObject.Instantiate(template); + button.IsTemplate = false; + } + } +} diff --git a/Assets/UI/DatePicker/DatePicker_DayButton_Pool.cs.meta b/Assets/UI/DatePicker/DatePicker_DayButton_Pool.cs.meta new file mode 100644 index 0000000..770fab7 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DayButton_Pool.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ac0061fa239b2684bae435fb5f8418ff +timeCreated: 1487598754 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_DayHeader.cs b/Assets/UI/DatePicker/DatePicker_DayHeader.cs new file mode 100644 index 0000000..d613947 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DayHeader.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.UI; +using UI.Tables; +using UnityEngine.Serialization; +using TMPro; + +namespace UI.Dates +{ + public class DatePicker_DayHeader : MonoBehaviour + { +#pragma warning disable + [SerializeField, FormerlySerializedAs("HeaderText"), HideInInspector] + private Text oldHeaderText; +#pragma warning restore + + [SerializeField] + private TextMeshProUGUI m_HeaderText; + + public TextMeshProUGUI HeaderText + { + get + { + if (m_HeaderText == null) + { + if (oldHeaderText == null) + { + Debug.LogError("[DatePicker] An error ocurred while upgrading to TextMesh Pro - unable to locate original text element for a day header."); + return null; + } + + m_HeaderText = DatePicker_TextMeshProUtilities.ReplaceTextElementWithTextMeshPro(oldHeaderText); + + m_HeaderText.enableAutoSizing = true; + m_HeaderText.fontSizeMin = 2; + m_HeaderText.fontSizeMax = 16; + } + + return m_HeaderText; + } + } + + + public TableCell Cell; + } +} diff --git a/Assets/UI/DatePicker/DatePicker_DayHeader.cs.meta b/Assets/UI/DatePicker/DatePicker_DayHeader.cs.meta new file mode 100644 index 0000000..48d23dd --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_DayHeader.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 18a923d3d6950f942b48f9378fd1df80 +timeCreated: 1467802994 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_Enums.cs b/Assets/UI/DatePicker/DatePicker_Enums.cs new file mode 100644 index 0000000..7a120bc --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Enums.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.UI; +using UI.Tables; + +namespace UI.Dates +{ + public enum Animation + { + None, + Slide, + Fade + } + + public enum DatePickerPosition + { + Below, + Above + } + + public enum AnimationType + { + Show, + Hide + } + + public enum Alignment + { + Left, + Center, + Right + } + + public enum VisibleDateDefaultBehaviour + { + UseStoredValue, + UseTodaysDate + } + + public enum DateSelectionMode + { + SingleDate, + MultipleDates + } + + public enum WeekNumberMode + { + WeekOfMonth, + WeekOfYear + } + + public enum DatePickerDayButtonType + { + Today, + SelectedDay, + CurrentMonth, + OtherMonths + } +} diff --git a/Assets/UI/DatePicker/DatePicker_Enums.cs.meta b/Assets/UI/DatePicker/DatePicker_Enums.cs.meta new file mode 100644 index 0000000..a187744 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Enums.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 84b11e32f7d528d4786576c3f0d1048d +timeCreated: 1469020948 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_Header.cs b/Assets/UI/DatePicker/DatePicker_Header.cs new file mode 100644 index 0000000..fd06e57 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Header.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.Serialization; +using UnityEngine.UI; +using UI.Tables; +using TMPro; + +namespace UI.Dates +{ + public class DatePicker_Header : MonoBehaviour + { + #pragma warning disable + [SerializeField, FormerlySerializedAs("HeaderText")] + private Text oldHeaderText; + #pragma warning restore + + [SerializeField] + private TextMeshProUGUI m_HeaderText; + + public TextMeshProUGUI HeaderText + { + get + { + if (m_HeaderText == null) + { + if (oldHeaderText == null) + { + Debug.LogError("[DatePicker] An error ocurred while upgrading to TextMesh Pro - unable to locate original header text element."); + return null; + } + + m_HeaderText = DatePicker_TextMeshProUtilities.ReplaceTextElementWithTextMeshPro(oldHeaderText); + } + + return m_HeaderText; + } + } + + public DatePicker_Button PreviousMonthButton; + public DatePicker_Button NextMonthButton; + public DatePicker_Button PreviousYearButton; + public DatePicker_Button NextYearButton; + public Image Background; + public TableRow Row; + public TableLayout TableLayout; + } +} diff --git a/Assets/UI/DatePicker/DatePicker_Header.cs.meta b/Assets/UI/DatePicker/DatePicker_Header.cs.meta new file mode 100644 index 0000000..0cb688b --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_Header.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 59f0e0eff86cd8d4da0e663da0496ba0 +timeCreated: 1467815188 +licenseType: Store +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UI/DatePicker/DatePicker_HoldButton.cs b/Assets/UI/DatePicker/DatePicker_HoldButton.cs new file mode 100644 index 0000000..1bfa512 --- /dev/null +++ b/Assets/UI/DatePicker/DatePicker_HoldButton.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections; +using System.Globalization; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using UI.Tables; + +namespace UI.Dates +{ + /// + /// A special button which responds when held down + /// Note: These are intended to supplement the existing Next/Previous buttons, + /// and as such, they require that the existing buttons already have an event handler defined + /// (which this component will then extract and replace at runtime) + /// + public class DatePicker_HoldButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler + { + public Button Button; + public float Delay = 0.5f; + + private bool pointerDown = false; + private Action action; + private float lastInvokeTime = 0; + private int executionCount = 0; + + void Start() + { + Button = this.GetComponent