Skip to content

Commit

Permalink
Merge pull request #10 from StefanKunde/dev
Browse files Browse the repository at this point in the history
Implemented support for shaped maps.
  • Loading branch information
StefanKunde authored Dec 24, 2018
2 parents f972bb4 + 018ceeb commit 42edcb0
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 5 deletions.
46 changes: 42 additions & 4 deletions src/main/java/gui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
import listener.CorruptedCheckBoxListener;
import listener.CurrencyBulksCmbListener;
import listener.CurrencyComboboxListener;
import listener.ElderChBoxListener;
import listener.ExitButtonListener;
import listener.MapCmbBoxBulksListener;
import listener.MapComboboxListener;
import listener.MinimizeButtonListener;
import listener.NextButtonBulksListener;
import listener.NextButtonListener;
import listener.PricePerMapTxtBoxListener;
import listener.ShapedChBoxListener;
import listener.TierComboboxListener;
import listener.UpdateButtonBulksListener;
import listener.UpdateButtonListener;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<String> allMapsAsList = new ArrayList<String>();
System.out.println("selectedTier " + selectedTier);
Expand All @@ -935,7 +975,5 @@ private void loadMapsFromJson() {
for(int i = 0; i < allMapsAsList.size(); i++) {
getCmb_maps_bulks().addItem( allMapsAsList.get(i) );
}


}
}
32 changes: 32 additions & 0 deletions src/main/java/listener/ElderChBoxListener.java
Original file line number Diff line number Diff line change
@@ -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();
}

}

}
67 changes: 67 additions & 0 deletions src/main/java/listener/ShapedChBoxListener.java
Original file line number Diff line number Diff line change
@@ -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<String> allMapsAsList = new ArrayList<String>();
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) );
}
}

}
2 changes: 1 addition & 1 deletion src/main/resources/com/stefank/allMaps.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/com/stefank/shapedMaps.json
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit 42edcb0

Please sign in to comment.