diff --git a/bin/ScenarioEditor/BotEntity.class b/bin/ScenarioEditor/BotEntity.class new file mode 100644 index 0000000..f15e657 Binary files /dev/null and b/bin/ScenarioEditor/BotEntity.class differ diff --git a/bin/ScenarioEditor/BotForce.class b/bin/ScenarioEditor/BotForce.class new file mode 100644 index 0000000..5f712ef Binary files /dev/null and b/bin/ScenarioEditor/BotForce.class differ diff --git a/bin/ScenarioEditor/Mission.class b/bin/ScenarioEditor/Mission.class new file mode 100644 index 0000000..95506f1 Binary files /dev/null and b/bin/ScenarioEditor/Mission.class differ diff --git a/bin/ScenarioEditor/Scenario.class b/bin/ScenarioEditor/Scenario.class new file mode 100644 index 0000000..dc92c53 Binary files /dev/null and b/bin/ScenarioEditor/Scenario.class differ diff --git a/bin/ScenarioEditor/ScenarioEditor.class b/bin/ScenarioEditor/ScenarioEditor.class new file mode 100644 index 0000000..506f61e Binary files /dev/null and b/bin/ScenarioEditor/ScenarioEditor.class differ diff --git a/bin/ScenarioEditor/ScenarioEditorGUI.class b/bin/ScenarioEditor/ScenarioEditorGUI.class new file mode 100644 index 0000000..0676a3d Binary files /dev/null and b/bin/ScenarioEditor/ScenarioEditorGUI.class differ diff --git a/bin/ScenarioEditor/ScenarioPanel$1.class b/bin/ScenarioEditor/ScenarioPanel$1.class new file mode 100644 index 0000000..92c7bfc Binary files /dev/null and b/bin/ScenarioEditor/ScenarioPanel$1.class differ diff --git a/bin/ScenarioEditor/ScenarioPanel$2.class b/bin/ScenarioEditor/ScenarioPanel$2.class new file mode 100644 index 0000000..2eddd70 Binary files /dev/null and b/bin/ScenarioEditor/ScenarioPanel$2.class differ diff --git a/bin/ScenarioEditor/ScenarioPanel.class b/bin/ScenarioEditor/ScenarioPanel.class new file mode 100644 index 0000000..a4fa863 Binary files /dev/null and b/bin/ScenarioEditor/ScenarioPanel.class differ diff --git a/bin/ScenarioEditor/Unit.class b/bin/ScenarioEditor/Unit.class new file mode 100644 index 0000000..d2ab40e Binary files /dev/null and b/bin/ScenarioEditor/Unit.class differ diff --git a/bin/ScenarioEditor/UnitPanel$1.class b/bin/ScenarioEditor/UnitPanel$1.class new file mode 100644 index 0000000..523a634 Binary files /dev/null and b/bin/ScenarioEditor/UnitPanel$1.class differ diff --git a/bin/ScenarioEditor/UnitPanel$2.class b/bin/ScenarioEditor/UnitPanel$2.class new file mode 100644 index 0000000..4c9ba8b Binary files /dev/null and b/bin/ScenarioEditor/UnitPanel$2.class differ diff --git a/bin/ScenarioEditor/UnitPanel.class b/bin/ScenarioEditor/UnitPanel.class new file mode 100644 index 0000000..5525b5a Binary files /dev/null and b/bin/ScenarioEditor/UnitPanel.class differ diff --git a/bin/ScenerioEditor.class b/bin/ScenerioEditor.class deleted file mode 100644 index b054627..0000000 Binary files a/bin/ScenerioEditor.class and /dev/null differ diff --git a/bin/ScenerioEditorGUI.class b/bin/ScenerioEditorGUI.class deleted file mode 100644 index d051d82..0000000 Binary files a/bin/ScenerioEditorGUI.class and /dev/null differ diff --git a/bin/UnitPanel.class b/bin/UnitPanel.class deleted file mode 100644 index d91dd07..0000000 Binary files a/bin/UnitPanel.class and /dev/null differ diff --git a/src/ScenarioEditor/BotEntity.java b/src/ScenarioEditor/BotEntity.java new file mode 100644 index 0000000..894cd22 --- /dev/null +++ b/src/ScenarioEditor/BotEntity.java @@ -0,0 +1,27 @@ +package ScenarioEditor; + +public class BotEntity { + private String id = ""; + private String name = ""; + + + public BotEntity() { + + } + + public void setID(String s) { + id = s; + } + + public String getID() { + return id; + } + + public void setName(String s) { + name = s; + } + + public String getName() { + return name; + } +} diff --git a/src/ScenarioEditor/BotForce.java b/src/ScenarioEditor/BotForce.java new file mode 100644 index 0000000..0c48ed9 --- /dev/null +++ b/src/ScenarioEditor/BotForce.java @@ -0,0 +1,38 @@ +package ScenarioEditor; + +import java.util.Vector; + +public class BotForce { + private Vector botEntities = new Vector(4,2); + private String id = ""; + private String name = ""; + + + /* + * Constructor + */ + public BotForce() { + + } + + public String getID() { + return id; + } + + public void setID(String s) { + id = s; + } + + public void setName(String s) { + name = s; + } + + public String getName() { + return name; + } + + public void addBotEntity(BotEntity be) { + botEntities.add(be); + } + +} diff --git a/src/ScenarioEditor/Mission.java b/src/ScenarioEditor/Mission.java new file mode 100644 index 0000000..9c55de5 --- /dev/null +++ b/src/ScenarioEditor/Mission.java @@ -0,0 +1,138 @@ +package ScenarioEditor; + +import java.util.Iterator; +import java.util.Vector; + +public class Mission { + + private String cnt = ""; + private String missionID = ""; + + private String missionName = ""; + private String missionType = ""; + private String missionPlanetID = ""; + private String missionStatus = ""; + private String missionDesc = ""; + private String missionTypeDesc = ""; + private Vector scenarios = null; + + public Mission() { + scenarios = new Vector(4,2); + } + + public String toString() { + String s = ""; + s = "Cnt : " + cnt +"\r\n"; + s += "Mission ID : " + missionID + "\r\n"; + s += "Mission Name : " + missionName + "\r\n"; + s += "Mission Type : " + missionType + "\r\n"; + s += "Planet ID : " + missionPlanetID + "\r\n"; + s += "Status : " + missionStatus + "\r\n"; + s += "Description : " + missionDesc + "\r\n"; + s += "Mission Type Desc: " + missionTypeDesc + "\r\n"; + + return s; + } + public String getCnt() { + return cnt; + } + + public void setCnt(String c) { + cnt = c; + } + + public String getMissionID() { + return missionID; + } + + public void setMissionID(String s) { + missionID = s; + } + + public void setMissionName(String s) { + missionName = s; + } + + public String getMissionName() { + return missionName; + } + public void setMissionType(String s) { + missionType = s; + } + + public String getMissionType() { + return missionType; + } + + public void setPlanetID(String s) { + missionPlanetID = s; + } + + public String getPlanetID() { + return missionPlanetID; + } + + public void setMissionStatus(String s) { + missionStatus = s; + } + + public String getMissionStatus() { + return missionStatus; + } + + public void setMissionDesc(String s) { + missionDesc = s; + } + + public String getMissionDesc() { + return missionDesc; + } + + public void setMissionTypeDesc(String s) { + missionTypeDesc = s; + } + + public String getMissionTypeDesc() { + return missionTypeDesc; + } + + public void addScenario(Scenario s) { + scenarios.add(s); + } + + /* + * get Scenario by ID / cnt + */ + public Scenario getScenarioByCnt(String s) { + Scenario ul= null; + Iterator itr = scenarios.iterator(); + do{ + ul = itr.next(); + }while(!s.equals(ul.getCnt())); + return ul; + } + + /* + * helper method to replace a Scenario object + * once it has been updated or modified in + * some way + */ + public void replaceScenario(Scenario u) { + Scenario ul= null; + int cnt = 0; + try { + Iterator itr = scenarios.iterator(); + while(itr.hasNext()) { + ul = itr.next(); + if(u.getCnt().equals(ul.getCnt())) { + scenarios.set(cnt, u); + } + cnt++; + } + }catch(Exception e) { + System.err.println("Inside ReplaceScenario :" +e.toString()); + } + + } + +} diff --git a/src/ScenarioEditor/Scenario.java b/src/ScenarioEditor/Scenario.java new file mode 100644 index 0000000..2523737 --- /dev/null +++ b/src/ScenarioEditor/Scenario.java @@ -0,0 +1,235 @@ +package ScenarioEditor; + +import java.util.Vector; + +public class Scenario { + private String cnt = ""; + private String type = ""; + private String name = ""; + private String desc = ""; + private String report = ""; + private String status = ""; + private String id = ""; + private String date = ""; + private String attackers = ""; + private String lanceForceId = ""; + private String lanceRole = ""; + private String terrainType = ""; + private String light = ""; + private String weather = ""; + private String wind = ""; + private String fog = ""; + private String atmosphere = ""; + private String gravity = ""; + private String start = ""; + private String deploymentDelay = ""; + private String mapSize = ""; + private String map = ""; + private String lanceCount = ""; + private String rerollsRemaining = ""; + private Vector botForce = new Vector(4,2); + + /* + * Constructor + */ + public Scenario() { + + } + + public void setCnt(String s) { + cnt = s; + } + + public String getCnt() { + return cnt; + } + + public void setType(String s) { + type = s; + } + + public String getType() { + return type; + } + + public void setName(String s) { + name = s; + } + + public String getName() { + return name; + } + + public void setDesc(String s) { + desc = s; + } + + public String getDesc() { + return desc; + } + + public void setReport(String s) { + report = s; + } + + public String getReport() { + return report; + } + + public void setStatus(String s) { + status = s; + } + + public String getStatus() { + return status; + } + + public void setID(String s) { + id = s; + } + + public String getID() { + return id; + } + + public void setDate(String s) { + date = s; + } + + public String getDate() { + return date; + } + + public void setAttackers(String s) { + attackers = s; + } + + public String getAttackers() { + return attackers; + } + + public void setLanceForceId(String s) { + lanceForceId = s; + } + + public String getLanceForceId() { + return lanceForceId; + } + + public void setLanceRole(String s) { + lanceRole = s; + } + + public String getLanceRole() { + return lanceRole; + } + + public void setTerrainType(String s) { + terrainType = s; + } + + public String getTerrainType() { + return terrainType; + } + + public void setLight(String s) { + light = s; + } + + public String getLight() { + return light; + } + + public void setWeather(String s) { + weather = s; + } + + public String getWeather() { + return weather; + } + + public void setWind(String s) { + wind = s; + } + + public String getWind() { + return wind; + } + + public void setFog(String s) { + fog = s; + } + + public String getFog() { + return fog; + } + + public void setAtmosphere(String s) { + atmosphere = s; + } + + public String getAtmosphere() { + return atmosphere; + } + + public void setGravity(String s) { + gravity = s; + } + + public String getGravity() { + return gravity; + } + + public void setStart(String s) { + start = s; + } + + public String getStart() { + return start; + } + + public void setDeploymentDelay(String s) { + deploymentDelay = s; + } + + public String getDeploymentDelay() { + return deploymentDelay; + } + + public void setMapSize(String s) { + mapSize = s; + } + + public String getMapSize() { + return mapSize; + } + + public void setMap(String s) { + map = s; + } + + public String getMap() { + return map; + } + + public void setLanceCount(String s) { + lanceCount = s; + } + + public String getLanceCount() { + return lanceCount; + } + + public void setRerollsRemaining(String s) { + rerollsRemaining = s; + } + + public String getRerollsRemaining() { + return rerollsRemaining; + } + + public void addBotForce(BotForce b) { + botForce.add(b); + } + +} diff --git a/src/ScenarioEditor/ScenarioEditor.java b/src/ScenarioEditor/ScenarioEditor.java new file mode 100644 index 0000000..2cb8cda --- /dev/null +++ b/src/ScenarioEditor/ScenarioEditor.java @@ -0,0 +1,600 @@ +package ScenarioEditor; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +//import javax.xml.parsers.*; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.NamedNodeMap; +import mekhq.Version; +import java.lang.Integer; +import java.util.Iterator; + +import mekhq.campaign.mission.atb.scenario.*; +import mekhq.campaign.mission.AtBScenario; +import mekhq.campaign.mission.atb.AtBScenarioFactory; +//import mekhq.campaign.mission.Scenario; +//import mekhq.campaign.Campaign; +//import megamek.MegaMek; +//import megameklab.com.*; +//import java.io.FileInputStream; +import java.util.UUID; +import java.io.*; +import javax.swing.*; +//import java.math.*; +import java.util.Vector; +import java.util.Collection; +import java.util.Map; +import java.util.HashMap; +import javax.swing.JFileChooser; +import java.util.NoSuchElementException; + +public class ScenarioEditor { + ScenarioEditorGUI mFrame = null; + Version version = null; + private Vector units = new Vector(10,2); + private Vector missions = new Vector(4,2); + private Vector scenarios = new Vector(4,2); + private Vector ScenarioNames = new Vector(4,2); + + /* + * Scenario Editor Constructor + */ + public ScenarioEditor() { + // value returned by FileChooser + int returnVal = 0; + try { + listOfScenarios(); + + mFrame = new ScenarioEditorGUI("Scenario Editor", this); + mFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + + + JFileChooser jfc = new JFileChooser(); + returnVal = jfc.showOpenDialog(mFrame); + if(returnVal == 1) { + System.err.println(returnVal); + } + + String sfn = jfc.getCurrentDirectory() + "\\" + jfc.getSelectedFile().getName(); + Document doc = dBuilder.parse(new File(sfn)); +// Document doc = dBuilder.parse(new File("C:\\MekHQ\\campaigns\\Solo\\Solo30270514.cpnx")); + + Element campaignEle = doc.getDocumentElement(); + NodeList nl = campaignEle.getChildNodes(); + campaignEle.normalize(); + version = new Version(campaignEle.getAttribute("version")); + System.out.println(campaignEle.getAttribute("version")); + + + // Step through the file to get + for (int x = 0; x < nl.getLength(); x++) { + Node wn = nl.item(x); + + if (wn.getParentNode() != campaignEle) { + continue; + } + int xc = wn.getNodeType(); + + if (xc == Node.ELEMENT_NODE) { + // This is what we really care about. + // All the meat of our document is in this node type, at this + // level. + // Okay, so what element is it? + String xn = wn.getNodeName(); + + if (xn.equalsIgnoreCase("units")) { + processUnitNodes( wn); + } + if (xn.equalsIgnoreCase("parts")) { + processPartNodes(wn); + } + if (xn.equalsIgnoreCase("missions")) { + processMissionNodes(wn); + } + } + System.out.println("."); + } + } catch (Exception e) { + /*err handling*/ + System.err.println(e.toString()); + } + if(returnVal == 0) { + mFrame.getUnitPanel().LoadUnit(getUnitByCnt("1")); + mFrame.getScenarioPanel().loadScenario(getScenarioByID(Integer.toString(getMinimumScenarioID()))); + } + } + + public Vector getScenarioNames() { + return ScenarioNames; + } + private void listOfScenarios() { + ScenarioNames.add(new String[] { "AceDuel", "mekhq.campaign.mission.atb.scenario.AceDuelBuiltInScenario"}); + + ScenarioNames.add(new String[] { "AlliedTraitors", "mekhq.campaign.mission.atb.scenario.AlliedTraitorsBuiltInScenario"}); + + ScenarioNames.add(new String[] { "AllyRescue", "mekhq.campaign.mission.atb.scenario.AllyRescueBuiltInScenario"}); + + ScenarioNames.add(new String[] { "Ambush", "mekhq.campaign.mission.atb.scenario.AmbushBuiltInScenario"}); + + ScenarioNames.add(new String[] { "BaseAttack", "mekhq.campaign.mission.atb.scenario.BaseAttackBuiltInScenario"}); + + ScenarioNames.add(new String[] { "Breakthrough", "mekhq.campaign.mission.atb.scenario.BreakthroughBuiltInScenario"}); + + ScenarioNames.add(new String[] { "Chase", "mekhq.campaign.mission.atb.scenario.ChaseBuiltInScenario"}); + + ScenarioNames.add(new String[] { "CivilianHelp","mekhq.campaign.mission.atb.scenario.CivilianHelpBuiltInScenario"}); + + ScenarioNames.add(new String[] { "CivilianRiot", "mekhq.campaign.mission.atb.scenario.CivilianRiotBuiltInScenario"}); + + ScenarioNames.add(new String[] { "ConvoyAttack", "mekhq.campaign.mission.atb.scenario.ConvoyAttackBuiltInScenario"}); + + ScenarioNames.add(new String[] { "Extraction", "mekhq.campaign.mission.atb.scenario.ExtractionBuiltInScenario"}); + + ScenarioNames.add(new String[] { "HideAndSeek", "mekhq.campaign.mission.atb.scenario.HideAndSeekBuiltInScenario"}); + + ScenarioNames.add(new String[] { "HoldTheLine", "mekhq.campaign.mission.atb.scenario.HoldTheLineBuiltInScenario"}); + + ScenarioNames.add(new String[] { "OfficerDual", "mekhq.campaign.mission.atb.scenario.OfficerDualBuiltInScenario"}); + + ScenarioNames.add(new String[] { "PirateFreeForAll", "mekhq.campaign.mission.atb.scenario.PirateFreeForAllBuiltInScenario"}); + + ScenarioNames.add(new String[] { "PrisonBreak", "mekhq.campaign.mission.atb.scenario.PrisonBreakBuiltInScenario"}); + + ScenarioNames.add(new String[] { "Probe", "mekhq.campaign.mission.atb.scenario.ProbeBuiltInScenario"}); + + ScenarioNames.add(new String[] { "ReconRaid", "mekhq.campaign.mission.atb.scenario.ReconRaidBuiltInScenario"}); + + ScenarioNames.add(new String[] { "StandUp", "mekhq.campaign.mission.atb.scenario.StandUpBuiltInScenario"}); + + ScenarioNames.add(new String[] { "StarLeagueCache1", "mekhq.campaign.mission.atb.scenario.StarLeagueCache1BuiltInScenario"}); + + ScenarioNames.add(new String[] { "StarLeagueCache2", "mekhq.campaign.mission.atb.scenario.StarLeagueCache2BuiltInScenario"}); + } + + + /* + * Process the Mission nodes in the campaign file + */ + private void processMissionNodes(Node wn){ + NodeList wList = wn.getChildNodes(); + + // iterate through the children, + for (int x = 0; x < wList.getLength(); x++) { + Node wn2 = wList.item(x); + + // If it's not an element node, we ignore it. + if (wn2.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + + if (!wn2.getNodeName().equalsIgnoreCase("mission")) { + continue; + } + Mission m = new Mission(); + + NamedNodeMap attrs = wn2.getAttributes(); + // Mission ID + Node idNode = attrs.getNamedItem("id"); + m.setCnt(idNode.getTextContent()); + // Mission Type + idNode = attrs.getNamedItem("type"); + m.setMissionType(idNode.getTextContent()); + + // Okay, now load scenario specific fields + NodeList nl = wn2.getChildNodes(); + + try { + for (int y=0; y itr = units.iterator(); + do{ + ul = itr.next(); + }while(!s.equals(ul.getCnt())); + }catch(NoSuchElementException nsee) { + return new Unit(); + }catch(Exception e) { + + } + return ul; + } + + /* + * get unit object from vector by unique ID + */ + public Unit getUnitByUnitID(String s) { + Unit ul= null; + Iterator itr = units.iterator(); + do{ + ul = itr.next(); + }while(!s.equals(ul.getUnitID())); + return ul; + } + + /* + * helper method to replace a unit object + * once it has been updated or modified in + * some way + */ + public void replaceUnit(Unit u) { + Unit ul= null; + int cnt = 0; + try { + Iterator itr = units.iterator(); + while(itr.hasNext()) { + ul = itr.next(); + if(u.getCnt().equals(ul.getCnt())) { + units.set(cnt, u); + } + cnt++; + } + }catch(Exception e) { + System.err.println("Inside ReplaceUnit :" +e.toString()); + } + + } + + /* + * get size of Units + */ + public int getUnitsSize() { + return units.size(); + } + + /* + * get scenario object by id + */ + public Scenario getScenarioByID(String s) { + Scenario ss = null; + try { + Iterator itr = scenarios.iterator(); + do { + ss = itr.next(); + }while(!s.equals(ss.getCnt())); + }catch(NoSuchElementException nsee) { + return new Scenario(); + }catch(Exception e) { + + } + return ss; + } + + /* + * get scenario object by id + */ + public int getScenarioSize() { + return scenarios.size(); + } + + /* + * get minimum ID of scenerio in scenerios + */ + public int getMinimumScenarioID() { + int i = 1000; + int v = 0; + try { + Scenario ss = null; + Iterator itr = scenarios.iterator(); + do { + ss = itr.next(); + v = new Integer(ss.getCnt()).intValue(); + if(i > v) { + i = v; + } + }while(itr.hasNext()); + }catch(NoSuchElementException nsee) { + return i; + }catch (Exception e) { + + } + return i; + } + + /* + * get maximum ID of scenerio in scenerios + */ + public int getMaximumScenarioID() { + int i = 0; + int v = 0; + Scenario ss = null; + Iterator itr = scenarios.iterator(); + do { + ss = itr.next(); + v = new Integer(ss.getCnt()).intValue(); + if(i < v) { + i = v; + } + }while(itr.hasNext()); + return i; + } + + + + public static void main(String[] args){ + ScenarioEditor s = new ScenarioEditor(); + } + + +} diff --git a/src/ScenarioEditor/ScenarioEditorGUI.java b/src/ScenarioEditor/ScenarioEditorGUI.java new file mode 100644 index 0000000..de5f299 --- /dev/null +++ b/src/ScenarioEditor/ScenarioEditorGUI.java @@ -0,0 +1,47 @@ +package ScenarioEditor; +import javax.swing.*; +import java.awt.*; + +public class ScenarioEditorGUI extends JFrame{ + private UnitPanel up = null; + private ScenarioPanel sp = null; + private ScenarioEditor SE = null; + private JTabbedPane JTP = null; + + public ScenarioEditorGUI(String s, ScenarioEditor se) { + super(s); + this.setLayout(new BorderLayout()); + this.setSize(640, 480); + JTP = new JTabbedPane(); + SE = se; + + //add tabbed Pane to Frame + this.add(JTP,BorderLayout.CENTER); + + //Create Unit Tab add to Tabbed Pane + up = new UnitPanel(this); + JTP.addTab("Units", up); + + //Create the Scenario Panel add to tabbed pane + sp = new ScenarioPanel(this); + JScrollPane jsp = new JScrollPane(sp); + JTP.addTab("Scenarios", jsp); + + + this.setVisible(true); + this.validate(); + up.setUID("TEST"); + } + + public UnitPanel getUnitPanel() { + return up; + } + + public ScenarioPanel getScenarioPanel() { + return sp; + } + + public ScenarioEditor getScenarioEditor() { + return SE; + } +} diff --git a/src/ScenarioEditor/ScenarioPanel.java b/src/ScenarioEditor/ScenarioPanel.java new file mode 100644 index 0000000..b8dda94 --- /dev/null +++ b/src/ScenarioEditor/ScenarioPanel.java @@ -0,0 +1,482 @@ +package ScenarioEditor; + +import java.awt.Color; +import javax.swing.JComboBox; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.JTextArea; +import javax.swing.BoxLayout; +import javax.swing.JScrollPane; + +public class ScenarioPanel extends JPanel{ + private ScenarioEditorGUI SEG = null; + private JTextField id = null; +// private JTextField type = null; + private JTextField name = null; + private JTextField desc = null; + private JTextField status = null; + private JTextField date = null; + private JTextField attacker = null; + private JTextField lanceForceId = null; + private JTextField lanceRole = null; + private JTextField terrainType = null; + private JTextField light = null; + private JTextField weather = null; + private JTextField wind = null; + private JTextField fog = null; + private JTextField atmosphere = null; + private JTextField gravity = null; + private JTextField start = null; + private JTextField deploymentDelay = null; + private JTextField mapSize = null; + private JTextField map = null; + private JTextField lanceCount = null; + private JTextField rerollsRemaining = null; + private JTextArea botForceStub = null; + private JComboBox type = null; + private Vectorsn = new Vector(); + + + + + public ScenarioPanel(ScenarioEditorGUI seg) { + super(); + SEG = seg; + sn = (SEG.getScenarioEditor()).getScenarioNames(); + JButton n = new JButton("Next"); + JButton p = new JButton("Prev"); + + this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + + // build all the elements + id = new JTextField(10); + type = buildType(); + name = new JTextField(10); + desc = new JTextField(10); + status = new JTextField(10); + date = new JTextField(10); + attacker = new JTextField(10); + lanceForceId = new JTextField(10); + lanceRole = new JTextField(10); + terrainType = new JTextField(10); + light = new JTextField(10); + weather = new JTextField(10); + wind = new JTextField(10); + fog = new JTextField(10); + atmosphere = new JTextField(10); + gravity = new JTextField(10); + start = new JTextField(10); + deploymentDelay = new JTextField(10); + mapSize = new JTextField(10); + map = new JTextField(10); + lanceCount = new JTextField(10); + rerollsRemaining = new JTextField(10); + botForceStub = new JTextArea(5,30); + + JScrollPane jsp = new JScrollPane(botForceStub); + + /* + * Build all the JPanels for the display of + * the Scenario + */ + + //ID + JPanel jp0 = new JPanel(); + jp0.setLayout(new GridLayout(0,2)); + jp0.add(new JLabel("ID")); + id.setEnabled(false); + id.setDisabledTextColor(Color.black); + jp0.add(id); + + //type + JPanel jp1 = new JPanel(); + jp1.setLayout(new GridLayout(0,2)); + jp1.add(new JLabel("Type")); + //type.setEnabled(false); + //type.setDisabledTextColor(Color.black); + jp1.add(type); + + //name + JPanel jp2 = new JPanel(); + jp2.setLayout(new GridLayout(0,2)); + jp2.add(new JLabel("Name")); + name.setEnabled(false); + name.setDisabledTextColor(Color.black); + jp2.add(name); + + //desc + JPanel jp3 = new JPanel(); + jp3.setLayout(new GridLayout(0,2)); + jp3.add(new JLabel("Desc")); + desc.setEnabled(false); + desc.setDisabledTextColor(Color.black); + jp3.add(desc); + + //status + JPanel jp4 = new JPanel(); + jp4.setLayout(new GridLayout(0,2)); + jp4.add(new JLabel("Status")); + status.setEnabled(false); + status.setDisabledTextColor(Color.black); + jp4.add(status); + + //date + JPanel jp5 = new JPanel(); + jp5.setLayout(new GridLayout(0,2)); + jp5.add(new JLabel("Date")); + date.setEnabled(false); + date.setDisabledTextColor(Color.black); + jp5.add(date); + + //attacker + JPanel jp6 = new JPanel(); + jp6.setLayout(new GridLayout(0,2)); + jp6.add(new JLabel("Attacker")); + attacker.setEnabled(false); + attacker.setDisabledTextColor(Color.black); + jp6.add(attacker); + + //lanceForceId + JPanel jp7 = new JPanel(); + jp7.setLayout(new GridLayout(0,2)); + jp7.add(new JLabel("lanceForceId")); + lanceForceId.setEnabled(false); + lanceForceId.setDisabledTextColor(Color.black); + jp7.add(lanceForceId); + + //lanceRole + JPanel jp8 = new JPanel(); + jp8.setLayout(new GridLayout(0,2)); + jp8.add(new JLabel("lanceRole")); + lanceRole.setEnabled(false); + lanceRole.setDisabledTextColor(Color.black); + jp8.add(lanceRole); + + //terrainType + JPanel jp9 = new JPanel(); + jp9.setLayout(new GridLayout(0,2)); + jp9.add(new JLabel("terrainType")); + terrainType.setEnabled(false); + terrainType.setDisabledTextColor(Color.black); + jp9.add(terrainType); + + //light + JPanel jp10 = new JPanel(); + jp10.setLayout(new GridLayout(0,2)); + jp10.add(new JLabel("light")); + light.setEnabled(false); + light.setDisabledTextColor(Color.black); + jp10.add(light); + + //weather + JPanel jp11 = new JPanel(); + jp11.setLayout(new GridLayout(0,2)); + jp11.add(new JLabel("Weather")); + weather.setEnabled(false); + weather.setDisabledTextColor(Color.black); + jp11.add(weather); + + //wind + JPanel jp12 = new JPanel(); + jp12.setLayout(new GridLayout(0,2)); + jp12.add(new JLabel("Wind")); + wind.setEnabled(false); + wind.setDisabledTextColor(Color.black); + jp12.add(wind); + + //fog + JPanel jp13 = new JPanel(); + jp13.setLayout(new GridLayout(0,2)); + jp13.add(new JLabel("Fog")); + fog.setEnabled(false); + fog.setDisabledTextColor(Color.black); + jp13.add(fog); + + //atmosphere + JPanel jp14 = new JPanel(); + jp14.setLayout(new GridLayout(0,2)); + jp14.add(new JLabel("Atmosphere")); + atmosphere.setEnabled(false); + atmosphere.setDisabledTextColor(Color.black); + jp14.add(atmosphere); + + //gravity + JPanel jp15 = new JPanel(); + jp15.setLayout(new GridLayout(0,2)); + jp15.add(new JLabel("Gravity")); + gravity.setEnabled(false); + gravity.setDisabledTextColor(Color.black); + jp15.add(gravity); + + //start + JPanel jp16 = new JPanel(); + jp16.setLayout(new GridLayout(0,2)); + jp16.add(new JLabel("Start")); + start.setEnabled(false); + start.setDisabledTextColor(Color.black); + jp16.add(start); + + //deploymentDelay + JPanel jp17 = new JPanel(); + jp17.setLayout(new GridLayout(0,2)); + jp17.add(new JLabel("deploymentDelay")); + deploymentDelay.setEnabled(false); + deploymentDelay.setDisabledTextColor(Color.black); + jp17.add(deploymentDelay); + + + //mapSize + JPanel jp18 = new JPanel(); + jp18.setLayout(new GridLayout(0,2)); + jp18.add(new JLabel("mapSize")); + mapSize.setEnabled(false); + mapSize.setDisabledTextColor(Color.black); + jp18.add(mapSize); + + //map + JPanel jp19 = new JPanel(); + jp19.setLayout(new GridLayout(0,2)); + jp19.add(new JLabel("map")); + map.setEnabled(false); + map.setDisabledTextColor(Color.black); + jp19.add(map); + + //lanceCount + JPanel jp20 = new JPanel(); + jp20.setLayout(new GridLayout(0,2)); + jp20.add(new JLabel("lanceCount")); + lanceCount.setEnabled(false); + lanceCount.setDisabledTextColor(Color.black); + jp20.add(lanceCount); + + //rerollsRemaining + JPanel jp21 = new JPanel(); + jp21.setLayout(new GridLayout(0,2)); + jp21.add(new JLabel("rerollsRemaining")); + rerollsRemaining.setEnabled(false); + rerollsRemaining.setDisabledTextColor(Color.black); + jp21.add(rerollsRemaining); + + //botForceStub JScrollPane + JPanel jp22 = new JPanel(); + jp22.setLayout(new GridLayout(0,2)); + jp22.add(new JLabel("BotForceStub")); + botForceStub.setEnabled(false); + botForceStub.setDisabledTextColor(Color.black); + jp22.add(jsp); + + //Button Panel + JPanel jp23 = new JPanel(); + jp23.setLayout(new GridLayout(0,2)); + jp23.add(p); + jp23.add(n); + + + /* + * Add all the Panels to the Display + */ + this.add(jp0); + this.add(jp1); + this.add(jp2); + this.add(jp3); + this.add(jp4); + this.add(jp5); + this.add(jp6); + this.add(jp7); + this.add(jp8); + this.add(jp9); + this.add(jp10); + this.add(jp11); + this.add(jp12); + this.add(jp13); + this.add(jp14); + this.add(jp15); + this.add(jp16); + this.add(jp17); + this.add(jp18); + this.add(jp19); + this.add(jp20); + this.add(jp21); + this.add(jp22); + this.add(jp23); + + this.setVisible(true); + /* + * Add the Action listeners for the buttons + */ + n.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent arg0) { + int x = new Integer(id.getText()).intValue() + 1; + if (x > SEG.getScenarioEditor().getMaximumScenarioID()) { + x = 1; + } + SEG.getScenarioPanel().loadScenario(SEG.getScenarioEditor().getScenarioByID(Integer.toString(x))); + } + }); + + p.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent arg0) { + int x = new Integer(id.getText()).intValue() - 1; + if (x < 1 ) { + x = SEG.getScenarioEditor().getMaximumScenarioID(); + } + SEG.getScenarioPanel().loadScenario(SEG.getScenarioEditor().getScenarioByID(Integer.toString(x))); + } + }); + + } + + public void setId(String s) { + id.setText(s); + } + + public void setType(String s) { + type.setSelectedItem(s); + } + + public void setNName(String s) { + name.setText(s); + } + + public void setDesc(String s) { + desc.setText(s); + } + + public void setStatus(String s) { + status.setText(s); + } + + public void setDate(String s) { + date.setText(s); + } + + public void setAttacker(String s) { + attacker.setText(s); + } + + public void setLanceForceId(String s) { + lanceForceId.setText(s); + } + + public void setLanceRole(String s) { + lanceRole.setText(s); + } + + public void setTerrainType(String s) { + terrainType.setText(s); + } + + public void setLight(String s) { + light.setText(s); + } + + public void setWeather(String s) { + weather.setText(s); + } + + public void setWind(String s) { + wind.setText(s); + } + + public void setFog(String s) { + fog.setText(s); + } + + public void setAtmosphere(String s) { + atmosphere.setText(s); + } + + public void setGravity(String s) { + gravity.setText(s); + } + + public void setStart(String s) { + start.setText(s); + } + + public void setDeploymentDelay(String s) { + deploymentDelay.setText(s); + } + + public void setMapSize(String s) { + mapSize.setText(s); + } + + public void setMap(String s) { + map.setText(s); + } + + public void setLanceCount(String s) { + lanceCount.setText(s); + } + + public void setRerollsRemaining(String s) { + rerollsRemaining.setText(s); + } + + public void setBotForceStub(String s) { + botForceStub.append(s); + } + + public void clearBotForceStub() { + botForceStub.setText(""); + } + + private JComboBox buildType() { + JComboBox jcb = new JComboBox(); + Iterator i = sn.iterator(); + while(i.hasNext()) { + String[] s = (String[])i.next(); + jcb.addItem(s[1]); + } + return jcb; + } + + public void loadScenario(Scenario s) { + id.setText(s.getID()); + type.setSelectedItem(s.getType()); + name.setText(s.getName()); + desc.setText(s.getDesc()); + status.setText(s.getStatus()); + date.setText(s.getDate()); + attacker.setText(s.getAttackers()); + lanceForceId.setText(s.getLanceForceId()); + lanceRole.setText(s.getLanceRole()); + terrainType.setText(s.getTerrainType()); + light.setText(s.getLight()); + weather.setText(s.getWeather()); + wind.setText(s.getWind()); + fog.setText(s.getFog()); + atmosphere.setText(s.getAtmosphere()); + gravity.setText(s.getGravity()); + start.setText(s.getStart()); + deploymentDelay.setText(s.getDeploymentDelay()); + mapSize.setText(s.getMapSize()); + map.setText(s.getMap()); + lanceCount.setText(s.getLanceCount()); + rerollsRemaining.setText(s.getRerollsRemaining()); + } + + + + public ScenarioEditorGUI getScenarioEditorGUI() { + return SEG; + } + + +} diff --git a/src/ScenarioEditor/Unit.java b/src/ScenarioEditor/Unit.java new file mode 100644 index 0000000..17d8ab1 --- /dev/null +++ b/src/ScenarioEditor/Unit.java @@ -0,0 +1,76 @@ +package ScenarioEditor; + + + +public class Unit { + private String unitID = ""; + private String chassisType = ""; + private String model = ""; + private String mType = ""; + private String unitCommander = ""; + private String cnt = ""; + private String Weapons = ""; + + public Unit() { + + } + + public void setUnitID(String s) { + unitID = s; + } + + public String getUnitID() { + return unitID; + } + + public void setChassisType(String s) { + chassisType = s; + } + + public String getChassisType() { + return chassisType; + } + + public void setModel(String s) { + model = s; + } + + public String getModel() { + return model; + } + + public void setMType(String s) { + mType = s; + } + + public String getMType() { + return mType; + } + + public void setUnitCommander(String s) { + unitCommander = s; + } + + public String getUnitCommander() { + return unitCommander; + } + + public void setCnt(String s) { + cnt = s; + } + + public String getCnt() { + return cnt; + } + + public void setWeapons(String s) { + Weapons = Weapons + s+ "\r\n"; + } + + + public String getWeapons() { + return Weapons; + } + + +} diff --git a/src/ScenarioEditor/UnitPanel.java b/src/ScenarioEditor/UnitPanel.java new file mode 100644 index 0000000..0ac6a9f --- /dev/null +++ b/src/ScenarioEditor/UnitPanel.java @@ -0,0 +1,189 @@ +package ScenarioEditor; +import javax.swing.*; +import javax.swing.border.EtchedBorder; +//import java.awt.Event; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.*; + +public class UnitPanel extends JPanel { + private JTextField uID = null; + private JTextField chassisType = null; + private JTextField model = null; + private JTextField mType = null; + private JTextField unitCommander = null; + private JTextField cnt = null; + private JTextArea Weapons = null; + private ScenarioEditorGUI SEG = null; + + public UnitPanel(ScenarioEditorGUI seg) { + super(); + SEG = seg; + JButton j = new JButton("Next"); + JButton p = new JButton("Prev"); + + + this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + + //accessable textfields + cnt = new JTextField(10); + uID = new JTextField(10); + chassisType = new JTextField(10); + model = new JTextField(10); + mType = new JTextField(10); + unitCommander = new JTextField(10); + Weapons = new JTextArea(4,40); + JScrollPane jsp = new JScrollPane(Weapons); + + //Weapons Panel + JPanel jpw = new JPanel(); + jpw.setLayout(new GridLayout(0,2)); + jpw.add(new JLabel("Weapons")); + Weapons.setEnabled(false); + Weapons.setDisabledTextColor(Color.black); + jpw.add(jsp); + + + //Counter + JPanel jp0 = new JPanel(); + jp0.setLayout(new GridLayout(0,2)); + jp0.add(new JLabel("Count")); + cnt.setEnabled(false); + cnt.setDisabledTextColor(Color.black); + jp0.add(cnt); + + // unit ID + JPanel jp = new JPanel(); + jp.setLayout(new GridLayout(0,2)); + jp.add(new JLabel("Unit ID")); + uID.setEnabled(false); + uID.setDisabledTextColor(Color.black); + jp.add(uID); + + // Chassis Type + JPanel jp1 = new JPanel(); + jp1.setLayout(new GridLayout(0,2)); + jp1.add(new JLabel("Chassis Type")); + chassisType.setEnabled(false); + chassisType.setDisabledTextColor(Color.black); + jp1.add(chassisType); + + //Model + JPanel jp2 = new JPanel(); + jp2.setLayout(new GridLayout(0,2)); + jp2.add(new JLabel("Model")); + model.setEnabled(false); + model.setDisabledTextColor(Color.black); + jp2.add(model); + + //Mech type + JPanel jp3 = new JPanel(); + jp3.setLayout(new GridLayout(0,2)); + jp3.add(new JLabel("Type")); + mType.setEnabled(false); + mType.setDisabledTextColor(Color.black); + jp3.add(mType); + + //unitCommander + JPanel jp4 = new JPanel(); + jp4.setLayout(new GridLayout(0,2)); + jp4.add(new JLabel("Unit Commander")); + unitCommander.setEnabled(false); + unitCommander.setDisabledTextColor(Color.black); + jp4.add(unitCommander); + + + //Buttons + JPanel jpb = new JPanel(); + jpb.setLayout(new GridLayout(0,2)); + jpb.add(p); + jpb.add(j); + + // add the Jpanels + this.add(jp0); + this.add(jp); + this.add(jp1); + this.add(jp2); + this.add(jp3); + this.add(jp4); + this.add(jpw); + this.add(jpb); + + this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED )); + this.setVisible(true); + + /* + * Add the Action listeners for the buttons + */ + j.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent arg0) { + int x = new Integer(cnt.getText()).intValue() + 1; + if (x > SEG.getScenarioEditor().getUnitsSize()) { + x = 1; + } + SEG.getUnitPanel().LoadUnit(SEG.getScenarioEditor().getUnitByCnt(Integer.toString(x))); + } + }); + + p.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent arg0) { + int x = new Integer(cnt.getText()).intValue() - 1; + if (x < 1 ) { + x = SEG.getScenarioEditor().getUnitsSize(); + } + SEG.getUnitPanel().LoadUnit(SEG.getScenarioEditor().getUnitByCnt(Integer.toString(x))); + } + }); + } + + public void setUID(String s) { + uID.setText(s); + } + + public void setChassisType(String s) { + chassisType.setText(s); + } + + public void setModel(String s) { + model.setText(s); + } + + public void setMType(String s) { + mType.setText(s); + } + + public void setunitCommander(String s) { + unitCommander.setText(s); + } + + public void setCounter(String s) { + cnt.setText(s); + } + + public void addWeapon(String s) { + Weapons.append(s+"\r\n"); + } + + public void LoadUnit(Unit u) { + cnt.setText(u.getCnt()); + uID.setText(u.getUnitID()); + chassisType.setText(u.getChassisType()); + model.setText(u.getModel()); + mType.setText(u.getMType()); + unitCommander.setText(u.getUnitCommander()); + clearWeapons(); + Weapons.append(u.getWeapons()); + } + + public void clearWeapons() { + Weapons.setText(""); + } + + public ScenarioEditorGUI getScenarioEditorGUI() { + return SEG; + } +} diff --git a/src/ScenerioEditor.java b/src/ScenerioEditor.java deleted file mode 100644 index 991931f..0000000 --- a/src/ScenerioEditor.java +++ /dev/null @@ -1,232 +0,0 @@ -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.*; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.NamedNodeMap; -import mekhq.campaign.unit.*; -import mekhq.Version; - - -//import mekhq.campaign.Campaign; -//import megamek.MegaMek; -//import megameklab.com.*; -import java.io.FileInputStream; -import java.util.UUID; -import java.io.*; -import javax.swing.*; - - -public class ScenerioEditor { - ScenerioEditorGUI mFrame = null; - Version version = null; - - public ScenerioEditor() { - try { - mFrame = new ScenerioEditorGUI("Scenerio Editor"); - DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - Document doc = dBuilder.parse(new File("C:\\Users\\jhahn\\eclipse-workspace\\MekHQ\\mekhq-master\\MekHQ\\campaigns\\Fist and Falcon\\test.cpnx")); - Element campaignEle = doc.getDocumentElement(); - NodeList nl = campaignEle.getChildNodes(); - campaignEle.normalize(); - version = new Version(campaignEle.getAttribute("version")); - System.out.println(campaignEle.getAttribute("version")); - - - // we need to iterate through three times, the first time to collect - // any custom units that might not be written yet - for (int x = 0; x < nl.getLength(); x++) { - Node wn = nl.item(x); - - if (wn.getParentNode() != campaignEle) { - continue; - } - int xc = wn.getNodeType(); - - if (xc == Node.ELEMENT_NODE) { - // This is what we really care about. - // All the meat of our document is in this node type, at this - // level. - // Okay, so what element is it? - String xn = wn.getNodeName(); - - if (xn.equalsIgnoreCase("units")) { // This is needed so that the campaign name gets set in retVal - processUnitNodes( wn); - } - } - } -/* NodeList nl=doc.getDocumentElement().getChildNodes(); - for(int k=0;k0 ) { - System.out.print("<"+nodes.getNodeName()); - for( int i =0 ; i < nnm.getLength() ; i++) { - Node nk = nnm.item(i); - System.out.print (" " +nk.getNodeName() + "=\"" + nk.getNodeValue()+"\""); - } - System.out.println(">"); - } - //System.out.println(nodes.getAttributes()); - - } - if(nodes.hasChildNodes() || nodes.getNodeType()!=3){ - NodeList nl=nodes.getChildNodes(); - System.out.println("<"+nodes.getNodeName()+">"); - - for(int j=0;j