2020-01-10 13:14:11 +00:00
|
|
|
// Menu system written by Marco.
|
2022-09-03 17:26:40 +00:00
|
|
|
class KFGUI_Base extends Object
|
2021-05-16 09:40:02 +00:00
|
|
|
abstract;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
var KF2GUIController Owner;
|
2022-09-03 17:26:40 +00:00
|
|
|
var YAS_HUD HUDOwner;
|
2020-01-10 13:14:11 +00:00
|
|
|
var KFGUI_Base ParentComponent; // Parent component if any.
|
|
|
|
var transient Canvas Canvas;
|
|
|
|
|
|
|
|
enum EMenuSound
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
MN_Focus,
|
|
|
|
MN_LostFocus,
|
|
|
|
MN_FocusHover,
|
|
|
|
MN_ClickButton,
|
|
|
|
MN_ClickCheckboxOn,
|
|
|
|
MN_ClickCheckboxOff,
|
|
|
|
MN_Dropdown,
|
|
|
|
MN_DropdownChange,
|
2020-01-10 13:14:11 +00:00
|
|
|
};
|
|
|
|
|
2021-06-13 02:54:35 +00:00
|
|
|
var() float XPosition, YPosition, XSize, YSize;
|
2020-01-10 13:14:11 +00:00
|
|
|
var() name ID; // Just for internal purposes, you can give the components unique ID values.
|
|
|
|
var() int IDValue; // Integer ID value.
|
2021-06-13 02:54:35 +00:00
|
|
|
var transient float CompPos[4], InputPos[4];
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
var transient KFGUI_Base MouseArea; // Next in recurse line of the mouse pointer focus area.
|
|
|
|
|
2021-06-13 02:54:35 +00:00
|
|
|
var() bool bDisabled, bClickable, bCanFocus;
|
2020-01-10 13:14:11 +00:00
|
|
|
var bool bFocusedPostDrawItem; // If this component has been given input focus, should it receive draw menu call after everything else been drawn?
|
2021-06-13 02:54:35 +00:00
|
|
|
var transient bool bFocused, bTextureInit, bVisible;
|
|
|
|
var bool bIsHUDWidget, bEnableInputs, bNoLookInputs;
|
2021-06-13 03:17:40 +00:00
|
|
|
var array<name> TimerNames;
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
function InitMenu(); // Menu was initialized for the first time.
|
|
|
|
function ShowMenu(); // Menu was opened.
|
|
|
|
function PreDraw()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (!bVisible)
|
2021-05-16 09:40:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ComputeCoords();
|
2021-06-13 02:54:35 +00:00
|
|
|
Canvas.SetDrawColor(255, 255, 255);
|
|
|
|
Canvas.SetOrigin(CompPos[0], CompPos[1]);
|
|
|
|
Canvas.SetClip(CompPos[0]+CompPos[2], CompPos[1]+CompPos[3]);
|
2021-05-16 09:40:02 +00:00
|
|
|
DrawMenu();
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function DrawMenu(); // Draw menu now.
|
|
|
|
function CloseMenu(); // Menu was closed.
|
|
|
|
function InventoryChanged(optional KFWeapon Wep, optional bool bRemove); // Called when a players inventory is changed.
|
2021-06-13 03:00:19 +00:00
|
|
|
function MenuTick(float DeltaTime);
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
final function SetTimer(float InRate, optional bool inbLoop, optional Name inTimerFunc='Timer')
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (InRate <= 0.f)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
ClearTimer(inTimerFunc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (TimerNames.Find(inTimerFunc) == INDEX_NONE)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
TimerNames.AddItem(inTimerFunc);
|
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
`TimerHelper.SetTimer(InRate, inbLoop, inTimerFunc, self);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
final function ClearTimer(optional Name inTimerFunc='Timer')
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (TimerNames.Find(inTimerFunc) != INDEX_NONE)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
TimerNames.RemoveItem(inTimerFunc);
|
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
`TimerHelper.ClearTimer(inTimerFunc, self);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function Timer();
|
|
|
|
|
|
|
|
function MouseEnter()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
bFocused = true;
|
2021-06-13 02:54:35 +00:00
|
|
|
OnFocus(Self, True);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function MouseLeave()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
bFocused = false;
|
2021-06-13 02:54:35 +00:00
|
|
|
OnFocus(Self, False);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
function MouseClick(bool bRight);
|
|
|
|
function MouseRelease(bool bRight);
|
|
|
|
function DoubleMouseClick(bool bRight ) // User rapidly double clicked this component.
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
MouseClick(bRight);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
function ScrollMouseWheel(bool bUp);
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
function bool ReceievedControllerInput(int ControllerId, name Key, EInputEvent Event)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final function PlayerController GetPlayer()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return Owner.PlayerOwner;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
function SetDisabled(bool bDisable)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
bDisabled = bDisable;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
Delegate OnFocus(KFGUI_Base Sender, bool bBecame);
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
final function ComputeCoords()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
CompPos[0] = XPosition*InputPos[2]+InputPos[0];
|
|
|
|
CompPos[1] = YPosition*InputPos[3]+InputPos[1];
|
|
|
|
CompPos[2] = XSize*InputPos[2];
|
|
|
|
CompPos[3] = YSize*InputPos[3];
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function bool CaptureMouse()
|
|
|
|
{
|
2021-06-13 03:00:19 +00:00
|
|
|
return bVisible && ( Owner.MousePosition.X >= CompPos[0] && Owner.MousePosition.Y >= CompPos[1] && Owner.MousePosition.X <= (CompPos[0]+CompPos[2]) && Owner.MousePosition.Y <= (CompPos[1]+CompPos[3]));
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final function KFGUI_Base GetMouseFocus()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local KFGUI_Base M;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
for (M=Self; M.MouseArea != None; M=M.MouseArea)
|
2021-05-16 09:40:02 +00:00
|
|
|
{}
|
|
|
|
return M;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetVisibility(bool Visible)
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
bVisible = Visible;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function DoClose()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local int i;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
for (i=0; i < TimerNames.Length; i++)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
ClearTimer(TimerNames[i]);
|
|
|
|
}
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ParentComponent != None)
|
2021-05-16 09:40:02 +00:00
|
|
|
ParentComponent.DoClose();
|
|
|
|
else Owner.PopCloseMenu(Self);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function byte GetCursorStyle()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return (bClickable ? `PEN_BLACK : `PEN_WHITE);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function UserPressedEsc() // user pressed escape while this menu was active.
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ParentComponent != None)
|
2021-05-16 09:40:02 +00:00
|
|
|
ParentComponent.UserPressedEsc();
|
|
|
|
else DoClose();
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function bool BringPageToFront()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ParentComponent != None)
|
2021-05-16 09:40:02 +00:00
|
|
|
return ParentComponent.BringPageToFront();
|
|
|
|
return true; // Allow user to bring this page to front.
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
final function bool IsTopMenu()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
return (Owner.ActiveMenus.Length > 0 && GetPageTop() == Owner.ActiveMenus[0]);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
final function KFGUI_Page GetPageTop()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local KFGUI_Base M;
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
for (M=Self; M.ParentComponent != None; M=M.ParentComponent)
|
2021-05-16 09:40:02 +00:00
|
|
|
{}
|
|
|
|
return KFGUI_Page(M);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
function KFGUI_Base FindComponentID(name InID)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ID == InID)
|
2021-05-16 09:40:02 +00:00
|
|
|
return Self;
|
|
|
|
return None;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 07:29:12 +00:00
|
|
|
function FindAllComponentID(name InID, out array<KFGUI_Base> Res)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (ID == InID)
|
2021-05-16 09:40:02 +00:00
|
|
|
Res[Res.Length] = Self;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
function RemoveComponent(KFGUI_Base B);
|
2020-01-10 13:14:11 +00:00
|
|
|
|
|
|
|
function GetInputFocus()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Owner.InputFocus != None)
|
2021-05-16 09:40:02 +00:00
|
|
|
Owner.InputFocus.LostInputFocus();
|
|
|
|
Owner.InputFocus = Self;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function DropInputFocus()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Owner.InputFocus == Self)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
Owner.InputFocus.LostInputFocus();
|
|
|
|
Owner.InputFocus = None;
|
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function LostInputFocus();
|
|
|
|
|
|
|
|
// Obtain keyboard focus.
|
|
|
|
final function GrabKeyFocus()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
Owner.GrabInputFocus(Self);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
final function ReleaseKeyFocus()
|
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Owner.KeyboardFocus == Self)
|
2021-05-16 09:40:02 +00:00
|
|
|
Owner.GrabInputFocus(None);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
function LostKeyFocus();
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
function bool NotifyInputKey(int ControllerId, name Key, EInputEvent Event, float AmountDepressed, bool bGamepad)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-06-13 02:53:33 +00:00
|
|
|
if (bIsHUDWidget && bEnableInputs)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
2021-06-13 03:00:19 +00:00
|
|
|
switch (Key)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
case 'XboxTypeS_Start':
|
|
|
|
case 'Escape':
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Event == IE_Pressed)
|
2021-05-16 09:40:02 +00:00
|
|
|
UserPressedEsc();
|
|
|
|
return true;
|
|
|
|
case 'XboxTypeS_DPad_Up':
|
|
|
|
case 'XboxTypeS_DPad_Down':
|
|
|
|
case 'XboxTypeS_DPad_Left':
|
|
|
|
case 'XboxTypeS_DPad_Right':
|
|
|
|
case 'MouseScrollDown':
|
|
|
|
case 'MouseScrollUp':
|
|
|
|
case 'MouseScrollDown':
|
|
|
|
case 'MouseScrollUp':
|
2021-06-13 02:53:33 +00:00
|
|
|
if (Event == IE_Pressed)
|
|
|
|
ScrollMouseWheel(Key == 'MouseScrollUp' || Key == 'XboxTypeS_DPad_Up' || Key == 'XboxTypeS_DPad_Left');
|
2021-05-16 09:40:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
function bool NotifyInputAxis(int ControllerId, name Key, float Delta, float DeltaTime, bool bGamepad)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
function bool NotifyInputChar(int ControllerId, string Unicode)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// While on input focus mode, notify that mouse just moved over the threshold.
|
|
|
|
function InputMouseMoved();
|
|
|
|
|
|
|
|
// Notify any focused menu element that mouse has been idle over it.
|
|
|
|
function NotifyMousePaused();
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
final function GetActualPos(out float X, out float Y)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
X = ((XPosition+X)*InputPos[2]) + InputPos[0];
|
|
|
|
Y = ((YPosition+Y)*InputPos[3]) + InputPos[1];
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
2021-06-13 03:00:19 +00:00
|
|
|
final function GetRealtivePos(out float X, out float Y)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
X = X / CompPos[2];
|
|
|
|
Y = Y / CompPos[2];
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
simulated final function PlayMenuSound(EMenuSound Slot)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local SoundCue S;
|
|
|
|
local KFGameEngine Engine;
|
|
|
|
|
|
|
|
Engine = KFGameEngine(class'Engine'.static.GetEngine());
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
switch (Slot)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
case MN_FocusHover:
|
|
|
|
case MN_Focus:
|
|
|
|
S = Owner.CurrentStyle.MenuHover;
|
|
|
|
break;
|
|
|
|
case MN_LostFocus:
|
|
|
|
S = Owner.CurrentStyle.MenuFade;
|
|
|
|
break;
|
|
|
|
case MN_ClickButton:
|
|
|
|
case MN_ClickCheckboxOff:
|
|
|
|
S = Owner.CurrentStyle.MenuClick;
|
|
|
|
break;
|
|
|
|
case MN_Dropdown:
|
|
|
|
S = Owner.CurrentStyle.MenuDown;
|
|
|
|
break;
|
|
|
|
case MN_DropdownChange:
|
|
|
|
S = Owner.CurrentStyle.MenuEdit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-13 02:53:33 +00:00
|
|
|
if (S != None)
|
2021-05-16 09:40:02 +00:00
|
|
|
{
|
|
|
|
S.VolumeMultiplier = (Engine.SFxVolumeMultiplier/100.f) * (Engine.MasterVolumeMultiplier/100.f);
|
2021-06-13 02:54:35 +00:00
|
|
|
GetPlayer().PlaySound(S, true, ,false);
|
2021-05-16 09:40:02 +00:00
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pre level change notification.
|
|
|
|
function NotifyLevelChange();
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
final function SetPosition(float X, float Y, float XS, float YS)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
XPosition = X;
|
|
|
|
YPosition = Y;
|
|
|
|
XSize = XS;
|
|
|
|
YSize = YS;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 03:00:19 +00:00
|
|
|
static final function string MakeSortStr(int Value)
|
2020-01-10 13:14:11 +00:00
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local string S;
|
|
|
|
local int i;
|
|
|
|
|
|
|
|
// Prefix with zeroes to properly sort this string.
|
|
|
|
S = string(Value);
|
|
|
|
i = Len(S);
|
2021-06-13 02:53:33 +00:00
|
|
|
if (i < 10)
|
2021-06-13 02:54:35 +00:00
|
|
|
return Mid("0000000000", i)$S;
|
2021-05-16 09:40:02 +00:00
|
|
|
return S;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
XSize=1
|
|
|
|
YSize=1
|
|
|
|
bCanFocus=true
|
|
|
|
bVisible=true
|
2023-05-02 19:15:42 +00:00
|
|
|
}
|