311 lines
9.2 KiB
C#
311 lines
9.2 KiB
C#
//-------------------------------------------------
|
|
// InventoryGui.cs
|
|
//-------------------------------------------------
|
|
|
|
$invCount = -1;
|
|
$CurrentBottomSlot = 11;
|
|
|
|
new ActionMap(InvMap);
|
|
InvMap.bindCmd(keyboard, "i", "toggleInventory();", "");
|
|
|
|
function InventoryGui::onWake()
|
|
{
|
|
displayWindow.setEmpty();
|
|
DisplayText.setText("");
|
|
|
|
$enableDirectInput = "1";
|
|
activateDirectInput();
|
|
|
|
InvMap.push();
|
|
}
|
|
|
|
function InventoryGui::onSleep()
|
|
{
|
|
InvMap.pop();
|
|
}
|
|
|
|
function clientCmdPopInventory(%player) {
|
|
|
|
//reset the Bottom Slot to default
|
|
$CurrentBottomSlot = 11;
|
|
$invCount = -1;
|
|
|
|
//Set the Pointer back to the beginning
|
|
if (%player.moveCurPtr("first") == 0) {
|
|
echo("Inventory Manager::Pointer error");
|
|
return 0;
|
|
}
|
|
|
|
if (%player.getInvItem("current","amount") > 0) {
|
|
|
|
$invCount++;
|
|
$ItemTokens[$invCount] = %player.getInvItem("current","name");
|
|
$AmountTokens[$invCount] = %player.getInvItem("current","amount");
|
|
$TypeTokens[$invCount] = %player.getInvItem("current","type");
|
|
$DescTokens[$invCount] = %player.getInvItem("current","description");
|
|
|
|
//right now only useful for ammo and healthkit (hackish but required because of the paths for the model viewer)
|
|
if (%player.getInvItem("current","type") $= "healthKit")
|
|
$strippedItemTokens[$invCount] = "items";
|
|
else
|
|
$strippedItemTokens[$invCount] = strreplace($ItemTokens[$invCount],"Ammo","");
|
|
|
|
}
|
|
|
|
while (%player.moveCurPtr("next") == 1) {
|
|
|
|
if (%player.getInvItem("current","amount") > 0) {
|
|
|
|
$invCount++;
|
|
$ItemTokens[$invCount] = %player.getInvItem("current","name");
|
|
$AmountTokens[$invCount] = %player.getInvItem("current","amount");
|
|
$TypeTokens[$invCount] = %player.getInvItem("current","type");
|
|
$DescTokens[$invCount] = %player.getInvItem("current","description");
|
|
|
|
if (%player.getInvItem("current","type") $= "healthKit")
|
|
$strippedItemTokens[$invCount] = "items";
|
|
else
|
|
$strippedItemTokens[$invCount] = strreplace($ItemTokens[$invCount],"Ammo","");
|
|
}
|
|
}
|
|
|
|
//This block is copy and pasted 11 times due to the hardcoded GUI names...not
|
|
//sure of a better way to do this
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > -1) { //Slot 1
|
|
|
|
Slot1.setText($ItemTokens[0]);
|
|
Amount1.setText("Amount: " @ $AmountTokens[0]);
|
|
|
|
} else {
|
|
Slot1.setText("");
|
|
Amount1.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 0) { //Slot 2
|
|
|
|
Slot2.setText($ItemTokens[1]);
|
|
Amount2.setText("Amount: " @ $AmountTokens[1]);
|
|
|
|
} else {
|
|
Slot2.setText("");
|
|
Amount2.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 1) { //Slot 3
|
|
|
|
Slot3.setText($ItemTokens[2]);
|
|
Amount3.setText("Amount: " @ $AmountTokens[2]);
|
|
|
|
} else {
|
|
Slot3.setText("");
|
|
Amount3.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 2) { //Slot 4
|
|
|
|
Slot4.setText($ItemTokens[3]);
|
|
Amount4.setText("Amount: " @ $AmountTokens[3]);
|
|
|
|
} else {
|
|
Slot4.setText("");
|
|
Amount4.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 3) { //Slot 5
|
|
|
|
Slot5.setText($ItemTokens[4]);
|
|
Amount5.setText("Amount: " @ $AmountTokens[4]);
|
|
|
|
} else {
|
|
Slot5.setText("");
|
|
Amount5.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 4) { //Slot 6
|
|
|
|
Slot6.setText($ItemTokens[5]);
|
|
Amount6.setText("Amount: " @ $AmountTokens[5]);
|
|
|
|
} else {
|
|
Slot6.setText("");
|
|
Amount6.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 5) { //Slot 7
|
|
|
|
Slot7.setText($ItemTokens[6]);
|
|
Amount7.setText("Amount: " @ $AmountTokens[6]);
|
|
|
|
|
|
} else {
|
|
Slot7.setText("");
|
|
Amount7.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 6) { //Slot 8
|
|
|
|
Slot8.setText($ItemTokens[7]);
|
|
Amount8.setText("Amount: " @ $AmountTokens[7]);
|
|
|
|
} else {
|
|
Slot8.setText("");
|
|
Amount8.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 7) { //Slot 9
|
|
|
|
Slot9.setText($ItemTokens[8]);
|
|
Amount9.setText("Amount: " @ $AmountTokens[8]);
|
|
|
|
} else {
|
|
Slot9.setText("");
|
|
Amount9.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 8) { //Slot 10
|
|
|
|
Slot10.setText($ItemTokens[9]);
|
|
Amount10.setText("Amount: " @ $AmountTokens[9]);
|
|
|
|
} else {
|
|
Slot10.setText("");
|
|
Amount10.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
if ($invCount > 9) { //Slot 11
|
|
|
|
Slot11.setText($ItemTokens[10]);
|
|
Amount11.setText("Amount: " @ $AmountTokens[10]);
|
|
|
|
} else {
|
|
Slot11.setText("");
|
|
Amount11.setText("");
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
Canvas.setContent( InventoryGui );
|
|
}
|
|
|
|
//--------------------------------------------------------------------
|
|
// Display function
|
|
//--------------------------------------------------------------------
|
|
function DisplayItem(%num) {
|
|
|
|
displayWindow.setModel("fps/data/shapes/" @ $strippedItemTokens[%num] @ "/" @ $TypeTokens[%num] @ ".dts" , "");
|
|
DisplayText.setText($DescTokens[%num]);
|
|
|
|
}
|
|
//--------------------------------------------------------------------
|
|
// Slot click events
|
|
//--------------------------------------------------------------------
|
|
function Slot1::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 11);
|
|
}
|
|
|
|
function Slot2::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 10);
|
|
}
|
|
|
|
function Slot3::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 9);
|
|
}
|
|
|
|
function Slot4::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 8);
|
|
}
|
|
|
|
function Slot5::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 7);
|
|
}
|
|
|
|
function Slot6::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 6);
|
|
}
|
|
|
|
function Slot7::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 5);
|
|
}
|
|
|
|
function Slot8::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 4);
|
|
}
|
|
|
|
function Slot9::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 3);
|
|
}
|
|
|
|
function Slot10::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 2);
|
|
}
|
|
|
|
function Slot11::onMouseDown(%this, %obj) {
|
|
DisplayItem($CurrentBottomSlot - 1);
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
// "Arrow Keys"
|
|
//--------------------------------------------------------------------
|
|
|
|
function UpArrow::onMouseDown(%this, %obj)
|
|
{
|
|
if ($invCount > 10 && $CurrentBottomSlot > 11) {
|
|
|
|
$CurrentBottomSlot--;
|
|
|
|
Shift();
|
|
|
|
}
|
|
}
|
|
|
|
function DownArrow::onMouseDown(%this, %obj)
|
|
{
|
|
if ($invCount > 10 && $CurrentBottomSlot < ($invCount+1)) {
|
|
|
|
$CurrentBottomSlot++;
|
|
|
|
Shift();
|
|
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------
|
|
// Shift - shifts the slots
|
|
//-----------------------------------------------------------------
|
|
function Shift() {
|
|
|
|
Slot1.setText($ItemTokens[$CurrentBottomSlot-11]);
|
|
Amount1.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-11]);
|
|
|
|
Slot2.setText($ItemTokens[$CurrentBottomSlot-10]);
|
|
Amount2.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-10]);
|
|
|
|
Slot3.setText($ItemTokens[$CurrentBottomSlot-9]);
|
|
Amount3.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-9]);
|
|
|
|
Slot4.setText($ItemTokens[$CurrentBottomSlot-8]);
|
|
Amount4.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-8]);
|
|
|
|
Slot5.setText($ItemTokens[$CurrentBottomSlot-7]);
|
|
Amount5.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-7]);
|
|
|
|
Slot6.setText($ItemTokens[$CurrentBottomSlot-6]);
|
|
Amount6.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-6]);
|
|
|
|
Slot7.setText($ItemTokens[$CurrentBottomSlot-5]);
|
|
Amount7.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-5]);
|
|
|
|
Slot8.setText($ItemTokens[$CurrentBottomSlot-4]);
|
|
Amount8.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-4]);
|
|
|
|
Slot9.setText($ItemTokens[$CurrentBottomSlot-3]);
|
|
Amount9.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-3]);
|
|
|
|
Slot10.setText($ItemTokens[$CurrentBottomSlot-2]);
|
|
Amount10.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-2]);
|
|
|
|
Slot11.setText($ItemTokens[$CurrentBottomSlot-1]);
|
|
Amount11.setText("Amount: " @ $AmountTokens[$CurrentBottomSlot-1]);
|
|
|
|
} |