Simple GUI list for default Full Template.
by Wayne Eversole · 02/11/2016 (3:07 pm) · 2 comments
This is an update to one of Dreamers MMORPG Tutorial, inventory for the client found here.
www.garagegames.com/community/resources/view/7514
There is no need to add the first 2 links from Dreamers page as T3D 3.8 already has those installed.
InventoryGUI.gui
InventoryGUI.cs
Client / client_commands.cs
Client default.bind.cs
This should give you the ability to equip / drop items out of your inventory.
I am not a coder so there may be bugs.
Thank you to the IRC Channel for all the help.
UPDATE. Change server/inventory.cs function ShapeBase::setInventory(%this, %data, %value) to this.
www.garagegames.com/community/resources/view/7514
There is no need to add the first 2 links from Dreamers page as T3D 3.8 already has those installed.
InventoryGUI.gui
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(InventoryGUI) {
position = "0 0";
extent = "1920 1200";
minExtent = "8 2";
horizSizing = "center";
vertSizing = "center";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "1";
new GuiWindowCtrl(InventoryWindow) {
text = "Inventory";
resizeWidth = "1";
resizeHeight = "1";
canMove = "1";
canClose = "1";
canMinimize = "1";
canMaximize = "1";
canCollapse = "0";
closeCommand = "Canvas.PopDialog(InventoryGUI);";
edgeSnap = "1";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "322 197";
extent = "621 524";
minExtent = "8 2";
horizSizing = "relative";
vertSizing = "relative";
profile = "GuiWindowProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
new GuiScrollCtrl() {
willFirstRespond = "1";
hScrollBar = "alwaysOn";
vScrollBar = "alwaysOn";
lockHorizScroll = "0";
lockVertScroll = "0";
constantThumbHeight = "0";
childMargin = "0 0";
mouseWheelScrollSpeed = "-1";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "396 31";
extent = "200 400";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiScrollProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
new GuiTextListCtrl(InventoryListView) {
columns = "0";
fitParentWidth = "1";
clipColumnText = "0";
position = "1 1";
extent = "182 2";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiTextArrayProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
};
};
new GuiObjectView(InventoryItemView) {
mountedNode = "mount0";
lightColor = "1 1 1 1";
lightAmbient = "0.5 0.5 0.5 1";
lightDirection = "0 0.707 -0.707";
orbitDiststance = "2";
minOrbitDiststance = "1.103";
maxOrbitDiststance = "5";
cameraSpeed = "0";
cameraRotation = "0 0 3.8";
cameraZRot = "0";
forceFOV = "0";
reflectPriority = "0";
renderStyle = "standard";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "14 31";
extent = "284 395";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiButtonCtrl(Drop) {
text = "Drop Item";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "426 474";
extent = "140 30";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiButtonProfile";
visible = "1";
active = "1";
command = "throwItem();";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiButtonCtrl(MountItem) {
text = "Equip";
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "62 479";
extent = "140 30";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "GuiButtonProfile";
visible = "1";
active = "1";
command = "commandToServer('use',$SelectedItem);";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
canSave = "1";
canSaveDynamicFields = "0";
};
};
};
//--- OBJECT WRITE END ---InventoryGUI.cs
function toggleInventoryGUI(%val){
if(%val)
InventoryGUI.toggle();
}
function InventoryGUI::OnWake(%this){
UpdateInventoryListView();
}
//This function updates the InventoryListView
function UpdateInventoryListView(){
echo("UpdatingInventoryListView, lets start by clearing it");
InventoryListView.clear();
echo("Clearing Done now looping through Inventory");
for(%x = 0; %x < $Inventory.count(); %x++){
InventoryListView.addRow(%x,$Inventory.getKey(%x) SPC $Inventory.getValue(%x));
echo("Added Item at "@%x);
echo("Here is %x ------", %x);
}
//echo("Complete!, now sorting and cleaning");
echo("Complete!, now sorting and cleaning" SPC $Inventory.count() SPC "rows");
InventoryListView.sort(0);
//InventoryListView.setSelectedRow(0);
InventoryListView.scrollVisible(0);
}
function InventoryGUI::toggle(%this)
{
if (%this.isAwake()){
Canvas.popDialog(%this);
}else{
Canvas.pushDialog(%this);
}
}
function InventoryListView::OnSelect( %this, %id, %text ){
echo("Items = ------------------- ", %text);
$SelectedItem = getField(InventoryListView.getRowTextById(%id),0);
$SelectedItem = getWord($SelectedItem,0);
InventoryItemView.setModel($SelectedItem.shapefile);
//commandToServer('use',$SelectedItem);
}Client / client_commands.cs
$Inventory = new arrayObject();
$InventoryImage = new arrayObject();
function clientCmdUpdateInventory(%Item,%Amount,%Image)
{
echo("Recieved Inventory Item Update from server");
if(%Item !$="")
{
echo("Item is not NULL");
%Index = $Inventory.getIndexFromKey(%Item);
if (%amount==0)
{
%RemoveMe = new arrayObject();
%RemoveMe.add(%Item, %Amount);
$Inventory.crop(%RemoveMe);
$InventoryImage.crop(%RemoveMe);
}
else
{
if(%Index==-1)
{
echo("Evidently a new item");
$Inventory.add(%Item, %Amount);
$InventoryImage.add(%Item,%Image);
echo("Added new item successfully");
}
else
{
echo("We already had 1 or more of these");
//$Inventory.setValue(%Item,%Amount);
$Inventory.setValue(%Amount,$Inventory.getIndexFromKey(%Item));
echo("Updated Inventory Amount");
}
}
}
else
{
echo("Whoops! There was no Item in that call!");
}
echo("Recieved "@$Inventory.getValue(%Item)@" of "@%Item);
UpdateInventoryListView();
}
function throwItem()
{
commandToServer('Throw', $SelectedItem);
}Client default.bind.cs
// For toggling the inventory.
function toggleInventory(%val)
{
if( %val )
{
if( isObject(PlayGui) )
{
if( PlayGui.controlIsChild( InventoryGUI ) )
{
PlayGui.remove( InventoryGUI );
hideCursor();
}
else
{
PlayGui.add( InventoryGUI );
showCursor();
}
}
}
}
moveMap.bind(keyboard, "e", toggleInventory);This should give you the ability to equip / drop items out of your inventory.
I am not a coder so there may be bugs.
Thank you to the IRC Channel for all the help.
UPDATE. Change server/inventory.cs function ShapeBase::setInventory(%this, %data, %value) to this.
function ShapeBase::setInventory(%this, %data, %value)
{
// Set the inventory amount for this datablock and invoke inventory
// callbacks. All changes to inventory go through this single method.
// Impose inventory limits
if (%value < 0)
%value = 0;
else
{
%max = %this.maxInventory(%data);
if (%value > %max)
%value = %max;
}
// Set the value and invoke object callbacks
%name = %data.getName();
if (%this.inv[%name] != %value)
{
%this.inv[%name] = %value;
%data.onInventory(%this, %value);
%this.getDataBlock().onInventory(%data, %value);
CommandToClient(%this.client,'UpdateInventory',%name,%value,%Image);
echo("If we are seeing this then client inventory command has been issued");
echo("nnnnnSent the following info to client",%this.client,%name,%value,%Image);
}
return %value;
}
Torque Owner Nathan Martin
TRON 2001 Network