2020-01-10 13:14:11 +00:00
|
|
|
// Same as SwitchComponent, but with buttons.
|
|
|
|
Class KFGUI_SwitchMenuBar extends KFGUI_MultiComponent;
|
|
|
|
|
2021-06-12 20:11:37 +00:00
|
|
|
`include(Build.uci)
|
|
|
|
`include(Logger.uci)
|
|
|
|
|
2020-01-10 13:14:11 +00:00
|
|
|
var array<KFGUI_Base> SubPages;
|
|
|
|
var() byte ButtonPosition; // 0 = top, 1 = bottom, 2 = left, 3 = right
|
|
|
|
var() float BorderWidth,ButtonAxisSize; // Width for buttons.
|
|
|
|
var() float PagePadding; // Padding for pages
|
|
|
|
|
|
|
|
var int NumButtons,CurrentPageNum,PageComponentIndex;
|
|
|
|
var array<KFGUI_Button> PageButtons;
|
|
|
|
|
|
|
|
function ShowMenu()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
GrabKeyFocus();
|
|
|
|
Super.ShowMenu();
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function CloseMenu()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
ReleaseKeyFocus();
|
|
|
|
Super.CloseMenu();
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remember to call InitMenu() on the newly created page after.
|
|
|
|
final function KFGUI_Base AddPage( class<KFGUI_Base> PageClass, string Caption, string Hint, optional out KFGUI_Button Button )
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local KFGUI_Base P;
|
|
|
|
local KFGUI_Button B;
|
|
|
|
|
|
|
|
// Add page.
|
|
|
|
P = new (Self) PageClass;
|
|
|
|
P.Owner = Owner;
|
|
|
|
P.ParentComponent = Self;
|
|
|
|
SubPages.AddItem(P);
|
|
|
|
|
|
|
|
// Add page switch button.
|
|
|
|
B = new (Self) class'KFGUI_Button';
|
|
|
|
B.ButtonText = Caption;
|
|
|
|
B.ToolTip = Hint;
|
|
|
|
B.OnClickLeft = PageSwitched;
|
|
|
|
B.OnClickRight = PageSwitched;
|
|
|
|
B.IDValue = NumButtons;
|
|
|
|
|
|
|
|
if( ButtonPosition<2 )
|
|
|
|
{
|
|
|
|
B.XPosition = NumButtons*ButtonAxisSize;
|
|
|
|
B.XSize = ButtonAxisSize*0.99;
|
|
|
|
|
|
|
|
if( ButtonPosition==0 )
|
|
|
|
B.YPosition = 0.f;
|
|
|
|
else B.YPosition = YSize-BorderWidth*0.99;
|
|
|
|
B.YSize = BorderWidth*0.99;
|
|
|
|
|
|
|
|
if( NumButtons>0 )
|
|
|
|
PageButtons[PageButtons.Length-1].ExtravDir = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( ButtonPosition==2 )
|
|
|
|
B.XPosition = 0.f;
|
|
|
|
else B.XPosition = XSize-BorderWidth*0.99;
|
|
|
|
B.XSize = BorderWidth*0.99;
|
|
|
|
|
|
|
|
B.YPosition = NumButtons*ButtonAxisSize;
|
|
|
|
B.YSize = ButtonAxisSize*0.99;
|
|
|
|
if( NumButtons>0 )
|
|
|
|
PageButtons[PageButtons.Length-1].ExtravDir = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
++NumButtons;
|
|
|
|
PageButtons.AddItem(B);
|
|
|
|
AddComponent(B);
|
|
|
|
Button = B;
|
|
|
|
return P;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function PageSwitched( KFGUI_Button Sender )
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
SelectPage(Sender.IDValue);
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final function SelectPage( int Index )
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
PlayMenuSound(MN_LostFocus);
|
|
|
|
|
|
|
|
if( CurrentPageNum>=0 )
|
|
|
|
{
|
|
|
|
PageButtons[CurrentPageNum].bIsHighlighted = false;
|
|
|
|
SubPages[CurrentPageNum].CloseMenu();
|
|
|
|
Components.Remove(PageComponentIndex,1);
|
|
|
|
PageComponentIndex = -1;
|
|
|
|
}
|
|
|
|
CurrentPageNum = (Index>=0 && Index<SubPages.Length) ? Index : -1;
|
|
|
|
if( CurrentPageNum>=0 )
|
|
|
|
{
|
|
|
|
PageButtons[CurrentPageNum].bIsHighlighted = true;
|
|
|
|
SubPages[CurrentPageNum].ShowMenu();
|
|
|
|
PageComponentIndex = Components.Length;
|
|
|
|
Components.AddItem(SubPages[CurrentPageNum]);
|
|
|
|
}
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function PreDraw()
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
local int i;
|
|
|
|
local byte j;
|
|
|
|
|
|
|
|
if( !bVisible )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( CurrentPageNum==-1 && NumButtons>0 )
|
|
|
|
SelectPage(0);
|
|
|
|
ComputeCoords();
|
|
|
|
Canvas.SetOrigin(CompPos[0],CompPos[1]);
|
|
|
|
Canvas.SetClip(CompPos[0]+CompPos[2],CompPos[1]+CompPos[3]);
|
|
|
|
DrawMenu();
|
|
|
|
for( i=0; i<Components.Length; ++i )
|
|
|
|
{
|
|
|
|
Components[i].Canvas = Canvas;
|
|
|
|
for( j=0; j<4; ++j )
|
|
|
|
Components[i].InputPos[j] = CompPos[j];
|
|
|
|
if( i==PageComponentIndex )
|
|
|
|
{
|
|
|
|
switch( ButtonPosition )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Components[i].InputPos[1] += (InputPos[3]*BorderWidth*PagePadding);
|
|
|
|
case 1:
|
|
|
|
Components[i].InputPos[3] -= (InputPos[3]*BorderWidth*PagePadding);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Components[i].InputPos[0] += (InputPos[2]*BorderWidth*PagePadding);
|
|
|
|
default:
|
|
|
|
Components[i].InputPos[2] -= (InputPos[2]*BorderWidth*PagePadding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Components[i].PreDraw();
|
|
|
|
}
|
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
|
|
|
switch(Key)
|
|
|
|
{
|
|
|
|
case 'XboxTypeS_LeftShoulder':
|
|
|
|
if( Event == IE_Pressed )
|
|
|
|
SelectPage(Clamp(CurrentPageNum - 1, 0, NumButtons));
|
|
|
|
return true;
|
|
|
|
case 'XboxTypeS_RightShoulder':
|
|
|
|
if( Event == IE_Pressed )
|
|
|
|
SelectPage(Clamp(CurrentPageNum + 1, 0, NumButtons));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
2021-05-16 09:40:02 +00:00
|
|
|
PagePadding=1.0
|
|
|
|
BorderWidth=0.05
|
|
|
|
ButtonAxisSize=0.08
|
|
|
|
CurrentPageNum=-1
|
|
|
|
PageComponentIndex=-1
|
2020-01-10 13:14:11 +00:00
|
|
|
}
|