KF2-YetAnotherScoreboard/ScoreboardExt/Classes/KF2GUIController.uc

900 lines
20 KiB
Ucode
Raw Normal View History

2020-01-10 13:14:11 +00:00
Class KF2GUIController extends Info
transient;
2020-01-10 13:14:11 +00:00
2021-06-12 20:11:37 +00:00
`include(Build.uci)
`include(Logger.uci)
2021-06-13 02:53:33 +00:00
var() class < GUIStyleBase> DefaultStyle;
2020-01-10 13:14:11 +00:00
var PlayerController PlayerOwner;
2021-05-16 03:37:39 +00:00
var ScoreboardExtHUD HUDOwner;
2020-01-10 13:14:11 +00:00
var transient KF2GUIInput CustomInput;
var transient PlayerInput BackupInput;
var transient GameViewportClient ClientViewport;
2021-06-13 02:53:33 +00:00
var delegate < Interaction.OnReceivedNativeInputKey> OldOnReceivedNativeInputKey;
var delegate < Interaction.OnReceivedNativeInputAxis> OldOnReceivedNativeInputAxis;
var delegate < Interaction.OnReceivedNativeInputChar> OldOnReceivedNativeInputChar;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
var delegate < GameViewportClient.HandleInputAxis> OldHandleInputAxis;
2020-01-10 13:14:11 +00:00
2021-06-13 02:54:35 +00:00
var array < KFGUI_Page> ActiveMenus, PersistentMenus;
var transient KFGUI_Base MouseFocus, InputFocus, KeyboardFocus;
var IntPoint MousePosition, ScreenSize, OldMousePos, LastMousePos, LastClickPos[2];
var transient float MousePauseTime, MenuTime, LastClickTimes[2];
2020-01-10 13:14:11 +00:00
var transient GUIStyleBase CurrentStyle;
var transient Console OrgConsole;
var transient KFGUIConsoleHack HackConsole;
2021-06-13 02:53:33 +00:00
var array < Texture2D> CursorTextures;
2020-01-10 13:14:11 +00:00
var Color CursorColor;
var int CurrentCursorIndex, CursorSize;
var Texture DefaultPens[3];
var byte CursorFade, FastCursorFade, CursorFlash;
var int CursorStep, FastCursorStep;
2021-06-13 02:54:35 +00:00
var int FontBlurX, FontBlurX2, FontBlurY, FontBlurY2, FastFontBlurX, FastFontBlurX2, FastFontBlurY, FastFontBlurY2;
2020-01-10 13:14:11 +00:00
2021-06-13 02:54:35 +00:00
var bool bMouseWasIdle, bIsInMenuState, bAbsorbInput, bIsInvalid, bHideCursor, bUsingGamepad, bForceEngineCursor, bNoInputReset;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
static function KF2GUIController GetGUIController( PlayerController PC)
2020-01-10 13:14:11 +00:00
{
local KF2GUIController G;
2021-06-13 02:53:33 +00:00
if (PC.Player == None)
{
return None;
}
2021-06-13 02:54:35 +00:00
foreach PC.ChildActors(class'ScoreboardExt.KF2GUIController', G)
{
2021-06-13 02:53:33 +00:00
if (!G.bIsInvalid)
{
break;
}
}
2021-06-13 02:53:33 +00:00
if (G == None)
{
2021-06-13 02:54:35 +00:00
G = PC.Spawn(class'ScoreboardExt.KF2GUIController', PC);
}
return G;
2020-01-10 13:14:11 +00:00
}
simulated function PostBeginPlay()
{
PlayerOwner = PlayerController(Owner);
ClientViewport = LocalPlayer(PlayerOwner.Player).ViewportClient;
HUDOwner = ScoreboardExtHUD(PlayerOwner.myHUD);
CurrentStyle = new (None) DefaultStyle;
CurrentStyle.InitStyle();
CurrentStyle.Owner = self;
SetTimer(0.1, true, 'SetupFontBlur');
SetTimer(0.05, true, 'SetupFastFontBlur');
SetTimer(0.75, true, 'SetupCursorFlash');
2020-01-10 13:14:11 +00:00
}
simulated function SetupCursorFlash()
{
2021-06-13 02:53:33 +00:00
if (CursorFlash == 255)
CursorFlash = 0;
else CursorFlash = 255;
2020-01-10 13:14:11 +00:00
}
simulated function SetupFastFontBlur()
{
FastFontBlurX = RandRange(-8, 8);
FastFontBlurX2 = RandRange(-8, 8);
FastFontBlurY = RandRange(-8, 8);
FastFontBlurY2 = RandRange(-8, 8);
2020-01-10 13:14:11 +00:00
}
simulated function SetupFontBlur()
{
FontBlurX = RandRange(-8, 8);
FontBlurX2 = RandRange(-8, 8);
FontBlurY = RandRange(-8, 8);
FontBlurY2 = RandRange(-8, 8);
2020-01-10 13:14:11 +00:00
}
simulated function Tick(float DT)
{
Super.Tick(DT);
DT /= WorldInfo.TimeDilation;
CursorFade += 255 * DT * CursorStep;
2021-06-13 02:53:33 +00:00
if (CursorFade <= 0)
{
CursorFade = 0;
CursorStep = 1;
}
2021-06-13 02:53:33 +00:00
else if (CursorFade >= 255)
{
CursorFade = 255;
CursorStep = -1;
}
FastCursorFade += 8192 * DT * FastCursorStep;
2021-06-13 02:53:33 +00:00
if (FastCursorFade <= 0)
{
FastCursorFade = 0;
FastCursorStep = 1;
}
2021-06-13 02:53:33 +00:00
else if (FastCursorFade >= 255)
{
FastCursorFade = 255;
FastCursorStep = -1;
}
2020-01-10 13:14:11 +00:00
}
simulated function Destroyed()
{
2021-06-13 02:53:33 +00:00
if (PlayerOwner != None)
SetMenuState(false);
2020-01-10 13:14:11 +00:00
}
simulated function HandleDrawMenu()
{
2021-06-13 02:53:33 +00:00
if (HackConsole == None)
{
HackConsole = new(ClientViewport)class'ScoreboardExt.KFGUIConsoleHack';
HackConsole.OutputObject = Self;
}
2021-06-13 02:53:33 +00:00
if (HackConsole != ClientViewport.ViewportConsole)
{
OrgConsole = ClientViewport.ViewportConsole;
ClientViewport.ViewportConsole = HackConsole;
// Make sure nothing overrides these settings while menu is being open.
2021-06-13 02:53:33 +00:00
if (bIsInMenuState ) PlayerOwner.PlayerInput = CustomInput;
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function RenderMenu( Canvas C)
2020-01-10 13:14:11 +00:00
{
local int i;
2021-06-13 02:54:35 +00:00
local float OrgX, OrgY, ClipX, ClipY;
ClientViewport.ViewportConsole = OrgConsole;
OrgX = C.OrgX;
OrgY = C.OrgY;
ClipX = C.ClipX;
ClipY = C.ClipY;
ScreenSize.X = C.SizeX;
ScreenSize.Y = C.SizeY;
CurrentStyle.Canvas = C;
CurrentStyle.PickDefaultFontSize(C.SizeY);
2021-06-13 02:53:33 +00:00
if (!KFPlayerController(PlayerOwner).MyGFxManager.bMenusActive)
{
HUDOwner.Canvas = C;
2021-06-13 02:53:33 +00:00
for (i=(HUDOwner.HUDWidgets.Length-1); i >= 0; --i)
{
HUDOwner.HUDWidgets[i].InputPos[0] = 0.f;
HUDOwner.HUDWidgets[i].InputPos[1] = 0.f;
HUDOwner.HUDWidgets[i].InputPos[2] = ScreenSize.X;
HUDOwner.HUDWidgets[i].InputPos[3] = ScreenSize.Y;
HUDOwner.HUDWidgets[i].Canvas = C;
HUDOwner.HUDWidgets[i].PreDraw();
}
2021-06-13 02:54:35 +00:00
C.SetOrigin(OrgX, OrgY);
C.SetClip(ClipX, ClipY);
}
2021-06-13 02:53:33 +00:00
if (bIsInMenuState)
{
2021-06-13 02:53:33 +00:00
for (i=(ActiveMenus.Length-1); i >= 0; --i)
{
2021-06-13 02:53:33 +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();
}
2021-06-13 02:53:33 +00:00
if (InputFocus != None && InputFocus.bFocusedPostDrawItem)
{
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();
}
2021-06-13 02:54:35 +00:00
C.SetOrigin(OrgX, OrgY);
C.SetClip(ClipX, ClipY);
if (!bHideCursor)
{
DrawCursor(C, MousePosition.X, MousePosition.Y);
}
}
2021-06-13 02:53:33 +00:00
if (OrgConsole != None)
OrgConsole.PostRender_Console(C);
OrgConsole = None;
2020-01-10 13:14:11 +00:00
}
simulated function DrawCursor(Canvas C, float PosX, float PosY)
{
C.SetPos(PosX, PosY);
C.DrawColor = CursorColor;
2021-06-13 02:54:35 +00:00
C.DrawTile(CursorTextures[CurrentCursorIndex], CurrentStyle.ScreenScale(CursorSize), CurrentStyle.ScreenScale(CursorSize), 0.f, 0.f, CursorTextures[CurrentCursorIndex].SizeX, CursorTextures[CurrentCursorIndex].SizeY, , true);
2020-01-10 13:14:11 +00:00
}
simulated final function InventoryChanged(optional KFWeapon Wep, optional bool bRemove)
{
local int i;
2021-06-13 02:53:33 +00:00
for (i=(ActiveMenus.Length-1); i >= 0; --i)
{
2021-06-13 02:54:35 +00:00
ActiveMenus[i].InventoryChanged(Wep, bRemove);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated final function SetMenuState( bool bActive)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:53:33 +00:00
if (PlayerOwner.PlayerInput == None)
{
NotifyLevelChange();
bActive = false;
}
2021-06-13 02:53:33 +00:00
if (bIsInMenuState == bActive)
return;
bIsInMenuState = bActive;
bHideCursor = !bActive;
2021-06-13 02:53:33 +00:00
if (bActive)
{
2021-06-13 02:53:33 +00:00
if (CustomInput == None)
{
CustomInput = new (KFPlayerController(PlayerOwner)) class'ScoreboardExt.KF2GUIInput';
CustomInput.ControllerOwner = Self;
CustomInput.OnReceivedNativeInputKey = ReceivedInputKey;
CustomInput.BaseInput = PlayerOwner.PlayerInput;
BackupInput = PlayerOwner.PlayerInput;
PlayerOwner.Interactions.AddItem(CustomInput);
}
OldOnReceivedNativeInputKey = BackupInput.OnReceivedNativeInputKey;
OldOnReceivedNativeInputAxis = BackupInput.OnReceivedNativeInputAxis;
OldOnReceivedNativeInputChar = BackupInput.OnReceivedNativeInputChar;
BackupInput.OnReceivedNativeInputKey = ReceivedInputKey;
BackupInput.OnReceivedNativeInputAxis = ReceivedInputAxis;
BackupInput.OnReceivedNativeInputChar = ReceivedInputChar;
OldHandleInputAxis = ClientViewport.HandleInputAxis;
ClientViewport.HandleInputAxis = ReceivedInputAxis;
PlayerOwner.PlayerInput = CustomInput;
2021-06-13 02:53:33 +00:00
if (LastMousePos != default.LastMousePos)
2021-06-13 02:54:35 +00:00
ClientViewport.SetMouse(LastMousePos.X, LastMousePos.Y);
}
else
{
LastMousePos = MousePosition;
ClientViewport.HandleInputAxis = None;
2021-06-13 02:53:33 +00:00
if (BackupInput != None)
{
PlayerOwner.PlayerInput = BackupInput;
BackupInput.OnReceivedNativeInputKey = OldOnReceivedNativeInputKey;
BackupInput.OnReceivedNativeInputAxis = OldOnReceivedNativeInputAxis;
BackupInput.OnReceivedNativeInputChar = OldOnReceivedNativeInputChar;
ClientViewport.HandleInputAxis = OldHandleInputAxis;
}
LastClickTimes[0] = 0;
LastClickTimes[1] = 0;
}
2021-06-13 02:53:33 +00:00
if (!bNoInputReset)
{
PlayerOwner.PlayerInput.ResetInput();
}
2020-01-10 13:14:11 +00:00
}
simulated function NotifyLevelChange()
{
local int i;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (bIsInvalid)
return;
bIsInvalid = true;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (InputFocus != None)
{
InputFocus.LostInputFocus();
InputFocus = None;
}
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
for (i=(ActiveMenus.Length-1); i >= 0; --i)
ActiveMenus[i].NotifyLevelChange();
2021-06-13 02:53:33 +00:00
for (i=(PersistentMenus.Length-1); i >= 0; --i)
PersistentMenus[i].NotifyLevelChange();
2020-01-10 13:14:11 +00:00
SetMenuState(false);
2020-01-10 13:14:11 +00:00
}
simulated function MenuInput(float DeltaTime)
{
local int i;
local vector2D V;
2021-06-13 02:53:33 +00:00
if (PlayerOwner.PlayerInput == None)
{
NotifyLevelChange();
return;
}
2021-06-13 02:53:33 +00:00
if (InputFocus != None)
InputFocus.MenuTick(DeltaTime);
2021-06-13 02:53:33 +00:00
for (i=0; i < ActiveMenus.Length; ++i)
ActiveMenus[i].MenuTick(DeltaTime);
// Check idle.
2021-06-13 02:53:33 +00:00
if (Abs(MousePosition.X-OldMousePos.X) > 5.f || Abs(MousePosition.Y-OldMousePos.Y) > 5.f || (bMouseWasIdle && MousePauseTime < 0.5f))
{
2021-06-13 02:53:33 +00:00
if (bMouseWasIdle)
{
bMouseWasIdle = false;
2021-06-13 02:53:33 +00:00
if (InputFocus != None)
InputFocus.InputMouseMoved();
}
OldMousePos = MousePosition;
MousePauseTime = 0.f;
}
2021-06-13 02:53:33 +00:00
else if (!bMouseWasIdle && (MousePauseTime+=DeltaTime) > 0.5f)
{
bMouseWasIdle = true;
2021-06-13 02:53:33 +00:00
if (MouseFocus != None)
MouseFocus.NotifyMousePaused();
}
2021-06-13 02:53:33 +00:00
if (ActiveMenus.Length > 0)
MenuTime+=DeltaTime;
V = ClientViewport.GetMousePosition();
MousePosition.X = Clamp(V.X, 0, ScreenSize.X);
MousePosition.Y = Clamp(V.Y, 0, ScreenSize.Y);
MouseMove();
2020-01-10 13:14:11 +00:00
}
simulated function MouseMove()
{
local int i;
local KFGUI_Base F;
// Capture mouse for GUI
2021-06-13 02:53:33 +00:00
if (InputFocus != None && InputFocus.bCanFocus)
{
2021-06-13 02:53:33 +00:00
if (InputFocus.CaptureMouse())
{
F = InputFocus.GetMouseFocus();
2021-06-13 02:53:33 +00:00
if (F != MouseFocus)
{
MousePauseTime = 0;
2021-06-13 02:53:33 +00:00
if (MouseFocus != None)
MouseFocus.MouseLeave();
MouseFocus = F;
F.MouseEnter();
}
}
else i = ActiveMenus.Length;
}
else
{
2021-06-13 02:53:33 +00:00
for (i=0; i < ActiveMenus.Length; ++i)
{
2021-06-13 02:53:33 +00:00
if (ActiveMenus[i].CaptureMouse())
{
F = ActiveMenus[i].GetMouseFocus();
2021-06-13 02:53:33 +00:00
if (F != MouseFocus)
{
MousePauseTime = 0;
2021-06-13 02:53:33 +00:00
if (MouseFocus != None)
MouseFocus.MouseLeave();
MouseFocus = F;
F.MouseEnter();
}
break;
}
2021-06-13 02:53:33 +00:00
else if (ActiveMenus[i].bOnlyThisFocus ) // Discard any other menus after this one.
{
i = ActiveMenus.Length;
break;
}
}
}
2021-06-13 02:53:33 +00:00
if (MouseFocus != None && i == ActiveMenus.Length ) // Hovering over nothing.
{
MousePauseTime = 0;
2021-06-13 02:53:33 +00:00
if (MouseFocus != None)
MouseFocus.MouseLeave();
MouseFocus = None;
}
2020-01-10 13:14:11 +00:00
}
simulated final function int GetFreeIndex( bool bNewAlwaysTop ) // Find first allowed top index of the stack.
{
local int i;
2021-06-13 02:53:33 +00:00
for (i=0; i < ActiveMenus.Length; ++i)
if (bNewAlwaysTop || !ActiveMenus[i].bAlwaysTop)
{
2021-06-13 02:54:35 +00:00
ActiveMenus.Insert(i, 1);
return i;
}
i = ActiveMenus.Length;
ActiveMenus.Length = i+1;
return i;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function KFGUI_Base InitializeHUDWidget( class < KFGUI_Base> GUIClass)
2020-01-10 13:14:11 +00:00
{
local KFGUI_Base Widget;
2021-06-13 02:53:33 +00:00
if (GUIClass == None)
return None;
Widget = New(None) GUIClass;
2021-06-13 02:53:33 +00:00
if (Widget == None)
return None;
HUDOwner.HUDWidgets.AddItem(Widget);
Widget.Owner = Self;
Widget.HUDOwner = HUDOwner;
Widget.InitMenu();
Widget.ShowMenu();
Widget.bIsHUDWidget = true;
return Widget;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function KFGUI_Page OpenMenu( class < KFGUI_Page> MenuClass)
2020-01-10 13:14:11 +00:00
{
local int i;
local KFGUI_Page M;
2021-06-13 02:53:33 +00:00
if (MenuClass == None)
return None;
2021-06-13 02:53:33 +00:00
if (KeyboardFocus != None)
GrabInputFocus(None);
2021-06-13 02:53:33 +00:00
if (InputFocus != None)
{
InputFocus.LostInputFocus();
InputFocus = None;
}
// Enable mouse on UI if disabled.
SetMenuState(true);
// Check if should use pre-excisting menu.
2021-06-13 02:53:33 +00:00
if (MenuClass.Default.bUnique)
{
2021-06-13 02:53:33 +00:00
for (i=0; i < ActiveMenus.Length; ++i)
if (ActiveMenus[i].Class == MenuClass)
{
2021-06-13 02:53:33 +00:00
if (i > 0 && ActiveMenus[i].BringPageToFront() ) // Sort it upfront.
{
M = ActiveMenus[i];
2021-06-13 02:54:35 +00:00
ActiveMenus.Remove(i, 1);
i = GetFreeIndex(M.bAlwaysTop);
ActiveMenus[i] = M;
}
return M;
}
2021-06-13 02:53:33 +00:00
if (MenuClass.Default.bPersistant)
{
2021-06-13 02:53:33 +00:00
for (i=0; i < PersistentMenus.Length; ++i)
if (PersistentMenus[i].Class == MenuClass)
{
M = PersistentMenus[i];
2021-06-13 02:54:35 +00:00
PersistentMenus.Remove(i, 1);
i = GetFreeIndex(M.bAlwaysTop);
ActiveMenus[i] = M;
M.ShowMenu();
return M;
}
}
}
M = New(None)MenuClass;
2021-06-13 02:53:33 +00:00
if (M == None ) // Probably abstract class.
return None;
i = GetFreeIndex(M.bAlwaysTop);
ActiveMenus[i] = M;
M.Owner = Self;
M.InitMenu();
M.ShowMenu();
return M;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function CloseMenu( class < KFGUI_Page> MenuClass, optional bool bCloseAll)
2020-01-10 13:14:11 +00:00
{
local int i, j;
local KFGUI_Page M;
2021-06-13 02:53:33 +00:00
if (!bCloseAll && MenuClass == None)
return;
2021-06-13 02:53:33 +00:00
if (KeyboardFocus != None)
GrabInputFocus(None);
2021-06-13 02:53:33 +00:00
if (InputFocus != None)
{
InputFocus.LostInputFocus();
InputFocus = None;
}
2021-06-13 02:53:33 +00:00
for (i=(ActiveMenus.Length-1); i >= 0; --i)
{
2021-06-13 02:53:33 +00:00
if (bCloseAll || ActiveMenus[i].Class == MenuClass)
{
M = ActiveMenus[i];
2021-06-13 02:54:35 +00:00
ActiveMenus.Remove(i, 1);
M.CloseMenu();
2021-06-13 02:53:33 +00:00
for (j=0; j < M.TimerNames.Length; j++)
{
M.ClearTimer(M.TimerNames[j]);
}
// Cache menu.
2021-06-13 02:53:33 +00:00
if (M.bPersistant && M.bUnique)
PersistentMenus[PersistentMenus.Length] = M;
}
}
2021-06-13 02:53:33 +00:00
if (ActiveMenus.Length == 0)
{
SetMenuState(false);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function PopCloseMenu( KFGUI_Base Item)
2020-01-10 13:14:11 +00:00
{
local int i;
local KFGUI_Page M;
2021-06-13 02:53:33 +00:00
if (Item == None)
return;
2021-06-13 02:53:33 +00:00
if (Item.bIsHUDWidget)
{
HUDOwner.HUDWidgets.RemoveItem(Item);
Item.CloseMenu();
return;
}
2021-06-13 02:53:33 +00:00
if (KeyboardFocus != None)
GrabInputFocus(None);
2021-06-13 02:53:33 +00:00
if (InputFocus != None)
{
InputFocus.LostInputFocus();
InputFocus = None;
}
2021-06-13 02:53:33 +00:00
for (i=(ActiveMenus.Length-1); i >= 0; --i)
if (ActiveMenus[i] == Item)
{
M = ActiveMenus[i];
2021-06-13 02:54:35 +00:00
ActiveMenus.Remove(i, 1);
M.CloseMenu();
// Cache menu.
2021-06-13 02:53:33 +00:00
if (M.bPersistant && M.bUnique)
PersistentMenus[PersistentMenus.Length] = M;
break;
}
2021-06-13 02:53:33 +00:00
if (ActiveMenus.Length == 0)
SetMenuState(false);
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function BringMenuToFront( KFGUI_Page Page)
2020-01-10 13:14:11 +00:00
{
local int i;
2021-06-13 02:53:33 +00:00
if (ActiveMenus[0].bAlwaysTop && !Page.bAlwaysTop)
return; // Can't override this menu.
// Try to remove from current position at stack.
2021-06-13 02:53:33 +00:00
for (i=(ActiveMenus.Length-1); i >= 0; --i)
if (ActiveMenus[i] == Page)
{
2021-06-13 02:54:35 +00:00
ActiveMenus.Remove(i, 1);
break;
}
2021-06-13 02:53:33 +00:00
if (i == -1)
return; // Page isn't open.
// Put on front of stack.
2021-06-13 02:54:35 +00:00
ActiveMenus.Insert(0, 1);
ActiveMenus[0] = Page;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated final function bool MenuIsOpen( optional class < KFGUI_Page> MenuClass)
2020-01-10 13:14:11 +00:00
{
local int i;
2021-06-13 02:53:33 +00:00
for (i=(ActiveMenus.Length-1); i >= 0; --i)
if (MenuClass == None || ActiveMenus[i].Class == MenuClass)
return true;
return false;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated final function GrabInputFocus( KFGUI_Base Comp, optional bool bForce)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:53:33 +00:00
if (Comp == KeyboardFocus && !bForce)
return;
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (KeyboardFocus != None)
KeyboardFocus.LostKeyFocus();
2020-01-10 13:14:11 +00:00
2021-06-13 02:53:33 +00:00
if (Comp == None)
{
OnInputKey = InternalInputKey;
OnReceivedInputChar = InternalReceivedInputChar;
}
2021-06-13 02:53:33 +00:00
else if (KeyboardFocus == None)
{
OnInputKey = Comp.NotifyInputKey;
OnReceivedInputChar = Comp.NotifyInputChar;
OnReceivedInputAxis = Comp.NotifyInputAxis;
}
KeyboardFocus = Comp;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated final function GUI_InputMouse( bool bPressed, bool bRight)
2020-01-10 13:14:11 +00:00
{
local byte i;
MousePauseTime = 0;
2021-06-13 02:53:33 +00:00
if (bPressed)
{
2021-06-13 02:53:33 +00:00
if (KeyboardFocus != None && KeyboardFocus != MouseFocus)
{
GrabInputFocus(None);
LastClickTimes[0] = 0;
LastClickTimes[1] = 0;
}
2021-06-13 02:53:33 +00:00
if (MouseFocus != None)
{
2021-06-13 02:53:33 +00:00
if (MouseFocus != InputFocus && !MouseFocus.bClickable && !MouseFocus.IsTopMenu() && MouseFocus.BringPageToFront())
{
BringMenuToFront(MouseFocus.GetPageTop());
LastClickTimes[0] = 0;
LastClickTimes[1] = 0;
}
else
{
i = byte(bRight);
2021-06-13 02:53:33 +00:00
if ((MenuTime-LastClickTimes[i]) < 0.2 && Abs(LastClickPos[i].X-MousePosition.X) < 5 && Abs(LastClickPos[i].Y-MousePosition.Y) < 5)
{
LastClickTimes[i] = 0;
MouseFocus.DoubleMouseClick(bRight);
}
else
{
MouseFocus.MouseClick(bRight);
LastClickTimes[i] = MenuTime;
LastClickPos[i] = MousePosition;
}
}
}
2021-06-13 02:53:33 +00:00
else if (InputFocus != None)
{
InputFocus.LostInputFocus();
InputFocus = None;
LastClickTimes[0] = 0;
LastClickTimes[1] = 0;
}
}
else
{
2021-06-13 02:53:33 +00:00
if (InputFocus != None)
InputFocus.MouseRelease(bRight);
2021-06-13 02:53:33 +00:00
else if (MouseFocus != None)
MouseFocus.MouseRelease(bRight);
}
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated final function bool CheckMouse( name Key, EInputEvent Event)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:53:33 +00:00
if (Event == IE_Pressed)
{
2021-06-13 02:53:33 +00:00
switch( Key)
{
case 'XboxTypeS_A':
case 'LeftMouseButton':
2021-06-13 02:54:35 +00:00
GUI_InputMouse(true, false);
return true;
case 'XboxTypeS_B':
case 'RightMouseButton':
2021-06-13 02:54:35 +00:00
GUI_InputMouse(true, true);
return true;
}
}
2021-06-13 02:53:33 +00:00
else if (Event == IE_Released)
{
2021-06-13 02:53:33 +00:00
switch( Key)
{
case 'XboxTypeS_A':
case 'LeftMouseButton':
2021-06-13 02:54:35 +00:00
GUI_InputMouse(false, false);
return true;
case 'XboxTypeS_B':
case 'RightMouseButton':
2021-06-13 02:54:35 +00:00
GUI_InputMouse(false, true);
return true;
}
}
return false;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function bool ReceivedInputKey( int ControllerId, name Key, EInputEvent Event, optional float AmountDepressed=1.f, optional bool bGamepad)
2020-01-10 13:14:11 +00:00
{
local KFPlayerInput KFInput;
local KeyBind BoundKey;
2021-06-13 02:53:33 +00:00
if (!bIsInMenuState)
return false;
bUsingGamepad = bGamepad;
KFInput = KFPlayerInput(BackupInput);
2021-06-13 02:53:33 +00:00
if (KFInput == None)
{
KFInput = KFPlayerInput(PlayerOwner.PlayerInput);
}
2021-06-13 02:53:33 +00:00
if (KeyboardFocus == None)
{
2021-06-13 02:53:33 +00:00
if (KFInput != None)
{
KFInput.GetKeyBindFromCommand(BoundKey, "GBA_VoiceChat", false);
2021-06-13 02:53:33 +00:00
if (string(Key) ~= KFInput.GetBindDisplayName(BoundKey))
{
2021-06-13 02:53:33 +00:00
if (Event == IE_Pressed)
{
KFInput.StartVoiceChat(true);
}
2021-06-13 02:53:33 +00:00
else if (Event == IE_Released)
{
KFInput.StopVoiceChat();
}
return true;
}
}
}
2021-06-13 02:54:35 +00:00
if (!CheckMouse(Key, Event) && !OnInputKey(ControllerId, Key, Event, AmountDepressed, bGamepad))
{
2021-06-13 02:53:33 +00:00
if (bGamepad)
{
2021-06-13 02:53:33 +00:00
if (ActiveMenus[0].ReceievedControllerInput(ControllerId, Key, Event))
return true;
}
2021-06-13 02:53:33 +00:00
switch( Key)
{
case 'XboxTypeS_Start':
case 'Escape':
2021-06-13 02:53:33 +00:00
if (Event == IE_Pressed)
ActiveMenus[0].UserPressedEsc(); // Pop top menu if possible. // IE_Released
return true;
case 'XboxTypeS_DPad_Up':
case 'XboxTypeS_DPad_Down':
case 'XboxTypeS_DPad_Left':
case 'XboxTypeS_DPad_Right':
case 'MouseScrollDown':
case 'MouseScrollUp':
2021-06-13 02:53:33 +00:00
if (Event == IE_Pressed && MouseFocus != None)
MouseFocus.ScrollMouseWheel(Key == 'MouseScrollUp' || Key == 'XboxTypeS_DPad_Up' || Key == 'XboxTypeS_DPad_Left');
return true;
}
return bAbsorbInput;
}
return true;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function bool ReceivedInputAxis( int ControllerId, name Key, float Delta, float DeltaTime, bool bGamepad)
2020-01-10 13:14:11 +00:00
{
local Vector2D V;
local KFPlayerInput KFInput;
2021-06-13 02:54:35 +00:00
local float GamepadSensitivity, OldMouseX, OldMouseY, MoveDelta, MoveDeltaInvert;
2021-06-13 02:53:33 +00:00
if (!bIsInMenuState)
return false;
2021-06-13 02:53:33 +00:00
if (bGamepad )
{
2021-06-13 02:53:33 +00:00
if (Abs(Delta) > 0.2f)
{
bUsingGamepad = true;
V = ClientViewport.GetMousePosition();
OldMouseX = V.X;
OldMouseY = V.Y;
KFInput = KFPlayerInput(BackupInput);
GamepadSensitivity = KFInput.GamepadSensitivityScale * 10;
MoveDelta = Delta * (KFInput.bInvertController ? -GamepadSensitivity : GamepadSensitivity);
MoveDeltaInvert = Delta * (KFInput.bInvertController ? GamepadSensitivity : -GamepadSensitivity);
switch(Key)
{
case 'XboxTypeS_LeftX':
case 'XboxTypeS_RightX':
2021-06-13 02:53:33 +00:00
if (Delta < 0)
V.X = Clamp(V.X - MoveDeltaInvert, 0, ScreenSize.X);
else V.X = Clamp(V.X + MoveDelta, 0, ScreenSize.X);
break;
case 'XboxTypeS_LeftY':
2021-06-13 02:53:33 +00:00
if (Delta < 0)
V.Y = Clamp(V.Y + MoveDeltaInvert, 0, ScreenSize.Y);
else V.Y = Clamp(V.Y - MoveDelta, 0, ScreenSize.Y);
break;
case 'XboxTypeS_RightY':
2021-06-13 02:53:33 +00:00
if (Delta < 0)
V.Y = Clamp(V.Y - MoveDeltaInvert, 0, ScreenSize.Y);
else V.Y = Clamp(V.Y + MoveDelta, 0, ScreenSize.Y);
break;
}
2021-06-13 02:53:33 +00:00
if (OldMouseX != V.X || OldMouseY != V.Y)
ClientViewport.SetMouse(V.X, V.Y);
}
}
return OnReceivedInputAxis(ControllerId, Key, Delta, DeltaTime, bGamepad);
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated function bool ReceivedInputChar( int ControllerId, string Unicode)
2020-01-10 13:14:11 +00:00
{
2021-06-13 02:53:33 +00:00
if (!bIsInMenuState)
return false;
2021-06-13 02:54:35 +00:00
return OnReceivedInputChar(ControllerId, Unicode);
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated Delegate bool OnInputKey( int ControllerId, name Key, EInputEvent Event, optional float AmountDepressed=1.f, optional bool bGamepad)
2020-01-10 13:14:11 +00:00
{
return false;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated Delegate bool OnReceivedInputAxis( int ControllerId, name Key, float Delta, float DeltaTime, bool bGamepad)
2020-01-10 13:14:11 +00:00
{
return false;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated Delegate bool OnReceivedInputChar( int ControllerId, string Unicode)
2020-01-10 13:14:11 +00:00
{
return false;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated Delegate bool InternalInputKey( int ControllerId, name Key, EInputEvent Event, optional float AmountDepressed=1.f, optional bool bGamepad)
2020-01-10 13:14:11 +00:00
{
return false;
2020-01-10 13:14:11 +00:00
}
2021-06-13 02:53:33 +00:00
simulated Delegate bool InternalReceivedInputChar( int ControllerId, string Unicode)
2020-01-10 13:14:11 +00:00
{
return false;
2020-01-10 13:14:11 +00:00
}
defaultproperties
{
CursorSize=24
2021-06-13 02:54:35 +00:00
CursorColor=(R=255, G=255, B=255, A=255)
CursorTextures[`CURSOR_DEFAULT]=Texture2D'UI_Managers.LoaderManager_SWF_I13'
CurrentCursorIndex=`CURSOR_DEFAULT
DefaultStyle=class'ClassicStyle'
bAbsorbInput=true
bAlwaysTick=true
bHideCursor=true
2020-01-10 13:14:11 +00:00
}