2017-10-20 02:00:49 +00:00
|
|
|
Class KFGUI_RightClickMenu extends KFGUI_Clickable;
|
|
|
|
|
|
|
|
struct FRowItem
|
|
|
|
{
|
|
|
|
var string Text;
|
|
|
|
var int Value;
|
|
|
|
var bool bSplitter,bDisabled;
|
|
|
|
};
|
|
|
|
var array<FRowItem> ItemRows;
|
|
|
|
var int CurrentRow,OldRow;
|
|
|
|
var int EdgeSize;
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function OpenMenu(KFGUI_Base Menu)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Owner = Menu.Owner;
|
|
|
|
InitMenu();
|
|
|
|
PlayMenuSound(MN_Dropdown);
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
// Calc needed size for this menu.
|
|
|
|
ComputeSize();
|
|
|
|
XPosition = float(Owner.MousePosition.X+4) / Owner.ScreenSize.X;
|
|
|
|
YPosition = float(Owner.MousePosition.Y+4) / Owner.ScreenSize.Y;
|
2020-11-28 20:12:58 +00:00
|
|
|
if ((XPosition+XSize)>1.f)
|
2017-10-20 02:00:49 +00:00
|
|
|
YPosition = (float(Owner.MousePosition.X) / Owner.ScreenSize.X) - XSize; // Move to left side of mouse pointer.
|
2020-11-28 20:12:58 +00:00
|
|
|
if ((YPosition+YSize)>1.f)
|
2017-10-20 02:00:49 +00:00
|
|
|
YPosition-=((YPosition+YSize)-1.f); // Move up until fit on screen.
|
|
|
|
GetInputFocus();
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
final function ComputeSize()
|
|
|
|
{
|
|
|
|
local float XS,YS,Scalar;
|
|
|
|
local int i,XL,YL;
|
|
|
|
local Font F;
|
|
|
|
local string S;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ItemRows.Length==0)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
YS = 0;
|
|
|
|
XS = 50;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
YS = Owner.CurrentStyle.DefaultHeight * ItemRows.Length;
|
|
|
|
XS = 20;
|
|
|
|
F = Owner.CurrentStyle.PickFont(Owner.CurrentStyle.DefaultFontSize,Scalar);
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<ItemRows.Length; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ItemRows[i].bSplitter)
|
2017-10-20 02:00:49 +00:00
|
|
|
S = "----";
|
|
|
|
else S = ItemRows[i].Text;
|
|
|
|
F.GetStringHeightAndWidth(S,YL,XL);
|
|
|
|
XS = FMax(XS,float(XL)*Scalar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XSize = (XS+(EdgeSize*2)) / Owner.ScreenSize.X;
|
|
|
|
YSize = (YS+(EdgeSize*2)) / Owner.ScreenSize.Y;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
final function AddRow(string Text, bool bDisable)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
local int i;
|
2023-05-14 02:49:12 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
i = ItemRows.Length;
|
|
|
|
ItemRows.Length = i+1;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Text=="-")
|
2017-10-20 02:00:49 +00:00
|
|
|
ItemRows[i].bSplitter = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ItemRows[i].Text = Text;
|
|
|
|
ItemRows[i].bDisabled = bDisable;
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function DrawMenu()
|
|
|
|
{
|
|
|
|
Owner.CurrentStyle.RenderRightClickMenu(Self);
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function HandleMouseClick(bool bRight)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (CurrentRow>=0 && (ItemRows[CurrentRow].bSplitter || ItemRows[CurrentRow].bDisabled))
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
|
|
|
PlayMenuSound(MN_ClickButton);
|
|
|
|
DropInputFocus();
|
2020-11-28 20:12:58 +00:00
|
|
|
if (CurrentRow>=0)
|
2017-10-20 02:00:49 +00:00
|
|
|
OnSelectedItem(CurrentRow);
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function LostInputFocus()
|
|
|
|
{
|
|
|
|
OnBecameHidden(Self);
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
Delegate OnSelectedItem(int Index);
|
|
|
|
Delegate OnBecameHidden(KFGUI_RightClickMenu M);
|
2017-10-20 02:00:49 +00:00
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
|
|
|
CurrentRow=-1
|
|
|
|
OldRow=-1
|
|
|
|
bFocusedPostDrawItem=true
|
|
|
|
EdgeSize=4
|
2023-05-14 02:49:12 +00:00
|
|
|
}
|