Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.navybofus;
- import com.jme3.app.SimpleApplication;
- import com.jme3.asset.AssetManager;
- import com.jme3.input.event.MouseButtonEvent;
- import com.jme3.math.Vector2f;
- import com.jme3.math.Vector4f;
- import com.jme3.system.AppSettings;
- import com.jme3.texture.Texture;
- import java.util.ArrayList;
- import java.util.List;
- import tonegod.gui.controls.buttons.ButtonAdapter;
- import tonegod.gui.controls.windows.Window;
- import tonegod.gui.core.Element;
- import tonegod.gui.core.Screen;
- import tonegod.gui.core.layouts.LayoutHelper;
- import tonegod.gui.core.utils.UIDUtil;
- /**
- *
- * @author Jessica
- */
- public class GUI {
- public static enum InventoryType {
- DragDrop,
- PointClick
- }
- private InventoryType inventoryType = InventoryType.DragDrop;
- private Screen screen;
- private AppSettings settings;
- private ButtonAdapter cursor;
- public int winCount = 0;
- private Texture objIcons;
- private int iconSize = 40;
- private String iconDefault = "x=64|y=64|w=64|h=64";
- private Window invWindow;
- List<ButtonAdapter> slots = new ArrayList();
- public GUI(SimpleApplication app, AppSettings settings, AssetManager assetManager) {
- this.screen = new Screen(app, "Styles/defEdit/style_map.gui.xml");
- this.settings = settings;
- initInventory(app);
- }
- private void initInventory(SimpleApplication app) {
- objIcons = app.getAssetManager().loadTexture("Textures/ObjIcons.png");
- createInventoryWindow();
- cursor = new ButtonAdapter(screen, UIDUtil.getUID(), Vector2f.ZERO, new Vector2f(iconSize, iconSize), Vector4f.ZERO, null) {
- @Override
- public void update(float tpf) {
- setPosition(screen.getMouseXY().x + 25, screen.getMouseXY().y - 50);
- }
- };
- cursor.setIsEnabled(false);
- cursor.setInterval(1);
- cursor.setTextureAtlasImage(objIcons, iconDefault);
- cursor.setIsModal(true);
- cursor.setIsGlobalModal(true);
- cursor.setEffectZOrder(false);
- cursor.setIgnoreMouse(true);
- screen.addElement(cursor);
- cursor.move(0, 0, 20);
- }
- private void createInventoryWindow() {
- invWindow = getInvWindow();
- screen.addElement(invWindow);
- createInventorySlots();
- }
- private void createInventorySlots() {
- LayoutHelper.reset();
- Element lastEl = null;
- int index = 0;
- for (int y = 0; y < 4; y++) {
- LayoutHelper.resetX();
- for (int x = 0; x < 4; x++) {
- ButtonAdapter e = createInventorySlot(index, LayoutHelper.position());
- e.setScaleEW(false);
- e.setScaleNS(false);
- e.setDocking(Element.Docking.SW);
- e.setEffectZOrder(false);
- invWindow.getContentArea().addChild(e);
- slots.add(e);
- lastEl = e;
- LayoutHelper.advanceX(lastEl, true);
- index++;
- }
- LayoutHelper.advanceY(lastEl, true);
- }
- }
- private ButtonAdapter createInventorySlot(int index, Vector2f position) {
- ButtonAdapter slot = new ButtonAdapter(
- screen,
- "InvSlot" + index,
- position,
- LayoutHelper.dimensions(iconSize, iconSize),
- screen.getStyle("CheckBox").getVector4f("resizeBorders"),
- screen.getStyle("CheckBox").getString("defaultImg")) {
- @Override
- public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
- if (inventoryType == InventoryType.PointClick) {
- InteractiveNode prevNode = null;
- InteractiveNode nextNode = null;
- if (getUserData("worldObject") != null) {
- prevNode = getUserData("worldObject");
- setToolTipText("");
- setUserData("worldObject", null);
- setButtonIcon(iconSize, iconSize, iconDefault);
- }
- if (cursor.getUserData("worldObject") != null) {
- nextNode = cursor.getUserData("worldObject");
- cursor.setTextureAtlasImage(objIcons, iconDefault);
- cursor.setUserData("worldObject", null);
- }
- if (nextNode != null) {
- String ttt = nextNode.getToolTipText();
- setToolTipText(ttt.substring(0, ttt.indexOf("\n")) + "\n\nDrop me back into\nthe world.");
- setUserData("worldObject", nextNode);
- setButtonIcon(iconSize, iconSize, nextNode.getIcon());
- }
- if (prevNode != null) {
- cursor.setUserData("worldObject", prevNode);
- cursor.setTextureAtlasImage(objIcons, prevNode.getIcon());
- }
- }
- }
- };
- slot.clearAltImages();
- slot.setEffectZOrder(false);
- slot.setButtonIcon(iconSize, iconSize, iconDefault);
- slot.getButtonIcon().setTextureAtlasImage(objIcons, iconDefault);
- slot.setIsDragDropDropElement(true);
- return slot;
- }
- private Window getInvWindow() {
- Vector2f dim = new Vector2f(300, 400);
- Window nWin = new Window(screen, "Window" + winCount,
- new Vector2f(settings.getWidth() - dim.x, settings.getHeight()));
- nWin.setWindowTitle("Inventory");
- nWin.setIsMovable(true);
- nWin.setIsResizable(false);
- winCount++;
- return nWin;
- }
- public Screen getScreen() {
- return screen;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment