From 346b22a9dff14a1a63314c36e4f05fdfc54f01d3 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Tue, 24 Feb 2015 18:16:14 -0500 Subject: [PATCH] Updated TransactionUI --- MerchantRPGCSE2102/src/controller/RPGame.java | 4 +--- .../src/controller/Transaction.java | 23 ++++++++++++++++++- .../src/view/TransactionUI.java | 6 ++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index 7fa2db1..686f23e 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -102,7 +102,6 @@ else if (merchantNumber == 3) } } - /** * This method returns the player's inventory list * @@ -127,7 +126,6 @@ public void createTransaction(Player player, Merchant targetMerchant) /** * Toggles the movement on or off based on the input - * * @param command either "ON" or "OFF" */ public void toggleMovement(String command) @@ -166,7 +164,7 @@ else if(merchantNum == 2) /** * Main method used to test the GUI components since test classes do not maintain the GUI - * @param args + * @param args no need for input */ public static void main(String[] args) { diff --git a/MerchantRPGCSE2102/src/controller/Transaction.java b/MerchantRPGCSE2102/src/controller/Transaction.java index 1815a09..4769e31 100644 --- a/MerchantRPGCSE2102/src/controller/Transaction.java +++ b/MerchantRPGCSE2102/src/controller/Transaction.java @@ -1,6 +1,7 @@ package controller; import view.TransactionUI; +import model.Item; import model.Merchant; import model.Player; @@ -58,7 +59,7 @@ public boolean actionSell(String itemName, int amount) /** * This method will push a true up to the class calling it - * + * incomplete method * @return returns true */ public boolean actionCancel() @@ -66,6 +67,26 @@ public boolean actionCancel() return true; } + /** + * Searches the player inventory for the item matching the item name + * @param itemName name of the item + * @return returns the item with the corresponding name + */ + public Item searchPlayerInventory(String itemName) + { + return _player.getItem(itemName); + } + + /** + * Searches the merchant's inventory for the item matching the item name + * @param itemName name of the item + * @return returns item with the corresponding name + */ + public Item searchMerchantInventory(String itemName) + { + return _targetMerchant.getItem(itemName); + } + /** * Returns the player in transaction * @return returns the player diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index 8400ba3..e018ce1 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -90,6 +90,7 @@ public void mouseClicked(MouseEvent e) { @Override public void mouseClicked(MouseEvent e) { System.out.println("Cancel"); //temporary test code + MASTER.actionCancel(); exitWindow(); } }); @@ -109,6 +110,7 @@ public void mouseClicked(MouseEvent e) { /** * Will exit the transaction window + * incomplete method */ public void exitWindow() { @@ -157,6 +159,7 @@ public static void createSellWindow() contentPane.setLayout(null); String[] itemList = new String[MASTER.getPlayer().getInventory().length]; //create a new array of strings with the length of the player's inventory + String chosenItem; //item that the player chooses from the combobox for(int i = 0; i < itemList.length; i++) //adds all the item names to the item list { itemList[i] = MASTER.getPlayer().getInventory()[i].getItemName(); @@ -165,8 +168,9 @@ public static void createSellWindow() JComboBox comboBox = new JComboBox(itemList); comboBox.setBounds(61, 141, 131, 20); contentPane.add(comboBox); + chosenItem = comboBox.getSelectedItem().toString(); - JSlider slider = new JSlider(); + JSlider slider = new JSlider(0, MASTER.searchPlayerInventory(chosenItem).getQuantity(), 0); //sets the slider quantity slider.setBounds(61, 237, 200, 26); contentPane.add(slider);