eclipse plugin: Units wizard (part1)

This commit is contained in:
Timotei Dolean 2010-07-08 22:06:40 +00:00
parent 547b8cd9c9
commit cff59652ff
21 changed files with 2303 additions and 7 deletions

View file

@ -243,6 +243,17 @@
Create a new Wesnoth faction.
</description>
</wizard>
<wizard
category="wesnoth.eclipse.newWizards"
class="wesnoth_eclipse_plugin.wizards.unit.UnitsNewWizard"
icon="icons/wesnoth-icon_16.png"
id="wesnoth_eclipse_plugin.wizard.unitNewWizard"
name="Wesnoth Unit"
project="false">
<description>
Creates a new unit
</description>
</wizard>
</extension>
<extension
point="org.eclipse.ui.commands">

View file

@ -0,0 +1,92 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.jface;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class DoubleInputDialog extends Dialog
{
private Text txtValue1_;
private Text txtValue2_;
private Label lblValue1;
private Label lblValue2;
private String resStr1 = "", resStr2 = "";
private String val1String = "", val2String = "";
public DoubleInputDialog(Shell parentShell, String value1String, String value2String) {
super(parentShell);
setShellStyle(SWT.DIALOG_TRIM);
val1String = value1String + ":";
val2String = value2String + ":";
}
@Override
protected Control createDialogArea(Composite parent)
{
Composite container = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = (GridLayout) container.getLayout();
gridLayout.numColumns = 3;
lblValue1 = new Label(container, SWT.NONE);
lblValue1.setText(val1String);
Label label = new Label(container, SWT.NONE);
label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
txtValue1_ = new Text(container, SWT.BORDER);
txtValue1_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
lblValue2 = new Label(container, SWT.NONE);
lblValue2.setText(val2String);
Label label_3 = new Label(container, SWT.NONE);
label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
txtValue2_ = new Text(container, SWT.BORDER);
txtValue2_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
return container;
}
@Override
protected void createButtonsForButtonBar(Composite parent)
{
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
@Override
public boolean close()
{
resStr1 = txtValue1_.getText();
resStr2 = txtValue2_.getText();
return super.close();
}
@Override
protected Point getInitialSize()
{
return new Point(385, 155);
}
public String getFirstValue()
{
return resStr1;
}
public String getSecondValue()
{
return resStr2;
}
}

View file

@ -11,22 +11,35 @@ public class GUIUtils
{
/**
* Shows a message box with the specified message (thread-safe)
*
* @param window the window where to show the message box
* @param message the message to print
*/
public static void showMessageBox(final IWorkbenchWindow window,final String message)
public static void showMessageBox(final String message)
{
showMessageBox(window, message,SWT.DEFAULT);
showMessageBox(WorkspaceUtils.getWorkbenchWindow(), message, SWT.DEFAULT);
}
/**
* Shows a message box with the specified message (thread-safe)
*
* @param window the window where to show the message box
* @param message the message to print
*/
public static void showMessageBox(final IWorkbenchWindow window,final String message,final int style)
public static void showMessageBox(final IWorkbenchWindow window, final String message)
{
if (window == null || window.getShell() == null)
showMessageBox(window, message, SWT.DEFAULT);
}
/**
* Shows a message box with the specified message (thread-safe)
*
* @param window the window where to show the message box
* @param message the message to print
*/
public static void showMessageBox(final IWorkbenchWindow window, final String message, final int style)
{
if (window == null || window.getShell() == null)
return;
try
{
@ -39,8 +52,7 @@ public class GUIUtils
box.open();
}
});
}
catch (Exception e)
} catch (Exception e)
{
e.printStackTrace();
}

View file

@ -0,0 +1,48 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.utils;
import java.util.List;
public class ListUtils
{
/**
* Concatenates the list of strings using the provided separator
*
* @param list the list to concatenate
* @param separator the separator used to concatenate the elements of the list
* @return
*/
public static String concatenateList(List<String> list, String separator)
{
String result = "";
for (int i = 0; i < list.size() - 1; i++)
{
result += (list.get(i) + separator);
}
if (!list.isEmpty())
result += list.get(list.size() - 1);
return result;
}
/**
* Concatenates the array of strings using the provided separator
*
* @param array the array to concatenate
* @param separator the separator used to concatenate the elements of the list
* @return
*/
public static String concatenateArray(String[] array, String separator)
{
String result = "";
for (int i = 0; i < array.length - 1; i++)
{
result += (array[i] + separator);
}
if (array.length > 0)
result += array[array.length - 1];
return result;
}
}

View file

