2017-10-20 02:00:49 +00:00
|
|
|
// List box with custom render code for the items.
|
|
|
|
Class KFGUI_List extends KFGUI_MultiComponent;
|
|
|
|
|
|
|
|
var() bool bDrawBackground;
|
|
|
|
var() protected int ListCount;
|
|
|
|
var() int ListItemsPerPage;
|
|
|
|
var() color BackgroundColor;
|
|
|
|
var KFGUI_ScrollBarV ScrollBar;
|
|
|
|
|
|
|
|
var transient float OldXSize,ItemHeight,MouseYHit;
|
|
|
|
var transient int FocusMouseItem,LastFocusItem;
|
|
|
|
|
|
|
|
var byte PressedDown[2];
|
|
|
|
var bool bPressedDown;
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
delegate OnDrawItem(Canvas C, int Index, float YOffset, float Height, float Width, bool bFocus);
|
2017-10-20 02:00:49 +00:00
|
|
|
|
|
|
|
// Requires bClickable=true to receive this event.
|
2020-11-28 20:04:55 +00:00
|
|
|
delegate OnClickedItem(int Index, bool bRight, int MouseX, int MouseY);
|
|
|
|
delegate OnDblClickedItem(int Index, bool bRight, int MouseX, int MouseY);
|
2017-10-20 02:00:49 +00:00
|
|
|
|
|
|
|
function InitMenu()
|
|
|
|
{
|
|
|
|
Super.InitMenu();
|
|
|
|
ScrollBar = KFGUI_ScrollBarV(FindComponentID('Scrollbar'));
|
|
|
|
UpdateListVis();
|
|
|
|
}
|
|
|
|
|
|
|
|
function DrawMenu()
|
|
|
|
{
|
|
|
|
local int i,n;
|
|
|
|
local float Y;
|
|
|
|
local bool bCheckMouse;
|
|
|
|
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bDrawBackground)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
Canvas.DrawColor = BackgroundColor;
|
|
|
|
Canvas.SetPos(0.f,0.f);
|
|
|
|
Owner.CurrentStyle.DrawWhiteBox(CompPos[2],CompPos[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse focused item check.
|
|
|
|
bCheckMouse = bClickable && bFocused;
|
|
|
|
FocusMouseItem = -1;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bCheckMouse)
|
2017-10-20 02:00:49 +00:00
|
|
|
MouseYHit = Owner.MousePosition.Y - CompPos[1];
|
|
|
|
|
|
|
|
n = ScrollBar.CurrentScroll;
|
|
|
|
ItemHeight = CompPos[3] / ListItemsPerPage;
|
|
|
|
Y = 0;
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<ListItemsPerPage; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (n>=ListCount)
|
2017-10-20 02:00:49 +00:00
|
|
|
break;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (bCheckMouse && FocusMouseItem==-1)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (MouseYHit<ItemHeight)
|
2017-10-20 02:00:49 +00:00
|
|
|
FocusMouseItem = n;
|
|
|
|
else MouseYHit-=ItemHeight;
|
|
|
|
}
|
|
|
|
OnDrawItem(Canvas,n,Y,ItemHeight,CompPos[2],(FocusMouseItem==n));
|
|
|
|
Y+=ItemHeight;
|
|
|
|
++n;
|
|
|
|
}
|
2020-11-28 20:12:58 +00:00
|
|
|
if (LastFocusItem!=FocusMouseItem)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (LastFocusItem!=-1 && !bDisabled && bClickable)
|
2017-10-20 02:00:49 +00:00
|
|
|
PlayMenuSound(MN_DropdownChange);
|
|
|
|
LastFocusItem = FocusMouseItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function PreDraw()
|
|
|
|
{
|
|
|
|
local int i;
|
|
|
|
local byte j;
|
|
|
|
|
|
|
|
ComputeCoords();
|
|
|
|
|
|
|
|
// First draw scrollbar to allow it to resize itself.
|
2020-11-28 20:12:58 +00:00
|
|
|
for (j=0; j<4; ++j)
|
2017-10-20 02:00:49 +00:00
|
|
|
ScrollBar.InputPos[j] = CompPos[j];
|
2020-11-28 20:12:58 +00:00
|
|
|
if (OldXSize!=InputPos[2])
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
OldXSize = InputPos[2];
|
|
|
|
ScrollBar.XPosition = 1.f - ScrollBar.GetWidth();
|
|
|
|
}
|
|
|
|
ScrollBar.Canvas = Canvas;
|
|
|
|
ScrollBar.PreDraw();
|
|
|
|
|
|
|
|
// Then downscale our selves to give room for scrollbar.
|
|
|
|
CompPos[2] -= ScrollBar.CompPos[2];
|
|
|
|
Canvas.SetOrigin(CompPos[0],CompPos[1]);
|
|
|
|
Canvas.SetClip(CompPos[0]+CompPos[2],CompPos[1]+CompPos[3]);
|
|
|
|
DrawMenu();
|
|
|
|
CompPos[2] += ScrollBar.CompPos[2];
|
|
|
|
|
|
|
|
// Then draw rest of components.
|
2020-11-28 20:12:58 +00:00
|
|
|
for (i=0; i<Components.Length; ++i)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Components[i]!=ScrollBar)
|
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];
|
|
|
|
Components[i].PreDraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function UpdateListVis()
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ListCount<=ListItemsPerPage)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
ScrollBar.UpdateScrollSize(0,1,1,1);
|
|
|
|
ScrollBar.SetDisabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ScrollBar.UpdateScrollSize(ScrollBar.CurrentScroll,(ListCount-ListItemsPerPage),1,ListItemsPerPage);
|
|
|
|
ScrollBar.SetDisabled(false);
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function ChangeListSize(int NewSize)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (ListCount==NewSize)
|
2017-10-20 02:00:49 +00:00
|
|
|
return;
|
|
|
|
ListCount = NewSize;
|
|
|
|
UpdateListVis();
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
final function int GetListSize()
|
|
|
|
{
|
|
|
|
return ListCount;
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function DoubleMouseClick(bool bRight)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bDisabled && bClickable)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
PlayMenuSound(MN_ClickButton);
|
|
|
|
PressedDown[byte(bRight)] = 0;
|
|
|
|
bPressedDown = (PressedDown[0]!=0 || PressedDown[1]!=0);
|
|
|
|
OnDblClickedItem(FocusMouseItem,bRight,Owner.MousePosition.X-CompPos[0],MouseYHit);
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function MouseClick(bool bRight)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bDisabled && bClickable)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
PressedDown[byte(bRight)] = 1;
|
|
|
|
bPressedDown = true;
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function MouseRelease(bool bRight)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bDisabled && bClickable && PressedDown[byte(bRight)]==1)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
|
|
|
PlayMenuSound(MN_ClickButton);
|
|
|
|
PressedDown[byte(bRight)] = 0;
|
|
|
|
bPressedDown = (PressedDown[0]!=0 || PressedDown[1]!=0);
|
|
|
|
OnClickedItem(FocusMouseItem,bRight,Owner.MousePosition.X-CompPos[0],MouseYHit);
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function MouseLeave()
|
|
|
|
{
|
|
|
|
Super.MouseLeave();
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bDisabled && bClickable)
|
2017-10-20 02:00:49 +00:00
|
|
|
PlayMenuSound(MN_LostFocus);
|
|
|
|
PressedDown[0] = 0;
|
|
|
|
PressedDown[1] = 0;
|
|
|
|
bPressedDown = false;
|
|
|
|
}
|
2020-11-28 21:54:57 +00:00
|
|
|
|
2017-10-20 02:00:49 +00:00
|
|
|
function MouseEnter()
|
|
|
|
{
|
|
|
|
Super.MouseEnter();
|
|
|
|
LastFocusItem = -1;
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!bDisabled && bClickable)
|
2017-10-20 02:00:49 +00:00
|
|
|
PlayMenuSound(MN_Focus);
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
function ScrollMouseWheel(bool bUp)
|
2017-10-20 02:00:49 +00:00
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (!ScrollBar.bDisabled)
|
2017-10-20 02:00:49 +00:00
|
|
|
ScrollBar.ScrollMouseWheel(bUp);
|
|
|
|
}
|
|
|
|
|
|
|
|
function NotifyMousePaused()
|
|
|
|
{
|
2020-11-28 20:12:58 +00:00
|
|
|
if (Owner.InputFocus==None && FocusMouseItem>=0)
|
2017-10-20 02:00:49 +00:00
|
|
|
OnMouseRest(FocusMouseItem);
|
|
|
|
}
|
|
|
|
|
2020-11-28 20:04:55 +00:00
|
|
|
Delegate OnMouseRest(int Item);
|
2017-10-20 02:00:49 +00:00
|
|
|
|
|
|
|
defaultproperties
|
|
|
|
{
|
|
|
|
ListItemsPerPage=10
|
|
|
|
ListCount=1
|
|
|
|
BackgroundColor=(R=32,G=3,B=2,A=255)
|
|
|
|
bDrawBackground=true
|
|
|
|
|
|
|
|
Begin Object Class=KFGUI_ScrollBarV Name=ListScroller
|
|
|
|
XPosition=0.96
|
|
|
|
YPosition=0
|
|
|
|
XSize=0.04
|
|
|
|
YSize=1
|
|
|
|
ID="Scrollbar"
|
|
|
|
End Object
|
|
|
|
Components.Add(ListScroller)
|
|
|
|
}
|