Show InventoryTest.java syntax highlighted
/*
* Copyright (C) 2001-2005 Pleasant nightmare studio
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package skunkworks;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.action.InputActionEvent;
import com.jme.input.action.KeyInputAction;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.MaterialState;
import org.pleasantnightmare.riotinecity.ActionNames;
import org.pleasantnightmare.riotinecity.ConsoleGame;
import org.pleasantnightmare.riotinecity.inventory.Container;
import org.pleasantnightmare.riotinecity.inventory.InventoryContext;
import org.pleasantnightmare.riotinecity.inventory.InventorySpaceError;
import org.pleasantnightmare.riotinecity.inventory.Item;
import org.pleasantnightmare.riotinecity.model.EquipPlace;
import org.pleasantnightmare.riotinecity.model.Player;
/**
* @author deus
* @version 1.0
* @since Mar 27, 2007 10:34:29 PM
*/
public class InventoryTest extends ConsoleGame {
private InventoryContext context;
protected void simpleInitGame() {
Player player = new Player();
context = new InventoryContext(player);
sceneRoot.attachChild(testBall());
inputController();
equipPlayer(player);
MouseInput.get().setCursorVisible(true);
}
private void equipPlayer(Player player) {
Container backpack = new Container(4, 5, "Backpack", "backpack");
backpack.addInventorySpace("Main pocket", 6, 7);
backpack.addInventorySpace("L. pocket", 2, 6);
backpack.addInventorySpace("R. pocket", 2, 6);
backpack.setEquipPlace(EquipPlace.TORSO_BACK);
Item ms = new Item(2, 2, "Monkey spring", "stolenicon1");
ms.setEquipPlace(EquipPlace.HEAD);
Container wallet = new Container(2, 2, "Wallet", "wallet", 8, 2);
Item creditCard = new Item(2, 2, "Credit card", "credit-card-item");
try {
wallet.getInventorySpaces().iterator().next().setItemTo(0, 0, creditCard);
backpack.getInventorySpaces().iterator().next().setItemTo(0, 0, ms);
backpack.getInventorySpaces().iterator().next().setItemTo(0, 5, wallet);
} catch (InventorySpaceError inventorySpaceError) {
throw new RuntimeException(inventorySpaceError);
}
player.getEquipSlot(EquipPlace.TORSO_BACK).equip(backpack);
}
private Spatial testBall() {
Sphere sferica = new Sphere("sphery", 10, 10, 3.0f);
MaterialState ms = display.getRenderer().createMaterialState();
ms.setAmbient(new ColorRGBA(0.0f, 0.3f, 0.3f, 1.0f));
ms.setDiffuse(new ColorRGBA(0.0f, 1.0f, 1.0f, 1.0f));
ms.setEnabled(true);
sferica.setRenderState(ms);
sferica.updateRenderState();
Node objectOfInterest = new Node("objectOfInterest");
objectOfInterest.attachChild(sferica);
return sferica;
}
private void inputController() {
final InputHandler input = new InputHandler();
addHandler(input);
KeyBindingManager.getKeyBindingManager().add(ActionNames.TOGGLE_EQUIP_SCREEN, new int[]{KeyInput.KEY_I});
input.addAction(new KeyInputAction() {
public boolean show = false;
public void performAction(InputActionEvent evt) {
show = !show;
if (show)
context.activate(hudRoot, input);
else
context.deactivate();
}
}, ActionNames.TOGGLE_EQUIP_SCREEN, false);
}
public static void main(String[] args) {
InventoryTest g = new InventoryTest();
g.start();
}
}
See more files for this project here