@ -25,7 +25,7 @@ public class StringUtils
public static int countOf(String target, char character)
{
if (target.indexOf(character) == -1)
return -1;
return 0;
int cnt = 0;
String tmpString = target;
while (tmpString.contains(new String(new char[] { character })))
@ -99,6 +99,8 @@ public class StringUtils
public static String[] getLines(String string)
{
if (string == null)
return new String[0];
return string.split("\\r?\\n");
}

View file

@ -0,0 +1,134 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class AttackDialog extends TitleAreaDialog
{
private Text text;
private Text text_1;
private Text text_2;
private Text text_3;
private Text text_4;
private Text text_5;
private Text text_6;
private Text text_7;
/**
* Create the dialog.
*
* @param parentShell
*/
public AttackDialog(Shell parentShell) {
super(parentShell);
}
/**
* Create contents of the dialog.
*
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent)
{
setTitle("Create a new attack");
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayout(new GridLayout(6, false));
container.setLayoutData(new GridData(GridData.FILL_BOTH));
Label lblName = new Label(container, SWT.NONE);
lblName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblName.setText("Name:");
text = new Text(container, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblType = new Label(container, SWT.NONE);
lblType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblType.setText("Type:");
text_1 = new Text(container, SWT.BORDER);
text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblRange = new Label(container, SWT.NONE);
lblRange.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblRange.setText("Range:");
text_2 = new Text(container, SWT.BORDER);
text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblDamage = new Label(container, SWT.NONE);
lblDamage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblDamage.setText("Damage:");
text_3 = new Text(container, SWT.BORDER);
text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblNumber = new Label(container, SWT.NONE);
lblNumber.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblNumber.setText("Number:");
text_4 = new Text(container, SWT.BORDER);
text_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblIcon = new Label(container, SWT.NONE);
lblIcon.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblIcon.setText("Icon:");
text_5 = new Text(container, SWT.BORDER);
text_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblMovementUsed = new Label(container, SWT.NONE);
lblMovementUsed.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblMovementUsed.setText("Movement used:");
text_7 = new Text(container, SWT.BORDER);
text_7.setText("0");
text_7.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblDescription = new Label(container, SWT.NONE);
lblDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblDescription.setText("Description:");
text_6 = new Text(container, SWT.BORDER);
text_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 5, 1));
return area;
}
/**
* Create contents of the button bar.
*
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent)
{
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
/**
* Return the initial size of the dialog.
*/
@Override
protected Point getInitialSize()
{
return new Point(450, 300);
}
}

View file

@ -0,0 +1,46 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
public class EffectDialog extends TitleAreaDialog
{
public EffectDialog(Shell parentShell) {
super(parentShell);
}
@Override
protected Control createDialogArea(Composite parent)
{
setTitle("Create a new effect");
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
return area;
}
@Override
protected void createButtonsForButtonBar(Composite parent)
{
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
@Override
protected Point getInitialSize()
{
return new Point(450, 300);
}
}

View file

@ -0,0 +1,282 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import java.util.ArrayList;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import wesnoth_eclipse_plugin.jface.DoubleInputDialog;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.utils.ListUtils;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
import wesnoth_eclipse_plugin.wizards.ReplaceableParameter;
import wesnoth_eclipse_plugin.wizards.TemplateProvider;
public class MoveTypeWizard extends NewWizardTemplate
{
private MoveTypePage0 page0_;
public MoveTypeWizard() {
setWindowTitle("Movetype tag wizard");
}
@Override
public void addPages()
{
page0_ = new MoveTypePage0();
addPage(page0_);
super.addPages();
}
@Override
public boolean performFinish()
{
isFinished_ = true;
ArrayList<ReplaceableParameter> params = new ArrayList<ReplaceableParameter>();
objectName_ = page0_.getName();
params.add(new ReplaceableParameter("$$movetype_name", page0_.getName()));
params.add(new ReplaceableParameter("$$flies", String.valueOf(page0_.getFlies())));
params.add(new ReplaceableParameter("$$movement_costs", page0_.getMovementCosts()));
params.add(new ReplaceableParameter("$$defense", page0_.getDefense()));
params.add(new ReplaceableParameter("$$resistance", page0_.getResistance()));
String template = TemplateProvider.getInstance().getProcessedTemplate("movetype", params);
if (template == null)
{
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(), "Template for \"movetype\" not found.");
return false;
}
data_ = template;
return true;
}
public class MoveTypePage0 extends WizardPage
{
private Button chkFlies;
private Text txtName_;
private Group grpmovementcosts;
private Group grpdefense;
private List lstMoveCosts_;
private List lstDef_;
private Group grpresistance;
private List lstResist_;
private Button btnAddRes;
private Button btnRemoveRes;
public MoveTypePage0() {
super("moveTypePage0");
setTitle("Move type wizard");
setDescription("Create a new [movetype]");
}
private void updatePageIsComplete()
{
setPageComplete(false);
if (getName().isEmpty())
{
setErrorMessage("The movetype needs a unique name.");
return;
}
setErrorMessage(null);
setPageComplete(true);
}
@Override
public void createControl(Composite parent)
{
parent.setLocation(0, 0);
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
container.setLayout(new GridLayout(3, false));
Label lblName = new Label(container, SWT.NONE);
GridData gd_lblName = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_lblName.widthHint = 68;
lblName.setLayoutData(gd_lblName);
lblName.setText("Name*:");
txtName_ = new Text(container, SWT.BORDER);
txtName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
txtName_.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e)
{
updatePageIsComplete();
}
});
chkFlies = new Button(container, SWT.CHECK);
chkFlies.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
chkFlies.setText("Flies");
grpmovementcosts = new Group(container, SWT.NONE);
grpmovementcosts.setText("[movement_costs]");
grpmovementcosts.setLayout(null);
GridData gd_grpmovementcosts = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
gd_grpmovementcosts.widthHint = 269;
grpmovementcosts.setLayoutData(gd_grpmovementcosts);
lstMoveCosts_ = new List(grpmovementcosts, SWT.BORDER);
lstMoveCosts_.setBounds(4, 25, 190, 68);
Button btnAddMove = new Button(grpmovementcosts, SWT.NONE);
btnAddMove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addNewItem(lstMoveCosts_, "Terrain", "Speed");
}
});
btnAddMove.setBounds(200, 24, 65, 25);
btnAddMove.setText("Add");
Button btnRemoveMove = new Button(grpmovementcosts, SWT.NONE);
btnRemoveMove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeSelectedItem(lstMoveCosts_);
}
});
btnRemoveMove.setText("Remove");
btnRemoveMove.setBounds(200, 68, 65, 25);
grpdefense = new Group(container, SWT.NONE);
grpdefense.setText("[defense]");
grpdefense.setLayout(null);
grpdefense.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lstDef_ = new List(grpdefense, SWT.BORDER);
lstDef_.setBounds(4, 25, 190, 68);
Button btnRemoveDef = new Button(grpdefense, SWT.NONE);
btnRemoveDef.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeSelectedItem(lstDef_);
}
});
btnRemoveDef.setText("Remove");
btnRemoveDef.setBounds(209, 68, 65, 25);
Button btnAddDef = new Button(grpdefense, SWT.NONE);
btnAddDef.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addNewItem(lstDef_, "Terrain", "Defense");
}
});
btnAddDef.setText("Add");
btnAddDef.setBounds(209, 25, 65, 25);
grpresistance = new Group(container, SWT.NONE);
grpresistance.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
grpresistance.setLayout(null);
grpresistance.setText("[resistance]");
lstResist_ = new List(grpresistance, SWT.BORDER);
lstResist_.setBounds(4, 25, 190, 68);
btnAddRes = new Button(grpresistance, SWT.NONE);
btnAddRes.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addNewItem(lstResist_, "Attack Type", "Resistance");
}
});
btnAddRes.setText("Add");
btnAddRes.setBounds(200, 24, 65, 25);
btnRemoveRes = new Button(grpresistance, SWT.NONE);
btnRemoveRes.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeSelectedItem(lstResist_);
}
});
btnRemoveRes.setText("Remove");
btnRemoveRes.setBounds(200, 68, 65, 25);
new Label(container, SWT.NONE);
updatePageIsComplete();
}
private void addNewItem(List targetList, String firstValueName, String secondValueName)
{
DoubleInputDialog dialog = new DoubleInputDialog(getShell(), firstValueName, secondValueName);
if (dialog.open() == Window.OK)
addItem(dialog.getFirstValue(), dialog.getSecondValue(), targetList);
}
private void addItem(String name, String value, List targetList)
{
if (targetList == null)
return;
targetList.add(name + "=" + value);
}
private void removeSelectedItem(List targetList)
{
if (targetList == null)
return;
if (targetList.getSelectionCount() == 0)
{
GUIUtils.showMessageBox("Please select an item before deleting it.");
return;
}
targetList.remove(targetList.getSelectionIndex());
}
@Override
public String getName()
{
return txtName_.getText();
}
public boolean getFlies()
{
return chkFlies.getSelection();
}
public String getDefense()
{
return ListUtils.concatenateArray(lstDef_.getItems(), "\n\t");
}
public String getResistance()
{
return ListUtils.concatenateArray(lstResist_.getItems(), "\n\t");
}
public String getMovementCosts()
{
return ListUtils.concatenateArray(lstMoveCosts_.getItems(), "\n\t");
}
}
}

View file

@ -0,0 +1,316 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import java.util.ArrayList;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.utils.ListUtils;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
import wesnoth_eclipse_plugin.wizards.ReplaceableParameter;
import wesnoth_eclipse_plugin.wizards.TemplateProvider;
public class RaceWizard extends NewWizardTemplate
{
private boolean isFinished_ = false;
private RacePage0 page0_;
public RaceWizard() {
setWindowTitle("Race tag wizard");
}
@Override
public void addPages()
{
page0_ = new RacePage0();
addPage(page0_);
super.addPages();
}
@Override
public boolean isFinished()
{
return isFinished_;
}
@Override
public boolean performFinish()
{
isFinished_ = true;
ArrayList<ReplaceableParameter> params = new ArrayList<ReplaceableParameter>();
objectName_ = page0_.getName();
params.add(new ReplaceableParameter("$$race_id", page0_.getRaceId()));
params.add(new ReplaceableParameter("$$plural_name", page0_.getPluralName()));
params.add(new ReplaceableParameter("$$male_name", page0_.getMaleName()));
params.add(new ReplaceableParameter("$$female_name", page0_.getFemaleName()));
params.add(new ReplaceableParameter("$$description", page0_.getRaceDescription()));
params.add(new ReplaceableParameter("$$num_traits", String.valueOf(page0_.getTraitsNumber())));
params.add(new ReplaceableParameter("$$ignore_global_traits", String.valueOf(page0_.getIgnoreGlobalTraits())));
params.add(new ReplaceableParameter("$$traits", page0_.getTraits()));
String template = TemplateProvider.getInstance().getProcessedTemplate("race", params);
if (template == null)
{
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(), "Template for \"race\" not found.");
return false;
}
data_ = template;
return true;
}
public class RacePage0 extends WizardPage
{
private List lstTrait_;
private Button btnAddTrait;
private Button btnRemoveTrait;
private Text txtId_;
private Text txtPluralName_;
private Text txtMaleName_;
private Text txtFemaleName_;
private Button chkIgnoreGlobalTraits;
private Spinner txtTraitsNumber_;
private Text txtRaceName_;
private java.util.List<String> traitsList_;
private Label lblDescription;
private Text txtDescription_;
public RacePage0() {
super("racePage0");
setTitle("Race wizard");
setDescription("Create a new [race]");
traitsList_ = new ArrayList<String>();
}
@Override
public void createControl(Composite parent)
{
ModifyListener modifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e)
{
updatePageIsComplete();
}
};
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
container.setLayout(new GridLayout(4, false));
Label lblId = new Label(container, SWT.NONE);
lblId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblId.setText("Id*:");
txtId_ = new Text(container, SWT.BORDER);
txtId_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
txtId_.addModifyListener(modifyListener);
Label lblPluralname = new Label(container, SWT.NONE);
lblPluralname.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblPluralname.setText("Plural_name*:");
txtPluralName_ = new Text(container, SWT.BORDER);
GridData gd_txtPluralName_ = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_txtPluralName_.widthHint = 211;
txtPluralName_.setLayoutData(gd_txtPluralName_);
txtPluralName_.addModifyListener(modifyListener);
Label lblName_3 = new Label(container, SWT.NONE);
lblName_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblName_3.setText("Name:");
txtRaceName_ = new Text(container, SWT.BORDER);
txtRaceName_.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e)
{
if (!(e.getSource() instanceof Text))
return;
boolean otherNamesEnabled = false;
if (((Text) e.getSource()).getText().isEmpty())
{
otherNamesEnabled = true;
}
txtFemaleName_.setEnabled(otherNamesEnabled);
txtMaleName_.setEnabled(otherNamesEnabled);
}
});
txtRaceName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblName_1 = new Label(container, SWT.NONE);
lblName_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblName_1.setText("Male Name:");
txtMaleName_ = new Text(container, SWT.BORDER);
txtMaleName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Label lblFemaleName = new Label(container, SWT.NONE);
lblFemaleName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblFemaleName.setText("Female name:");
txtFemaleName_ = new Text(container, SWT.BORDER);
txtFemaleName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
chkIgnoreGlobalTraits = new Button(container, SWT.CHECK);
chkIgnoreGlobalTraits.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
chkIgnoreGlobalTraits.setText("Ignore global traits");
Label lblTraitsNumber = new Label(container, SWT.NONE);
lblTraitsNumber.setText("Traits number:");
txtTraitsNumber_ = new Spinner(container, SWT.BORDER);
lblDescription = new Label(container, SWT.NONE);
lblDescription.setText("Description:");
txtDescription_ = new Text(container, SWT.BORDER | SWT.MULTI);
GridData gd_txtDescription_ = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
gd_txtDescription_.heightHint = 51;
txtDescription_.setLayoutData(gd_txtDescription_);
Group grptrait = new Group(container, SWT.NONE);
grptrait.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
grptrait.setLayout(null);
grptrait.setText("[trait]");
lstTrait_ = new List(grptrait, SWT.BORDER);
lstTrait_.setBounds(4, 25, 190, 68);
btnAddTrait = new Button(grptrait, SWT.NONE);
btnAddTrait.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addNewItem();
}
});
btnAddTrait.setText("Add");
btnAddTrait.setBounds(200, 24, 65, 25);
btnRemoveTrait = new Button(grptrait, SWT.NONE);
btnRemoveTrait.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeSelectedItem();
}
});
btnRemoveTrait.setText("Remove");
btnRemoveTrait.setBounds(200, 68, 65, 25);
new Label(container, SWT.NONE);
new Label(container, SWT.NONE);
updatePageIsComplete();
}
private void addNewItem()
{
TraitDialog dialog = new TraitDialog(getShell());
if (dialog.open() == Window.OK)
{
lstTrait_.add(dialog.getTraitId());
traitsList_.add(dialog.getTrait());
}
}
private void removeSelectedItem()
{
if (lstTrait_ == null)
return;
if (lstTrait_.getSelectionCount() == 0 || lstTrait_.getItems().length == 0)
{
GUIUtils.showMessageBox("Please select a trait before deleting it.");
return;
}
traitsList_.remove(lstTrait_.getSelectionIndex());
lstTrait_.remove(lstTrait_.getSelectionIndex());
}
private void updatePageIsComplete()
{
setPageComplete(false);
setErrorMessage(null);
if (getRaceId().isEmpty())
{
setErrorMessage("The ID cannot be empty.");
return;
}
if (getPluralName().isEmpty())
{
setErrorMessage("The plural_name cannot be empty.");
return;
}
setPageComplete(true);
}
public boolean getIgnoreGlobalTraits()
{
return chkIgnoreGlobalTraits.getSelection();
}
public String getTraits()
{
return ListUtils.concatenateList(traitsList_, "\n\t");
}
public String getRaceId()
{
return txtId_.getText();
}
public String getMaleName()
{
return getRaceName().isEmpty() ? txtMaleName_.getText() : getRaceName();
}
public String getFemaleName()
{
return getRaceName().isEmpty() ? txtFemaleName_.getText() : getRaceName();
}
public String getRaceName()
{
return txtRaceName_.getText();
}
public String getPluralName()
{
return txtPluralName_.getText();
}
public int getTraitsNumber()
{
return txtTraitsNumber_.getSelection();
}
public String getRaceDescription()
{
return txtDescription_.getText();
}
}
}

