mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-02 19:41:15 +00:00
eclipse plugin: add a better way to enter the starting gold by difficulties
This commit is contained in:
parent
3ba322db84
commit
bc06902727
@ -24,6 +24,34 @@ public class TestHandler extends AbstractHandler
|
||||
@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>();
|
||||
|
@ -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 @@ import org.eclipse.ui.IWorkbench;
|
||||
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 @@ public abstract class NewWizardTemplate extends Wizard implements INewWizard
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ import wesnoth_eclipse_plugin.wizards.TemplateProvider;
|
||||
public class ScenarioNewWizard extends NewWizardTemplate
|
||||
{
|
||||
private ScenarioPage0 page0_;
|
||||
private ScenarioPage1 page1_;
|
||||
private ScenarioPage1 page1_;
|
||||
private ScenarioPage2 page2_;
|
||||
|
||||
/**
|
||||
* Constructor for ScenarioNewWizard.
|
||||
@ -71,6 +72,9 @@ public class ScenarioNewWizard extends NewWizardTemplate
|
||||
page1_ = new ScenarioPage1();
|
||||
addPage(page1_);
|
||||
|
||||
page2_ = new ScenarioPage2();
|
||||
addPage(page2_);
|
||||
|
||||
super.addPages();
|
||||
}
|
||||
|
||||
@ -208,16 +212,16 @@ public class ScenarioNewWizard extends NewWizardTemplate
|
||||
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)
|
||||
{
|
||||
|
@ -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.Spinner;
|
||||
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 @@ public class ScenarioPage0 extends WizardPage
|
||||
|
||||
private IContainer container_;
|
||||
private String rawMapPath_;
|
||||
private Label lblDifficulty;
|
||||
private Label lblDifficulties;
|
||||
private Text txtStartingGold_;
|
||||
|
||||
/**
|
||||
* Constructor for SampleNewWizardPage.
|
||||
@ -171,42 +165,6 @@ public class ScenarioPage0 extends WizardPage
|
||||
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 @@ public class ScenarioPage0 extends WizardPage
|
||||
container = ((IResource) obj).getParent();
|
||||
}
|
||||
container_ = container;
|
||||
((NewWizardTemplate)getWizard()).setSelectionContainer(container_);
|
||||
txtProject_.setText(container.getFullPath().toString());
|
||||
}
|
||||
}
|
||||
@ -377,6 +336,7 @@ public class ScenarioPage0 extends WizardPage
|
||||
// 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 @@ public class ScenarioPage0 extends WizardPage
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contents of the wizard.
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
@Override
|
||||
public void createControl(Composite parent)
|
||||
{
|
||||
Composite container = new Composite(parent, SWT.NULL);
|
||||
container_ = new Composite(parent, SWT.NULL);
|
||||
|
||||
setControl(container);
|
||||
container.setLayout(new GridLayout(1, false));
|
||||
setControl(container_);
|
||||
container_.setLayout(new GridLayout(4, 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)
|
||||
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)
|
||||
{
|
||||
if (!(e.getSource() instanceof Button))
|
||||
return;
|
||||
setMPSettings(((Button) e.getSource()).getSelection());
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
chkAllowNewGame_ = new Button(container, SWT.CHECK);
|
||||
chkAllowNewGame_.setSelection(true);
|
||||
chkAllowNewGame_.setEnabled(false);
|
||||
chkAllowNewGame_.setText("Allow new game");
|
||||
}
|
||||
}
|
||||
|
||||
private void setMPSettings(boolean status)
|
||||
/**
|
||||
* Gets the starting gold as #ifdef based on difficulties
|
||||
*/
|
||||
public String getStartingGoldByDifficulties()
|
||||
{
|
||||
chkAllowNewGame_.setEnabled(status);
|
||||
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();
|
||||
}
|
||||
|
||||
public String getAllowNewGame()
|
||||
{
|
||||
return isMultiplayerScenario() ? String.valueOf(chkAllowNewGame_.getSelection()) : "";
|
||||
}
|
||||
|
||||
public boolean isMultiplayerScenario()
|
||||
{
|
||||
return chkIsMultiplayerScenario_.getSelection();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2010 by Timotei Dolean <timotei21@gmail.com>
|
||||
*
|
||||
* This program and the accompanying materials are made available
|
||||
* under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package wesnoth_eclipse_plugin.wizards.scenario;
|
||||
|
||||
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.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
public class ScenarioPage2 extends WizardPage
|
||||
{
|
||||
Button chkIsMultiplayerScenario_;
|
||||
Button chkAllowNewGame_;
|
||||
|
||||
/**
|
||||
* Create the wizard.
|
||||
*/
|
||||
public ScenarioPage2() {
|
||||
super("scenarioPage2");
|
||||
setTitle("Scenario file");
|
||||
setDescription("Set multiplayer scenario details");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contents of the wizard.
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
@Override
|
||||
public void createControl(Composite parent)
|
||||
{
|
||||
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");
|
||||
}
|
||||
|
||||
private void setMPSettings(boolean status)
|
||||
{
|
||||
chkAllowNewGame_.setEnabled(status);
|
||||
}
|
||||
|
||||
public String getAllowNewGame()
|
||||
{
|
||||
return isMultiplayerScenario() ? String.valueOf(chkAllowNewGame_.getSelection()) : "";
|
||||
}
|
||||
|
||||
public boolean isMultiplayerScenario()
|
||||
{
|
||||
return chkIsMultiplayerScenario_.getSelection();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user