2022-09-03 17:26:40 +00:00
|
|
|
class KFGUI_EditBox extends KFGUI_Clickable;
|
2021-06-12 20:11:37 +00:00
|
|
|
|
2020-01-10 13:14:11 +00:00
|
|
|
var enum eTextCase
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
TXTC_None,
|
|
|
|
TXTC_Upper,
|
|
|
|
TXTC_Lower,
|
2020-01-10 13:14:11 +00:00
|
|
|
} TextCase;
|
|
|
|
|
|
|
|
var Color FontColor;
|
|
|
|
|
2021-06-13 02:54:35 +00:00
|
|
|
var string TextStr, AllowedCharSet;
|
|
|
|
var bool bDrawBackground, bNoClearOnEnter, bMaskText, bIntOnly, bFloatOnly, bIncludeSign, bConvertSpaces, bCtrl, bAllSelected, bForceShowCaret;
|
2020-01-10 13:14:11 +00:00
|
|
|
var int MaxWidth;
|
2021-06-13 02:54:35 +00:00
|
|
|
var bool bReadOnly, bAlwaysNotify;
|
|
|
|
var int CaretPos, FirstVis, LastSizeX, LastCaret, LastLength;
|
2020-01-10 13:14:11 +00:00
|
|
|
var float TextScale;
|
|
|
|
|
|
|
|
function InitMenu()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
Super.InitMenu();
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bIntOnly || bFloatOnly)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
AllowedCharSet = "0123456789";
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
if (bFloatOnly)
|
|
|
|
AllowedCharSet $= ".";
|
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
bAllSelected = true;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetText(string NewText, optional bool bIgnoreDelegate)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local bool bChanged;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
bChanged = bAlwaysNotify || TextStr != NewText;
|
|
|
|
TextStr = NewText;
|
|
|
|
CaretPos = Len(TextStr);
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
if (bChanged && !bIgnoreDelegate)
|
|
|
|
TextChanged();
|
2020-01-10 13:14:11 +00:00
|
|
|
|
2021-05-16 09:40:02 +00:00
|
|
|
bAllSelected=true;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function bool NotifyInputChar(int Key, string Unicode)
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
local string Temp, S;
|
2021-05-16 09:40:02 +00:00
|
|
|
|
|
|
|
if (bReadOnly)
|
|
|
|
return false;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (UniCode != "")
|
2021-05-16 09:40:02 +00:00
|
|
|
S = Unicode;
|
|
|
|
else S = Chr(Key);
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Asc(S) == 13 || Asc(S) == 8 || Asc(S) == 27)
|
2021-05-16 09:40:02 +00:00
|
|
|
return false;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bCtrl)
|
2021-05-16 09:40:02 +00:00
|
|
|
return false;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bAllSelected)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
TextStr="";
|
|
|
|
CaretPos=0;
|
|
|
|
bAllSelected=false;
|
|
|
|
}
|
|
|
|
|
2021-06-13 02:54:35 +00:00
|
|
|
if ((AllowedCharSet == "") || ( (bIncludeSign) && ( (S == "-") || (S == "+") ) && (TextStr == "") ) || (InStr(AllowedCharSet, S) >= 0))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if ((MaxWidth == 0) || (Len(TextStr) < MaxWidth))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if ((bConvertSpaces) && ((S == " ") || (S == "?") || (S == "\\")))
|
2021-05-16 09:40:02 +00:00
|
|
|
S = "_";
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
if ((TextStr == "") || ( CaretPos == Len(TextStr)))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
TextStr = TextStr$S;
|
|
|
|
CaretPos=Len(TextStr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Temp = Left(TextStr, CaretPos)$S$Mid(TextStr, CaretPos);
|
2021-05-16 09:40:02 +00:00
|
|
|
TextStr = Temp;
|
|
|
|
CaretPos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextChanged();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetInputText(string S)
|
|
|
|
{
|
2021-06-13 03:00:19 +00:00
|
|
|
switch (TextCase)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
case TXTC_Upper:
|
|
|
|
S = Caps(S);
|
|
|
|
break;
|
|
|
|
case TXTC_Lower:
|
|
|
|
S = Locs(S);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextStr = S;
|
|
|
|
TextChanged();
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function AppendInputText(string Text)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local int Character;
|
|
|
|
|
|
|
|
while (Len(Text) > 0)
|
|
|
|
{
|
|
|
|
Character = Asc(Left(Text, 1));
|
|
|
|
Text = Mid(Text, 1);
|
|
|
|
|
|
|
|
if (Character >= 0x20 && Character < 0x100)
|
|
|
|
{
|
|
|
|
SetInputText(Left(TextStr, CaretPos) $ Chr(Character) $ Right(TextStr, Len(TextStr) - CaretPos));
|
|
|
|
CaretPos += 1;
|
|
|
|
}
|
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function bool ProcessControlKey(name Key, EInputEvent Event)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
if (Key == 'LeftControl' || Key == 'RightControl')
|
|
|
|
{
|
|
|
|
if (Event == IE_Released)
|
|
|
|
{
|
|
|
|
bCtrl = false;
|
|
|
|
}
|
|
|
|
else if (Event == IE_Pressed)
|
|
|
|
{
|
|
|
|
bCtrl = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (bCtrl && Event == IE_Pressed && GetPlayer() != None)
|
|
|
|
{
|
|
|
|
if (Key == 'V')
|
|
|
|
{
|
|
|
|
// paste
|
|
|
|
AppendInputText(GetPlayer().PasteFromClipboard());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (Key == 'C')
|
|
|
|
{
|
|
|
|
// copy
|
|
|
|
GetPlayer().CopyToClipboard(TextStr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (Key == 'X')
|
|
|
|
{
|
|
|
|
// cut
|
|
|
|
if (TextStr != "")
|
|
|
|
{
|
|
|
|
GetPlayer().CopyToClipboard(TextStr);
|
|
|
|
SetInputText("");
|
|
|
|
CaretPos = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function bool NotifyInputKey(int ControllerId, name Key, EInputEvent Event, float AmountDepressed, bool bGamepad)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local string Temp;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bReadOnly)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ProcessControlKey(Key, Event))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (Key == 'Escape' && Event == IE_Pressed)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (TextStr != "")
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
SetInputText("");
|
|
|
|
CaretPos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ParentComponent != None)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
ParentComponent.UserPressedEsc();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (Key == 'Enter' && Event == IE_Released)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (TextStr != "")
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
Temp = TextStr;
|
|
|
|
OnTextFinished(self, Temp);
|
2021-06-13 02:53:33 +00:00
|
|
|
if (!bNoClearOnEnter)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
SetInputText("");
|
|
|
|
CaretPos = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (Key == 'Home')
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
CaretPos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (Key == 'End')
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
CaretPos = Len(TextStr);
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (Event == IE_Pressed || Event == IE_Repeat)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Key == 'Backspace' || Key == 'Delete')
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bAllSelected)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
SetInputText("");
|
|
|
|
CaretPos = 0;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (CaretPos > 0)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
SetInputText(Left(TextStr, CaretPos-1) $ Right(TextStr, Len(TextStr) - CaretPos));
|
2021-05-16 09:40:02 +00:00
|
|
|
CaretPos -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (Key == 'Left')
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
CaretPos = Max(0, CaretPos - 1);
|
|
|
|
return true;
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
else if (Key == 'Right')
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
CaretPos = Min(Len(TextStr), CaretPos + 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function string ConvertIllegal(string InputStr)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local int i, Max;
|
|
|
|
local string Retval;
|
|
|
|
local string C;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
Max = Len(InputStr);
|
2021-06-13 02:53:33 +00:00
|
|
|
while ( i < Max)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
C = Mid(InputStr, i,1);
|
|
|
|
if (AllowedCharSet != "" && InStr(AllowedCharSet, C) < 0)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
C = "";
|
|
|
|
}
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bConvertSpaces &&
|
2021-06-13 03:00:19 +00:00
|
|
|
((C == " ") || (C =="?") || (C == "\\")))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
C = "_";
|
|
|
|
}
|
|
|
|
Retval = Retval $ C;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MaxWidth > 0)
|
2021-06-13 02:54:35 +00:00
|
|
|
return Left(Retval, MaxWidth);
|
2021-05-16 09:40:02 +00:00
|
|
|
|
|
|
|
return Retval;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function string GetText()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return TextStr;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function TextChanged()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
OnChange(Self);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DrawMenu()
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
local string Storage, FinalDraw, TmpString;
|
|
|
|
local int MaskIndex, StorageLength;
|
|
|
|
local float XL, YL, BoxWidth, FontScale, CursorY, BorderSize;
|
2021-05-16 09:40:02 +00:00
|
|
|
local FontRenderInfo FRI;
|
|
|
|
|
|
|
|
Super.DrawMenu();
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bDrawBackground)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetDrawColor(250, 250, 250, 255);
|
|
|
|
Canvas.SetPos(0.f, 0.f);
|
|
|
|
Canvas.DrawTileStretched(Owner.CurrentStyle.BorderTextures[`BOX_SMALL], CompPos[2], CompPos[3], 0,0, Owner.CurrentStyle.BorderTextures[`BOX_SMALL].GetSurfaceWidth(), Owner.CurrentStyle.BorderTextures[`BOX_SMALL].GetSurfaceHeight());
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BorderSize = Owner.CurrentStyle.ScreenScale(4.f);
|
|
|
|
|
|
|
|
FRI.bClipText = true;
|
|
|
|
FRI.bEnableShadow = true;
|
|
|
|
|
|
|
|
Storage = TextStr;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bMaskText && Len(Storage) > 0)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
StorageLength = Len(Storage);
|
|
|
|
|
|
|
|
Storage = "";
|
2021-06-13 02:53:33 +00:00
|
|
|
for (MaskIndex=1; MaskIndex <= StorageLength; MaskIndex++)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
Storage $= "*";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Canvas.Font = Owner.CurrentStyle.PickFont(FontScale);
|
|
|
|
FontScale *= TextScale;
|
|
|
|
|
|
|
|
BoxWidth=CompPos[2]*0.9875;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if ((Len(Storage) != LastLength) || (CaretPos != LastCaret))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (CaretPos <= FirstVis)
|
2021-06-13 02:54:35 +00:00
|
|
|
FirstVis = Max(0, CaretPos-1);
|
2021-05-16 09:40:02 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FinalDraw = Mid(Storage, FirstVis, CaretPos-FirstVis);
|
|
|
|
Canvas.TextSize(FinalDraw, XL, YL, FontScale, FontScale);
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
while ( (XL >= BoxWidth) && (FirstVis < Len(Storage)))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
FirstVis++;
|
|
|
|
FinalDraw = Mid(Storage, FirstVis, CaretPos-FirstVis);
|
|
|
|
Canvas.TextSize(FinalDraw, XL, YL, FontScale, FontScale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LastLength = Len(Storage);
|
|
|
|
|
|
|
|
if (bReadOnly)
|
|
|
|
{
|
|
|
|
FirstVis = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
FinalDraw = Mid(Storage, FirstVis, Len(Storage)-FirstVis);
|
|
|
|
|
|
|
|
if (!bReadOnly && (Owner.KeyboardFocus == self || bForceShowCaret))
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if ((FirstVis == CaretPos) || (Len(FinalDraw) == 0))
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
Canvas.TextSize("W", XL, YL, FontScale, FontScale);
|
|
|
|
XL = BorderSize;
|
|
|
|
bAllSelected=false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TmpString = Mid(FinalDraw, 0, CaretPos-FirstVis);
|
|
|
|
Canvas.TextSize(TmpString, XL, YL, FontScale, FontScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
CursorY = (CompPos[3]/2) - ((YL-Owner.HUDOwner.ScaledBorderSize)/2);
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bAllSelected)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetDrawColor(255, 255, 255, 195);
|
2021-05-16 09:40:02 +00:00
|
|
|
Canvas.SetPos(BorderSize, CursorY);
|
2021-06-13 03:00:19 +00:00
|
|
|
Canvas.DrawTile(Owner.DefaultPens[`PEN_WHITE], XL, YL-Owner.HUDOwner.ScaledBorderSize, 0, 0, Owner.DefaultPens[`PEN_WHITE].GetSurfaceWidth(), Owner.DefaultPens[`PEN_WHITE].GetSurfaceHeight());
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetDrawColor(255, 255, 255, Owner.CursorFlash);
|
2021-05-16 09:40:02 +00:00
|
|
|
Canvas.SetPos(XL + (Len(FinalDraw) == 0 ? 0 : 3), CursorY);
|
2021-06-13 03:00:19 +00:00
|
|
|
Canvas.DrawTile(Owner.DefaultPens[`PEN_WHITE], 3, YL-Owner.HUDOwner.ScaledBorderSize, 0, 0, Owner.DefaultPens[`PEN_WHITE].GetSurfaceWidth(), Owner.DefaultPens[`PEN_WHITE].GetSurfaceHeight());
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Canvas.DrawColor = FontColor;
|
|
|
|
Canvas.SetPos(BorderSize, (CompPos[3]/2) - (YL/2));
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.DrawText(FinalDraw, ,FontScale, FontScale, FRI);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
function HandleMouseClick(bool bRight)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Owner.KeyboardFocus != self)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
GrabKeyFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
CaretPos = Len(TextStr);
|
|
|
|
bAllSelected = !bAllSelected;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Delegate OnChange(KFGUI_EditBox Sender);
|
|
|
|
Delegate OnTextFinished(KFGUI_EditBox Sender, string S);
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
2021-06-13 02:54:35 +00:00
|
|
|
FontColor=(R=255, G=255, B=255, A=255)
|
2021-05-16 09:40:02 +00:00
|
|
|
MaxWidth=768
|
|
|
|
TextScale=1
|
|
|
|
TextCase=TXTC_None
|
|
|
|
LastCaret=-1
|
|
|
|
LastLength=-1
|
|
|
|
|
|
|
|
YSize=0.06
|
2023-05-02 19:15:42 +00:00
|
|
|
}
|