View file

@ -0,0 +1,186 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import java.util.ArrayList;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TraitDialog extends TitleAreaDialog
{
private Text txtId_;
private Text txtName_;
private Text txtMaleName_;
private Text txtFemaleName_;
private Text txtDescription_;
private Combo txtAvailability;
java.util.List<String> effects_;
private List lstEffect;
private String traitId_;
public TraitDialog(Shell parentShell) {
super(parentShell);
effects_ = new ArrayList<String>();
}
@Override
protected Control createDialogArea(Composite parent)
{
setTitle("Create a new trait");
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayout(new GridLayout(4, false));
container.setLayoutData(new GridData(GridData.FILL_BOTH));
Label lblId = new Label(container, SWT.NONE);
lblId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblId.setText("Id*:");
txtId_ = new Text(container, SWT.BORDER);
txtId_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblAvailability = new Label(container, SWT.NONE);
lblAvailability.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblAvailability.setText("Availability:");
txtAvailability = new Combo(container, SWT.READ_ONLY);
txtAvailability.setItems(new String[] { "", "musthave", "any", "none" });
txtAvailability.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblName = new Label(container, SWT.NONE);
lblName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblName.setText("Name:");
txtName_ = new Text(container, SWT.BORDER);
txtName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblMaleName = new Label(container, SWT.NONE);
lblMaleName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblMaleName.setText("Male name:");
txtMaleName_ = new Text(container, SWT.BORDER);
txtMaleName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblFemaleName = new Label(container, SWT.NONE);
lblFemaleName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblFemaleName.setText("Female name:");
txtFemaleName_ = new Text(container, SWT.BORDER);
txtFemaleName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblDescription = new Label(container, SWT.NONE);
lblDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblDescription.setText("Description:");
txtDescription_ = new Text(container, SWT.BORDER);
txtDescription_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lbleffect = new Label(container, SWT.NONE);
lbleffect.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2));
lbleffect.setText("[effect]");
lstEffect = new List(container, SWT.BORDER);
lstEffect.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 2));
Button btnAdd = new Button(container, SWT.NONE);
btnAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addEffect();
}
});
btnAdd.setText("Add");
new Label(container, SWT.NONE);
Button btnRemove = new Button(container, SWT.NONE);
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeEffect();
}
});
btnRemove.setText("Remove");
new Label(container, SWT.NONE);
return area;
}
private void addEffect()
{
EffectDialog dialog = new EffectDialog(getShell());
if (dialog.open() == Window.OK)
{
// add the effect
}
}
private void removeEffect()
{
if (lstEffect.getSelectionCount() == 0 || lstEffect.getItems().length == 0)
return;
effects_.remove(lstEffect.getSelectionCount());
lstEffect.remove(lstEffect.getSelectionIndex());
}
@Override
protected void createButtonsForButtonBar(Composite parent)
{
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
@Override
protected Point getInitialSize()
{
return new Point(450, 337);
}
@Override
public boolean close()
{
traitId_ = txtId_.getText();
return super.close();
}
public void updateIsComplete()
{
getButton(IDialogConstants.OK_ID).setEnabled(false);
// validation
setErrorMessage(null);
getButton(IDialogConstants.OK_ID).setEnabled(true);
}
public String getTrait()
{
String result = traitId_;
// process the template
return result;
}
public String getTraitId()
{
return traitId_;
}
}

View file

