KF2-Server-Extension/ServerExt/Classes/KFGUI_EditBox.uc

266 lines
5.2 KiB
Ucode
Raw Normal View History

2017-10-20 02:00:49 +00:00
Class KFGUI_EditBox extends KFGUI_EditControl;
var string Value;
var int TypePos,ScrollOffset;
var() int MaxTextLength;
var() color TextColor;
var bool bIsTyping,bAllSelected,bTextDirty,bHoldCtrl;
2020-11-28 20:04:55 +00:00
delegate OnTextChange(KFGUI_EditBox Sender);
delegate bool OnHitEnter(KFGUI_EditBox Sender); // Return true to keep focus.
2017-10-20 02:00:49 +00:00
2020-11-28 20:04:55 +00:00
function ChangeValue(string V)
2017-10-20 02:00:49 +00:00
{
Value = V;
TypePos = Len(V);
ScrollOffset = 0;
}
function InitMenu()
{
Super.InitMenu();
bClickable = !bDisabled;
}
function DrawMenu()
{
local float X,Y,XS,YS;
local Color C;
Owner.CurrentStyle.RenderEditBox(Self);
2020-11-28 20:12:58 +00:00
if (bDisabled)
2017-10-20 02:00:49 +00:00
C = TextColor*(0.5f);
else C = TextColor;
X = TextHeight*0.025f + 5.f;
Y = (CompPos[3]-TextHeight)*0.5f;
2023-05-14 02:49:12 +00:00
2020-11-28 20:12:58 +00:00
if (bIsTyping)
2017-10-20 02:00:49 +00:00
{
XS = Owner.MenuTime % 1.f;
2020-11-28 20:12:58 +00:00
if (XS>0.5f)
2017-10-20 02:00:49 +00:00
XS = (1.f-XS);
Canvas.DrawColor = C*(Sin(XS*2.f*Pi)*0.45f);
2023-05-14 02:49:12 +00:00
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
Canvas.TextSize(Mid(Value,ScrollOffset),XS,YS,TextScale,TextScale);
Canvas.SetPos(X,Y);
Canvas.DrawTile(class'WorldInfo'.Default.WhiteSquareTexture,FMin(XS,CompPos[2]-(X*2)),TextHeight,0,0,1,1,,,BLEND_Additive);
}
else
{
2020-11-28 20:12:58 +00:00
if (ScrollOffset>(TypePos-4))
2017-10-20 02:00:49 +00:00
ScrollOffset = Max(TypePos-4,0);
Retry:
Canvas.TextSize(Mid(Value,ScrollOffset,TypePos-ScrollOffset),XS,YS,TextScale,TextScale);
Canvas.SetPos(X+XS,Y);
2020-11-28 20:12:58 +00:00
if (Canvas.CurX<(CompPos[2]-X))
2017-10-20 02:00:49 +00:00
Canvas.DrawText("|",,TextScale,TextScale,TextFontInfo);
else
{
++ScrollOffset; // Keep scrolling forward until we find space.
goto'Retry';
}
}
}
2020-11-28 20:12:58 +00:00
if (Value!="")
2017-10-20 02:00:49 +00:00
{
Canvas.DrawColor = C;
Canvas.SetPos(X,Y);
2020-11-28 20:12:58 +00:00
if (ScrollOffset>5)
2017-10-20 02:00:49 +00:00
ScrollOffset = Min(ScrollOffset,Len(Value)-6);
DrawClippedText(Mid(Value,ScrollOffset),TextScale,CompPos[2]);
2023-05-14 02:49:12 +00:00
2017-10-20 02:00:49 +00:00
// FIXME: PushMaskRegion is broken in KF2?!
//Canvas.PushMaskRegion(Canvas.OrgX,Canvas.OrgY,Canvas.ClipX-4,Canvas.ClipY);
//Canvas.DrawText(Mid(Value,ScrollOffset),,TextScale,TextScale,TextFontInfo);
//Canvas.PopMaskRegion();
}
}
2020-11-28 20:04:55 +00:00
function bool NotifyInputKey(int ControllerId, name Key, EInputEvent Event, float AmountDepressed, bool bGamepad)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Owner.CheckMouse(Key,Event))
2017-10-20 02:00:49 +00:00
return true;
2020-11-28 20:12:58 +00:00
if (Key=='LeftControl')
2017-10-20 02:00:49 +00:00
{
bHoldCtrl = (Event!=IE_Released);
}
2020-11-28 20:12:58 +00:00
else if (Event == IE_Released)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Key=='Escape' || Key=='Enter')
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Key=='Enter' && OnHitEnter(Self))
2017-10-20 02:00:49 +00:00
return true;
ReleaseKeyFocus();
}
}
2020-11-28 20:12:58 +00:00
else if (Event==IE_Pressed || Event==IE_Repeat)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Key=='backspace')
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bTextDirty = (Value!="");
Value = "";
TypePos = 0;
bAllSelected = false;
}
2020-11-28 20:12:58 +00:00
else if (TypePos>0)
2017-10-20 02:00:49 +00:00
{
bTextDirty = true;
2020-11-28 20:12:58 +00:00
if (TypePos==Len(Value))
2017-10-20 02:00:49 +00:00
Value = Left(Value,TypePos-1);
else Value = Left(Value,TypePos-1)$Mid(Value,TypePos);
--TypePos;
}
}
2020-11-28 20:12:58 +00:00
else if (Key=='delete')
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bTextDirty = (Value!="");
Value = "";
TypePos = 0;
bAllSelected = false;
}
2020-11-28 20:12:58 +00:00
else if (TypePos<Len(Value))
2017-10-20 02:00:49 +00:00
{
bTextDirty = true;
2020-11-28 20:12:58 +00:00
if (TypePos==0)
2017-10-20 02:00:49 +00:00
Value = Mid(Value,1);
else Value = Left(Value,TypePos)$Mid(Value,TypePos+1);
}
}
2020-11-28 20:04:55 +00:00
else if (Key=='left')
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bAllSelected = false;
TypePos = 0;
}
else TypePos = Max(TypePos-1,0);
}
2020-11-28 20:04:55 +00:00
else if (Key=='right')
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bAllSelected = false;
TypePos = Len(Value);
}
else TypePos = Min(TypePos+1,Len(Value));
}
2020-11-28 20:12:58 +00:00
else if (Key=='home')
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bAllSelected = false;
TypePos = 0;
}
else TypePos = 0;
}
2020-11-28 20:12:58 +00:00
else if (Key=='end')
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bAllSelected = false;
TypePos = Len(Value);
}
else TypePos = Len(Value);
}
2020-11-28 20:12:58 +00:00
else if (Key=='C' && bHoldCtrl)
2017-10-20 02:00:49 +00:00
GetPlayer().CopyToClipboard(Value);
2020-11-28 20:12:58 +00:00
else if (Key=='V' && bHoldCtrl)
2017-10-20 02:00:49 +00:00
PasteText();
2020-11-28 20:12:58 +00:00
else if (Key=='X' && bHoldCtrl)
2017-10-20 02:00:49 +00:00
{
bTextDirty = true;
GetPlayer().CopyToClipboard(Value);
Value = "";
TypePos = 0;
}
}
return true;
}
2020-11-28 21:54:57 +00:00
2017-10-20 02:00:49 +00:00
final function PasteText()
{
local string S;
2023-05-14 02:49:12 +00:00
2017-10-20 02:00:49 +00:00
S = GetPlayer().PasteFromClipboard();
2020-11-28 20:12:58 +00:00
if ((bAllSelected ? (Len(Value)+Len(S)) : Len(S))>MaxTextLength)
2017-10-20 02:00:49 +00:00
return;
bTextDirty = true;
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bAllSelected = false;
Value = S;
TypePos = 0;
}
2020-11-28 20:12:58 +00:00
else if (TypePos==Len(Value))
2017-10-20 02:00:49 +00:00
Value $= S;
else Value = Left(Value,TypePos) $ S $ Mid(Value,TypePos);
TypePos+=Len(S);
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
function bool NotifyInputChar(int ControllerId, string Unicode)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if ((!bAllSelected && Len(Value)>=MaxTextLength) || (bHoldCtrl && (Unicode~="C" || Unicode~="X" || Unicode~="V")))
2017-10-20 02:00:49 +00:00
return true;
2020-11-28 20:12:58 +00:00
if (Asc(Unicode)>=32) // Skip system characters.
2017-10-20 02:00:49 +00:00
{
bTextDirty = true;
2020-11-28 20:12:58 +00:00
if (bAllSelected)
2017-10-20 02:00:49 +00:00
{
bAllSelected = false;
Value = Unicode;
TypePos = 0;
}
2020-11-28 20:12:58 +00:00
else if (TypePos==Len(Value))
2017-10-20 02:00:49 +00:00
Value $= Unicode;
else Value = Left(Value,TypePos) $ Unicode $ Mid(Value,TypePos);
++TypePos;
}
return true;
}
2020-11-28 20:04:55 +00:00
function HandleMouseClick(bool bRight)
2017-10-20 02:00:49 +00:00
{
PlayMenuSound(MN_ClickButton);
2020-11-28 20:12:58 +00:00
if (bIsTyping)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Value!="")
2017-10-20 02:00:49 +00:00
bAllSelected = !bAllSelected;
}
else
{
bIsTyping = true;
bAllSelected = (Value!="");
GrabKeyFocus();
}
TypePos = Len(Value);
}
function LostKeyFocus()
{
2020-11-28 20:12:58 +00:00
if (bTextDirty)
2017-10-20 02:00:49 +00:00
{
OnTextChange(Self);
bTextDirty = false;
}
bHoldCtrl = false;
bIsTyping = false;
}
defaultproperties
{
MaxTextLength=2147483638
TextColor=(R=255,G=255,B=255,A=255)
2023-05-14 02:49:12 +00:00
}