Преглед на файлове

Add super-basic info panel for Items.
TODOS:
For Items: properties, description, prototypes, purchase/sell/use/discard
For Equipment: Generic equipment panel
For Armor/Weapon: Mixin weapon info (e.g. Masterwork, Magic), Mixin value, Mixin properties.

Sam Jaffe преди 8 години
родител
ревизия
2edbd8063a

+ 8 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/inventory/EquipmentInfoMenu.java

@@ -5,6 +5,7 @@ import javax.swing.JPopupMenu;
 import org.leumasjaffe.charsheet.model.inventory.DDItem;
 import org.leumasjaffe.function.VoidVoidFunction;
 
+import javax.swing.JFrame;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 
@@ -18,7 +19,13 @@ class EquipmentInfoMenu extends JPopupMenu {
 		
 		JMenuItem mntmInfo = new JMenuItem("Info");
 		add(mntmInfo);
-		
+		mntmInfo.addActionListener(e -> {
+			JFrame frame = new JFrame(item.getName());
+			frame.add(new ItemInfoPanel(item));
+			frame.pack();
+			frame.setVisible(true);
+		});
+
 		JMenuItem mntmEquip = new JMenuItem("Unequip");
 		mntmEquip.addActionListener(e -> {
 			if (JOptionPane.showConfirmDialog(null, 

+ 8 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/inventory/ItemInfoMenu.java

@@ -6,6 +6,7 @@ import org.leumasjaffe.charsheet.model.inventory.DDItem;
 import org.leumasjaffe.charsheet.model.inventory.EquipmentSlot;
 import org.leumasjaffe.function.VoidVoidFunction;
 
+import javax.swing.JFrame;
 import javax.swing.JMenuItem;
 
 class ItemInfoMenu extends JPopupMenu {
@@ -18,8 +19,14 @@ class ItemInfoMenu extends JPopupMenu {
 		
 		JMenuItem mntmInfo = new JMenuItem("Info");
 		add(mntmInfo);
+		mntmInfo.addActionListener(e -> {
+			JFrame frame = new JFrame(item.getName());
+			frame.add(new ItemInfoPanel(item));
+			frame.pack();
+			frame.setVisible(true);
+		});
 		
-		if ( item.getSlot() != EquipmentSlot.NONE && item.getUnequippedCount() > 0 ) {
+		if (item.getSlot() != EquipmentSlot.NONE && item.getUnequippedCount() > 0) {
 			JMenuItem mntmEquip = new JMenuItem("Equip");
 			mntmEquip.addActionListener(e -> cons.apply());
 			add(mntmEquip);

+ 236 - 0
src/main/lombok/org/leumasjaffe/charsheet/view/inventory/ItemInfoPanel.java

@@ -0,0 +1,236 @@
+package org.leumasjaffe.charsheet.view.inventory;
+
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+
+import javax.swing.JPanel;
+
+import org.leumasjaffe.charsheet.model.inventory.DDItem;
+import org.leumasjaffe.charsheet.util.StringHelper;
+
+import java.awt.Insets;
+import javax.swing.JLabel;
+import java.awt.Color;
+import java.awt.Font;
+import javax.swing.SwingConstants;
+import java.awt.Component;
+import java.awt.Dimension;
+
+import javax.swing.Box;
+import javax.swing.JTextField;
+
+class ItemInfoPanel extends JPanel {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public ItemInfoPanel(final DDItem item) {
+		GridBagLayout gridBagLayout = new GridBagLayout();
+		gridBagLayout.columnWidths = new int[]{0, 0};
+		gridBagLayout.rowHeights = new int[]{0, 0, 0};
+		gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
+		gridBagLayout.rowWeights = new double[]{1.0, 1.0, Double.MIN_VALUE};
+		setLayout(gridBagLayout);
+		
+		JPanel panel = new JPanel();
+		GridBagConstraints gbc_panel = new GridBagConstraints();
+		gbc_panel.insets = new Insets(0, 0, 0, 0);
+		gbc_panel.fill = GridBagConstraints.BOTH;
+		gbc_panel.gridx = 0;
+		gbc_panel.gridy = 0;
+		add(panel, gbc_panel);
+		GridBagLayout gbl_panel = new GridBagLayout();
+		gbl_panel.columnWidths = new int[]{120, 0, 0, 0, 0, 0, 0, 0, 0};
+		gbl_panel.rowHeights = new int[]{0, 0, 0, 0};
+		gbl_panel.columnWeights = new double[]{1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, Double.MIN_VALUE};
+		gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
+		panel.setLayout(gbl_panel);
+		
+		JLabel lblName = new JLabel("ITEM NAME");
+		lblName.setOpaque(true);
+		lblName.setHorizontalAlignment(SwingConstants.CENTER);
+		lblName.setForeground(Color.WHITE);
+		lblName.setFont(new Font("Tahoma", Font.BOLD, 10));
+		lblName.setBackground(Color.BLACK);
+		GridBagConstraints gbc_lblName = new GridBagConstraints();
+		gbc_lblName.fill = GridBagConstraints.BOTH;
+		gbc_lblName.gridheight = 2;
+		gbc_lblName.insets = new Insets(0, 0, 0, 1);
+		gbc_lblName.gridx = 0;
+		gbc_lblName.gridy = 0;
+		panel.add(lblName, gbc_lblName);
+		
+		Component verticalStrut = Box.createVerticalStrut(20);
+		verticalStrut.setMinimumSize(new Dimension(0, 10));
+		verticalStrut.setMaximumSize(new Dimension(32767, 10));
+		verticalStrut.setPreferredSize(new Dimension(0, 10));
+		GridBagConstraints gbc_verticalStrut = new GridBagConstraints();
+		gbc_verticalStrut.insets = new Insets(0, 0, 0, 1);
+		gbc_verticalStrut.fill = GridBagConstraints.HORIZONTAL;
+		gbc_verticalStrut.gridx = 1;
+		gbc_verticalStrut.gridy = 0;
+		panel.add(verticalStrut, gbc_verticalStrut);
+		
+		JLabel lblWeight = new JLabel("WEIGHT");
+		lblWeight.setOpaque(true);
+		lblWeight.setHorizontalAlignment(SwingConstants.CENTER);
+		lblWeight.setForeground(Color.WHITE);
+		lblWeight.setFont(new Font("Tahoma", Font.BOLD, 8));
+		lblWeight.setBackground(Color.BLACK);
+		GridBagConstraints gbc_lblWeight = new GridBagConstraints();
+		gbc_lblWeight.fill = GridBagConstraints.HORIZONTAL;
+		gbc_lblWeight.insets = new Insets(0, 0, 0, 1);
+		gbc_lblWeight.gridx = 1;
+		gbc_lblWeight.gridy = 1;
+		panel.add(lblWeight, gbc_lblWeight);
+		
+		JLabel lblPage = new JLabel("PAGE");
+		lblPage.setOpaque(true);
+		lblPage.setHorizontalAlignment(SwingConstants.CENTER);
+		lblPage.setForeground(Color.WHITE);
+		lblPage.setFont(new Font("Tahoma", Font.BOLD, 8));
+		lblPage.setBackground(Color.BLACK);
+		GridBagConstraints gbc_lblPage = new GridBagConstraints();
+		gbc_lblPage.fill = GridBagConstraints.HORIZONTAL;
+		gbc_lblPage.insets = new Insets(0, 0, 0, 1);
+		gbc_lblPage.gridx = 2;
+		gbc_lblPage.gridy = 1;
+		panel.add(lblPage, gbc_lblPage);
+		
+		JLabel lblPp = new JLabel("pp");
+		lblPp.setOpaque(true);
+		lblPp.setHorizontalAlignment(SwingConstants.CENTER);
+		lblPp.setForeground(Color.WHITE);
+		lblPp.setFont(new Font("Tahoma", Font.BOLD, 8));
+		lblPp.setBackground(Color.BLACK);
+		GridBagConstraints gbc_lblPp = new GridBagConstraints();
+		gbc_lblPp.fill = GridBagConstraints.HORIZONTAL;
+		gbc_lblPp.insets = new Insets(0, 0, 0, 1);
+		gbc_lblPp.gridx = 4;
+		gbc_lblPp.gridy = 1;
+		panel.add(lblPp, gbc_lblPp);
+		
+		JLabel lblGp = new JLabel("gp");
+		lblGp.setOpaque(true);
+		lblGp.setHorizontalAlignment(SwingConstants.CENTER);
+		lblGp.setForeground(Color.WHITE);
+		lblGp.setFont(new Font("Tahoma", Font.BOLD, 8));
+		lblGp.setBackground(Color.BLACK);
+		GridBagConstraints gbc_lblGp = new GridBagConstraints();
+		gbc_lblGp.fill = GridBagConstraints.HORIZONTAL;
+		gbc_lblGp.insets = new Insets(0, 0, 0, 1);
+		gbc_lblGp.gridx = 5;
+		gbc_lblGp.gridy = 1;
+		panel.add(lblGp, gbc_lblGp);
+		
+		JLabel lblSp = new JLabel("sp");
+		lblSp.setOpaque(true);
+		lblSp.setHorizontalAlignment(SwingConstants.CENTER);
+		lblSp.setForeground(Color.WHITE);
+		lblSp.setFont(new Font("Tahoma", Font.BOLD, 8));
+		lblSp.setBackground(Color.BLACK);
+		GridBagConstraints gbc_lblSp = new GridBagConstraints();
+		gbc_lblSp.fill = GridBagConstraints.HORIZONTAL;
+		gbc_lblSp.insets = new Insets(0, 0, 0, 1);
+		gbc_lblSp.gridx = 6;
+		gbc_lblSp.gridy = 1;
+		panel.add(lblSp, gbc_lblSp);
+		
+		JLabel lblCp = new JLabel("cp");
+		lblCp.setOpaque(true);
+		lblCp.setHorizontalAlignment(SwingConstants.CENTER);
+		lblCp.setForeground(Color.WHITE);
+		lblCp.setFont(new Font("Tahoma", Font.BOLD, 8));
+		lblCp.setBackground(Color.BLACK);
+		GridBagConstraints gbc_lblCp = new GridBagConstraints();
+		gbc_lblCp.insets = new Insets(0, 0, 0, 0);
+		gbc_lblCp.fill = GridBagConstraints.HORIZONTAL;
+		gbc_lblCp.gridx = 7;
+		gbc_lblCp.gridy = 1;
+		panel.add(lblCp, gbc_lblCp);
+		
+		JTextField txtName = new JTextField(item.getName());
+		txtName.setEditable(false);
+		txtName.setColumns(10);
+		GridBagConstraints gbc_txtName = new GridBagConstraints();
+		gbc_txtName.insets = new Insets(0, 0, 0, 1);
+		gbc_txtName.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtName.gridx = 0;
+		gbc_txtName.gridy = 2;
+		panel.add(txtName, gbc_txtName);
+				
+		JTextField txtWeight = new JTextField(StringHelper.toString(item.getWeight()) + " lb.");
+		txtWeight.setEditable(false);
+		txtWeight.setColumns(10);
+		GridBagConstraints gbc_txtWeight = new GridBagConstraints();
+		gbc_txtWeight.insets = new Insets(0, 0, 0, 1);
+		gbc_txtWeight.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtWeight.gridx = 1;
+		gbc_txtWeight.gridy = 2;
+		panel.add(txtWeight, gbc_txtWeight);
+		
+		JTextField txtPage = new JTextField(StringHelper.toString(item.getPage()));
+		txtPage.setEditable(false);
+		txtPage.setColumns(10);
+		GridBagConstraints gbc_txtPage = new GridBagConstraints();
+		gbc_txtPage.insets = new Insets(0, 0, 0, 1);
+		gbc_txtPage.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtPage.gridx = 2;
+		gbc_txtPage.gridy = 2;
+		panel.add(txtPage, gbc_txtPage);
+		
+		Component horizontalStrut = Box.createHorizontalStrut(20);
+		GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
+		gbc_horizontalStrut.insets = new Insets(0, 0, 0, 1);
+		gbc_horizontalStrut.gridx = 3;
+		gbc_horizontalStrut.gridy = 2;
+		panel.add(horizontalStrut, gbc_horizontalStrut);
+		
+		JTextField txtPP = new JTextField(StringHelper.toString(item.getValue().getPp()));
+		txtPP.setEditable(false);
+		txtPP.setColumns(10);
+		GridBagConstraints gbc_txtPP = new GridBagConstraints();
+		gbc_txtPP.insets = new Insets(0, 0, 0, 1);
+		gbc_txtPP.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtPP.gridx = 4;
+		gbc_txtPP.gridy = 2;
+		panel.add(txtPP, gbc_txtPP);
+		
+		JTextField txtGP = new JTextField(StringHelper.toString(item.getValue().getGp()));
+		txtGP.setEditable(false);
+		txtGP.setColumns(10);
+		GridBagConstraints gbc_txtGP = new GridBagConstraints();
+		gbc_txtGP.insets = new Insets(0, 0, 0, 1);
+		gbc_txtGP.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtGP.gridx = 5;
+		gbc_txtGP.gridy = 2;
+		panel.add(txtGP, gbc_txtGP);
+		
+		JTextField txtSP = new JTextField(StringHelper.toString(item.getValue().getSp()));
+		txtSP.setEditable(false);
+		txtSP.setColumns(10);
+		GridBagConstraints gbc_txtSP = new GridBagConstraints();
+		gbc_txtSP.insets = new Insets(0, 0, 0, 1);
+		gbc_txtSP.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtSP.gridx = 6;
+		gbc_txtSP.gridy = 2;
+		panel.add(txtSP, gbc_txtSP);
+		
+		JTextField txtCP = new JTextField(StringHelper.toString(item.getValue().getCp()));
+		txtCP.setEditable(false);
+		txtCP.setColumns(10);
+		GridBagConstraints gbc_txtCP = new GridBagConstraints();
+		gbc_txtCP.fill = GridBagConstraints.HORIZONTAL;
+		gbc_txtCP.gridx = 7;
+		gbc_txtCP.gridy = 2;
+		panel.add(txtCP, gbc_txtCP);
+		
+		JPanel panel_1 = new JPanel();
+		GridBagConstraints gbc_panel_1 = new GridBagConstraints();
+		gbc_panel_1.fill = GridBagConstraints.BOTH;
+		gbc_panel_1.gridx = 0;
+		gbc_panel_1.gridy = 1;
+		add(panel_1, gbc_panel_1);
+	}
+}