@ -0,0 +1,400 @@
package wesnoth_eclipse_plugin.wizards.unit;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
public class UnitTypePage0 extends WizardPage
{
private Text txtId_;
private Text txtUnitTypeName_;
private Text txtAdvancesTo_;
private Text txtCost;
private Text txtUsage_;
private Text txtExperience;
private Text txtHitpoints_;
private Text txtLevel_;
private Text txtMovement_;
private Text txtMovementType_;
private Text txtRace_;
private Text txtTraitsNumber_;
private Text txtImage_;
private Text txtProfile_;
private Text txtUndeadVariation_;
private Combo cmbZoc_;
private Text txtEllipse_;
private Text txtDieSound_;
private Text txtDecscription_;
private Combo cmbIgnoreTraits_;
private Combo cmbHideHelp_;
private Combo cmbAlignment_;
private Text txtBaseUnitId_;
private Combo cmbGender;
private Spinner txtAttacks;
public UnitTypePage0() {
super("unitTypePage0");
setTitle("Unit type wizard");
setDescription("Create a new [unit_type]");
}
@Override
public void createControl(Composite parent)
{
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
container.setLayout(new GridLayout(8, false));
Label lblName = new Label(container, SWT.NONE);
GridData gd_lblName = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_lblName.widthHint = 68;
lblName.setLayoutData(gd_lblName);
lblName.setText("Id*:");
txtId_ = new Text(container, SWT.BORDER);
GridData gd_txtId_ = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
gd_txtId_.widthHint = 190;
txtId_.setLayoutData(gd_txtId_);
Label lblName_1 = new Label(container, SWT.NONE);
lblName_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblName_1.setText("Name:");
txtUnitTypeName_ = new Text(container, SWT.BORDER);
txtUnitTypeName_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblAdvancesTo = new Label(container, SWT.NONE);
lblAdvancesTo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblAdvancesTo.setText("Advances to:");
txtAdvancesTo_ = new Text(container, SWT.BORDER);
GridData gd_txtAdvancesTo_ = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
gd_txtAdvancesTo_.widthHint = 190;
txtAdvancesTo_.setLayoutData(gd_txtAdvancesTo_);
Label lblAttacks = new Label(container, SWT.NONE);
lblAttacks.setText("Attacks:");
txtAttacks = new Spinner(container, SWT.BORDER);
txtAttacks.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
txtAttacks.setMinimum(1);
Label lblGender = new Label(container, SWT.NONE);
lblGender.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblGender.setText("Gender:");
cmbGender = new Combo(container, SWT.READ_ONLY);
cmbGender.setItems(new String[] { "Male", "Female" });
cmbGender.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cmbGender.select(0);
Label lblCost = new Label(container, SWT.NONE);
lblCost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblCost.setText("Cost:");
txtCost = new Text(container, SWT.BORDER);
GridData gd_txtCost = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtCost.widthHint = 68;
txtCost.setLayoutData(gd_txtCost);
Label lblExperience = new Label(container, SWT.NONE);
lblExperience.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblExperience.setText("Experience:");
txtExperience = new Text(container, SWT.BORDER);
GridData gd_txtExperience = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtExperience.widthHint = 52;
txtExperience.setLayoutData(gd_txtExperience);
Label lblUsage = new Label(container, SWT.NONE);
lblUsage.setText("Usage:");
txtUsage_ = new Text(container, SWT.BORDER);
txtUsage_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblRace = new Label(container, SWT.NONE);
lblRace.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblRace.setText("Race:");
txtRace_ = new Text(container, SWT.BORDER);
txtRace_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblHitpoints = new Label(container, SWT.NONE);
lblHitpoints.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblHitpoints.setText("Hitpoints:");
txtHitpoints_ = new Text(container, SWT.BORDER);
txtHitpoints_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblLevel = new Label(container, SWT.NONE);
lblLevel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblLevel.setText("Level:");
txtLevel_ = new Text(container, SWT.BORDER);
GridData gd_txtLevel_ = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtLevel_.widthHint = 51;
txtLevel_.setLayoutData(gd_txtLevel_);
Label lblMovement = new Label(container, SWT.NONE);
lblMovement.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblMovement.setText("Movement:");
txtMovement_ = new Text(container, SWT.BORDER);
txtMovement_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblMovementType = new Label(container, SWT.NONE);
lblMovementType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblMovementType.setText("Movement type:");
txtMovementType_ = new Text(container, SWT.BORDER);
GridData gd_txtMovementType_ = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtMovementType_.widthHint = 89;
txtMovementType_.setLayoutData(gd_txtMovementType_);
Label lblIgnoreGlobalTraits = new Label(container, SWT.NONE);
lblIgnoreGlobalTraits.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblIgnoreGlobalTraits.setText("Ignore race traits:");
cmbIgnoreTraits_ = new Combo(container, SWT.READ_ONLY);
cmbIgnoreTraits_.setItems(new String[] { "false", "true" });
cmbIgnoreTraits_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cmbIgnoreTraits_.select(0);
new Label(container, SWT.NONE);
new Label(container, SWT.NONE);
Label lblTraitsNumber = new Label(container, SWT.NONE);
lblTraitsNumber.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblTraitsNumber.setText("Traits number:");
txtTraitsNumber_ = new Text(container, SWT.BORDER);
txtTraitsNumber_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblAlignment = new Label(container, SWT.NONE);
lblAlignment.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblAlignment.setText("Alignment:");
cmbAlignment_ = new Combo(container, SWT.READ_ONLY);
cmbAlignment_.setItems(new String[] { "neutral", "chaotic", "lawful" });
cmbAlignment_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cmbAlignment_.select(0);
Label lblImage = new Label(container, SWT.NONE);
lblImage.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblImage.setText("Image:");
txtImage_ = new Text(container, SWT.BORDER);
txtImage_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblPortrait = new Label(container, SWT.NONE);
lblPortrait.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblPortrait.setText("Profile:");
txtProfile_ = new Text(container, SWT.BORDER);
txtProfile_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblEllipse = new Label(container, SWT.NONE);
lblEllipse.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblEllipse.setText("Ellipse:");
txtEllipse_ = new Text(container, SWT.BORDER);
txtEllipse_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblDieSound = new Label(container, SWT.NONE);
lblDieSound.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblDieSound.setText("Die sound:");
txtDieSound_ = new Text(container, SWT.BORDER);
txtDieSound_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblUndeadVariation = new Label(container, SWT.NONE);
lblUndeadVariation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblUndeadVariation.setText("Undead variation:");
txtUndeadVariation_ = new Text(container, SWT.BORDER);
txtUndeadVariation_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblZoc = new Label(container, SWT.NONE);
lblZoc.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblZoc.setText("ZOC:");
cmbZoc_ = new Combo(container, SWT.READ_ONLY);
cmbZoc_.setItems(new String[] { "", "yes", "no" });
cmbZoc_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cmbZoc_.select(0);
Label lblHideHelp = new Label(container, SWT.NONE);
lblHideHelp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblHideHelp.setText("Hide help:");
cmbHideHelp_ = new Combo(container, SWT.READ_ONLY);
cmbHideHelp_.setItems(new String[] { "false", "true" });
cmbHideHelp_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cmbHideHelp_.select(0);
Label lblDescription = new Label(container, SWT.NONE);
lblDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblDescription.setText("Description:");
txtDecscription_ = new Text(container, SWT.BORDER | SWT.MULTI);
txtDecscription_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 7, 1));
Label lblbaseunitId = new Label(container, SWT.NONE);
lblbaseunitId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblbaseunitId.setText("[base_unit] id:");
txtBaseUnitId_ = new Text(container, SWT.BORDER);
txtBaseUnitId_.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(container, SWT.NONE);
new Label(container, SWT.NONE);
new Label(container, SWT.NONE);
new Label(container, SWT.NONE);
new Label(container, SWT.NONE);
new Label(container, SWT.NONE);
updatePageIsComplete();
}
private void updatePageIsComplete()
{
setPageComplete(false);
setErrorMessage(null);
if (getId().isEmpty())
{
setErrorMessage("ID cannot be empty");
return;
}
setPageComplete(true);
}
public String getAlignment()
{
return cmbAlignment_.getText();
}
public String getId()
{
return txtId_.getText();
}
public String getUnitTypeName()
{
return txtUnitTypeName_.getText();
}
public String getAdvancesTo()
{
return txtAdvancesTo_.getText();
}
public String getCost()
{
return txtCost.getText();
}
public String getExperience()
{
return txtExperience.getText();
}
public String getHitpoints()
{
return txtHitpoints_.getText();
}
public String getLevel()
{
return txtLevel_.getText();
}
public String getMovement()
{
return txtMovement_.getText();
}
public String getMovementType()
{
return txtMovementType_.getText();
}
public String getRace()
{
return txtRace_.getText();
}
public String getTraitsNumber()
{
return txtTraitsNumber_.getText();
}
public String getUnitTypeImage()
{
return txtImage_.getText();
}
public String getProfile()
{
return txtProfile_.getText();
}
public String getUndeadVariation()
{
return txtUndeadVariation_.getText();
}
public String getZoc()
{
return cmbZoc_.getText();
}
public String getEllipse()
{
return txtEllipse_.getText();
}
public String getDieSound()
{
return txtDieSound_.getText();
}
public String getDecscription()
{
return txtDecscription_.getText();
}
public String getIgnoreTraits()
{
return cmbIgnoreTraits_.getText();
}
public String getHideHelp()
{
return cmbHideHelp_.getText();
}
public String getBaseUnitId()
{
return txtBaseUnitId_.getText();
}
public String getGender()
{
return cmbGender.getText();
}
public String getAttacks()
{
return txtAttacks.getText();
}
public String getUsage()
{
return txtUsage_.getText();
}
}

