From baf604837704b4e62d5eef17b3417d222a5bdec7 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 3 Feb 2023 11:22:41 -0600 Subject: [PATCH 01/16] Added Play, pause, and stop functions to particle effect for more manual control if needed. --- Source/Engine/Particles/ParticleEffect.cpp | 45 ++++++++++++++++++++++ Source/Engine/Particles/ParticleEffect.h | 32 ++++++++++++++- 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 4b7923439..6b7346de3 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -275,6 +275,30 @@ void ParticleEffect::UpdateSimulation(bool singleFrame) Particles::UpdateEffect(this); } +void ParticleEffect::Play(bool reset) +{ + _play = true; + IsPlaying = true; + + if (reset) + ResetSimulation(); + else + UpdateSimulation(true); +} + +void ParticleEffect::Pause() +{ + _play = false; + IsPlaying = false; +} + +void ParticleEffect::Stop() +{ + _play = false; + IsPlaying = false; + ResetSimulation(); +} + void ParticleEffect::UpdateBounds() { BoundingBox bounds = BoundingBox::Empty; @@ -395,6 +419,9 @@ void ParticleEffect::SetParametersOverrides(const Array& valu void ParticleEffect::Update() { + if (!_play) + return; + // Skip if off-screen if (!UpdateWhenOffscreen && _lastMinDstSqr >= MAX_Real) return; @@ -417,7 +444,14 @@ void ParticleEffect::Update() void ParticleEffect::UpdateExecuteInEditor() { if (!Editor::IsPlayMode) + { + // Always Play in editor while not playing. + // Could be useful to have a GUI to change this state + if (!_play) + _play = true; + Update(); + } } #endif @@ -576,6 +610,7 @@ void ParticleEffect::Serialize(SerializeStream& stream, const void* otherObj) SERIALIZE(SimulationSpeed); SERIALIZE(UseTimeScale); SERIALIZE(IsLooping); + SERIALIZE(PlayOnStart); SERIALIZE(UpdateWhenOffscreen); SERIALIZE(DrawModes); SERIALIZE(SortOrder); @@ -675,6 +710,7 @@ void ParticleEffect::Deserialize(DeserializeStream& stream, ISerializeModifier* DESERIALIZE(SimulationSpeed); DESERIALIZE(UseTimeScale); DESERIALIZE(IsLooping); + DESERIALIZE(PlayOnStart); DESERIALIZE(UpdateWhenOffscreen); DESERIALIZE(DrawModes); DESERIALIZE(SortOrder); @@ -685,6 +721,12 @@ void ParticleEffect::Deserialize(DeserializeStream& stream, ISerializeModifier* } } +void ParticleEffect::BeginPlay(SceneBeginData* data) +{ + + Actor::BeginPlay(data); +} + void ParticleEffect::EndPlay() { CacheModifiedParameters(); @@ -706,6 +748,9 @@ void ParticleEffect::OnEnable() GetScene()->Ticking.Update.AddTickExecuteInEditor(this); #endif + if (PlayOnStart) + Play(); + // Base Actor::OnEnable(); } diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index 3487a35f4..a88628ccd 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -184,6 +184,7 @@ private: uint32 _parametersVersion = 0; // Version number for _parameters to be in sync with Instance.ParametersVersion Array _parameters; // Cached for scripting API Array _parametersOverrides; // Cached parameter modifications to be applied to the parameters + bool _play = false; public: /// @@ -235,9 +236,21 @@ public: bool IsLooping = true; /// - /// If true, the particle simulation will be updated even when an actor cannot be seen by any camera. Otherwise, the simulation will stop running when the actor is off-screen. + /// Determines whether the particle effect should play on start. /// API_FIELD(Attributes="EditorDisplay(\"Particle Effect\"), DefaultValue(true), EditorOrder(60)") + bool PlayOnStart = true; + + /// + /// If true, the particle effect is playing. + /// + API_FIELD() + bool IsPlaying = false; + + /// + /// If true, the particle simulation will be updated even when an actor cannot be seen by any camera. Otherwise, the simulation will stop running when the actor is off-screen. + /// + API_FIELD(Attributes="EditorDisplay(\"Particle Effect\"), DefaultValue(true), EditorOrder(70)") bool UpdateWhenOffscreen = true; /// @@ -337,6 +350,22 @@ public: /// True if update animation by a single frame only (time time since last engine update), otherwise will update simulation with delta time since last update. API_FUNCTION() void UpdateSimulation(bool singleFrame = false); + /// + /// Plays the simulation. + /// + /// /// If true, the simulation will be reset + API_FUNCTION() void Play(bool reset = true); + + /// + /// Pauses the simulation. + /// + API_FUNCTION() void Pause(); + + /// + /// Stops and resets the simulation. + /// + API_FUNCTION() void Stop(); + /// /// Updates the actor bounds. /// @@ -389,6 +418,7 @@ public: protected: // [Actor] + void BeginPlay(SceneBeginData* data) override; void EndPlay() override; void OnEnable() override; void OnDisable() override; From 2d98a46d94b2af98d4c389d72a52d5f09400540d Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 3 Feb 2023 11:27:11 -0600 Subject: [PATCH 02/16] Clean up code --- Source/Engine/Particles/ParticleEffect.cpp | 6 ------ Source/Engine/Particles/ParticleEffect.h | 1 - 2 files changed, 7 deletions(-) diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 6b7346de3..2e76ea65b 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -721,12 +721,6 @@ void ParticleEffect::Deserialize(DeserializeStream& stream, ISerializeModifier* } } -void ParticleEffect::BeginPlay(SceneBeginData* data) -{ - - Actor::BeginPlay(data); -} - void ParticleEffect::EndPlay() { CacheModifiedParameters(); diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index a88628ccd..832327935 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -418,7 +418,6 @@ public: protected: // [Actor] - void BeginPlay(SceneBeginData* data) override; void EndPlay() override; void OnEnable() override; void OnDisable() override; From dbee9f681652f059640a02dc1ac9bab9ef82a5df Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 3 Feb 2023 12:11:18 -0600 Subject: [PATCH 03/16] Small fix --- Source/Engine/Particles/ParticleEffect.cpp | 11 ++++++++--- Source/Engine/Particles/ParticleEffect.h | 12 ++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 2e76ea65b..04fd6eedb 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -253,6 +253,11 @@ int32 ParticleEffect::GetParticlesCount() const return Instance.GetParticlesCount(); } +bool ParticleEffect::GetIsPlaying() const +{ + return _isPlaying; +} + void ParticleEffect::ResetSimulation() { Instance.ClearState(); @@ -278,7 +283,7 @@ void ParticleEffect::UpdateSimulation(bool singleFrame) void ParticleEffect::Play(bool reset) { _play = true; - IsPlaying = true; + _isPlaying = true; if (reset) ResetSimulation(); @@ -289,13 +294,13 @@ void ParticleEffect::Play(bool reset) void ParticleEffect::Pause() { _play = false; - IsPlaying = false; + _isPlaying = false; } void ParticleEffect::Stop() { _play = false; - IsPlaying = false; + _isPlaying = false; ResetSimulation(); } diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index 832327935..5a4bae771 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -185,6 +185,7 @@ private: Array _parameters; // Cached for scripting API Array _parametersOverrides; // Cached parameter modifications to be applied to the parameters bool _play = false; + bool _isPlaying = false; public: /// @@ -241,12 +242,6 @@ public: API_FIELD(Attributes="EditorDisplay(\"Particle Effect\"), DefaultValue(true), EditorOrder(60)") bool PlayOnStart = true; - /// - /// If true, the particle effect is playing. - /// - API_FIELD() - bool IsPlaying = false; - /// /// If true, the particle simulation will be updated even when an actor cannot be seen by any camera. Otherwise, the simulation will stop running when the actor is off-screen. /// @@ -339,6 +334,11 @@ public: /// API_PROPERTY() int32 GetParticlesCount() const; + /// + /// Gets whether or not the particle effect is playing. + /// + API_PROPERTY(Attributes="NoSerialize, HideInEditor") bool GetIsPlaying() const; + /// /// Resets the particles simulation state (clears the instance state data but preserves the instance parameters values). /// From f3b2011feff8c82742d2041f7a5055c9f330fc9f Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 4 Feb 2023 08:25:07 -0600 Subject: [PATCH 04/16] Small fix --- Source/Engine/Particles/ParticleEffect.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 04fd6eedb..651ff719b 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -453,7 +453,10 @@ void ParticleEffect::UpdateExecuteInEditor() // Always Play in editor while not playing. // Could be useful to have a GUI to change this state if (!_play) - _play = true; + { + _play = true; + _isPlaying = true; + } Update(); } From 2b59cbf0f14387a76652a528313a1d9e9e56f25f Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 10 May 2023 07:43:40 -0500 Subject: [PATCH 05/16] Organize the style groups of UI controls --- Source/Engine/UI/GUI/Common/Button.cs | 78 +++++++++++----------- Source/Engine/UI/GUI/Common/CheckBox.cs | 20 +++--- Source/Engine/UI/GUI/Common/Dropdown.cs | 26 ++++---- Source/Engine/UI/GUI/Common/Image.cs | 6 +- Source/Engine/UI/GUI/Common/Label.cs | 14 ++-- Source/Engine/UI/GUI/Common/ProgressBar.cs | 6 +- Source/Engine/UI/GUI/Common/TextBox.cs | 12 ++-- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 14 ++-- Source/Engine/UI/GUI/Control.cs | 2 +- Source/Engine/UI/GUI/Panels/DropPanel.cs | 70 +++++++++---------- 10 files changed, 125 insertions(+), 123 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/Button.cs b/Source/Engine/UI/GUI/Common/Button.cs index 0e0d29615..41ea3a0d4 100644 --- a/Source/Engine/UI/GUI/Common/Button.cs +++ b/Source/Engine/UI/GUI/Common/Button.cs @@ -42,7 +42,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the font used to draw button text. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Text Style"), EditorOrder(2022), ExpandGroups] public FontReference Font { get => _font; @@ -52,14 +52,50 @@ namespace FlaxEngine.GUI /// /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] + [EditorDisplay("Text Style"), EditorOrder(2021), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] public MaterialBase TextMaterial { get; set; } /// /// Gets or sets the color used to draw button text. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Text Style"), EditorOrder(2020)] public Color TextColor; + + /// + /// Gets or sets the brush used for background drawing. + /// + [EditorDisplay("Background Style"), EditorOrder(1999), Tooltip("The brush used for background drawing."), ExpandGroups] + public IBrush BackgroundBrush { get; set; } + + /// + /// Gets or sets the background color when button is highlighted. + /// + [EditorDisplay("Background Style"), EditorOrder(2001)] + public Color BackgroundColorHighlighted { get; set; } + + /// + /// Gets or sets the background color when button is selected. + /// + [EditorDisplay("Background Style"), EditorOrder(2002)] + public Color BackgroundColorSelected { get; set; } + + /// + /// Gets or sets the color of the border. + /// + [EditorDisplay("Border Style"), EditorOrder(2010), ExpandGroups] + public Color BorderColor { get; set; } + + /// + /// Gets or sets the border color when button is highlighted. + /// + [EditorDisplay("Border Style"), EditorOrder(2011)] + public Color BorderColorHighlighted { get; set; } + + /// + /// Gets or sets the border color when button is selected. + /// + [EditorDisplay("Border Style"), EditorOrder(2012)] + public Color BorderColorSelected { get; set; } /// /// Event fired when user clicks on the button. @@ -81,42 +117,6 @@ namespace FlaxEngine.GUI /// public event Action HoverEnd; - /// - /// Gets or sets the brush used for background drawing. - /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The brush used for background drawing.")] - public IBrush BackgroundBrush { get; set; } - - /// - /// Gets or sets the color of the border. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public Color BorderColor { get; set; } - - /// - /// Gets or sets the background color when button is selected. - /// - [EditorDisplay("Style"), EditorOrder(2010)] - public Color BackgroundColorSelected { get; set; } - - /// - /// Gets or sets the border color when button is selected. - /// - [EditorDisplay("Style"), EditorOrder(2020)] - public Color BorderColorSelected { get; set; } - - /// - /// Gets or sets the background color when button is highlighted. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public Color BackgroundColorHighlighted { get; set; } - - /// - /// Gets or sets the border color when button is highlighted. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public Color BorderColorHighlighted { get; set; } - /// /// Gets a value indicating whether this button is being pressed (by mouse or touch). /// diff --git a/Source/Engine/UI/GUI/Common/CheckBox.cs b/Source/Engine/UI/GUI/Common/CheckBox.cs index ab689bfc3..0f197422b 100644 --- a/Source/Engine/UI/GUI/Common/CheckBox.cs +++ b/Source/Engine/UI/GUI/Common/CheckBox.cs @@ -107,34 +107,34 @@ namespace FlaxEngine.GUI } } - /// - /// Gets or sets the color of the checkbox icon. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public Color ImageColor { get; set; } - /// /// Gets or sets the color of the border. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Border Style"), EditorOrder(2010), ExpandGroups] public Color BorderColor { get; set; } /// /// Gets or sets the border color when checkbox is hovered. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Border Style"), EditorOrder(2011)] public Color BorderColorHighlighted { get; set; } + + /// + /// Gets or sets the color of the checkbox icon. + /// + [EditorDisplay("Image Style"), EditorOrder(2020), ExpandGroups] + public Color ImageColor { get; set; } /// /// Gets or sets the image used to render checkbox checked state. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The image used to render checkbox checked state.")] + [EditorDisplay("Image Style"), EditorOrder(2021), Tooltip("The image used to render checkbox checked state.")] public IBrush CheckedImage { get; set; } /// /// Gets or sets the image used to render checkbox intermediate state. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The image used to render checkbox intermediate state.")] + [EditorDisplay("Image Style"), EditorOrder(2022), Tooltip("The image used to render checkbox intermediate state.")] public IBrush IntermediateImage { get; set; } /// diff --git a/Source/Engine/UI/GUI/Common/Dropdown.cs b/Source/Engine/UI/GUI/Common/Dropdown.cs index 80d4beb02..6ad962d6d 100644 --- a/Source/Engine/UI/GUI/Common/Dropdown.cs +++ b/Source/Engine/UI/GUI/Common/Dropdown.cs @@ -246,79 +246,79 @@ namespace FlaxEngine.GUI /// /// Gets or sets the font used to draw text. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Text Style"), EditorOrder(2021)] public FontReference Font { get; set; } /// /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] + [EditorDisplay("Text Style"), EditorOrder(2022), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] public MaterialBase FontMaterial { get; set; } /// /// Gets or sets the color of the text. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Text Style"), EditorOrder(2020), ExpandGroups] public Color TextColor { get; set; } /// /// Gets or sets the color of the border. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Border Style"), EditorOrder(2010), ExpandGroups] public Color BorderColor { get; set; } /// /// Gets or sets the background color when dropdown popup is opened. /// - [EditorDisplay("Style"), EditorOrder(2010)] + [EditorDisplay("Background Style"), EditorOrder(2002)] public Color BackgroundColorSelected { get; set; } /// /// Gets or sets the border color when dropdown popup is opened. /// - [EditorDisplay("Style"), EditorOrder(2020)] + [EditorDisplay("Border Style"), EditorOrder(2012)] public Color BorderColorSelected { get; set; } /// /// Gets or sets the background color when dropdown is highlighted. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Background Style"), EditorOrder(2001), ExpandGroups] public Color BackgroundColorHighlighted { get; set; } /// /// Gets or sets the border color when dropdown is highlighted. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Border Style"), EditorOrder(2011)] public Color BorderColorHighlighted { get; set; } /// /// Gets or sets the image used to render dropdown drop arrow icon. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The image used to render dropdown drop arrow icon.")] + [EditorDisplay("Icon Style"), EditorOrder(2033), Tooltip("The image used to render dropdown drop arrow icon.")] public IBrush ArrowImage { get; set; } /// /// Gets or sets the color used to render dropdown drop arrow icon. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color used to render dropdown drop arrow icon.")] + [EditorDisplay("Icon Style"), EditorOrder(2030), Tooltip("The color used to render dropdown drop arrow icon."), ExpandGroups] public Color ArrowColor { get; set; } /// /// Gets or sets the color used to render dropdown drop arrow icon (menu is opened). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color used to render dropdown drop arrow icon (menu is opened).")] + [EditorDisplay("Icon Style"), EditorOrder(2032), Tooltip("The color used to render dropdown drop arrow icon (menu is opened).")] public Color ArrowColorSelected { get; set; } /// /// Gets or sets the color used to render dropdown drop arrow icon (menu is highlighted). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color used to render dropdown drop arrow icon (menu is highlighted).")] + [EditorDisplay("Icon Style"), EditorOrder(2031), Tooltip("The color used to render dropdown drop arrow icon (menu is highlighted).")] public Color ArrowColorHighlighted { get; set; } /// /// Gets or sets the image used to render dropdown checked item icon. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The image used to render dropdown checked item icon.")] + [EditorDisplay("Icon Style"), EditorOrder(2034), Tooltip("The image used to render dropdown checked item icon.")] public IBrush CheckedImage { get; set; } /// diff --git a/Source/Engine/UI/GUI/Common/Image.cs b/Source/Engine/UI/GUI/Common/Image.cs index 98113b00c..f911664f6 100644 --- a/Source/Engine/UI/GUI/Common/Image.cs +++ b/Source/Engine/UI/GUI/Common/Image.cs @@ -25,19 +25,19 @@ namespace FlaxEngine.GUI /// /// Gets or sets the color used to multiply the image pixels. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Image Style"), EditorOrder(2010), ExpandGroups] public Color Color { get; set; } = Color.White; /// /// Gets or sets the color used to multiply the image pixels when mouse is over the image. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Image Style"), EditorOrder(2011)] public Color MouseOverColor { get; set; } = Color.White; /// /// Gets or sets the color used to multiply the image pixels when control is disabled. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Image Style"), EditorOrder(2012)] public Color DisabledTint { get; set; } = Color.Gray; /// diff --git a/Source/Engine/UI/GUI/Common/Label.cs b/Source/Engine/UI/GUI/Common/Label.cs index b64764a40..2779dfdea 100644 --- a/Source/Engine/UI/GUI/Common/Label.cs +++ b/Source/Engine/UI/GUI/Common/Label.cs @@ -47,37 +47,37 @@ namespace FlaxEngine.GUI /// /// Gets or sets the color of the text. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the text.")] + [EditorDisplay("Text Style"), EditorOrder(2010), Tooltip("The color of the text."), ExpandGroups] public Color TextColor { get; set; } /// /// Gets or sets the color of the text when it is highlighted (mouse is over). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the text when it is highlighted (mouse is over).")] + [EditorDisplay("Text Style"), EditorOrder(2011), Tooltip("The color of the text when it is highlighted (mouse is over).")] public Color TextColorHighlighted { get; set; } /// /// Gets or sets the horizontal text alignment within the control bounds. /// - [EditorDisplay("Style"), EditorOrder(2010), Tooltip("The horizontal text alignment within the control bounds.")] + [EditorDisplay("Text Style"), EditorOrder(2020), Tooltip("The horizontal text alignment within the control bounds.")] public TextAlignment HorizontalAlignment { get; set; } = TextAlignment.Center; /// /// Gets or sets the vertical text alignment within the control bounds. /// - [EditorDisplay("Style"), EditorOrder(2020), Tooltip("The vertical text alignment within the control bounds.")] + [EditorDisplay("Text Style"), EditorOrder(2021), Tooltip("The vertical text alignment within the control bounds.")] public TextAlignment VerticalAlignment { get; set; } = TextAlignment.Center; /// /// Gets or sets the text wrapping within the control bounds. /// - [EditorDisplay("Style"), EditorOrder(2030), Tooltip("The text wrapping within the control bounds.")] + [EditorDisplay("Text Style"), EditorOrder(2022), Tooltip("The text wrapping within the control bounds.")] public TextWrapping Wrapping { get; set; } = TextWrapping.NoWrap; /// /// Gets or sets the font. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Text Style"), EditorOrder(2023)] public FontReference Font { get => _font; @@ -99,7 +99,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Text Style"), EditorOrder(2024)] public MaterialBase Material { get; set; } /// diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index fa76d9d26..a742d3b43 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -99,19 +99,19 @@ namespace FlaxEngine.GUI /// /// Gets or sets the margin for the progress bar rectangle within the control bounds. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The margin for the progress bar rectangle within the control bounds.")] + [EditorDisplay("Bar Style"), EditorOrder(2011), Tooltip("The margin for the progress bar rectangle within the control bounds.")] public Margin BarMargin { get; set; } /// /// Gets or sets the color of the progress bar rectangle. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the progress bar rectangle.")] + [EditorDisplay("Bar Style"), EditorOrder(2010), Tooltip("The color of the progress bar rectangle."), ExpandGroups] public Color BarColor { get; set; } /// /// Gets or sets the brush used for progress bar drawing. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The brush used for progress bar drawing.")] + [EditorDisplay("Bar Style"), EditorOrder(2012), Tooltip("The brush used for progress bar drawing.")] public IBrush BarBrush { get; set; } /// diff --git a/Source/Engine/UI/GUI/Common/TextBox.cs b/Source/Engine/UI/GUI/Common/TextBox.cs index 00c381e01..5ec86a94e 100644 --- a/Source/Engine/UI/GUI/Common/TextBox.cs +++ b/Source/Engine/UI/GUI/Common/TextBox.cs @@ -27,7 +27,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the text wrapping within the control bounds. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The text wrapping within the control bounds.")] + [EditorDisplay("Text Style"), EditorOrder(2023), Tooltip("The text wrapping within the control bounds.")] public TextWrapping Wrapping { get => _layout.TextWrapping; @@ -37,31 +37,31 @@ namespace FlaxEngine.GUI /// /// Gets or sets the font. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorDisplay("Text Style"), EditorOrder(2024)] public FontReference Font { get; set; } /// /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] + [EditorDisplay("Text Style"), EditorOrder(2025), Tooltip("Custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] public MaterialBase TextMaterial { get; set; } /// /// Gets or sets the color of the text. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the text.")] + [EditorDisplay("Text Style"), EditorOrder(2020), Tooltip("The color of the text."), ExpandGroups] public Color TextColor { get; set; } /// /// Gets or sets the color of the text. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the watermark text.")] + [EditorDisplay("Text Style"), EditorOrder(2021), Tooltip("The color of the watermark text.")] public Color WatermarkTextColor { get; set; } /// /// Gets or sets the color of the selection (Transparent if not used). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the selection (Transparent if not used).")] + [EditorDisplay("Text Style"), EditorOrder(2022), Tooltip("The color of the selection (Transparent if not used).")] public Color SelectionColor { get; set; } /// diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index fb130bf18..9619f98bd 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -243,42 +243,43 @@ namespace FlaxEngine.GUI /// /// Gets or sets a value indicating whether you can scroll the text in the text box (eg. with a mouse wheel). /// + [EditorOrder(41)] public bool IsMultilineScrollable { get; set; } = true; /// /// Gets or sets textbox background color when the control is selected (has focus). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The textbox background color when the control is selected (has focus).")] + [EditorDisplay("Background Style"), EditorOrder(2001), Tooltip("The textbox background color when the control is selected (has focus)."), ExpandGroups] public Color BackgroundSelectedColor { get; set; } /// /// Gets or sets the color of the caret (Transparent if not used). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the caret (Transparent if not used).")] + [EditorDisplay("Caret Style"), EditorOrder(2020), Tooltip("The color of the caret (Transparent if not used)."), ExpandGroups] public Color CaretColor { get; set; } /// /// Gets or sets the speed of the caret flashing animation. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The speed of the caret flashing animation.")] + [EditorDisplay("Caret Style"), EditorOrder(2021), Tooltip("The speed of the caret flashing animation.")] public float CaretFlashSpeed { get; set; } = 6.0f; /// /// Gets or sets the speed of the selection background flashing animation. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The speed of the selection background flashing animation.")] + [EditorDisplay("Background Style"), EditorOrder(2002), Tooltip("The speed of the selection background flashing animation.")] public float BackgroundSelectedFlashSpeed { get; set; } = 6.0f; /// /// Gets or sets the color of the border (Transparent if not used). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the border (Transparent if not used).")] + [EditorDisplay("Border Style"), EditorOrder(2010), Tooltip("The color of the border (Transparent if not used)."), ExpandGroups] public Color BorderColor { get; set; } /// /// Gets or sets the color of the border when control is focused (Transparent if not used). /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The color of the border when control is focused (Transparent if not used)")] + [EditorDisplay("Border Style"), EditorOrder(2011), Tooltip("The color of the border when control is focused (Transparent if not used)")] public Color BorderSelectedColor { get; set; } /// @@ -409,6 +410,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the selection range. /// + [EditorOrder(50)] public TextRange SelectionRange { get => new TextRange(SelectionLeft, SelectionRight); diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs index 427c1aa8f..49b7f65d3 100644 --- a/Source/Engine/UI/GUI/Control.cs +++ b/Source/Engine/UI/GUI/Control.cs @@ -166,7 +166,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets control background color (transparent color (alpha=0) means no background rendering) /// - [ExpandGroups, EditorDisplay("Style"), EditorOrder(2000), Tooltip("The control background color. Use transparent color (alpha=0) to hide background.")] + [ExpandGroups, EditorDisplay("Background Style"), EditorOrder(2000), Tooltip("The control background color. Use transparent color (alpha=0) to hide background.")] public Color BackgroundColor { get => _backgroundColor; diff --git a/Source/Engine/UI/GUI/Panels/DropPanel.cs b/Source/Engine/UI/GUI/Panels/DropPanel.cs index 409209549..9662f61b9 100644 --- a/Source/Engine/UI/GUI/Panels/DropPanel.cs +++ b/Source/Engine/UI/GUI/Panels/DropPanel.cs @@ -94,49 +94,49 @@ namespace FlaxEngine.GUI } } } - - /// - /// Gets or sets the color used to draw header text. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public Color HeaderTextColor; - - /// - /// Gets or sets the color of the header. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public Color HeaderColor { get; set; } - - /// - /// Gets or sets the color of the header when mouse is over. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public Color HeaderColorMouseOver { get; set; } - - /// - /// Gets or sets the font used to render panel header text. - /// - [EditorDisplay("Style"), EditorOrder(2000)] - public FontReference HeaderTextFont { get; set; } - - /// - /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. - /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("Custom material used to render the header text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] - public MaterialBase HeaderTextMaterial { get; set; } - + /// /// Gets or sets a value indicating whether enable drop down icon drawing. /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorOrder(1)] public bool EnableDropDownIcon { get; set; } /// /// Gets or sets a value indicating whether to enable containment line drawing, /// - [EditorDisplay("Style"), EditorOrder(2000)] + [EditorOrder(2)] public bool EnableContainmentLines { get; set; } = false; + /// + /// Gets or sets the color used to draw header text. + /// + [EditorDisplay("Header Style"), EditorOrder(2010), ExpandGroups] + public Color HeaderTextColor; + + /// + /// Gets or sets the color of the header. + /// + [EditorDisplay("Header Style"), EditorOrder(2011)] + public Color HeaderColor { get; set; } + + /// + /// Gets or sets the color of the header when mouse is over. + /// + [EditorDisplay("Header Style"), EditorOrder(2012)] + public Color HeaderColorMouseOver { get; set; } + + /// + /// Gets or sets the font used to render panel header text. + /// + [EditorDisplay("Header Text Style"), EditorOrder(2020), ExpandGroups] + public FontReference HeaderTextFont { get; set; } + + /// + /// Gets or sets the custom material used to render the text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data. + /// + [EditorDisplay("Header Text Style"), EditorOrder(2021), Tooltip("Custom material used to render the header text. It must has domain set to GUI and have a public texture parameter named Font used to sample font atlas texture with font characters data.")] + public MaterialBase HeaderTextMaterial { get; set; } + /// /// Occurs when mouse right-clicks over the header. /// @@ -192,13 +192,13 @@ namespace FlaxEngine.GUI /// /// Gets or sets the image used to render drop panel drop arrow icon when panel is opened. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The image used to render drop panel drop arrow icon when panel is opened.")] + [EditorDisplay("Icon Style"), EditorOrder(2030), Tooltip("The image used to render drop panel drop arrow icon when panel is opened."), ExpandGroups] public IBrush ArrowImageOpened { get; set; } /// /// Gets or sets the image used to render drop panel drop arrow icon when panel is closed. /// - [EditorDisplay("Style"), EditorOrder(2000), Tooltip("The image used to render drop panel drop arrow icon when panel is closed.")] + [EditorDisplay("Icon Style"), EditorOrder(2031), Tooltip("The image used to render drop panel drop arrow icon when panel is closed.")] public IBrush ArrowImageClosed { get; set; } /// From eeaf7eb733b31b9b45ca74a8dcc127c5f329a3c5 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 10 May 2023 08:04:47 -0500 Subject: [PATCH 06/16] Move BoxSize --- Source/Engine/UI/GUI/Common/CheckBox.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Engine/UI/GUI/Common/CheckBox.cs b/Source/Engine/UI/GUI/Common/CheckBox.cs index 0f197422b..c5a6e3bb3 100644 --- a/Source/Engine/UI/GUI/Common/CheckBox.cs +++ b/Source/Engine/UI/GUI/Common/CheckBox.cs @@ -97,6 +97,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the size of the box. /// + [EditorOrder(20)] public float BoxSize { get => _boxSize; From f80ded20573a6f1d85e79fd42bee1696d47567a0 Mon Sep 17 00:00:00 2001 From: Olly Rybak Date: Thu, 11 May 2023 17:30:20 +1000 Subject: [PATCH 07/16] Initial setup --- Source/Engine/Input/Enums.h | 25 +++++++++++++++++++++++++ Source/Engine/Input/Input.cpp | 20 ++++++++++++++++++++ Source/Engine/Input/Input.h | 8 ++++++++ Source/Engine/Input/VirtualInput.h | 3 +++ 4 files changed, 56 insertions(+) diff --git a/Source/Engine/Input/Enums.h b/Source/Engine/Input/Enums.h index 80e10786f..272231e41 100644 --- a/Source/Engine/Input/Enums.h +++ b/Source/Engine/Input/Enums.h @@ -263,6 +263,31 @@ API_ENUM() enum class InputActionMode Release = 2, }; +/// +/// The input action event trigger modes. +/// +API_ENUM() enum class InputActionPhase +{ + /// + /// User is pressing the key/button. + /// + Pressing = 0, + + /// + /// User pressed the key/button (but wasn't pressing it in the previous frame). + /// + Press = 1, + + /// + /// User released the key/button (was pressing it in the previous frame). + /// + Release = 2, + + Waiting = 3, + + None = 4, +}; + /// /// The input gamepad index. /// diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 7a4547c62..32a672635 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -29,11 +29,13 @@ struct ActionData { bool Active; uint64 FrameIndex; + InputActionPhase Phase; ActionData() { Active = false; FrameIndex = 0; + Phase = InputActionPhase::None; } }; @@ -597,6 +599,16 @@ bool Input::GetAction(const StringView& name) return e ? e->Active : false; } +InputActionPhase Input::GetActionPhase(const StringView& name) +{ + const auto e = Actions.TryGet(name); + if (e != nullptr) + { + return e->Phase; + } + return InputActionPhase::None; +} + float Input::GetAxis(const StringView& name) { const auto e = Axes.TryGet(name); @@ -806,6 +818,7 @@ void InputService::Update() ActionData& data = Actions[name]; data.Active = false; + data.Phase = InputActionPhase::Waiting; // Mark as updated in this frame data.FrameIndex = frame; @@ -830,6 +843,13 @@ void InputService::Update() isActive = Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton); } + if (Input::GetKeyDown(config.Key) || Input::GetMouseButtonDown(config.MouseButton) || Input::GetGamepadButtonDown(config.Gamepad, config.GamepadButton)) + data.Phase = InputActionPhase::Press; + else if (Input::GetKey(config.Key) || Input::GetMouseButton(config.MouseButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadButton)) + data.Phase = InputActionPhase::Pressing; + else if (Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton)) + data.Phase = InputActionPhase::Release; + data.Active |= isActive; } diff --git a/Source/Engine/Input/Input.h b/Source/Engine/Input/Input.h index d9f86076b..dd40c485a 100644 --- a/Source/Engine/Input/Input.h +++ b/Source/Engine/Input/Input.h @@ -309,6 +309,14 @@ public: /// API_FUNCTION() static bool GetAction(const StringView& name); + /// + /// Gets the value of the virtual action identified by name. Use to get the current config. + /// + /// The action name. + /// True if action has been triggered in the current frame (e.g. button pressed), otherwise false. + /// + API_FUNCTION() static InputActionPhase GetActionPhase(const StringView& name); + /// /// Gets the value of the virtual axis identified by name. Use to get the current config. /// diff --git a/Source/Engine/Input/VirtualInput.h b/Source/Engine/Input/VirtualInput.h index 8fd4efeb4..e8f669632 100644 --- a/Source/Engine/Input/VirtualInput.h +++ b/Source/Engine/Input/VirtualInput.h @@ -48,6 +48,9 @@ API_STRUCT() struct ActionConfig /// API_FIELD(Attributes="EditorOrder(40)") InputGamepadIndex Gamepad; + + API_FIELD(Attributes = "EditorOrder(50)") + InputActionMode Phase; }; /// From 395a72b7d45fc8d50be120cef62a277aff7efa13 Mon Sep 17 00:00:00 2001 From: Olly Rybak Date: Thu, 11 May 2023 21:10:40 +1000 Subject: [PATCH 08/16] Added comments / reformat --- Source/Engine/Input/Enums.h | 22 ++++++++++++++-------- Source/Engine/Input/Input.cpp | 10 ++++++++-- Source/Engine/Input/Input.h | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Source/Engine/Input/Enums.h b/Source/Engine/Input/Enums.h index 272231e41..4c96f715f 100644 --- a/Source/Engine/Input/Enums.h +++ b/Source/Engine/Input/Enums.h @@ -264,28 +264,34 @@ API_ENUM() enum class InputActionMode }; /// -/// The input action event trigger modes. +/// The input action event phases. /// API_ENUM() enum class InputActionPhase { + /// + /// The key/button is not assigned. + /// + None = 0, + + /// + /// The key/button is waiting for input. + /// + Waiting = 1, + /// /// User is pressing the key/button. /// - Pressing = 0, + Pressing = 2, /// /// User pressed the key/button (but wasn't pressing it in the previous frame). /// - Press = 1, + Press = 3, /// /// User released the key/button (was pressing it in the previous frame). /// - Release = 2, - - Waiting = 3, - - None = 4, + Release = 4, }; /// diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 32a672635..2f45a4a16 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -25,7 +25,7 @@ struct AxisEvaluation bool Used; }; -struct ActionData +struct ActionData { bool Active; uint64 FrameIndex; @@ -35,7 +35,7 @@ struct ActionData { Active = false; FrameIndex = 0; - Phase = InputActionPhase::None; + Phase = InputActionPhase::Waiting; } }; @@ -844,11 +844,17 @@ void InputService::Update() } if (Input::GetKeyDown(config.Key) || Input::GetMouseButtonDown(config.MouseButton) || Input::GetGamepadButtonDown(config.Gamepad, config.GamepadButton)) + { data.Phase = InputActionPhase::Press; + } else if (Input::GetKey(config.Key) || Input::GetMouseButton(config.MouseButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadButton)) + { data.Phase = InputActionPhase::Pressing; + } else if (Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton)) + { data.Phase = InputActionPhase::Release; + } data.Active |= isActive; } diff --git a/Source/Engine/Input/Input.h b/Source/Engine/Input/Input.h index dd40c485a..35f3dac32 100644 --- a/Source/Engine/Input/Input.h +++ b/Source/Engine/Input/Input.h @@ -313,7 +313,7 @@ public: /// Gets the value of the virtual action identified by name. Use to get the current config. /// /// The action name. - /// True if action has been triggered in the current frame (e.g. button pressed), otherwise false. + /// A InputActionPhase determining the current phase of the Action (e.g If it was just pressed, is being held or just released). /// API_FUNCTION() static InputActionPhase GetActionPhase(const StringView& name); From d5237715a5b14cec7321b2cc8006c5d73481a540 Mon Sep 17 00:00:00 2001 From: Olly Rybak Date: Thu, 11 May 2023 21:12:03 +1000 Subject: [PATCH 09/16] Removed unused field --- Source/Engine/Input/VirtualInput.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Engine/Input/VirtualInput.h b/Source/Engine/Input/VirtualInput.h index e8f669632..8fd4efeb4 100644 --- a/Source/Engine/Input/VirtualInput.h +++ b/Source/Engine/Input/VirtualInput.h @@ -48,9 +48,6 @@ API_STRUCT() struct ActionConfig /// API_FIELD(Attributes="EditorOrder(40)") InputGamepadIndex Gamepad; - - API_FIELD(Attributes = "EditorOrder(50)") - InputActionMode Phase; }; /// From 4b4bf833a93fb6d2d28994f1f700b54ed16a9bae Mon Sep 17 00:00:00 2001 From: Olly Rybak Date: Fri, 12 May 2023 00:25:03 +1000 Subject: [PATCH 10/16] Rename Phase > State --- Source/Engine/Input/Enums.h | 2 +- Source/Engine/Input/Input.cpp | 16 ++++++++-------- Source/Engine/Input/Input.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Engine/Input/Enums.h b/Source/Engine/Input/Enums.h index 4c96f715f..82498f500 100644 --- a/Source/Engine/Input/Enums.h +++ b/Source/Engine/Input/Enums.h @@ -266,7 +266,7 @@ API_ENUM() enum class InputActionMode /// /// The input action event phases. /// -API_ENUM() enum class InputActionPhase +API_ENUM() enum class InputActionState { /// /// The key/button is not assigned. diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 2f45a4a16..b22efa4fc 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -29,13 +29,13 @@ struct ActionData { bool Active; uint64 FrameIndex; - InputActionPhase Phase; + InputActionState Phase; ActionData() { Active = false; FrameIndex = 0; - Phase = InputActionPhase::Waiting; + Phase = InputActionState::Waiting; } }; @@ -599,14 +599,14 @@ bool Input::GetAction(const StringView& name) return e ? e->Active : false; } -InputActionPhase Input::GetActionPhase(const StringView& name) +InputActionState Input::GetActionState(const StringView& name) { const auto e = Actions.TryGet(name); if (e != nullptr) { return e->Phase; } - return InputActionPhase::None; + return InputActionState::None; } float Input::GetAxis(const StringView& name) @@ -818,7 +818,7 @@ void InputService::Update() ActionData& data = Actions[name]; data.Active = false; - data.Phase = InputActionPhase::Waiting; + data.Phase = InputActionState::Waiting; // Mark as updated in this frame data.FrameIndex = frame; @@ -845,15 +845,15 @@ void InputService::Update() if (Input::GetKeyDown(config.Key) || Input::GetMouseButtonDown(config.MouseButton) || Input::GetGamepadButtonDown(config.Gamepad, config.GamepadButton)) { - data.Phase = InputActionPhase::Press; + data.Phase = InputActionState::Press; } else if (Input::GetKey(config.Key) || Input::GetMouseButton(config.MouseButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadButton)) { - data.Phase = InputActionPhase::Pressing; + data.Phase = InputActionState::Pressing; } else if (Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton)) { - data.Phase = InputActionPhase::Release; + data.Phase = InputActionState::Release; } data.Active |= isActive; diff --git a/Source/Engine/Input/Input.h b/Source/Engine/Input/Input.h index 35f3dac32..1fcb352ea 100644 --- a/Source/Engine/Input/Input.h +++ b/Source/Engine/Input/Input.h @@ -315,7 +315,7 @@ public: /// The action name. /// A InputActionPhase determining the current phase of the Action (e.g If it was just pressed, is being held or just released). /// - API_FUNCTION() static InputActionPhase GetActionPhase(const StringView& name); + API_FUNCTION() static InputActionState GetActionState(const StringView& name); /// /// Gets the value of the virtual axis identified by name. Use to get the current config. From b8ed115f63097210b667fbb67ba1e43216deec5e Mon Sep 17 00:00:00 2001 From: Olly Rybak Date: Fri, 12 May 2023 09:30:35 +1000 Subject: [PATCH 11/16] More renames --- Source/Engine/Input/Input.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index b22efa4fc..8658b984c 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -29,13 +29,13 @@ struct ActionData { bool Active; uint64 FrameIndex; - InputActionState Phase; + InputActionState State; ActionData() { Active = false; FrameIndex = 0; - Phase = InputActionState::Waiting; + State = InputActionState::Waiting; } }; @@ -604,7 +604,7 @@ InputActionState Input::GetActionState(const StringView& name) const auto e = Actions.TryGet(name); if (e != nullptr) { - return e->Phase; + return e->State; } return InputActionState::None; } @@ -818,7 +818,7 @@ void InputService::Update() ActionData& data = Actions[name]; data.Active = false; - data.Phase = InputActionState::Waiting; + data.State = InputActionState::Waiting; // Mark as updated in this frame data.FrameIndex = frame; @@ -845,15 +845,15 @@ void InputService::Update() if (Input::GetKeyDown(config.Key) || Input::GetMouseButtonDown(config.MouseButton) || Input::GetGamepadButtonDown(config.Gamepad, config.GamepadButton)) { - data.Phase = InputActionState::Press; + data.State = InputActionState::Press; } else if (Input::GetKey(config.Key) || Input::GetMouseButton(config.MouseButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadButton)) { - data.Phase = InputActionState::Pressing; + data.State = InputActionState::Pressing; } else if (Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton)) { - data.Phase = InputActionState::Release; + data.State = InputActionState::Release; } data.Active |= isActive; From d7327d62e2889fb3a1f870d8270a2b8d15e257f7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 12 May 2023 13:53:31 +0200 Subject: [PATCH 12/16] Fix text words wrapping deadlock #1093 --- Source/Engine/Render2D/Font.cpp | 92 ++++++++++----------------------- 1 file changed, 26 insertions(+), 66 deletions(-) diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index b026e2d80..c36f40515 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -118,16 +118,10 @@ void Font::ProcessText(const StringView& text, Array& outputLines tmpLine.FirstCharIndex = 0; tmpLine.LastCharIndex = -1; - int32 lastWhitespaceIndex = INVALID_INDEX; - float lastWhitespaceX = 0; + int32 lastWrapCharIndex = INVALID_INDEX; + float lastWrapCharX = 0; bool lastMoveLine = false; - int32 lastUpperIndex = INVALID_INDEX; - float lastUpperX = 0; - - int32 lastUnderscoreIndex = INVALID_INDEX; - float lastUnderscoreX = 0; - // Process each character to split text into single lines for (int32 currentIndex = 0; currentIndex < textLength;) { @@ -137,30 +131,14 @@ void Font::ProcessText(const StringView& text, Array& outputLines // Cache current character const Char currentChar = text[currentIndex]; - - // Check if character is a whitespace const bool isWhitespace = StringUtils::IsWhitespace(currentChar); - if (isWhitespace) - { - // Cache line break point - lastWhitespaceIndex = currentIndex; - lastWhitespaceX = cursorX; - } - // Check if character is an upper case letter - const bool isUpper = StringUtils::IsUpper(currentChar); - if (isUpper && currentIndex != 0) + // Check if character can wrap words + const bool isWrapChar = !StringUtils::IsAlnum(currentChar) || isWhitespace || StringUtils::IsUpper(currentChar); + if (isWrapChar && currentIndex != 0) { - lastUpperIndex = currentIndex; - lastUpperX = cursorX; - } - - // Check if character is an underscore - const bool isUnderscore = currentChar == '_'; - if (isUnderscore) - { - lastUnderscoreIndex = currentIndex; - lastUnderscoreX = cursorX; + lastWrapCharIndex = currentIndex; + lastWrapCharX = cursorX; } // Check if it's a newline character @@ -197,41 +175,31 @@ void Font::ProcessText(const StringView& text, Array& outputLines } else if (layout.TextWrapping == TextWrapping::WrapWords) { - // Move line but back to the last after-whitespace character - moveLine = true; - if (lastWhitespaceIndex != INVALID_INDEX) - { - cursorX = lastWhitespaceX; - tmpLine.LastCharIndex = lastWhitespaceIndex - 1; - nextCharIndex = currentIndex = lastWhitespaceIndex + 1; - } - else if (lastUpperIndex != INVALID_INDEX) + if (lastWrapCharIndex != INVALID_INDEX) { // Skip moving twice for the same character - if (outputLines.HasItems() && outputLines.Last().LastCharIndex == lastUpperIndex - 1) + if (outputLines.HasItems() && outputLines.Last().LastCharIndex == lastWrapCharIndex - 1) { currentIndex = nextCharIndex; lastMoveLine = moveLine; continue; } - cursorX = lastUpperX; - tmpLine.LastCharIndex = lastUpperIndex - 1; - nextCharIndex = currentIndex = lastUpperIndex; - } - else if (lastUnderscoreIndex != INVALID_INDEX) - { - cursorX = lastUnderscoreX; - tmpLine.LastCharIndex = lastUnderscoreIndex - 2; - nextCharIndex = currentIndex = lastUnderscoreIndex + 1; - } - else - { - nextCharIndex = currentIndex; - - // Skip moving twice for the same character - if (lastMoveLine) - break; + // Move line + const Char wrapChar = text[lastWrapCharIndex]; + moveLine = true; + cursorX = lastWrapCharX; + if (StringUtils::IsWhitespace(wrapChar)) + { + // Skip whitespaces + tmpLine.LastCharIndex = lastWrapCharIndex - 1; + nextCharIndex = currentIndex = lastWrapCharIndex + 1; + } + else + { + tmpLine.LastCharIndex = lastWrapCharIndex - 1; + nextCharIndex = currentIndex = lastWrapCharIndex; + } } } else if (layout.TextWrapping == TextWrapping::WrapChars) @@ -260,16 +228,8 @@ void Font::ProcessText(const StringView& text, Array& outputLines tmpLine.FirstCharIndex = currentIndex; tmpLine.LastCharIndex = currentIndex - 1; cursorX = 0; - - lastWhitespaceIndex = INVALID_INDEX; - lastWhitespaceX = 0; - - lastUpperIndex = INVALID_INDEX; - lastUpperX = 0; - - lastUnderscoreIndex = INVALID_INDEX; - lastUnderscoreX = 0; - + lastWrapCharIndex = INVALID_INDEX; + lastWrapCharX = 0; previous.IsValid = false; } From b5117af4b8fad5a76b9bb83aee86955f6c03244e Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 12 May 2023 14:19:40 +0200 Subject: [PATCH 13/16] Format code --- Source/Engine/Input/Input.cpp | 4 ++-- Source/Engine/UI/GUI/Common/Button.cs | 8 ++++---- Source/Engine/UI/GUI/Common/CheckBox.cs | 2 +- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 2 +- Source/Engine/UI/GUI/Panels/DropPanel.cs | 5 ++--- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 8658b984c..1fa7454ea 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -25,7 +25,7 @@ struct AxisEvaluation bool Used; }; -struct ActionData +struct ActionData { bool Active; uint64 FrameIndex; @@ -602,7 +602,7 @@ bool Input::GetAction(const StringView& name) InputActionState Input::GetActionState(const StringView& name) { const auto e = Actions.TryGet(name); - if (e != nullptr) + if (e != nullptr) { return e->State; } diff --git a/Source/Engine/UI/GUI/Common/Button.cs b/Source/Engine/UI/GUI/Common/Button.cs index 41ea3a0d4..e3bee0017 100644 --- a/Source/Engine/UI/GUI/Common/Button.cs +++ b/Source/Engine/UI/GUI/Common/Button.cs @@ -60,7 +60,7 @@ namespace FlaxEngine.GUI /// [EditorDisplay("Text Style"), EditorOrder(2020)] public Color TextColor; - + /// /// Gets or sets the brush used for background drawing. /// @@ -78,13 +78,13 @@ namespace FlaxEngine.GUI /// [EditorDisplay("Background Style"), EditorOrder(2002)] public Color BackgroundColorSelected { get; set; } - + /// /// Gets or sets the color of the border. /// [EditorDisplay("Border Style"), EditorOrder(2010), ExpandGroups] public Color BorderColor { get; set; } - + /// /// Gets or sets the border color when button is highlighted. /// @@ -209,7 +209,7 @@ namespace FlaxEngine.GUI public override void ClearState() { base.ClearState(); - + if (_isPressed) OnPressEnd(); } diff --git a/Source/Engine/UI/GUI/Common/CheckBox.cs b/Source/Engine/UI/GUI/Common/CheckBox.cs index c5a6e3bb3..939708f36 100644 --- a/Source/Engine/UI/GUI/Common/CheckBox.cs +++ b/Source/Engine/UI/GUI/Common/CheckBox.cs @@ -119,7 +119,7 @@ namespace FlaxEngine.GUI /// [EditorDisplay("Border Style"), EditorOrder(2011)] public Color BorderColorHighlighted { get; set; } - + /// /// Gets or sets the color of the checkbox icon. /// diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 9619f98bd..d94ff8854 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -1197,7 +1197,7 @@ namespace FlaxEngine.GUI { SetSelection(hitPos); } - + if (Cursor == CursorType.Default && _changeCursor) Cursor = CursorType.IBeam; diff --git a/Source/Engine/UI/GUI/Panels/DropPanel.cs b/Source/Engine/UI/GUI/Panels/DropPanel.cs index 9662f61b9..d650d6205 100644 --- a/Source/Engine/UI/GUI/Panels/DropPanel.cs +++ b/Source/Engine/UI/GUI/Panels/DropPanel.cs @@ -94,7 +94,7 @@ namespace FlaxEngine.GUI } } } - + /// /// Gets or sets a value indicating whether enable drop down icon drawing. /// @@ -376,7 +376,6 @@ namespace FlaxEngine.GUI Render2D.DrawText(HeaderTextFont.GetFont(), HeaderTextMaterial, HeaderText, textRect, textColor, TextAlignment.Near, TextAlignment.Center); - if (!_isClosed && EnableContainmentLines) { Color lineColor = Style.Current.ForegroundGrey - new Color(0, 0, 0, 100); @@ -385,7 +384,7 @@ namespace FlaxEngine.GUI Render2D.DrawLine(new Float2(1, Height), new Float2(Width, Height), lineColor, lineThickness); Render2D.DrawLine(new Float2(Width, HeaderHeight), new Float2(Width, Height), lineColor, lineThickness); } - + // Children DrawChildren(); } From a8f670a9c9246d6253daf53ae9ec0191cbd31f34 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 12 May 2023 14:39:25 +0200 Subject: [PATCH 14/16] Simplify changes from #924 and properly update after unpausing effect --- Source/Engine/Particles/ParticleEffect.cpp | 31 ++++++++-------------- Source/Engine/Particles/ParticleEffect.h | 4 +-- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Source/Engine/Particles/ParticleEffect.cpp b/Source/Engine/Particles/ParticleEffect.cpp index 651ff719b..18bcbdd54 100644 --- a/Source/Engine/Particles/ParticleEffect.cpp +++ b/Source/Engine/Particles/ParticleEffect.cpp @@ -280,26 +280,18 @@ void ParticleEffect::UpdateSimulation(bool singleFrame) Particles::UpdateEffect(this); } -void ParticleEffect::Play(bool reset) +void ParticleEffect::Play() { - _play = true; _isPlaying = true; - - if (reset) - ResetSimulation(); - else - UpdateSimulation(true); } void ParticleEffect::Pause() { - _play = false; _isPlaying = false; } void ParticleEffect::Stop() { - _play = false; _isPlaying = false; ResetSimulation(); } @@ -424,9 +416,13 @@ void ParticleEffect::SetParametersOverrides(const Array& valu void ParticleEffect::Update() { - if (!_play) + if (!_isPlaying) + { + // Move update timer forward while paused for correct delta time after unpause + Instance.LastUpdateTime = (UseTimeScale ? Time::Update.Time : Time::Update.UnscaledTime).GetTotalSeconds(); return; - + } + // Skip if off-screen if (!UpdateWhenOffscreen && _lastMinDstSqr >= MAX_Real) return; @@ -448,16 +444,10 @@ void ParticleEffect::Update() void ParticleEffect::UpdateExecuteInEditor() { + // Auto-play in Editor if (!Editor::IsPlayMode) { - // Always Play in editor while not playing. - // Could be useful to have a GUI to change this state - if (!_play) - { - _play = true; - _isPlaying = true; - } - + _isPlaying = true; Update(); } } @@ -632,6 +622,7 @@ void ParticleEffect::Deserialize(DeserializeStream& stream, ISerializeModifier* const auto overridesMember = stream.FindMember("Overrides"); if (overridesMember != stream.MemberEnd()) { + // [Deprecated on 25.11.2018, expires on 25.11.2022] if (modifier->EngineBuild < 6197) { const auto& overrides = overridesMember->value; @@ -752,7 +743,7 @@ void ParticleEffect::OnEnable() if (PlayOnStart) Play(); - + // Base Actor::OnEnable(); } diff --git a/Source/Engine/Particles/ParticleEffect.h b/Source/Engine/Particles/ParticleEffect.h index 5a4bae771..bfee23a3b 100644 --- a/Source/Engine/Particles/ParticleEffect.h +++ b/Source/Engine/Particles/ParticleEffect.h @@ -184,7 +184,6 @@ private: uint32 _parametersVersion = 0; // Version number for _parameters to be in sync with Instance.ParametersVersion Array _parameters; // Cached for scripting API Array _parametersOverrides; // Cached parameter modifications to be applied to the parameters - bool _play = false; bool _isPlaying = false; public: @@ -353,8 +352,7 @@ public: /// /// Plays the simulation. /// - /// /// If true, the simulation will be reset - API_FUNCTION() void Play(bool reset = true); + API_FUNCTION() void Play(); /// /// Pauses the simulation. From eab14e28da9922d2bcf1f86238209bb441b49dc7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 12 May 2023 14:39:57 +0200 Subject: [PATCH 15/16] Add play/pause/stop buttons to particle effect editor while in play-mode --- .../Dedicated/ParticleEffectEditor.cs | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Source/Editor/CustomEditors/Dedicated/ParticleEffectEditor.cs b/Source/Editor/CustomEditors/Dedicated/ParticleEffectEditor.cs index 75fec4eba..ec71348cf 100644 --- a/Source/Editor/CustomEditors/Dedicated/ParticleEffectEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/ParticleEffectEditor.cs @@ -1,8 +1,10 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. +using System; using System.Linq; using FlaxEditor.Surface; using FlaxEngine; +using FlaxEngine.GUI; namespace FlaxEditor.CustomEditors.Dedicated { @@ -13,6 +15,7 @@ namespace FlaxEditor.CustomEditors.Dedicated [CustomEditor(typeof(ParticleEffect)), DefaultEditor] public class ParticleEffectEditor : ActorEditor { + private Label _infoLabel; private bool _isValid; private bool _isActive; private uint _parametersVersion; @@ -48,6 +51,15 @@ namespace FlaxEditor.CustomEditors.Dedicated return null; } + private void Foreach(Action func) + { + foreach (var value in Values) + { + if (value is ParticleEffect player) + func(player); + } + } + /// public override void Initialize(LayoutElementsContainer layout) { @@ -60,6 +72,26 @@ namespace FlaxEditor.CustomEditors.Dedicated _parametersVersion = effect.ParametersVersion; _isActive = effect.IsActive; + // Show playback options during simulation + if (Editor.IsPlayMode) + { + var playbackGroup = layout.Group("Playback"); + playbackGroup.Panel.Open(); + + _infoLabel = playbackGroup.Label(string.Empty).Label; + _infoLabel.AutoHeight = true; + + var grid = playbackGroup.CustomContainer(); + var gridControl = grid.CustomControl; + gridControl.ClipChildren = false; + gridControl.Height = Button.DefaultHeight; + gridControl.SlotsHorizontally = 3; + gridControl.SlotsVertically = 1; + grid.Button("Play").Button.Clicked += () => Foreach(x => x.Play()); + grid.Button("Pause").Button.Clicked += () => Foreach(x => x.Pause()); + grid.Button("Stop").Button.Clicked += () => Foreach(x => x.Stop()); + } + // Show all effect parameters grouped by the emitter track name var groups = layout.Group("Parameters"); groups.Panel.Open(); @@ -99,7 +131,7 @@ namespace FlaxEditor.CustomEditors.Dedicated base.RefreshRootChild(); return; } - + for (int i = 0; i < ChildrenEditors.Count; i++) { if (_isActive != effect.IsActive || _parametersVersion != effect.ParametersVersion) From 1af69421fa5c9bb36238c215f4644044aadfee29 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 12 May 2023 18:41:58 +0200 Subject: [PATCH 16/16] Fix actor scene tree dragging regression from d813078e91062f031520ec55d8745a81b4519171 #1104 --- Source/Editor/SceneGraph/GUI/ActorTreeNode.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs index 5c87cbff6..8845c24bf 100644 --- a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs +++ b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs @@ -729,8 +729,6 @@ namespace FlaxEditor.SceneGraph.GUI { DragData data; var tree = ParentTree; - if (tree.Selection.Count == 1) - Select(); // Check if this node is selected if (tree.Selection.Contains(this))