Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

KFGui.KFBuyMenuOptionsList


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
//-----------------------------------------------------------
//
//-----------------------------------------------------------
class KFBuyMenuOptionsList extends GUIVertList;

// Settings
var	float					ItemBorder;			// Percent of Height to leave blank inside Item Background
var	float					TextTopOffset;		// Percent of Height to offset top of Text
var	float					ItemSpacing;		// Number of Pixels between Items

// Display
var	texture					ItemBackground;
var	texture					SelectedItemBackground;
var array<string>			PrimaryStrings;
var	array<string>			SecondaryStrings;

// state
var	GUIBuyable				TheBuyable;
var	int						MouseOverIndex;

var bool					bNeedsUpdate;
var	bool					bNoAutoFill;
var int						UpdateCounter;

var localized string		BuyString;
var localized string		SellString;
var localized string		BuyClipString;
var localized string		FillString;
var	localized string		AutoFillString;
var	localized string		ExitString;

var	int						AutoFillCost;

event InitComponent(GUIController MyController, GUIComponent MyOwner)
{
	Super.InitComponent(MyController, MyOwner);
	OnDrawItem = DrawInvItem;
}

event Closed(GUIComponent Sender, bool bCancelled)
{
	PrimaryStrings.Remove(0, PrimaryStrings.Length);
	SecondaryStrings.Remove(0, SecondaryStrings.Length);
	TheBuyable = none;

	super.Closed(Sender, bCancelled);
}

function UpdateList(GUIBuyable Buyable)
{
	// Clear the arrays
	PrimaryStrings.Remove(0, PrimaryStrings.Length);
	SecondaryStrings.Remove(0, SecondaryStrings.Length);

	//Reset item count
	ItemCount = 6;

	TheBuyable = Buyable;

	if ( TheBuyable != none )
	{
		// First we have to check if the item is inv or sale
		if ( !TheBuyable.bSaleList )
		{
			//Ok, this item is already in our inventory, now let's see if we can sell it or not
			if ( TheBuyable.bSellable )
			{
				// Now we have to check if it is a melee weapon && Check if we already have full ammo
				if ( !TheBuyable.bMelee && int(TheBuyable.ItemAmmoCurrent) < int(TheBuyable.ItemAmmoMax))
				{
					// Sell Button
					PrimaryStrings[0] = SellString;
					SecondaryStrings[0]	= "£" $ int(TheBuyable.ItemCost * 0.75) ;

					// Single Clip
					PrimaryStrings[1] = BuyClipString;
					SecondaryStrings[1] = "£" $ int(TheBuyable.ItemAmmoCost);

					// Fill up
					PrimaryStrings[2] = FillString;
					SecondaryStrings[2] = "£" $ int(TheBuyable.ItemFillAmmoCost);
				}
				else
				{
					// Sell Button
					PrimaryStrings[2] = SellString;
					SecondaryStrings[2]	= "£" $ int(TheBuyable.ItemCost * 0.75) ;
				}
			}
			else
			{
				//Check if it is a melee weapon
				if ( !TheBuyable.bMelee )
				{
					//Check if we already have full ammo
					if ( int(TheBuyable.ItemAmmoCurrent) < int(TheBuyable.ItemAmmoMax) )
					{
						// Single Clip
						PrimaryStrings[1] = BuyClipString;
						SecondaryStrings[1] = "£" $ int(TheBuyable.ItemAmmoCost);

						// Fill up
						PrimaryStrings[2] = FillString;
						SecondaryStrings[2] = "£" $ int(TheBuyable.ItemFillAmmoCost);
					}
				}
			}
		}
		else
		{
			//Too heavy? Too expensive?
			if ( TheBuyable.ItemWeight + KFHumanPawn(PlayerOwner().Pawn).CurrentWeight <= KFHumanPawn(PlayerOwner().Pawn).MaxCarryWeight &&
				 TheBuyable.ItemCost <= PlayerOwner().PlayerReplicationInfo.Score && PlayerOwner().SteamStatsAndAchievements.PlayerOwnsWeaponDLC(TheBuyable.ItemWeaponClass.Default.AppID) )
			{
		   		//This is an for sale item
				PrimaryStrings[2] = BuyString;
				SecondaryStrings[2] = "£" $ int(TheBuyable.ItemCost);
			}
		}

	}

	PrimaryStrings[4] = AutoFillString;
	SecondaryStrings[4] = "£" $ AutoFillCost;
	PrimaryStrings[5] = ExitString;
	SecondaryStrings[5] = "";

	if ( bNotify )
 	{
		CheckLinkedObjects(Self);
	}

	if ( MyScrollBar != none )
	{
		MyScrollBar.AlignThumb();
	}
}

function int FindCheapestAmmo()
{
    local Inventory CurInv;
    local int CurrentCheapest, CurrentCost;

    CurrentCheapest = 99999;

    for ( CurInv = PlayerOwner().Pawn.Inventory; CurInv != none; CurInv = CurInv.Inventory )
	{
        if ( CurInv.IsA('KFAmmunition') )
        {
            CurrentCost = FindAmmoCost(KFAmmunition(CurInv).Class);
        }
        else
        {
			continue;
		}

        if ( CurrentCost < CurrentCheapest )
        {
            CurrentCheapest = CurrentCost;
        }
	}

    return CurrentCheapest;
}