View file

@ -0,0 +1,134 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import java.util.ArrayList;
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.Group;
import org.eclipse.swt.widgets.List;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.utils.ListUtils;
public class UnitTypePage1 extends WizardPage
{
private List lstAttack_;
private List lstAdvancement_;
java.util.List<String> attacks_;
java.util.List<String> advancements_;
public UnitTypePage1() {
super("unitTypePage1");
setTitle("Unit type wizard");
setDescription("Unit type details");
attacks_ = new ArrayList<String>();
advancements_ = new ArrayList<String>();
}
@Override
public void createControl(Composite parent)
{
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
container.setLayout(new GridLayout(2, false));
Group grpattack = new Group(container, SWT.NONE);
grpattack.setLayout(null);
grpattack.setText("[attack]");
lstAttack_ = new List(grpattack, SWT.BORDER);
lstAttack_.setBounds(4, 25, 190, 68);
lstAttack_.setData(attacks_);
Button addAttack = new Button(grpattack, SWT.NONE);
addAttack.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addItem(lstAttack_, "attack");
}
});
addAttack.setText("Add");
addAttack.setBounds(200, 24, 65, 25);
Button RemoveAttack = new Button(grpattack, SWT.NONE);
RemoveAttack.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeItem(lstAttack_);
}
});
RemoveAttack.setText("Remove");
RemoveAttack.setBounds(200, 68, 65, 25);
Group grpadvancement = new Group(container, SWT.NONE);
grpadvancement.setLayout(null);
grpadvancement.setText("[advancement]");
lstAdvancement_ = new List(grpadvancement, SWT.BORDER);
lstAdvancement_.setBounds(4, 25, 190, 68);
lstAdvancement_.setData(advancements_);
Button addAdvancement = new Button(grpadvancement, SWT.NONE);
addAdvancement.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addItem(lstAdvancement_, "advancement");
}
});
addAdvancement.setText("Add");
addAdvancement.setBounds(200, 24, 65, 25);
Button btnRemoveAdvancement = new Button(grpadvancement, SWT.NONE);
btnRemoveAdvancement.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeItem(lstAdvancement_);
}
});
btnRemoveAdvancement.setText("Remove");
btnRemoveAdvancement.setBounds(200, 68, 65, 25);
setPageComplete(true);
}
private void addItem(List targetList, String type)
{
}
@SuppressWarnings("unchecked")
private void removeItem(List targetList)
{
if (targetList.getItemCount() == 0 || targetList.getSelectionCount() == 0)
{
GUIUtils.showMessageBox("Please select an item before trying to remove it.");
return;
}
((java.util.List<String>) targetList.getData()).remove(targetList.getSelectionIndex());
targetList.remove(targetList.getSelectionIndex());
}
public String getAdvancements()
{
return ListUtils.concatenateList(advancements_, "\n\t");
}
public String getAttacks()
{
return ListUtils.concatenateList(attacks_, "\n\t");
}
}

View file

@ -0,0 +1,60 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import java.util.ArrayList;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
import wesnoth_eclipse_plugin.wizards.ReplaceableParameter;
import wesnoth_eclipse_plugin.wizards.TemplateProvider;
public class UnitTypeWizard extends NewWizardTemplate
{
private boolean isFinished_ = false;
private UnitTypePage0 page0_;
public UnitTypeWizard() {
setWindowTitle("Unittype tag wizard");
}
@Override
public void addPages()
{
page0_ = new UnitTypePage0();
addPage(page0_);
super.addPages();
}
@Override
public boolean isFinished()
{
return isFinished_;
}
@Override
public boolean performFinish()
{
isFinished_ = true;
ArrayList<ReplaceableParameter> params = new ArrayList<ReplaceableParameter>();
objectName_ = page0_.getName();
//params.add(new ReplaceableParameter("$$movetype_name", page0_.getName()));
String template = TemplateProvider.getInstance().getProcessedTemplate("unit_type", params);
if (template == null)
{
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(), "Template for \"unit_type\" not found.");
return false;
}
data_ = template;
return true;
}
}

View file

@ -0,0 +1,155 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.utils.WorkspaceUtils;
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
import wesnoth_eclipse_plugin.wizards.ReplaceableParameter;
import wesnoth_eclipse_plugin.wizards.TemplateProvider;
public class UnitsNewWizard extends NewWizardTemplate
{
UnitsPage0 page0_;
public UnitsNewWizard() {
setWindowTitle("Unit type wizard");
}
@Override
public void addPages()
{
page0_ = new UnitsPage0(selection_);
addPage(page0_);
super.addPages();
}
@Override
public boolean performFinish()
{
final String containerName = page0_.getDirectoryName();
final String fileName = page0_.getFileName();
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException
{
try
{
doFinish(containerName, fileName, monitor);
} catch (CoreException e)
{
throw new InvocationTargetException(e);
} finally
{
monitor.done();
}
}
};
try
{
getContainer().run(false, false, op);
} catch (InterruptedException e)
{
return false;
} catch (InvocationTargetException e)
{
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), "Error", realException.getMessage());
return false;
}
return true;
}
private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException
{
monitor.beginTask("Creating " + fileName, 10);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(new Path(containerName));
IContainer container = (IContainer) resource;
final IFile file = container.getFile(new Path(fileName));
try
{
InputStream stream = getUnitStream();
if (stream == null)
return;
if (file.exists())
{
file.setContents(stream, true, true, monitor);
}
else
{
file.create(stream, true, monitor);
}
stream.close();
} catch (IOException e)
{
e.printStackTrace();
}
monitor.worked(5);
monitor.setTaskName("Opening file for editing...");
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run()
{
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try
{
IDE.openEditor(page, file, true);
} catch (PartInitException e)
{
}
}
});
monitor.worked(5);
}
private InputStream getUnitStream()
{
ArrayList<ReplaceableParameter> params = new ArrayList<ReplaceableParameter>();
params.add(new ReplaceableParameter("$$unit_types", page0_.getUnitTypes()));
params.add(new ReplaceableParameter("$$traits", page0_.getTraits()));
params.add(new ReplaceableParameter("$$move_types", page0_.getMoveTypes()));
params.add(new ReplaceableParameter("$$races", page0_.getRaces()));
String template = TemplateProvider.getInstance().getProcessedTemplate("units", params);
if (template == null)
{
GUIUtils.showMessageBox(WorkspaceUtils.getWorkbenchWindow(), "Template for \"units\" not found.");
return null;
}
return new ByteArrayInputStream(template.getBytes());
}
}

View file

