All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mmb.menu.world.inv.SingleInventoryController Maven / Gradle / Ivy

Go to download

Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world. THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<

The newest version!
/**
 * 
 */
package mmb.menu.world.inv;

import static mmb.engine.settings.GlobalSettings.$res;

import java.awt.Color;
import java.util.Collections;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.SwingConstants;

import mmb.engine.inv.Inventory;
import mmb.engine.inv.ItemRecord;
import mmb.engine.inv.storage.SingleItemInventory;
import mmb.engine.item.ItemEntry;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;

/**
 * @author oskar
 *
 */
public class SingleInventoryController extends Box implements AbstractInventoryController {
	
	private final SingleItemInventory inv;
	private final JLabel label;
	private final JLabel title;
	public SingleInventoryController(SingleItemInventory inv) {
		super(BoxLayout.Y_AXIS);
		this.inv = inv;
		
		title = new JLabel($res("wgui-inv"));
		title.setHorizontalAlignment(SwingConstants.LEFT);
		add(title);
		
		JButton button = new JButton($res("wgui-refresh"));
		button.addActionListener(e -> refresh());
		button.setBackground(Color.YELLOW);
		add(button);
		
		label = new JLabel();
		label.setHorizontalAlignment(SwingConstants.LEFT);
		add(label);
		
		refresh();
	}

	@Override
	public Inventory getInv() {
		return inv;
	}

	@Override
	public void refresh() {
		ItemEntry item = inv.getContents();
		if(item == null) {
			label.setText("(none)");
			label.setIcon(null);
			label.setToolTipText(null);
		}else {
			label.setText(item.title());
			label.setToolTipText(item.description());
			label.setIcon(item.icon());
		}
	}

	@Override
	public List getSelectedValuesList() {
		ItemRecord irecord = getSelectedValue();
		if(irecord == null) return Collections.emptyList();
		return List.of(irecord);
	}

	@Override
	public ItemRecord getSelectedValue() {
		return inv.nget();
	}
	
	public void setTitle(String title) {
		this.title.setText(title);
	}
	public String getTitle() {
		return title.getText();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy