mail[Wesnoth-commits] r44456 - in /trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin: handlers/ wizards/ wizards/scenario/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by timotei_cluj on July 20, 2010 - 23:59:
Author: timotei
Date: Tue Jul 20 23:59:51 2010
New Revision: 44456

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44456&view=rev
Log:
eclipse plugin: add a better way to enter the starting gold by difficulties

Added:
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage2.java
      - copied, changed from r44455, 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java
Modified:
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/TestHandler.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/NewWizardTemplate.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioNewWizard.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage0.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/TestHandler.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/TestHandler.java?rev=44456&r1=44455&r2=44456&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/TestHandler.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/handlers/TestHandler.java
 Tue Jul 20 23:59:51 2010
@@ -24,6 +24,34 @@
        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException
        {
+//             try
+//             {
+//                     IProject proj = WorkspaceUtils.getSelectedProject();
+//                     String path = proj.getLocation().toOSString() + 
"/.wesnoth";
+//                     Properties config = new Properties();
+//                     config.setProperty("diff", "val");
+//                     config.storeToXML(new FileOutputStream(path), null);
+//                     
GUIUtils.showInfoMessageBox(config.getProperty("diff"));
+////                   if (proj != null)
+////                   {
+////                           int go = GUIUtils.showMessageBox("a", SWT.YES 
| SWT.NO);
+////                           if (go == SWT.YES)
+////                           {
+////                                   
//org.eclipse.core.resources.textmarkerIMarker.TEXT
+////                                   IMarker mark = 
proj.createMarker("sett");
+////                                   mark.setAttribute("diff", "VAL");
+////                           }
+////                           else
+////                           {
+////                                   IMarker[] marks = 
proj.findMarkers("sett", true, IResource.DEPTH_INFINITE);
+////                                   System.out.println(marks.length);
+////                           }
+////                   }
+//             }
+//             catch (Exception e)
+//             {
+//                     e.printStackTrace();
+//             }
                //System.out.println(WorkspaceUtils.getSelectedContainer());
 //             MessageConsole con = GUIUtils.createConsole("TIMO", null, 
true);
 //             List<String> arguments = new ArrayList<String>();

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/NewWizardTemplate.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/NewWizardTemplate.java?rev=44456&r1=44455&r2=44456&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/NewWizardTemplate.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/NewWizardTemplate.java
 Tue Jul 20 23:59:51 2010
@@ -8,6 +8,7 @@
  
*******************************************************************************/
 package wesnoth_eclipse_plugin.wizards;
 
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.Wizard;
@@ -17,6 +18,7 @@
 public abstract class NewWizardTemplate extends Wizard implements INewWizard
 {
        protected IStructuredSelection  selection_;
+       protected IContainer                    selectionContainer_;
        protected int                                   lastPageHashCode_     
  = 0;
        protected boolean                               isFinished_           
          = false;
        protected Object                                data_                 
          = null;
@@ -73,4 +75,20 @@
        {
                return objectName_;
        }
+
+       /**
+        * Gets the container of the selection
+        */
+       public IContainer getSelectionContainer()
+       {
+               return selectionContainer_;
+       }
+
+       /**
+        * Sets the container of the selection
+        */
+       public void setSelectionContainer(IContainer container)
+       {
+               this.selectionContainer_ = container;
+       }
 }

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioNewWizard.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioNewWizard.java?rev=44456&r1=44455&r2=44456&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioNewWizard.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioNewWizard.java
 Tue Jul 20 23:59:51 2010
@@ -48,7 +48,8 @@
 public class ScenarioNewWizard extends NewWizardTemplate
 {
        private ScenarioPage0   page0_;
-       private ScenarioPage1   page1_;
+       private ScenarioPage1   page1_;
+       private ScenarioPage2   page2_;
 
        /**
         * Constructor for ScenarioNewWizard.
@@ -70,6 +71,9 @@
 
                page1_ = new ScenarioPage1();
                addPage(page1_);
+
+               page2_ = new ScenarioPage2();
+               addPage(page2_);
 
                super.addPages();
        }
@@ -208,16 +212,16 @@
                params.add(new ReplaceableParameter("$$map_data", mapData));
                params.add(new ReplaceableParameter("$$turns_number", 
String.valueOf(page0_.getTurnsNumber())));
 
-               String startingGold = page0_.getStartingGoldByDifficulties();
+               String startingGold = page1_.getStartingGoldByDifficulties();
                if (startingGold == null)
                        throw new Exception("incorrenct argument");
                params.add(new ReplaceableParameter("$$starting_gold", 
startingGold));
 
                // multiplayer only variables
-               params.add(new ReplaceableParameter("$$allow_new_game", 
page1_.getAllowNewGame()));
+               params.add(new ReplaceableParameter("$$allow_new_game", 
page2_.getAllowNewGame()));
 
                String template = 
TemplateProvider.getInstance().getProcessedTemplate(
-                               page1_.isMultiplayerScenario() ? 
"multiplayer" : "scenario", params);
+                               page2_.isMultiplayerScenario() ? 
"multiplayer" : "scenario", params);
 
                if (template == null)
                {

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage0.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage0.java?rev=44456&r1=44455&r2=44456&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage0.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage0.java
 Tue Jul 20 23:59:51 2010
@@ -9,8 +9,6 @@
 package wesnoth_eclipse_plugin.wizards.scenario;
 
 import java.io.File;
-import java.util.HashMap;
-import java.util.List;
 
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IResource;
@@ -34,8 +32,7 @@
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
 
-import wesnoth_eclipse_plugin.utils.GUIUtils;
-import wesnoth_eclipse_plugin.utils.ProjectUtils;
+import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
 
 /**
  * The "New" wizard page allows setting the container for the new file as 
well
@@ -70,9 +67,6 @@
 
        private IContainer container_;
        private String rawMapPath_;
-       private Label lblDifficulty;
-       private Label lblDifficulties;
-       private Text txtStartingGold_;
 
        /**
         * Constructor for SampleNewWizardPage.
@@ -170,42 +164,6 @@
                gd_txtTurns_.widthHint = 60;
                txtTurns_.setLayoutData(gd_txtTurns_);
                new Label(container, SWT.NONE);
-
-               if (container_ != null)
-               {
-                       HashMap<String, List<String>> prefs =
-                               
ProjectUtils.getPreferencesForProject(container_.getProject());
-                       if (prefs != null && !prefs.get("settings").isEmpty())
-                       {
-                               lblDifficulty = new Label(container, 
SWT.NONE);
-                               lblDifficulty.setText("Difficulty:");
-
-                               lblDifficulties = new Label(container, 
SWT.NONE);
-                               lblDifficulties.setText("difficulties");
-
-                               List<String> settings = prefs.get("settings");
-                               for (String setting : settings)
-                               {
-                                       if 
(setting.startsWith("difficulties"))
-                                       {
-                                               
lblDifficulties.setData("difficulties", setting.split("=")[1]);
-                                               
lblDifficulties.setText(setting.split("=")[1] +
-                                                               "  Specify 
the gold for each difficulty (separated with space):");
-                                               break;
-                                       }
-                               }
-
-                               new Label(container, SWT.NONE);
-
-                               Label label_2 = new Label(container, 
SWT.NONE);
-                               label_2.setText("Starting gold:");
-                               label_2.setLayoutData(new GridData(SWT.FILL, 
SWT.CENTER, false, false, 1, 1));
-
-                               txtStartingGold_ = new Text(container, 
SWT.BORDER);
-                               txtStartingGold_.setLayoutData(new 
GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
-                               new Label(container, SWT.NONE);
-                       }
-               }
 
                lblMapData = new Label(container, SWT.NONE);
                lblMapData.setText("Map data:");
@@ -317,6 +275,7 @@
                                        container = ((IResource) 
obj).getParent();
                                }
                                container_ = container;
+                               
((NewWizardTemplate)getWizard()).setSelectionContainer(container_);
                                
txtProject_.setText(container.getFullPath().toString());
                        }
                }
@@ -377,6 +336,7 @@
                                        // the path is a project
                                        container_ = 
ResourcesPlugin.getWorkspace().getRoot().getProject(result[0].toString());
                                }
+                               
((NewWizardTemplate)getWizard()).setSelectionContainer(container_);
                                txtProject_.setText(((Path) 
result[0]).toString());
                        }
                }
@@ -447,24 +407,4 @@
        {
                return chkEmbeddedMap_.getSelection();
        }
-
-       public String getStartingGoldByDifficulties()
-       {
-               if (lblDifficulties == null)
-                       return "";
-               StringBuilder result = new StringBuilder();
-               String[] difficulties = 
lblDifficulties.getData("difficulties").toString().split(",");
-               String[] gold = txtStartingGold_.getText().split(" ");
-               if (difficulties.length != gold.length)
-               {
-                       GUIUtils.showErrorMessageBox("Incomplete gold 
specifications.");
-                       return null;
-               }
-               for (int i=0;i<difficulties.length;i++)
-               {
-                       result.append(String.format("#ifdef 
%s\n\tgold=%s\n#endif\n",
-                                       difficulties[i],gold[i]));
-               }
-               return result.toString();
-       }
 }

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java?rev=44456&r1=44455&r2=44456&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java
 Tue Jul 20 23:59:51 2010
@@ -8,73 +8,89 @@
  
*******************************************************************************/
 package wesnoth_eclipse_plugin.wizards.scenario;
 
+import java.util.HashMap;
+
+import org.eclipse.core.resources.IContainer;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import wesnoth_eclipse_plugin.utils.ProjectUtils;
+import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
 
 public class ScenarioPage1 extends WizardPage
 {
-       Button  chkIsMultiplayerScenario_;
-       Button  chkAllowNewGame_;
+       private Composite container_;
 
-       /**
-        * Create the wizard.
-        */
        public ScenarioPage1() {
                super("scenarioPage1");
                setTitle("Scenario file");
-               setDescription("Set multiplayer scenario details");
+               setDescription("Set scenario details");
+       }
+
+       @Override
+       public void createControl(Composite parent)
+       {
+               container_ = new Composite(parent, SWT.NULL);
+
+               setControl(container_);
+               container_.setLayout(new GridLayout(4, false));
+
+               Label lblSpecifyTheGold = new Label(container_, SWT.NONE);
+               lblSpecifyTheGold.setLayoutData(new GridData(SWT.LEFT, 
SWT.CENTER, false, false, 4, 1));
+               lblSpecifyTheGold.setText("Specify the gold for each 
difficulty:");
+
+               IContainer selContainer = 
((NewWizardTemplate)getWizard()).getSelectionContainer();
+               if (selContainer != null)
+               {
+                       HashMap<String, String> prefs =
+                               
ProjectUtils.getSettingsForProject(selContainer.getProject());
+                       if (prefs != null && prefs.get("difficulties") != 
null)
+                       {
+                               String[] difficulties = 
prefs.get("difficulties").split(",");
+                               for (String diff : difficulties)
+                               {
+                                       if (diff.isEmpty())
+                                               continue;
+
+                                       Label label = new Label(container_, 
SWT.NONE);
+                                       label.setText("    ");
+
+                                       Label lblDiff = new Label(container_, 
SWT.NONE);
+                                       lblDiff.setLayoutData(new 
GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+                                       lblDiff.setText(diff + ":");
+
+                                       Text textBox = new Text(container_, 
SWT.BORDER);
+                                       GridData gd_text = new 
GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
+                                       gd_text.widthHint = 77;
+                                       textBox.setData("diff",diff);
+                                       textBox.setLayoutData(gd_text);
+                                       new Label(container_, SWT.NONE);
+                               }
+                       }
+               }
        }
 
        /**
-        * Create contents of the wizard.
-        *
-        * @param parent
+        * Gets the starting gold as #ifdef based on difficulties
         */
-       @Override
-       public void createControl(Composite parent)
+       public String getStartingGoldByDifficulties()
        {
-               Composite container = new Composite(parent, SWT.NULL);
-
-               setControl(container);
-               container.setLayout(new GridLayout(1, false));
-
-               chkIsMultiplayerScenario_ = new Button(container, SWT.CHECK);
-               chkIsMultiplayerScenario_.setText("This is a multiplayer 
scenario");
-               new Label(container, SWT.NONE);
-               chkIsMultiplayerScenario_.addSelectionListener(new 
SelectionAdapter() {
-                       @Override
-                       public void widgetSelected(SelectionEvent e)
-                       {
-                               if (!(e.getSource() instanceof Button))
-                                       return;
-                               setMPSettings(((Button) 
e.getSource()).getSelection());
-                       }
-               });
-
-               chkAllowNewGame_ = new Button(container, SWT.CHECK);
-               chkAllowNewGame_.setSelection(true);
-               chkAllowNewGame_.setEnabled(false);
-               chkAllowNewGame_.setText("Allow new game");
+               StringBuilder result = new StringBuilder();
+               for(Control control: container_.getChildren())
+               {
+                       if (!(control instanceof Text))
+                               continue;
+                       Text textBox = (Text)control;
+                       result.append(String.format("#ifdef 
%s\n\tgold=%s\n#endif\n",
+                                       textBox.getData("diff").toString(), 
textBox.getText()));
+               }
+               return result.toString();
        }
 
-       private void setMPSettings(boolean status)
-       {
-               chkAllowNewGame_.setEnabled(status);
-       }
-
-       public String getAllowNewGame()
-       {
-               return isMultiplayerScenario() ? 
String.valueOf(chkAllowNewGame_.getSelection()) : "";
-       }
-
-       public boolean isMultiplayerScenario()
-       {
-               return chkIsMultiplayerScenario_.getSelection();
-       }
 }

Copied: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage2.java
 (from r44455, 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java)
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage2.java?p2=trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage2.java&p1=trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java&r1=44455&r2=44456&rev=44456&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage1.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/scenario/ScenarioPage2.java
 Tue Jul 20 23:59:51 2010
@@ -17,7 +17,7 @@
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 
-public class ScenarioPage1 extends WizardPage
+public class ScenarioPage2 extends WizardPage
 {
        Button  chkIsMultiplayerScenario_;
        Button  chkAllowNewGame_;
@@ -25,8 +25,8 @@
        /**
         * Create the wizard.
         */
-       public ScenarioPage1() {
-               super("scenarioPage1");
+       public ScenarioPage2() {
+               super("scenarioPage2");
                setTitle("Scenario file");
                setDescription("Set multiplayer scenario details");
        }




Related Messages


Powered by MHonArc, Updated Wed Jul 21 00:20:13 2010