@ -0,0 +1,378 @@
/**
* @author Timotei Dolean
*
*/
package wesnoth_eclipse_plugin.wizards.unit;
import java.util.ArrayList;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.TypedEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
import wesnoth_eclipse_plugin.Activator;
import wesnoth_eclipse_plugin.utils.GUIUtils;
import wesnoth_eclipse_plugin.utils.ListUtils;
import wesnoth_eclipse_plugin.wizards.NewWizardTemplate;
public class UnitsPage0 extends WizardPage
{
private IStructuredSelection selection_;
private Text txtDirectory_;
private Text txtFileName_;
private List selectedList_;
java.util.List<String> unitTypes_;
java.util.List<String> traits_;
java.util.List<String> moveTypes_;
java.util.List<String> races_;
private List lstUnitTypes_;
private List lstTraits_;
private List lstMoveTypes_;
private List lstRaces_;
public UnitsPage0(IStructuredSelection selection) {
super("unitPage0");
setTitle("New unit wizard");
setDescription("Create a new unit");
selection_ = selection;
unitTypes_ = new ArrayList<String>();
traits_ = new ArrayList<String>();
moveTypes_ = new ArrayList<String>();
races_ = new ArrayList<String>();
}
@Override
public void createControl(Composite parent)
{
ModifyListener modifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e)
{
updatePageIsComplete();
}
};
SelectionAdapter listSelection = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
updateSelection(e);
}
};
MouseAdapter listSelectionMouse = new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e)
{
updateSelection(e);
}
};
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
container.setLayout(null);
Button button = new Button(container, SWT.NONE);
button.setText("Browse...");
button.setBounds(505, 10, 59, 25);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
handleBrowse();
}
});
txtDirectory_ = new Text(container, SWT.BORDER);
txtDirectory_.setBounds(90, 12, 409, 21);
txtDirectory_.addModifyListener(modifyListener);
Label label = new Label(container, SWT.NONE);
label.setText("Directory* :");
label.setBounds(10, 15, 75, 15);
Label label_1 = new Label(container, SWT.NONE);
label_1.setText("File name* :");
label_1.setBounds(10, 43, 75, 15);
txtFileName_ = new Text(container, SWT.BORDER);
txtFileName_.setBounds(90, 40, 409, 21);
txtFileName_.addModifyListener(modifyListener);
lstUnitTypes_ = new List(container, SWT.BORDER);
lstUnitTypes_.setBounds(10, 85, 120, 80);
lstUnitTypes_.addSelectionListener(listSelection);
lstUnitTypes_.addMouseListener(listSelectionMouse);
lstUnitTypes_.setData(unitTypes_);
Label lblUnitTypes = new Label(container, SWT.NONE);
lblUnitTypes.setBounds(40, 64, 64, 15);
lblUnitTypes.setText("Unit types:");
lstTraits_ = new List(container, SWT.BORDER);
lstTraits_.setBounds(155, 85, 120, 80);
lstTraits_.addSelectionListener(listSelection);
lstTraits_.addMouseListener(listSelectionMouse);
lstTraits_.setData(traits_);
Label lblMoveTypes = new Label(container, SWT.NONE);
lblMoveTypes.setText("Move types:");
lblMoveTypes.setBounds(326, 64, 75, 15);
lstMoveTypes_ = new List(container, SWT.BORDER);
lstMoveTypes_.setBounds(298, 85, 120, 80);
lstMoveTypes_.addSelectionListener(listSelection);
lstMoveTypes_.addMouseListener(listSelectionMouse);
lstMoveTypes_.setData(moveTypes_);
Button btnAdd = new Button(container, SWT.NONE);
btnAdd.setBounds(191, 171, 84, 25);
btnAdd.setText("Add");
btnAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
addNewItem();
}
});
Button btnRemove = new Button(container, SWT.NONE);
btnRemove.setBounds(298, 171, 84, 25);
btnRemove.setText("Remove");
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e)
{
removeSelectedItem();
}
});
lstRaces_ = new List(container, SWT.BORDER);
lstRaces_.setBounds(444, 85, 120, 80);
lstRaces_.addSelectionListener(listSelection);
lstRaces_.addMouseListener(listSelectionMouse);
lstRaces_.setData(races_);
Label lblRaces = new Label(container, SWT.NONE);
lblRaces.setText("Races:");
lblRaces.setBounds(478, 67, 46, 15);
Label lblTraits = new Label(container, SWT.NONE);
lblTraits.setText("Traits:");
lblTraits.setBounds(180, 67, 64, 15);
initialize();
updatePageIsComplete();
}
private void updateSelection(TypedEvent e)
{
if (!(e.getSource() instanceof List))
return;
if (selectedList_ != null && selectedList_ != (List) e.getSource())
selectedList_.deselectAll();
selectedList_ = (List) e.getSource();
}
@SuppressWarnings("unchecked")
private void removeSelectedItem()
{
if (selectedList_ == null || selectedList_.getSelection().length == 0)
{
GUIUtils.showMessageBox("Please select an item from a list first.");
return;
}
if (selectedList_.getData() != null && selectedList_.getData() instanceof java.util.List<?>)
((java.util.List<String>) selectedList_.getData()).remove(selectedList_.getSelectionIndex());
selectedList_.remove(selectedList_.getSelectionIndex());
}
@SuppressWarnings("unchecked")
private void addNewItem()
{
if (selectedList_ == null)
{
GUIUtils.showMessageBox("Please select a list first.");
return;
}
NewWizardTemplate wizard = null;
if (selectedList_.hashCode() == lstMoveTypes_.hashCode())
{
wizard = new MoveTypeWizard();
}
else if (selectedList_.hashCode() == lstRaces_.hashCode())
{
wizard = new RaceWizard();
}
else if (selectedList_.hashCode() == lstTraits_.hashCode())
{
//wizard = new TraitWizard();
GUIUtils.showMessageBox("Not implemented yet");
return;
}
else if (selectedList_.hashCode() == lstUnitTypes_.hashCode())
{
wizard = new UnitTypeWizard();
}
if (wizard == null)
return;
wizard.init(Activator.getDefault().getWorkbench(), selection_);
wizard.setForcePreviousAndNextButtons(true);
WizardDialog wizardDialog = new WizardDialog(getShell(), wizard);
wizardDialog.create();
wizardDialog.getShell().setLocation(getShell().getBounds().x, getShell().getBounds().y);
Activator.getDefault().getWorkbench().getHelpSystem().setHelp(wizardDialog.getShell(),
"org.eclipse.ui.new_wizard_context");
wizardDialog.open();
if (!wizard.isFinished())
return;
if (selectedList_.getData() != null && selectedList_.getData() instanceof java.util.List<?>)
((java.util.List<String>) selectedList_.getData()).add(wizard.getData().toString());
selectedList_.add(wizard.getObjectName());
}
private void updatePageIsComplete()
{
IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getDirectoryName()));
setPageComplete(false);
String fileName = getFileName();
if (getDirectoryName().isEmpty())
{
setErrorMessage("You need to specify a valid directory path first.");
return;
}
if (container == null || !container.exists() || !(container instanceof IContainer))
{
setErrorMessage("The directory must be created first and the selected folder to exist.");
return;
}
if (fileName.isEmpty())
{
setErrorMessage("File name must be specified.");
return;
}
if (fileName.replace('\\', '/').indexOf('/', 1) > 0)
{
setErrorMessage("File name must be valid.");
return;
}
int dotLoc = fileName.lastIndexOf('.');
if (dotLoc == -1 || fileName.substring(dotLoc + 1).equalsIgnoreCase("cfg") == false)
{
setErrorMessage("File extension must be 'cfg'.");
return;
}
setErrorMessage(null);
setPageComplete(true);
}
/**
* Tests if the current workbench selection is a suitable directory to use.
*/
private void initialize()
{
if (selection_ != null && selection_.isEmpty() == false &&
selection_ instanceof IStructuredSelection)
{
IStructuredSelection ssel = selection_;
if (ssel.size() > 1)
{
return;
}
Object obj = ssel.getFirstElement();
if (obj instanceof IResource)
{
IContainer container;
if (obj instanceof IContainer)
{
container = (IContainer) obj;
}
else
{
container = ((IResource) obj).getParent();
}
txtDirectory_.setText(container.getFullPath().toString());
}
}
}
private void handleBrowse()
{
ContainerSelectionDialog dialog =
new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
"Select a campaign project");
if (dialog.open() == ContainerSelectionDialog.OK)
{
Object[] result = dialog.getResult();
if (result.length == 1)
{
txtDirectory_.setText(((Path) result[0]).toString());
}
}
}
public String getDirectoryName()
{
return txtDirectory_.getText();
}
public String getFileName()
{
return txtFileName_.getText();
}
public String getUnitTypes()
{
return ListUtils.concatenateList(unitTypes_, "\n\t");
}
public String getTraits()
{
return ListUtils.concatenateList(traits_, "\n\t");
}
public String getMoveTypes()
{
return ListUtils.concatenateList(moveTypes_, "\n\t");
}
public String getRaces()
{
return ListUtils.concatenateList(races_, "\n\t");
}
}

View file

@ -0,0 +1,13 @@
[movetype]
name=$$movetype_name
flies=$$flies
[movement_costs]
$$movement_costs
[/movement_costs]
[defense]
$$defense
[/defense]
[resistance]
$$resistance
[/resistance]
[/movetype]

View file

@ -0,0 +1,11 @@
[race]
id=$$race_id
plural_name=$$plural_name
male_name=$$male_name
female_name=$$female_name
description=$$description
num_traits=$$num_traits
ignore_global_traits=$$ignore_global_traits
$$traits
[/race]

View file

@ -0,0 +1,2 @@
[trait]
[/trait]

View file

@ -0,0 +1,3 @@
[unit_type]
[/unit_type]

View file

@ -0,0 +1,6 @@
[units]
$$unit_types
$$traits
$$movetypes
$$races
[/units]

View file

@ -8,3 +8,8 @@ build_xml templates/build.xml
multiplayer templates/multiplayer.txt
era templates/era.txt
faction templates/faction.txt
units templates/units/units.txt
movetype templates/units/movetype.txt
race templates/units/race.txt
unit_type templates/units/unit_type.txt
trait templates/units/trait.txt