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

139 lines
3.1 KiB
Ucode
Raw Normal View History

2017-10-20 02:00:49 +00:00
// Same as SwitchComponent, but with buttons.
Class KFGUI_SwitchMenuBar extends KFGUI_MultiComponent;
var array<KFGUI_Base> SubPages;
var() byte ButtonPosition; // 0 = top, 1 = bottom, 2 = left, 3 = right
var() float BorderWidth,ButtonAxisSize; // Width for buttons.
var int NumButtons,CurrentPageNum,PageComponentIndex;
var array<KFGUI_Button> PageButtons;
// Remember to call InitMenu() on the newly created page after.
2020-11-28 20:04:55 +00:00
final function KFGUI_Base AddPage(class<KFGUI_Base> PageClass, optional out KFGUI_Button Button)
2017-10-20 02:00:49 +00:00
{
local KFGUI_Base P;
2020-06-26 04:17:32 +00:00
local KFGUI_Base C;
2017-10-20 02:00:49 +00:00
local KFGUI_Button B;
2020-06-26 04:17:32 +00:00
C = new PageClass;
2017-10-20 02:00:49 +00:00
// 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';
2020-06-26 04:17:32 +00:00
B.ButtonText = C.Caption;
B.ToolTip = C.Hint;
2017-10-20 02:00:49 +00:00
B.OnClickLeft = PageSwitched;
B.OnClickRight = PageSwitched;
B.IDValue = NumButtons;
2020-11-28 20:12:58 +00:00
if (ButtonPosition<2)
2017-10-20 02:00:49 +00:00
{
B.XPosition = NumButtons*ButtonAxisSize;
B.XSize = ButtonAxisSize*0.99;
2020-11-28 20:12:58 +00:00
if (ButtonPosition==0)
2017-10-20 02:00:49 +00:00
B.YPosition = 0.f;
else B.YPosition = YSize-BorderWidth*0.99;
B.YSize = BorderWidth*0.99;
2020-11-28 20:12:58 +00:00
if (NumButtons>0)
2017-10-20 02:00:49 +00:00
PageButtons[PageButtons.Length-1].ExtravDir = 1;
}
else
{
2020-11-28 20:12:58 +00:00
if (ButtonPosition==2)
2017-10-20 02:00:49 +00:00
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;
2020-11-28 20:12:58 +00:00
if (NumButtons>0)
2017-10-20 02:00:49 +00:00
PageButtons[PageButtons.Length-1].ExtravDir = 2;
}
++NumButtons;
PageButtons.AddItem(B);
AddComponent(B);
Button = B;
return P;
}
2020-11-28 20:04:55 +00:00
function PageSwitched(KFGUI_Button Sender)
2017-10-20 02:00:49 +00:00
{
SelectPage(Sender.IDValue);
}
2020-11-28 20:04:55 +00:00
final function SelectPage(int Index)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (CurrentPageNum>=0)
2017-10-20 02:00:49 +00:00
{
PageButtons[CurrentPageNum].bIsHighlighted = false;
SubPages[CurrentPageNum].CloseMenu();
Components.Remove(PageComponentIndex,1);
PageComponentIndex = -1;
}
CurrentPageNum = (Index>=0 && Index<SubPages.Length) ? Index : -1;
2020-11-28 20:12:58 +00:00
if (CurrentPageNum>=0)
2017-10-20 02:00:49 +00:00
{
PageButtons[CurrentPageNum].bIsHighlighted = true;
SubPages[CurrentPageNum].ShowMenu();
PageComponentIndex = Components.Length;
Components.AddItem(SubPages[CurrentPageNum]);
}
}
function PreDraw()
{
local int i;
local byte j;
2020-11-28 20:12:58 +00:00
if (CurrentPageNum==-1 && NumButtons>0)
2017-10-20 02:00:49 +00:00
SelectPage(0);
ComputeCoords();
Canvas.SetOrigin(CompPos[0],CompPos[1]);
Canvas.SetClip(CompPos[0]+CompPos[2],CompPos[1]+CompPos[3]);
DrawMenu();
2020-11-28 20:12:58 +00:00
for (i=0; i<Components.Length; ++i)
2017-10-20 02:00:49 +00:00
{
Components[i].Canvas = Canvas;
2020-11-28 20:12:58 +00:00
for (j=0; j<4; ++j)
2017-10-20 02:00:49 +00:00
Components[i].InputPos[j] = CompPos[j];
2020-11-28 20:12:58 +00:00
if (i==PageComponentIndex)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
switch (ButtonPosition)
2017-10-20 02:00:49 +00:00
{
case 0:
Components[i].InputPos[1] += (InputPos[3]*BorderWidth);
case 1:
Components[i].InputPos[3] -= (InputPos[3]*BorderWidth);
break;
case 2:
Components[i].InputPos[0] += (InputPos[2]*BorderWidth);
default:
Components[i].InputPos[2] -= (InputPos[2]*BorderWidth);
}
}
Components[i].PreDraw();
}
}
function DrawMenu()
{
Canvas.SetPos(0,0);
Canvas.SetDrawColor(48,16,16,86);
Owner.CurrentStyle.DrawWhiteBox(CompPos[2],CompPos[3]);
}
defaultproperties
{
BorderWidth=0.05
ButtonAxisSize=0.08
CurrentPageNum=-1
PageComponentIndex=-1
}