-
Notifications
You must be signed in to change notification settings - Fork 4
Add some OptionsDialog related controls & other impl/fixes #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,742
−131
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
086adc6
Add Slider, more ComboBox and Label impl
callumok2004 47e839a
Control Messages
callumok2004 f7b3049
Some progress for OptionsDialog
callumok2004 5d1892e
More TextEntry impl, fix some other stuff
callumok2004 8e7c9ce
Start on some ImagePanel funcs & Update MenuButton
callumok2004 da633e9
Merge branch 'main' of https://github.com/marchc1/Source.NET
callumok2004 713d904
Fix command history not removing items
callumok2004 736dd48
Some more LoadingDialog/GameUI impl
callumok2004 c84ad40
Fix typo
callumok2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| using Source.Common.Commands; | ||
| using Source.Common.Formats.Keyvalues; | ||
| using Source.Common.GUI; | ||
| using Source.GUI.Controls; | ||
|
|
||
| namespace Game.UI; | ||
|
|
||
| public class CvarNegateCheckButton : CheckButton | ||
| { | ||
| string? CvarName; | ||
| bool StartState; | ||
|
|
||
| public CvarNegateCheckButton(Panel parent, ReadOnlySpan<char> name, ReadOnlySpan<char> text, ReadOnlySpan<char> cvarName) : base(parent, name, text) { | ||
| CvarName = cvarName.Length > 0 ? new(cvarName) : null; | ||
| Reset(); | ||
| AddActionSignalTarget(this); | ||
| } | ||
|
|
||
| public override void Paint() { | ||
| if (CvarName == null) { | ||
| base.Paint(); | ||
| return; | ||
| } | ||
|
|
||
| ConVarRef var = new(CvarName); | ||
| if (!var.IsValid()) | ||
| return; | ||
|
|
||
| float value = var.GetFloat(); | ||
|
|
||
| if (value < 0) { | ||
| if (!StartState) { | ||
| SetSelected(true); | ||
| StartState = true; | ||
| } | ||
| } | ||
| else { | ||
| if (StartState) { | ||
| SetSelected(false); | ||
| StartState = false; | ||
| } | ||
| } | ||
|
|
||
| base.Paint(); | ||
| } | ||
|
|
||
| public void Reset() { | ||
| ConVarRef var = new(CvarName); | ||
| if (!var.IsValid()) | ||
| return; | ||
|
|
||
| float value = var.GetFloat(); | ||
|
|
||
| if (value < 0) | ||
| StartState = true; | ||
| else | ||
| StartState = false; | ||
|
|
||
| SetSelected(StartState); | ||
| } | ||
|
|
||
| public bool HasBeenModified() => IsSelected() != StartState; | ||
|
|
||
| public override void SetSelected(bool state) { | ||
| base.SetSelected(state); | ||
| } | ||
|
|
||
| public void ApplyChanges() { | ||
| if (CvarName == null || CvarName.Length == 0) | ||
| return; | ||
|
|
||
| ConVarRef var = new(CvarName); | ||
| float value = var.GetFloat(); | ||
|
|
||
| value = (float)MathF.Abs(value); | ||
| if (value < 0.00001) | ||
| value = 0.022f; | ||
|
|
||
| StartState = IsSelected(); | ||
| value = -value; | ||
|
|
||
| float ans = StartState ? value : -value; | ||
| var.SetValue(ans); | ||
| } | ||
|
|
||
| public void OnButtonChecked() { | ||
| if (HasBeenModified()) | ||
| PostActionSignal(new KeyValues("ControlModified")); // todo static | ||
| } | ||
|
|
||
| public override void OnMessage(KeyValues message, IPanel? from) { | ||
| if (message.Name.Equals("CheckButtonChecked", StringComparison.OrdinalIgnoreCase)) { | ||
| OnButtonChecked(); | ||
| return; | ||
| } | ||
|
|
||
| base.OnMessage(message, from); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| using Source; | ||
| using Source.Common.Commands; | ||
| using Source.Common.Formats.Keyvalues; | ||
| using Source.Common.GUI; | ||
| using Source.GUI.Controls; | ||
|
|
||
| namespace Game.UI; | ||
|
|
||
| public class CvarSlider : Slider | ||
| { | ||
| [PanelAnimationVar("use_convar_minmax", "0", "bool")] bool UseCvarMinMax; | ||
| bool AllowOutOfRange; | ||
| bool ModifiedOnce; | ||
| float StartValue; | ||
| int iStartValue; | ||
| float LastSliderValue; | ||
| float CurrentValue; | ||
| char[]? CvarName = new char[64]; | ||
| bool CreatedInCode; | ||
| float MinValue; | ||
| float MaxValue; | ||
| public CvarSlider(Panel panel, ReadOnlySpan<char> name) : base(panel, name) { | ||
| SetupSlider(0, 1, "", false); | ||
| CreatedInCode = false; | ||
| AddActionSignalTarget(this); | ||
| } | ||
|
|
||
| public CvarSlider(Panel parent, ReadOnlySpan<char> name, ReadOnlySpan<char> text, float minValue, float maxValue, ReadOnlySpan<char> cvarName, bool allowOutOfRange) : base(parent, name) { | ||
| AddActionSignalTarget(this); | ||
| SetupSlider(minValue, maxValue, cvarName, allowOutOfRange); | ||
| CreatedInCode = true; | ||
| } | ||
|
|
||
| public void SetupSlider(float minValue, float maxValue, ReadOnlySpan<char> cvarName, bool allowOutOfRange) { | ||
| ConVarRef var = new(cvarName, true); | ||
|
|
||
| if (var.IsValid()) { | ||
| float cvarMin; | ||
| if (var.GetMin(out double CVarMin)) { | ||
| cvarMin = (float)CVarMin; | ||
| minValue = UseCvarMinMax ? cvarMin : Math.Max(minValue, cvarMin); | ||
| } | ||
|
|
||
| float cvarMax; | ||
| if (var.GetMax(out double CVarMax)) { | ||
| cvarMax = (float)CVarMax; | ||
| maxValue = UseCvarMinMax ? cvarMax : Math.Min(maxValue, cvarMax); | ||
| } | ||
| } | ||
|
|
||
| MinValue = minValue; | ||
| MaxValue = maxValue; | ||
|
|
||
| SetRange((int)(100.0f * MinValue), (int)(100.0f * MaxValue)); | ||
|
|
||
| Span<char> min = stackalloc char[32]; | ||
| Span<char> max = stackalloc char[32]; | ||
|
|
||
| minValue.TryFormat(min, out int minLen, "F2"); | ||
| maxValue.TryFormat(max, out int maxLen, "F2"); | ||
|
|
||
| SetTickCaptions(min, max); | ||
|
|
||
| cvarName.CopyTo(CvarName); | ||
|
|
||
| ModifiedOnce = false; | ||
| AllowOutOfRange = allowOutOfRange; | ||
|
|
||
| Reset(); | ||
| } | ||
|
|
||
| public void SetTickColor(Color color) => TickColor = color; | ||
|
|
||
| public override void ApplySettings(KeyValues resourceData) { | ||
| base.ApplySettings(resourceData); | ||
|
|
||
| if (!CreatedInCode) { | ||
| float minValue = resourceData.GetFloat("minvalue", 0); | ||
| float maxValue = resourceData.GetFloat("maxvalue", 1); | ||
| ReadOnlySpan<char> cvarName = resourceData.GetString("cvar_name", ""); | ||
| bool allowOutOfRange = resourceData.GetInt("allow_out_of_range", 0) != 0; | ||
| SetupSlider(minValue, maxValue, cvarName, allowOutOfRange); | ||
|
|
||
| // HACK: If our parent is a property page, we want the dialog containing it | ||
| if (GetParent() is PropertyPage && GetParent()!.GetParent() != null) | ||
| GetParent()!.GetParent()!.AddActionSignalTarget(this); | ||
| else | ||
| GetParent()!.AddActionSignalTarget(this); | ||
| } | ||
| } | ||
|
|
||
| public override void GetSettings(KeyValues outResourceData) { | ||
| base.GetSettings(outResourceData); | ||
|
|
||
| if (!CreatedInCode) { | ||
| outResourceData.SetFloat("minvalue", MinValue); | ||
| outResourceData.SetFloat("maxvalue", MaxValue); | ||
| outResourceData.SetString("cvar_name", CvarName!); | ||
| outResourceData.SetInt("allow_out_of_range", AllowOutOfRange ? 1 : 0); | ||
| } | ||
| } | ||
|
|
||
| public void SetCVarName(ReadOnlySpan<char> cvarName) { | ||
| cvarName.CopyTo(CvarName); | ||
| ModifiedOnce = false; | ||
| Reset(); | ||
| } | ||
|
|
||
| public void SetMinMaxValues(float minValue, float maxValue, bool setTickDisplay) { | ||
| SetRange((int)(100.0f * minValue), (int)(100.0f * maxValue)); | ||
|
|
||
| if (setTickDisplay) { | ||
| Span<char> min = stackalloc char[32]; | ||
| Span<char> max = stackalloc char[32]; | ||
|
|
||
| minValue.TryFormat(min, out int minLen, "F2"); | ||
| maxValue.TryFormat(max, out int maxLen, "F2"); | ||
|
|
||
| SetTickCaptions(min, max); | ||
| } | ||
|
|
||
| Reset(); | ||
| } | ||
|
|
||
| public override void Paint() { | ||
| ConVarRef var = new(CvarName!, true); | ||
| if (!var.IsValid()) | ||
| return; | ||
|
|
||
| float curValue = var.GetFloat(); | ||
| if (curValue != StartValue) { | ||
| int value = (int)(curValue * 100.0f); | ||
| StartValue = curValue; | ||
| CurrentValue = curValue; | ||
|
|
||
| SetValue(value); | ||
| iStartValue = GetValue(); | ||
| } | ||
| base.Paint(); | ||
| } | ||
|
|
||
| public void ApplyChanges() { | ||
| if (ModifiedOnce) { | ||
| iStartValue = GetValue(); | ||
| if (AllowOutOfRange) | ||
| StartValue = CurrentValue; | ||
| else | ||
| StartValue = iStartValue / 100.0f; | ||
|
|
||
| ConVarRef var = new(CvarName!, true); | ||
| if (!var.IsValid()) | ||
| return; | ||
| var.SetValue(StartValue); | ||
| } | ||
| } | ||
|
|
||
| public float GetSliderValue() { | ||
| if (AllowOutOfRange) | ||
| return CurrentValue; | ||
| else | ||
| return GetValue() / 100.0f; | ||
| } | ||
|
|
||
| public void SetSliderValue(float value) { | ||
| int val = (int)(value * 100.0f); | ||
| SetValue(val, false); | ||
|
|
||
| LastSliderValue = value; | ||
|
|
||
| if (CurrentValue != value) { | ||
| CurrentValue = value; | ||
| ModifiedOnce = true; | ||
| } | ||
| } | ||
|
|
||
| public void Reset() { | ||
| ConVarRef var = new(CvarName!, true); | ||
|
|
||
| if (!var.IsValid()) { | ||
| CurrentValue = StartValue = 0.0f; | ||
| SetValue(0, false); | ||
| iStartValue = GetValue(); | ||
| LastSliderValue = iStartValue; | ||
| return; | ||
| } | ||
|
|
||
| StartValue = var.GetFloat(); | ||
| CurrentValue = StartValue; | ||
|
|
||
| int value = (int)(StartValue * 100.0f); | ||
| SetValue(value, false); | ||
|
|
||
| iStartValue = GetValue(); | ||
| LastSliderValue = iStartValue; | ||
| } | ||
|
|
||
| public bool HasBeenModified() { | ||
| if (GetValue() != iStartValue) | ||
| ModifiedOnce = true; | ||
| return ModifiedOnce; | ||
| } | ||
|
|
||
| public void OnSliderMoved() { | ||
| if (HasBeenModified()) { | ||
| if (LastSliderValue != GetValue()) { | ||
| LastSliderValue = GetValue(); | ||
| CurrentValue = GetValue() / 100.0f; | ||
| } | ||
|
|
||
| PostActionSignal(new KeyValues("ControlModified")); | ||
| } | ||
| } | ||
|
|
||
| // todo complete | ||
|
|
||
| public override void OnMessage(KeyValues message, IPanel? from) { | ||
| switch (message.Name) { | ||
| case "SliderMoved": | ||
| OnSliderMoved(); | ||
| break; | ||
| case "SliderDragEnd": | ||
| // OnSliderDragEnd(); | ||
| break; | ||
| default: | ||
| base.OnMessage(message, from); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.