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

170 lines
3.8 KiB
Ucode
Raw Permalink Normal View History

2017-10-20 02:00:49 +00:00
Class UIR_PerkStat extends KFGUI_MultiComponent;
var KFGUI_TextLable InfoText;
var KFGUI_NumericBox StatCountBox;
var KFGUI_Button AddButton;
var Ext_PerkBase MyPerk;
var int StatIndex,OldValue,CurrentCost,MaxStatValue;
2017-10-20 02:00:49 +00:00
var string ProgressStr;
var bool bCostDirty;
2020-09-01 04:38:15 +00:00
var localized string AddButtonToolTip;
var localized string CountBoxToolTip;
var localized string CostText;
2017-10-20 02:00:49 +00:00
function InitMenu()
{
InfoText = KFGUI_TextLable(FindComponentID('Info'));
StatCountBox = KFGUI_NumericBox(FindComponentID('CountBox'));
AddButton = KFGUI_Button(FindComponentID('AddBox'));
2023-05-14 02:49:12 +00:00
2020-09-01 04:38:15 +00:00
AddButton.ToolTip=AddButtonToolTip;
StatCountBox.ToolTip=CountBoxToolTip;
2023-05-14 02:49:12 +00:00
2017-10-20 02:00:49 +00:00
Super.InitMenu();
}
function ShowMenu()
{
Super.ShowMenu();
OldValue = -1;
SetTimer(0.1,true);
EditBoxChange(StatCountBox);
}
2020-11-28 21:54:57 +00:00
2017-10-20 02:00:49 +00:00
function CloseMenu()
{
Super.CloseMenu();
MyPerk = None;
SetTimer(0,false);
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
function SetActivePerk(Ext_PerkBase P)
2017-10-20 02:00:49 +00:00
{
MyPerk = P;
StatCountBox.Value = "5";
OldValue = -1;
}
2020-11-28 21:54:57 +00:00
2017-10-20 02:00:49 +00:00
function Timer()
{
2020-11-28 20:12:58 +00:00
if (OldValue!=MyPerk.PerkStats[StatIndex].CurrentValue || bCostDirty)
2017-10-20 02:00:49 +00:00
{
bCostDirty = false;
OldValue = MyPerk.PerkStats[StatIndex].CurrentValue;
2020-11-28 20:12:58 +00:00
if (CurrentCost != 0)
2020-09-01 04:38:15 +00:00
InfoText.SetText(MyPerk.GetStatUIStr(StatIndex)$" ["$OldValue$"/"$MaxStatValue$", "$CostText$" "$CurrentCost$", "$ProgressStr$"%]:");
else
InfoText.SetText(MyPerk.GetStatUIStr(StatIndex)$" ["$OldValue$"/"$MaxStatValue$", "$ProgressStr$"%]:");
2017-10-20 02:00:49 +00:00
}
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
function BuyStatPoint(KFGUI_Button Sender)
2017-10-20 02:00:49 +00:00
{
ExtPlayerController(GetPlayer()).BuyPerkStat(MyPerk.Class,StatIndex,StatCountBox.GetValueInt());
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
function EditBoxChange(KFGUI_EditBox Sender)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (MyPerk.PerkStats[StatIndex].CostPerValue > 1)
CurrentCost = StatCountBox.GetValueInt()*MyPerk.PerkStats[StatIndex].CostPerValue;
else
CurrentCost = 0;
MaxStatValue = MyPerk.PerkStats[StatIndex].MaxValue;
2017-10-20 02:00:49 +00:00
ProgressStr = ChopExtraDigits(MyPerk.PerkStats[StatIndex].Progress * StatCountBox.GetValueInt());
MaxStatValue = MyPerk.PerkStats[StatIndex].MaxValue;
2017-10-20 02:00:49 +00:00
bCostDirty = true;
Timer();
}
2020-11-28 21:54:57 +00:00
2017-10-20 02:00:49 +00:00
final function CheckBuyLimit()
{
local int i;
i = Max(Min(MyPerk.CurrentSP/MyPerk.PerkStats[StatIndex].CostPerValue,MyPerk.PerkStats[StatIndex].MaxValue-MyPerk.PerkStats[StatIndex].CurrentValue),0);
StatCountBox.MaxValue = i;
2020-11-28 20:12:58 +00:00
if (i==0)
2017-10-20 02:00:49 +00:00
StatCountBox.MinValue = 0;
else StatCountBox.MinValue = 1;
// Make the value clamped.
StatCountBox.ChangeValue(StatCountBox.Value);
2020-11-28 20:12:58 +00:00
if (MyPerk.PerkStats[StatIndex].CostPerValue > 1)
CurrentCost = StatCountBox.GetValueInt()*MyPerk.PerkStats[StatIndex].CostPerValue;
else
CurrentCost = 0;
2017-10-20 02:00:49 +00:00
ProgressStr = ChopExtraDigits(MyPerk.PerkStats[StatIndex].Progress * StatCountBox.GetValueInt());
MaxStatValue = MyPerk.PerkStats[StatIndex].MaxValue;
2023-05-14 02:49:12 +00:00
2017-10-20 02:00:49 +00:00
// Disable button if can not buy anymore.
AddButton.SetDisabled(i==0);
bCostDirty = true;
Timer();
}
2020-11-28 20:04:55 +00:00
final function string ChopExtraDigits(float Value)
2017-10-20 02:00:49 +00:00
{
local string S;
local bool bLoop;
S = string(Abs(Value));
bLoop = true;
// Chop off float digits that aren't needed.
2020-11-28 20:12:58 +00:00
while (bLoop)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
switch (Right(S,1))
2017-10-20 02:00:49 +00:00
{
case "0":
S = Left(S,Len(S)-1);
break;
case ".":
S = Left(S,Len(S)-1);
bLoop = false;
break;
default:
bLoop = false;
}
}
return S;
}
defaultproperties
{
Begin Object Class=KFGUI_TextLable Name=InfoLable
ID="Info"
XPosition=0
YPosition=0.2
XSize=0.71
YSize=0.7
AlignX=2
AlignY=1
TextFontInfo=(bClipText=true)
End Object
Begin Object Class=KFGUI_NumericBox Name=BuyCount
ID="CountBox"
XPosition=0.72
YPosition=0.1
XSize=0.18
YSize=0.8
OnTextChange=EditBoxChange
MaxValue=100
MinValue=1
bScaleByFontSize=false
End Object
Begin Object Class=KFGUI_Button Name=AddSButton
ID="AddBox"
XPosition=0.91
YPosition=0.1
XSize=0.08
YSize=0.8
ButtonText="+"
OnClickLeft=BuyStatPoint
OnClickRight=BuyStatPoint
End Object
Components.Add(InfoLable)
Components.Add(BuyCount)
Components.Add(AddSButton)
}