From a36fa66ec69dbc5293246a5f625eecee9f438859 Mon Sep 17 00:00:00 2001 From: Lukas Bagaric Date: Sun, 26 May 2024 18:39:29 +0200 Subject: [PATCH] Allow Negative Offsets To Be Entered For Crosshairs --- Classes/IGPlus_CrosshairSettingsContent.uc | 2 + Classes/IGPlus_EditBox.uc | 43 ++++++++++++++++++++++ Classes/IGPlus_EditControl.uc | 16 ++++++++ Classes/IGPlus_SettingsContent.uc | 1 + 4 files changed, 62 insertions(+) create mode 100644 Classes/IGPlus_EditBox.uc diff --git a/Classes/IGPlus_CrosshairSettingsContent.uc b/Classes/IGPlus_CrosshairSettingsContent.uc index 60709863..b086b0f9 100644 --- a/Classes/IGPlus_CrosshairSettingsContent.uc +++ b/Classes/IGPlus_CrosshairSettingsContent.uc @@ -206,6 +206,7 @@ function Created() { Edit_OffsetX.SetDelayedNotify(true); Edit_OffsetX.SetNumericOnly(true); Edit_OffsetX.SetNumericFloat(false); + Edit_OffsetX.SetNumericNegative(true); Edit_OffsetX.EditBoxWidthFraction = (1.0/3.0); Edit_OffsetX.EditBoxWidth = 50; @@ -217,6 +218,7 @@ function Created() { Edit_OffsetY.SetDelayedNotify(true); Edit_OffsetY.SetNumericOnly(true); Edit_OffsetY.SetNumericFloat(false); + Edit_OffsetY.SetNumericNegative(true); Edit_OffsetY.EditBoxWidthFraction = (1.0/3.0); Edit_OffsetY.EditBoxWidth = 50; diff --git a/Classes/IGPlus_EditBox.uc b/Classes/IGPlus_EditBox.uc new file mode 100644 index 00000000..2b38f4e2 --- /dev/null +++ b/Classes/IGPlus_EditBox.uc @@ -0,0 +1,43 @@ +class IGPlus_EditBox extends UWindowEditBox; + +var bool bNumericNegative; + +function KeyType(int Key, float MouseX, float MouseY) { + if (bCanEdit == false || bKeyDown == false) + return; + + if (bControlDown) + return; + + if (bAllSelected) + Clear(); + + bAllSelected = False; + + if (bNumericOnly) { + if (Key >= 0x30 && Key <= 0x39) + Insert(Key); + if (bNumericNegative) { + if (Key == 0x2D && Left(Value, 1) != "-") { + Value = "-"$Value; + CaretOffset += 1; + + if (bDelayedNotify) + bChangePending = true; + else + Notify(DE_Change); + } else if (Key == 0x2B && Left(Value, 1) == "-") { + Value = Mid(Value, 1); + CaretOffset -= 1; + + if (bDelayedNotify) + bChangePending = true; + else + Notify(DE_Change); + } + } + } else { + if (Key >= 0x20 && Key < 0x80) + Insert(Key); + } +} \ No newline at end of file diff --git a/Classes/IGPlus_EditControl.uc b/Classes/IGPlus_EditControl.uc index b4fbcd92..1730db5a 100644 --- a/Classes/IGPlus_EditControl.uc +++ b/Classes/IGPlus_EditControl.uc @@ -6,12 +6,28 @@ var float EditBoxMinWidth; var float EditBoxMaxWidth; var float EditBoxWidthFraction; +function Created() { + Super.Created(); + + EditBox = IGPlus_EditBox(CreateWindow(class'IGPlus_EditBox', 0, 0, WinWidth, WinHeight)); + EditBox.NotifyOwner = Self; + EditBox.bSelectOnFocus = True; + + EditBoxWidth = WinWidth / 2; + + SetEditTextColor(LookAndFeel.EditBoxTextColor); +} + function AfterCreate() { EditBoxWidthFraction = FClamp(EditBoxWidth / WinWidth, 0.05, 0.95); EditBoxMinWidth = WinWidth * EditBoxWidthFraction; EditBoxMaxWidth = WinWidth * EditBoxWidthFraction; } +function SetNumericNegative(bool bEnable) { + IGPlus_EditBox(EditBox).bNumericNegative = bEnable; +} + function MouseLeave() { Super.MouseLeave(); if(HelpText != "") ToolTip(""); diff --git a/Classes/IGPlus_SettingsContent.uc b/Classes/IGPlus_SettingsContent.uc index 050c8ab1..7188a3e1 100644 --- a/Classes/IGPlus_SettingsContent.uc +++ b/Classes/IGPlus_SettingsContent.uc @@ -908,6 +908,7 @@ function Created() { Cmb_HitMarkerColorMode.AddItem(HitMarkerColorModeTeamColor); Edit_HitMarkerSize = CreateEdit(ECT_Integer, HitMarkerSizeText, HitMarkerSizeHelp, , 64); Edit_HitMarkerOffset = CreateEdit(ECT_Integer, HitMarkerOffsetText, HitMarkerOffsetHelp, , 64); + Edit_HitMarkerOffset.SetNumericNegative(true); Edit_HitMarkerDuration = CreateEdit(ECT_Real, HitMarkerDurationText, HitMarkerDurationHelp, , 64); Edit_HitMarkerDecayExponent = CreateEdit(ECT_Real, HitMarkerDecayExponentText, HitMarkerDecayExponentHelp, , 64); Chk_EnableHitMarker = CreateCheckbox(EnableHitMarkerText, EnableHitMarkerHelp);