Advertisement
Guest User

RIT - League of Legends Tool

a guest
Sep 1st, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.44 KB | None | 0 0
  1. package rit;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import java.awt.GridBagLayout;
  7. import java.awt.FlowLayout;
  8. import javax.swing.JComboBox;
  9. import java.awt.GridBagConstraints;
  10. import java.awt.Insets;
  11. import java.awt.GridLayout;
  12. import java.io.BufferedReader;
  13. import java.io.BufferedWriter;
  14. import java.io.File;
  15. import java.io.FileReader;
  16. import java.io.FileWriter;
  17. import java.io.IOException;
  18. import java.util.HashMap;
  19. import java.util.Vector;
  20.  
  21. import javax.swing.JButton;
  22. import javax.swing.DefaultComboBoxModel;
  23. import javax.swing.JPanel;
  24. import java.awt.event.ActionListener;
  25. import java.awt.event.ActionEvent;
  26. import javax.swing.JTextField;
  27. import javax.swing.JTextArea;
  28.  
  29. public class GUI
  30. {
  31.     private JFrame frmRit;
  32.     private HashMap<String, Integer> items = new HashMap<String, Integer>();
  33.     private Vector<String> itemValues = new Vector<String>();
  34.     private Vector<String> champions = new Vector<String>();
  35.     private final String PATH = "C:/Riot Games/League of Legends/RADS/solutions/lol_game_client_sln/releases/0.0.0.71/deploy/DATA/Characters/";
  36.     private JTextField textField;
  37.     private JTextArea textArea;
  38.    
  39.     private String result = "";
  40.    
  41.    
  42.     // 0 = champ
  43.     // 1 = mode
  44.     // 2-7 = items
  45.     private String[] selectedItems = new String[8];
  46.     private String selectedChampion = "Akali";;
  47.     private String mode = "Classic";
  48.    
  49.  
  50.     /**
  51.      * Launch the application.
  52.      */
  53.     public static void main(String[] args) {
  54.         EventQueue.invokeLater(new Runnable() {
  55.             public void run() {
  56.                 try {
  57.                     GUI window = new GUI();
  58.                     window.frmRit.setVisible(true);
  59.                 } catch (Exception e) {
  60.                     e.printStackTrace();
  61.                 }
  62.             }
  63.         });
  64.     }
  65.  
  66.     /**
  67.      * Create the application.
  68.      */
  69.     public GUI()
  70.     {
  71.         LoadChampions("data/champions.txt");
  72.         LoadItems("data/itamz.txt");
  73.        
  74.         // 0 = champ
  75.         // 1 = mode
  76.         // 2-7 = items
  77.         selectedItems[0] = "Akali";
  78.         selectedItems[1] = "Classic";
  79.         selectedItems[2] = "Mercury's Treads";
  80.         selectedItems[3] = "Rylai's Crystal Scepter";
  81.         selectedItems[4] = "Hextech Gunblade";
  82.         selectedItems[5] = "Rabadon's Deathcap";
  83.         selectedItems[6] = "Banshee's Veil";
  84.         selectedItems[7] = "Lich Bane";
  85.        
  86.         initialize();
  87.     }
  88.  
  89.     /**
  90.      * Initialize the contents of the frame.
  91.      */
  92.     private void initialize()
  93.     {
  94.         frmRit = new JFrame();
  95.         frmRit.setTitle("RIT");
  96.         frmRit.setBounds(100, 100, 412, 343);
  97.         frmRit.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  98.         GridBagLayout gridBagLayout = new GridBagLayout();
  99.         gridBagLayout.columnWidths = new int[]{72, 0};
  100.         gridBagLayout.rowHeights = new int[]{1, 0, 0, 0, 0, 0, 0, 0, 0};
  101.         gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
  102.         gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE};
  103.         frmRit.getContentPane().setLayout(gridBagLayout);
  104.        
  105.         JPanel panel_1 = new JPanel();
  106.         GridBagConstraints gbc_panel_1 = new GridBagConstraints();
  107.         gbc_panel_1.gridheight = 2;
  108.         gbc_panel_1.anchor = GridBagConstraints.WEST;
  109.         gbc_panel_1.insets = new Insets(0, 0, 5, 0);
  110.         gbc_panel_1.fill = GridBagConstraints.VERTICAL;
  111.         gbc_panel_1.gridx = 0;
  112.         gbc_panel_1.gridy = 0;
  113.         frmRit.getContentPane().add(panel_1, gbc_panel_1);
  114.         panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
  115.        
  116.         final JComboBox<String> champs = new JComboBox<String>(champions);
  117.         champs.addActionListener(new ActionListener() {
  118.             public void actionPerformed(ActionEvent e) {
  119.                 selectedChampion = champs.getSelectedItem().toString();
  120.                 textField.setText(CreatePath());
  121.             }
  122.         });
  123.         panel_1.add(champs);
  124.        
  125.         final JComboBox gameMode = new JComboBox();
  126.         gameMode.addActionListener(new ActionListener() {
  127.             public void actionPerformed(ActionEvent e)
  128.             {
  129.                 mode = gameMode.getSelectedItem().toString();
  130.                 textField.setText(CreatePath());
  131.             }
  132.         });
  133.         panel_1.add(gameMode);
  134.         gameMode.setModel(new DefaultComboBoxModel(new String[] {"Classic", "Dominion"}));
  135.        
  136.         JPanel panel_2 = new JPanel();
  137.         GridBagConstraints gbc_panel_2 = new GridBagConstraints();
  138.         gbc_panel_2.insets = new Insets(0, 0, 5, 0);
  139.         gbc_panel_2.fill = GridBagConstraints.HORIZONTAL;
  140.         gbc_panel_2.gridx = 0;
  141.         gbc_panel_2.gridy = 2;
  142.         frmRit.getContentPane().add(panel_2, gbc_panel_2);
  143.         panel_2.setLayout(new GridLayout(1, 0, 0, 0));
  144.        
  145.         final JComboBox<String> item1 = new JComboBox<String>(itemValues);
  146.         item1.addActionListener(new ActionListener() {
  147.             public void actionPerformed(ActionEvent e)
  148.             {
  149.                 selectedItems[2] = item1.getSelectedItem().toString();
  150.                 textArea.setText(CreateOutput());
  151.             }
  152.         });
  153.         panel_2.add(item1);
  154.        
  155.         final JComboBox<String> item2 = new JComboBox<String>(itemValues);
  156.         item2.addActionListener(new ActionListener() {
  157.             public void actionPerformed(ActionEvent e) {
  158.                 selectedItems[3] = item2.getSelectedItem().toString();
  159.                 textArea.setText(CreateOutput());
  160.             }
  161.         });
  162.         panel_2.add(item2);
  163.        
  164.         final JComboBox<String> item3 = new JComboBox<String>(itemValues);
  165.         item3.addActionListener(new ActionListener() {
  166.             public void actionPerformed(ActionEvent e) {
  167.                 selectedItems[4] = item3.getSelectedItem().toString();
  168.                 textArea.setText(CreateOutput());
  169.             }
  170.         });
  171.         panel_2.add(item3);
  172.        
  173.         JPanel panel = new JPanel();
  174.         GridBagConstraints gbc_panel = new GridBagConstraints();
  175.         gbc_panel.insets = new Insets(0, 0, 5, 0);
  176.         gbc_panel.fill = GridBagConstraints.HORIZONTAL;
  177.         gbc_panel.gridx = 0;
  178.         gbc_panel.gridy = 3;
  179.         frmRit.getContentPane().add(panel, gbc_panel);
  180.         panel.setLayout(new GridLayout(1, 0, 0, 0));
  181.        
  182.         final JComboBox<String> item4 = new JComboBox<String>(itemValues);
  183.         item4.addActionListener(new ActionListener() {
  184.             public void actionPerformed(ActionEvent e) {
  185.                 selectedItems[5] = item4.getSelectedItem().toString();
  186.                 textArea.setText(CreateOutput());
  187.             }
  188.         });
  189.         panel.add(item4);
  190.        
  191.         final JComboBox<String> item5 = new JComboBox<String>(itemValues);
  192.         item5.addActionListener(new ActionListener() {
  193.             public void actionPerformed(ActionEvent e) {
  194.                 selectedItems[6] = item5.getSelectedItem().toString();
  195.                 textArea.setText(CreateOutput());
  196.             }
  197.         });
  198.         panel.add(item5);
  199.        
  200.         final JComboBox<String> item6 = new JComboBox<String>(itemValues);
  201.         item6.addActionListener(new ActionListener() {
  202.             public void actionPerformed(ActionEvent e) {
  203.                 selectedItems[7] = item6.getSelectedItem().toString();
  204.                 textArea.setText(CreateOutput());
  205.             }
  206.         });
  207.         panel.add(item6);
  208.        
  209.         textField = new JTextField();
  210.         GridBagConstraints gbc_textField = new GridBagConstraints();
  211.         gbc_textField.insets = new Insets(0, 0, 5, 0);
  212.         gbc_textField.fill = GridBagConstraints.HORIZONTAL;
  213.         gbc_textField.gridx = 0;
  214.         gbc_textField.gridy = 4;
  215.         frmRit.getContentPane().add(textField, gbc_textField);
  216.         textField.setColumns(10);
  217.        
  218.         JButton btnSave = new JButton("Save");
  219.         GridBagConstraints gbc_btnSave = new GridBagConstraints();
  220.         gbc_btnSave.anchor = GridBagConstraints.EAST;
  221.         gbc_btnSave.insets = new Insets(0, 0, 5, 0);
  222.         gbc_btnSave.gridx = 0;
  223.         gbc_btnSave.gridy = 5;
  224.         frmRit.getContentPane().add(btnSave, gbc_btnSave);
  225.         btnSave.addActionListener(new ActionListener() {
  226.             public void actionPerformed(ActionEvent arg0) {
  227.                 try
  228.                 {
  229.                     SaveFile();
  230.                 }
  231.                 catch(IOException e)
  232.                 {
  233.                     System.out.println(e);
  234.                 }
  235.             }
  236.         });
  237.        
  238.         textArea = new JTextArea();
  239.         textArea.setEditable(false);
  240.         GridBagConstraints gbc_textArea = new GridBagConstraints();
  241.         gbc_textArea.insets = new Insets(0, 0, 5, 0);
  242.         gbc_textArea.fill = GridBagConstraints.BOTH;
  243.         gbc_textArea.gridx = 0;
  244.         gbc_textArea.gridy = 6;
  245.         frmRit.getContentPane().add(textArea, gbc_textArea);
  246.        
  247.         JPanel panel_3 = new JPanel();
  248.         GridBagConstraints gbc_panel_3 = new GridBagConstraints();
  249.         gbc_panel_3.anchor = GridBagConstraints.NORTHEAST;
  250.         gbc_panel_3.gridx = 0;
  251.         gbc_panel_3.gridy = 7;
  252.         frmRit.getContentPane().add(panel_3, gbc_panel_3);
  253.         panel_3.setLayout(new GridLayout(0, 1, 0, 0));
  254.     }
  255.    
  256.     public void LoadItems(String filename)
  257.     {
  258.         BufferedReader in = null;
  259.         try
  260.         {
  261.             in = new BufferedReader(new FileReader(filename));
  262.         }
  263.         catch(Exception e)
  264.         {
  265.             System.out.println(e);
  266.         }
  267.        
  268.         String line;
  269.        
  270.         try
  271.         {
  272.             while((line = in.readLine()) != null)
  273.             {
  274.                 String[] tokens = line.split("\\s+");
  275.                
  276.                 String itemName = "";
  277.                
  278.                 for(int i = 1; i < tokens.length; i++)
  279.                 {
  280.                     itemName += tokens[i];
  281.                     if(i < tokens.length-1)
  282.                     {
  283.                         itemName += " ";
  284.                     }
  285.                 }
  286.                
  287.                 items.put(itemName, Integer.parseInt(tokens[0]));
  288.                 itemValues.add(itemName);
  289.                
  290.                 System.out.println(tokens[0] + itemName);
  291.             }
  292.         }
  293.         catch(IOException e)
  294.         {
  295.             System.out.println(e);
  296.         }
  297.        
  298.         try
  299.         {
  300.             in.close();
  301.         }
  302.         catch(IOException e)
  303.         {
  304.             System.out.println(e);
  305.         }
  306.     }
  307.    
  308.     public void LoadChampions(String filename)
  309.     {
  310.         BufferedReader in = null;
  311.         try
  312.         {
  313.             in = new BufferedReader(new FileReader(filename));
  314.         }
  315.         catch(Exception e)
  316.         {
  317.             System.out.println(e);
  318.         }
  319.        
  320.         String line;
  321.        
  322.         try
  323.         {
  324.             while((line = in.readLine()) != null)
  325.             {
  326.                 champions.add(line);
  327.                 System.out.println(line);
  328.             }
  329.         }
  330.         catch(IOException e)
  331.         {
  332.             System.out.println(e);
  333.         }
  334.        
  335.         try
  336.         {
  337.             in.close();
  338.         }
  339.         catch(IOException e)
  340.         {
  341.             System.out.println(e);
  342.         }
  343.     }
  344.    
  345.     public String CreateOutput()
  346.     {
  347.         String s = "";
  348.        
  349.         String a = System.getProperty("line.separator");
  350.        
  351.         s += "[ItemSet1]" + a;
  352.         s+= "SetName=Set1" + a;
  353.         s+= "RecItem1=" + items.get(selectedItems[2]) + a;
  354.         s+= "RecItem2=" + items.get(selectedItems[3]) + a;
  355.         s+= "RecItem3=" + items.get(selectedItems[4]) + a;
  356.         s+= "RecItem4=" + items.get(selectedItems[5]) + a;
  357.         s+= "RecItem5=" + items.get(selectedItems[6]) + a;
  358.         s+= "RecItem6=" + items.get(selectedItems[7]) + a;
  359.        
  360.         return s;
  361.     }
  362.    
  363.     public void SaveFile() throws IOException
  364.     {
  365.         String fullPath = PATH + selectedChampion + "/";
  366.        
  367.         File f = new File(fullPath);
  368.         f.mkdirs();    
  369.        
  370.         fullPath += "RecItems";
  371.        
  372.         if(mode == "Classic")
  373.             fullPath += "CLASSIC.ini";
  374.         else if(mode == "Dominion")
  375.             fullPath += "ODIN.ini";
  376.        
  377.         FileWriter fstream = new FileWriter(fullPath);
  378.         BufferedWriter out = new BufferedWriter(fstream);
  379.        
  380.         out.write(CreateOutput());
  381.        
  382.         out.close();
  383.     }
  384.    
  385.     public String CreatePath()
  386.     {
  387.         String fullPath = PATH + selectedChampion + "/";
  388.         fullPath += "RecItems";
  389.         if(mode == "Classic")
  390.             fullPath += "CLASSIC.ini";
  391.         else if(mode == "Dominion")
  392.             fullPath += "ODIN.ini";
  393.        
  394.         return fullPath;
  395.     }
  396. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement