diff --git a/src/main/java/gui/MainFrame.java b/src/main/java/gui/MainFrame.java index 1aed7f6..3d9e7d3 100644 --- a/src/main/java/gui/MainFrame.java +++ b/src/main/java/gui/MainFrame.java @@ -25,6 +25,7 @@ import listener.CorruptedCheckBoxListener; import listener.CurrencyBulksCmbListener; import listener.CurrencyComboboxListener; +import listener.ElderChBoxListener; import listener.ExitButtonListener; import listener.MapCmbBoxBulksListener; import listener.MapComboboxListener; @@ -32,6 +33,7 @@ import listener.NextButtonBulksListener; import listener.NextButtonListener; import listener.PricePerMapTxtBoxListener; +import listener.ShapedChBoxListener; import listener.TierComboboxListener; import listener.UpdateButtonBulksListener; import listener.UpdateButtonListener; @@ -109,6 +111,8 @@ public class MainFrame extends JDialog implements IHideable { boolean validAmountInput = false; boolean validPricePerMapInput = false; + boolean loadedShapedMaps = false; + boolean loadedElderMaps = false; boolean userWantsMinimize = false; private JLabel lblMadeByEzkk; @@ -121,6 +125,7 @@ public class MainFrame extends JDialog implements IHideable { private JLabel lblBulkAmount; private JTextField txt_amount_bulks; JCheckBox chckbxElderMap; + JCheckBox chckbxShapedMap; JComboBox cmb_maps_bulks; JLabel lbl_tradeables_bulks; JButton btn_update_bulks; @@ -381,7 +386,7 @@ private void initFrame() { chckbxElderMap.setBackground(new Color(188, 143, 143)); - chckbxElderMap.setBounds(138, 145, 153, 23); + chckbxElderMap.setBounds(186, 145, 153, 23); panel_bulksMaps.add(chckbxElderMap); @@ -434,6 +439,11 @@ private void initFrame() { txtbox_pricePerMap.setColumns(10); txtbox_pricePerMap.setBounds(139, 58, 153, 20); panel_bulksMaps.add(txtbox_pricePerMap); + + chckbxShapedMap = new JCheckBox("SHAPED MAP?"); + chckbxShapedMap.setBackground(new Color(153, 204, 204)); + chckbxShapedMap.setBounds(31, 145, 153, 23); + panel_bulksMaps.add(chckbxShapedMap); lblLoading.setVisible(false); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); @@ -463,6 +473,12 @@ private void initFrame() { WhiteCheckBoxListener whiteBoxListener = new WhiteCheckBoxListener(this); chckbx_white.addActionListener(whiteBoxListener); + ShapedChBoxListener shapedCbListener = new ShapedChBoxListener(this); + chckbxShapedMap.addActionListener(shapedCbListener); + + ElderChBoxListener elderCbListener = new ElderChBoxListener(this); + chckbxElderMap.addActionListener(elderCbListener); + ExitButtonListener exitListener = new ExitButtonListener(this); btn_exit.addActionListener(exitListener); btn_exit_bulks.addActionListener(exitListener); @@ -908,7 +924,31 @@ public void setTradeables(TradeableBulk tradeables) { this.tradeables = tradeables; } - private void loadMapsFromJson() { + public boolean isLoadedShapedMaps() { + return loadedShapedMaps; + } + + public void setLoadedShapedMaps(boolean loadedShapedMaps) { + this.loadedShapedMaps = loadedShapedMaps; + } + + public boolean isLoadedElderMaps() { + return loadedElderMaps; + } + + public void setLoadedElderMaps(boolean loadedElderMaps) { + this.loadedElderMaps = loadedElderMaps; + } + + public JCheckBox getChckbxShapedMap() { + return chckbxShapedMap; + } + + public void setChckbxShapedMap(JCheckBox chckbxShapedMap) { + this.chckbxShapedMap = chckbxShapedMap; + } + + public void loadMapsFromJson() { String[] allMaps; List allMapsAsList = new ArrayList(); System.out.println("selectedTier " + selectedTier); @@ -935,7 +975,5 @@ private void loadMapsFromJson() { for(int i = 0; i < allMapsAsList.size(); i++) { getCmb_maps_bulks().addItem( allMapsAsList.get(i) ); } - - } } diff --git a/src/main/java/listener/ElderChBoxListener.java b/src/main/java/listener/ElderChBoxListener.java new file mode 100644 index 0000000..837a22b --- /dev/null +++ b/src/main/java/listener/ElderChBoxListener.java @@ -0,0 +1,32 @@ +package listener; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import gui.MainFrame; + +public class ElderChBoxListener implements ActionListener { + + private MainFrame frame; + + public ElderChBoxListener(MainFrame frame) { + this.frame = frame; + + + } + + @Override + public void actionPerformed(ActionEvent e) { + if(frame.isLoadedElderMaps()) { + frame.getChckbxShapedMap().setEnabled(true); + frame.setLoadedShapedMaps(false); + frame.setLoadedElderMaps(false); + } else { + frame.getChckbxShapedMap().setEnabled(false); + frame.setLoadedElderMaps(true); + frame.loadMapsFromJson(); + } + + } + +} diff --git a/src/main/java/listener/ShapedChBoxListener.java b/src/main/java/listener/ShapedChBoxListener.java new file mode 100644 index 0000000..a55d88e --- /dev/null +++ b/src/main/java/listener/ShapedChBoxListener.java @@ -0,0 +1,67 @@ +package listener; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +import org.json.JSONArray; +import org.json.JSONObject; + +import com.stefank.Main; + +import gui.MainFrame; + +public class ShapedChBoxListener implements ActionListener { + + private MainFrame frame; + + public ShapedChBoxListener(MainFrame frame) { + this.frame = frame; + } + + @Override + public void actionPerformed(ActionEvent e) { + if(frame.isLoadedShapedMaps()) { + frame.getChckbxElderMap().setEnabled(true); + frame.setLoadedElderMaps(false); + frame.setLoadedShapedMaps(false); + } else { + frame.getChckbxElderMap().setEnabled(false); + frame.setLoadedShapedMaps(true); + loadMapsFromJson("shapedMaps.json"); + } + } + + private void loadMapsFromJson(String fileName) { + String[] allMaps; + List allMapsAsList = new ArrayList(); + String text = new Scanner(Main.class.getResourceAsStream(fileName)).useDelimiter("\\A").next(); + byte[] bytes; + String mapsAsJsonString = ""; + try { + bytes = text.getBytes("UTF-8"); + mapsAsJsonString = new String(bytes, "UTF-8"); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + JSONObject json = new JSONObject(mapsAsJsonString); + JSONArray maps = json.getJSONArray("maps"); + // convert json array into arraylist + for(int i = 0; i < maps.length(); i++) { + + allMapsAsList.add(maps.get(i).toString()); + } + Collections.sort(allMapsAsList, String.CASE_INSENSITIVE_ORDER); + frame.getCmb_maps_bulks().removeAllItems(); + + for(int i = 0; i < allMapsAsList.size(); i++) { + frame.getCmb_maps_bulks().addItem( allMapsAsList.get(i) ); + } + } + +} diff --git a/src/main/resources/com/stefank/allMaps.json b/src/main/resources/com/stefank/allMaps.json index f8d7c07..dab40f6 100644 --- a/src/main/resources/com/stefank/allMaps.json +++ b/src/main/resources/com/stefank/allMaps.json @@ -4,7 +4,7 @@ "Lookout", "Beach", "Marshes", "Strand", "Whakawairua Tuahu", "Lighthouse", "Spider Lair", "Barrows", "Courtyard", "The Vinktar Square", "Glacier", "Crater", "Alleyways", "Port", "City Square", "Maze", "Mausoleum", "Jungle Valley", "Underground Sea", "Residence", "Gardens", "Vaal Pyramid", "Vaults of Atziri", "Oba's Cursed Trove", "Doryani's Machinarium", "Volcano", "Canyon", "Sulpur Vents", "Haunted Mansion", "Fields", "Phantasmagoria", "Academy", "Wharf", "Ashen Wood", "Temple", "Poorjoy's Asylum", - "Precinct", "Cells", "Arcade", "Conservatory", "Toxic Sewer", "Lava Chamber", "Dunes", "Pillars of Arun", "Underground River", "Caer Blaidd, Wolfspack's Den", "Bazaar", + "Precinct", "Cells", "Arcade", "Conservatory", "Toxic Sewer", "Lava Chamber", "Dunes", "Pillars of Arun", "Underground River", "Bazaar", "Geode", "Primorial Pool", "Ghetto", "Arachnid Nest", "Laboratory", "Infested Valley", "Overgrown Ruin", "Mud Geyser", "Shore", "Mao Kun", "Mineral Pools", "Sepulchre", "Wasteland", "Orchard", "Promenade", "The Hall of the Grandmasters", "Relic Chambers", "Ancient City", "Cemetery", "Hallowed Ground", "Tropical Island", "Moon Temple", "The Twilight Temple", "Waste Pool", "Vault", "Arena", "Museum", "The Putrid Cloister", "Scriptorium", "Waterways", "Leyline", "Coral Ruins", "Plateau", "Estuary", "Belfry", diff --git a/src/main/resources/com/stefank/shapedMaps.json b/src/main/resources/com/stefank/shapedMaps.json new file mode 100644 index 0000000..04e8ed0 --- /dev/null +++ b/src/main/resources/com/stefank/shapedMaps.json @@ -0,0 +1,12 @@ +{ + "maps": [ "Shaped Flooded Mine", "Shaped Channel", "Shaped Atoll", "Shaped Ramparts", + "Shaped Dungeon", "Shaped Pen", "Shaped Arid Lake", "Shaped Iceberg", "Shaped Thicket", "Shaped Armoury", + "Shaped Graveyard", "Shaped Desert", "Shaped Cage", "Shaped Excavation", "Shaped Penisula", "Shaped Grotto", "Shaped Bone Crypt", "Shaped Shipyard", "Shaped Cursed Crypt", "Shaped Fungal Hallow", + "Shaped Lookout", "Shaped Beach", "Shaped Marshes", "Shaped Strand", "Shaped Lighthouse", "Shaped Spider Lair", "Shaped Barrows", "Shaped Courtyard", "Shaped Glacier", "Shaped Crater", + "Shaped Alleyways", "Shaped Port", "Shaped City Square", "Shaped Maze", "Shaped Mausoleum", "Shaped Jungle Valley", "Shaped Underground Sea", "Shaped Residence", "Shaped Gardens", "Shaped Vaal Pyramid", + "Shaped Volcano", "Shaped Canyon", "Shaped Sulpur Vents", "Shaped Haunted Mansion", "Shaped Fields", "Shaped Phantasmagoria", "Shaped Academy", "Shaped Wharf", "Shaped Ashen Wood", "Shaped Temple", "Shaped Precinct", + "Shaped Cells", "Shaped Arcade", "Shaped Conservatory", "Shaped Toxic Sewer", "Shaped Lava Chamber", "Shaped Dunes", "Shaped Underground River", "Shaped Bazaar", "Shaped Geode", "Shaped Primorial Pool", "Shaped Ghetto", + "Shaped Arachnid Nest", "Shaped Laboratory", "Shaped Infested Valley", "Shaped Overgrown Ruin", "Shaped Mud Geyser", "Shaped Shore", "Shaped Mineral Pools", "Shaped Sepulchre", "Shaped Wasteland", "Shaped Orchard", "Shaped Promenade", + "Shaped Relic Chambers", "Shaped Ancient City", "Shaped Cemetery", "Shaped Tropical Island", "Shaped Moon Temple", "Shaped Waste Pool", "Shaped Vault", "Shaped Arena", "Shaped Museum", "Shaped Scriptorium", "Shaped Waterways", + "Shaped Leyline", "Shaped Coral Ruins", "Shaped Plateau", "Shaped Estuary", "Shaped Belfry", "Shaped Pier", "Shaped Spider Forest", "Shaped Coves", "Shaped Pit", "Shaped Plaza"] +} \ No newline at end of file