2017-10-20 02:00:49 +00:00
|
|
|
Class KF2GUIController extends Info
|
|
|
|
transient;
|
|
|
|
|
|
|
|
var() class<GUIStyleBase> DefaultStyle;
|
|
|
|
|
|
|
|
var PlayerController PlayerOwner;
|
|
|
|
var transient KF2GUIInput CustomInput;
|
|
|
|
var transient PlayerInput BackupInput;
|
|
|
|
var transient GameViewportClient ClientViewport;
|
|
|
|
|
|
|
|
var array<KFGUI_Page> ActiveMenus,PersistentMenus;
|
|
|
|
var transient KFGUI_Base MouseFocus,InputFocus,KeyboardFocus;
|
|
|
|
var IntPoint MousePosition,ScreenSize,OldMousePos,LastClickPos[2];
|
|
|
|
var transient float MousePauseTime,MenuTime,LastClickTimes[2];
|
|
|
|
var transient GUIStyleBase CurrentStyle;
|
|
|
|
|
|
|
|
var transient Console OrgConsole;
|
|
|
|
var transient KFGUIConsoleHack HackConsole;
|
|
|
|
|
|
|
|
var bool bMouseWasIdle,bIsInMenuState,bAbsorbInput,bIsInvalid;
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
static function KF2GUIController GetGUIController(PlayerController PC)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local KF2GUIController G;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (PC.Player==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
return None;
|
|
|
|
foreach PC.ChildActors(class'KF2GUIController',G)
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!G.bIsInvalid)
|
2017-10-20 02:00:49 +00:00
|
|
|
break;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (G==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
G = PC.Spawn(class'KF2GUIController',PC);
|
|
|
|
return G;
|
|
|
|
}
|
|
|
|
|
|
|
|
simulated function PostBeginPlay()
|
|
|
|
{
|
|
|
|
PlayerOwner = PlayerController(Owner);
|
|
|
|
ClientViewport = LocalPlayer(PlayerOwner.Player).ViewportClient;
|
|
|
|
CurrentStyle = new (None) DefaultStyle;
|
|
|
|
CurrentStyle.InitStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
simulated function Destroyed()
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (PlayerOwner!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
SetMenuState(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
simulated function HandleDrawMenu()
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (HackConsole==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
HackConsole = new(ClientViewport)class'KFGUIConsoleHack';
|
|
|
|
HackConsole.OutputObject = Self;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (HackConsole!=ClientViewport.ViewportConsole)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
OrgConsole = ClientViewport.ViewportConsole;
|
|
|
|
ClientViewport.ViewportConsole = HackConsole;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Make sure nothing overrides these settings while menu is being open.
|
|
|
|
PlayerOwner.PlayerInput = CustomInput;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!ClientViewport.bDisplayHardwareMouseCursor)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
ClientViewport.bDisplayHardwareMouseCursor = true;
|
|
|
|
ClientViewport.ForceUpdateMouseCursor(TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function RenderMenu(Canvas C)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
local float OrgX,OrgY,ClipX,ClipY;
|
|
|
|
local vector2D V;
|
|
|
|
|
|
|
|
ClientViewport.ViewportConsole = OrgConsole;
|
|
|
|
|
|
|
|
ScreenSize.X = C.SizeX;
|
|
|
|
ScreenSize.Y = C.SizeY;
|
|
|
|
CurrentStyle.Canvas = C;
|
|
|
|
CurrentStyle.PickDefaultFontSize(C.SizeY);
|
|
|
|
|
|
|
|
V = ClientViewport.GetMousePosition();
|
|
|
|
MouseMove(V.X,V.Y);
|
|
|
|
|
|
|
|
OrgX = C.OrgX;
|
|
|
|
OrgY = C.OrgY;
|
|
|
|
ClipX = C.ClipX;
|
|
|
|
ClipY = C.ClipY;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=(ActiveMenus.Length-1); i>=0; --i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
ActiveMenus[i].bWindowFocused = (i==0);
|
|
|
|
ActiveMenus[i].InputPos[0] = 0.f;
|
|
|
|
ActiveMenus[i].InputPos[1] = 0.f;
|
|
|
|
ActiveMenus[i].InputPos[2] = ScreenSize.X;
|
|
|
|
ActiveMenus[i].InputPos[3] = ScreenSize.Y;
|
|
|
|
ActiveMenus[i].Canvas = C;
|
|
|
|
ActiveMenus[i].PreDraw();
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None && InputFocus.bFocusedPostDrawItem)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
InputFocus.InputPos[0] = 0.f;
|
|
|
|
InputFocus.InputPos[1] = 0.f;
|
|
|
|
InputFocus.InputPos[2] = ScreenSize.X;
|
|
|
|
InputFocus.InputPos[3] = ScreenSize.Y;
|
|
|
|
InputFocus.Canvas = C;
|
|
|
|
InputFocus.PreDraw();
|
|
|
|
}
|
|
|
|
C.SetOrigin(OrgX,OrgY);
|
|
|
|
C.SetClip(ClipX,ClipY);
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (OrgConsole!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
OrgConsole.PostRender_Console(C);
|
|
|
|
OrgConsole = None;
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated final function SetMenuState(bool bActive)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (PlayerOwner.PlayerInput==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
NotifyLevelChange();
|
|
|
|
bActive = false;
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bIsInMenuState==bActive)
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
|
|
|
bIsInMenuState = bActive;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bActive)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (CustomInput==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
CustomInput = new (KFPlayerController(PlayerOwner)) class'KF2GUIInput';
|
|
|
|
CustomInput.ControllerOwner = Self;
|
|
|
|
CustomInput.OnReceivedNativeInputKey = ReceivedInputKey;
|
|
|
|
CustomInput.BaseInput = PlayerOwner.PlayerInput;
|
|
|
|
BackupInput = PlayerOwner.PlayerInput;
|
|
|
|
PlayerOwner.Interactions.AddItem(CustomInput);
|
|
|
|
}
|
|
|
|
BackupInput.OnReceivedNativeInputKey = ReceivedInputKey;
|
|
|
|
BackupInput.OnReceivedNativeInputChar = ReceivedInputChar;
|
|
|
|
PlayerOwner.PlayerInput = CustomInput;
|
|
|
|
ClientViewport.SetHardwareMouseCursorVisibility(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (BackupInput!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
PlayerOwner.PlayerInput = BackupInput;
|
|
|
|
BackupInput.OnReceivedNativeInputKey = BackupInput.OnReceivedNativeInputKey;
|
|
|
|
BackupInput.OnReceivedNativeInputChar = BackupInput.OnReceivedNativeInputChar;
|
|
|
|
}
|
|
|
|
ClientViewport.SetHardwareMouseCursorVisibility(false);
|
|
|
|
LastClickTimes[0] = 0;
|
|
|
|
LastClickTimes[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
simulated function NotifyLevelChange()
|
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bIsInvalid)
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
|
|
|
bIsInvalid = true;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
InputFocus.LostInputFocus();
|
|
|
|
InputFocus = None;
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=(ActiveMenus.Length-1); i>=0; --i)
|
2017-10-20 02:00:49 +00:00
|
|
|
ActiveMenus[i].NotifyLevelChange();
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=(PersistentMenus.Length-1); i>=0; --i)
|
2017-10-20 02:00:49 +00:00
|
|
|
PersistentMenus[i].NotifyLevelChange();
|
|
|
|
|
|
|
|
SetMenuState(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
simulated function MenuInput(float DeltaTime)
|
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (PlayerOwner.PlayerInput==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
NotifyLevelChange();
|
|
|
|
return;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
InputFocus.MenuTick(DeltaTime);
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<ActiveMenus.Length; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
ActiveMenus[i].MenuTick(DeltaTime);
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Check idle.
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Abs(MousePosition.X-OldMousePos.X)>5.f || Abs(MousePosition.Y-OldMousePos.Y)>5.f || (bMouseWasIdle && MousePauseTime<0.5f))
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bMouseWasIdle)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
bMouseWasIdle = false;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
InputFocus.InputMouseMoved();
|
|
|
|
}
|
|
|
|
OldMousePos = MousePosition;
|
|
|
|
MousePauseTime = 0.f;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
else if (!bMouseWasIdle && (MousePauseTime+=DeltaTime)>0.5f)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
bMouseWasIdle = true;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
MouseFocus.NotifyMousePaused();
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ActiveMenus.Length>0)
|
2017-10-20 02:00:49 +00:00
|
|
|
MenuTime+=DeltaTime;
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function MouseMove(float MouseX, float MouseY)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
local KFGUI_Base F;
|
|
|
|
|
2023-05-14 02:49:12 +00:00
|
|
|
// Handle mouse
|
|
|
|
MousePosition.X = Clamp(MouseX, 0, ScreenSize.X);
|
|
|
|
MousePosition.Y = Clamp(MouseY, 0, ScreenSize.Y);
|
2017-10-20 02:00:49 +00:00
|
|
|
|
|
|
|
// Capture mouse for GUI
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None && InputFocus.bCanFocus)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus.CaptureMouse())
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
F = InputFocus.GetMouseFocus();
|
2020-11-28 20:12:58 +00:00
|
|
|
if (F!=MouseFocus)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
MousePauseTime = 0;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
MouseFocus.MouseLeave();
|
|
|
|
MouseFocus = F;
|
|
|
|
F.MouseEnter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else i = ActiveMenus.Length;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<ActiveMenus.Length; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ActiveMenus[i].CaptureMouse())
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
F = ActiveMenus[i].GetMouseFocus();
|
2020-11-28 20:12:58 +00:00
|
|
|
if (F!=MouseFocus)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
MousePauseTime = 0;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
MouseFocus.MouseLeave();
|
|
|
|
MouseFocus = F;
|
|
|
|
F.MouseEnter();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
else if (ActiveMenus[i].bOnlyThisFocus) // Discard any other menus after this one.
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
i = ActiveMenus.Length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseFocus!=None && i==ActiveMenus.Length) // Hovering over nothing.
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
MousePauseTime = 0;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
MouseFocus.MouseLeave();
|
|
|
|
MouseFocus = None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated final function int GetFreeIndex(bool bNewAlwaysTop) // Find first allowed top index of the stack.
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<ActiveMenus.Length; ++i)
|
|
|
|
if (bNewAlwaysTop || !ActiveMenus[i].bAlwaysTop)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
ActiveMenus.Insert(i,1);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
i = ActiveMenus.Length;
|
|
|
|
ActiveMenus.Length = i+1;
|
|
|
|
return i;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function KFGUI_Page OpenMenu(class<KFGUI_Page> MenuClass)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
local KFGUI_Page M;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MenuClass==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
return None;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (KeyboardFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
GrabInputFocus(None);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
InputFocus.LostInputFocus();
|
|
|
|
InputFocus = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable mouse on UI if disabled.
|
|
|
|
SetMenuState(true);
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Check if should use pre-excisting menu.
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MenuClass.Default.bUnique)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<ActiveMenus.Length; ++i)
|
|
|
|
if (ActiveMenus[i].Class==MenuClass)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (i>0 && ActiveMenus[i].BringPageToFront()) // Sort it upfront.
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
M = ActiveMenus[i];
|
|
|
|
ActiveMenus.Remove(i,1);
|
|
|
|
i = GetFreeIndex(M.bAlwaysTop);
|
|
|
|
ActiveMenus[i] = M;
|
|
|
|
}
|
|
|
|
return M;
|
|
|
|
}
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MenuClass.Default.bPersistant)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<PersistentMenus.Length; ++i)
|
|
|
|
if (PersistentMenus[i].Class==MenuClass)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
M = PersistentMenus[i];
|
|
|
|
PersistentMenus.Remove(i,1);
|
|
|
|
i = GetFreeIndex(M.bAlwaysTop);
|
|
|
|
ActiveMenus[i] = M;
|
|
|
|
M.ShowMenu();
|
|
|
|
return M;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
M = New(None)MenuClass;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (M==None) // Probably abstract class.
|
2017-10-20 02:00:49 +00:00
|
|
|
return None;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
i = GetFreeIndex(M.bAlwaysTop);
|
|
|
|
ActiveMenus[i] = M;
|
|
|
|
M.Owner = Self;
|
|
|
|
M.InitMenu();
|
|
|
|
M.ShowMenu();
|
|
|
|
return M;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function CloseMenu(class<KFGUI_Page> MenuClass, optional bool bCloseAll)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
local KFGUI_Page M;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bCloseAll && MenuClass==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (KeyboardFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
GrabInputFocus(None);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
InputFocus.LostInputFocus();
|
|
|
|
InputFocus = None;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=(ActiveMenus.Length-1); i>=0; --i)
|
|
|
|
if (bCloseAll || ActiveMenus[i].Class==MenuClass)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
M = ActiveMenus[i];
|
|
|
|
ActiveMenus.Remove(i,1);
|
|
|
|
M.CloseMenu();
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Cache menu.
|
2020-11-28 20:12:58 +00:00
|
|
|
if (M.bPersistant && M.bUnique)
|
2017-10-20 02:00:49 +00:00
|
|
|
PersistentMenus[PersistentMenus.Length] = M;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ActiveMenus.Length==0)
|
2017-10-20 02:00:49 +00:00
|
|
|
SetMenuState(false);
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function PopCloseMenu(KFGUI_Base Item)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
local KFGUI_Page M;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Item==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (KeyboardFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
GrabInputFocus(None);
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
InputFocus.LostInputFocus();
|
|
|
|
InputFocus = None;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=(ActiveMenus.Length-1); i>=0; --i)
|
|
|
|
if (ActiveMenus[i]==Item)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
M = ActiveMenus[i];
|
|
|
|
ActiveMenus.Remove(i,1);
|
|
|
|
M.CloseMenu();
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Cache menu.
|
2020-11-28 20:12:58 +00:00
|
|
|
if (M.bPersistant && M.bUnique)
|
2017-10-20 02:00:49 +00:00
|
|
|
PersistentMenus[PersistentMenus.Length] = M;
|
|
|
|
break;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ActiveMenus.Length==0)
|
2017-10-20 02:00:49 +00:00
|
|
|
SetMenuState(false);
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function BringMenuToFront(KFGUI_Page Page)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ActiveMenus[0].bAlwaysTop && !Page.bAlwaysTop)
|
2017-10-20 02:00:49 +00:00
|
|
|
return; // Can't override this menu.
|
|
|
|
|
|
|
|
// Try to remove from current position at stack.
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=(ActiveMenus.Length-1); i>=0; --i)
|
|
|
|
if (ActiveMenus[i]==Page)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
ActiveMenus.Remove(i,1);
|
|
|
|
break;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (i==-1)
|
2017-10-20 02:00:49 +00:00
|
|
|
return; // Page isn't open.
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Put on front of stack.
|
|
|
|
ActiveMenus.Insert(0,1);
|
|
|
|
ActiveMenus[0] = Page;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated final function bool MenuIsOpen(optional class<KFGUI_Page> MenuClass)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=(ActiveMenus.Length-1); i>=0; --i)
|
|
|
|
if (MenuClass==None || ActiveMenus[i].Class==MenuClass)
|
2017-10-20 02:00:49 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated final function GrabInputFocus(KFGUI_Base Comp, optional bool bForce)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Comp==KeyboardFocus && !bForce)
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (KeyboardFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
KeyboardFocus.LostKeyFocus();
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Comp==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
OnInputKey = InternalInputKey;
|
|
|
|
OnReceivedInputChar = InternalReceivedInputChar;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
else if (KeyboardFocus==None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
OnInputKey = Comp.NotifyInputKey;
|
|
|
|
OnReceivedInputChar = Comp.NotifyInputChar;
|
|
|
|
}
|
|
|
|
KeyboardFocus = Comp;
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated final function GUI_InputMouse(bool bPressed, bool bRight)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local byte i;
|
|
|
|
|
|
|
|
MousePauseTime = 0;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bPressed)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (KeyboardFocus!=None && KeyboardFocus!=MouseFocus)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
GrabInputFocus(None);
|
|
|
|
LastClickTimes[0] = 0;
|
|
|
|
LastClickTimes[1] = 0;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseFocus!=InputFocus && !MouseFocus.bClickable && !MouseFocus.IsTopMenu() && MouseFocus.BringPageToFront())
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
BringMenuToFront(MouseFocus.GetPageTop());
|
|
|
|
LastClickTimes[0] = 0;
|
|
|
|
LastClickTimes[1] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = byte(bRight);
|
2020-11-28 20:12:58 +00:00
|
|
|
if ((MenuTime-LastClickTimes[i])<0.2 && Abs(LastClickPos[i].X-MousePosition.X)<5 && Abs(LastClickPos[i].Y-MousePosition.Y)<5)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
LastClickTimes[i] = 0;
|
|
|
|
MouseFocus.DoubleMouseClick(bRight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MouseFocus.MouseClick(bRight);
|
|
|
|
LastClickTimes[i] = MenuTime;
|
|
|
|
LastClickPos[i] = MousePosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
else if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
InputFocus.LostInputFocus();
|
|
|
|
InputFocus = None;
|
|
|
|
LastClickTimes[0] = 0;
|
|
|
|
LastClickTimes[1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (InputFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
InputFocus.MouseRelease(bRight);
|
2020-11-28 20:12:58 +00:00
|
|
|
else if (MouseFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
MouseFocus.MouseRelease(bRight);
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated final function bool CheckMouse(name Key, EInputEvent Event)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:04:55 +00:00
|
|
|
if (Event == IE_Pressed)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
switch (Key)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
case 'LeftMouseButton':
|
|
|
|
GUI_InputMouse(true,false);
|
|
|
|
return true;
|
|
|
|
case 'RightMouseButton':
|
|
|
|
GUI_InputMouse(true,true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 20:04:55 +00:00
|
|
|
else if (Event == IE_Released)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
switch (Key)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
case 'LeftMouseButton':
|
|
|
|
GUI_InputMouse(false,false);
|
|
|
|
return true;
|
|
|
|
case 'RightMouseButton':
|
|
|
|
GUI_InputMouse(false,true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function bool ReceivedInputKey(int ControllerId, name Key, EInputEvent Event, optional float AmountDepressed=1.f, optional bool bGamepad)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bIsInMenuState)
|
2017-10-20 02:00:49 +00:00
|
|
|
return false;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!CheckMouse(Key,Event) && !OnInputKey(ControllerId,Key,Event,AmountDepressed,bGamepad))
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
switch (Key)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
case 'Escape':
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Event==IE_Pressed)
|
2017-10-20 02:00:49 +00:00
|
|
|
ActiveMenus[0].UserPressedEsc(); // Pop top menu if possible.
|
|
|
|
return true;
|
|
|
|
case 'MouseScrollDown':
|
|
|
|
case 'MouseScrollUp':
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Event==IE_Pressed && MouseFocus!=None)
|
2017-10-20 02:00:49 +00:00
|
|
|
MouseFocus.ScrollMouseWheel(Key=='MouseScrollUp');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return bAbsorbInput;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated function bool ReceivedInputChar(int ControllerId, string Unicode)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bIsInMenuState)
|
2017-10-20 02:00:49 +00:00
|
|
|
return false;
|
|
|
|
return OnReceivedInputChar(ControllerId,Unicode);
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated Delegate bool OnInputKey(int ControllerId, name Key, EInputEvent Event, optional float AmountDepressed=1.f, optional bool bGamepad)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated Delegate bool OnReceivedInputChar(int ControllerId, string Unicode)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated Delegate bool InternalInputKey(int ControllerId, name Key, EInputEvent Event, optional float AmountDepressed=1.f, optional bool bGamepad)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
simulated Delegate bool InternalReceivedInputChar(int ControllerId, string Unicode)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
|
|
|
DefaultStyle=class'KF2Style'
|
|
|
|
bAbsorbInput=true
|
2023-05-14 02:49:12 +00:00
|
|
|
}
|