function int FindAmmoCost(Class<Ammunition> AClass)
{
    local Inventory CurInv;
	local KFWeapon MyWeapon;

	for ( CurInv = PlayerOwner().Pawn.Inventory; CurInv != none; CurInv = CurInv.Inventory )
    {
        //if( CurInv.Class == AClass )
        //{
        //    MyAmmo = Ammunition(CurInv);
        //}
        if ( KFWeapon(CurInv) != None && (Weapon(CurInv).AmmoClass[0]==AClass || Weapon(CurInv).AmmoClass[1]==AClass) )
        {
        	MyWeapon = KFWeapon(CurInv);
        	break;
        }
    }

    if ( MyWeapon !=  none )
    {
    	return Class<KFWeaponPickup>(MyWeapon.PickupClass).Default.AmmoCost;
    }
    else
    {
	 	return 999999;
	}
}

function bool PreDraw(Canvas Canvas)
{
	if ( Controller.MouseX >= ClientBounds[0] && Controller.MouseX <= ClientBounds[2] && Controller.MouseY >= ClientBounds[1] )
	{
		//  Figure out which Item we're clicking on
		MouseOverIndex = Top + ((Controller.MouseY - ClientBounds[1]) / ItemHeight);
		if ( MouseOverIndex >= ItemCount )
		{
			MouseOverIndex = -1;
		}
	}
	else
	{
		MouseOverIndex = -1;
	}

	return false;
}

function DrawInvItem(Canvas Canvas, int CurIndex, float X, float Y, float Width, float Height, bool bSelected, bool bPending)
{
	local float TempX, TempY;
	local float StringHeight, StringWidth;

	if ( PrimaryStrings[CurIndex] == "" )
	{
		return;
	}

	OnClickSound=CS_Click;

	// Offset for the Background
	TempX = X;
	TempY = Y + ItemSpacing / 2.0;

	// Initialize the Canvas
	Canvas.Style = 1;

	// Draw Item Background
	Canvas.SetPos(TempX, TempY);

	if ( CurIndex == MouseOverIndex )
	{
		Canvas.SetDrawColor(210, 210, 210, 255);
		Canvas.DrawTileStretched(SelectedItemBackground, Width, Height - ItemSpacing);
	}
	else
	{
		Canvas.SetDrawColor(255, 255, 255, 255);
		Canvas.DrawTileStretched(ItemBackground, Width, Height - ItemSpacing);
	}

	// Select Text color
	if ( CurIndex == MouseOverIndex )
	{
		Canvas.SetDrawColor(189, 73, 74, 255);
	}
	else
	{
		Canvas.SetDrawColor(255, 255, 255, 255);
	}

	if ( CurIndex == 4 )
	{
		if ( PlayerOwner().PlayerReplicationInfo.Score < FindCheapestAmmo() )
		{
			Canvas.SetDrawColor(128, 128, 128, 255);
			bNoAutoFill = true;
		}
		else
		{
			bNoAutoFill = false;
		}
	}

	// Draw the function(Buy, Sell, etc.)
	Canvas.StrLen(PrimaryStrings[CurIndex], StringWidth, StringHeight);
	Canvas.SetPos(TempX+ (0.2 * Height), TempY + ((Height - ItemSpacing - StringHeight) / 2));
	Canvas.DrawText(PrimaryStrings[CurIndex]);

	// Draw the price(if any)
	Canvas.StrLen(SecondaryStrings[CurIndex], StringWidth, StringHeight);
	Canvas.SetPos(TempX + Width - (StringWidth + (0.2 * Height)), TempY + ((Height - ItemSpacing - StringHeight) / 2));
	Canvas.DrawText(SecondaryStrings[CurIndex]);
	Canvas.SetDrawColor(255, 255, 255, 255);
}

function float SaleItemHeight(Canvas c)
{
	return ((MenuOwner.ActualHeight() / 6.0) - 1.0);
}

defaultproperties
{
     ItemBorder=0.030000
     TextTopOffset=0.050000
     ItemSpacing=6.000000
     ItemBackground=Texture'InterfaceArt_tex.Menu.DownTickBlurry'
     SelectedItemBackground=Texture'InterfaceArt_tex.Menu.DownTickWatched'
     BuyString="Purchase"
     SellString="Sell Weapon"
     BuyClipString="Buy Single Clip"
     FillString="Fill Selected Ammo"
     AutoFillString="Auto Fill Ammo"
     ExitString="Exit Trader Menu"
     GetItemHeight=KFBuyMenuOptionsList.SaleItemHeight
     FontScale=FNS_Medium
     OnPreDraw=KFBuyMenuOptionsList.PreDraw
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Fri 13-10-2023 03:17:26.000 - Creation time: Fri 13-10-2023 03:19:03.161 - Created with UnCodeX