void SetWarpIndex(int i)
{
List<WarpSourceData> sourceDataList = sourceGroup.GetMapWarpSourceData(map);
indexSpinButton.Adjustment.Lower = -1;
indexSpinButton.Adjustment.Upper = sourceDataList.Count-1;
if (i > indexSpinButton.Adjustment.Upper)
i = (int)indexSpinButton.Adjustment.Upper;
indexSpinButton.Value = i;
valueEditorContainer.Remove(valueEditorContainer.Child);
if (i == -1) {
SetDestIndex(-1,-1);
return;
}
Gtk.HBox hbox = new Gtk.HBox();
WarpSourceData warpSourceData = sourceDataList[i];
if (warpSourceData.WarpSourceType == WarpSourceType.StandardWarp)
SetDestIndex(warpSourceData.DestGroup, warpSourceData.DestIndex);
sourceEditor = new ValueReferenceEditor(Project,
warpSourceData);
Alignment a = new Alignment(0,0,0,0);
a.Add(sourceEditor);
hbox.Add(a);
if (warpSourceData.WarpSourceType == WarpSourceType.PointerWarp) {
Table table = new Table(1, 1, false);
table.ColumnSpacing = 6;
table.RowSpacing = 6;
SpinButton pointerSpinButton = new SpinButton(0,10,1);
EventHandler valueChangedHandler = delegate(object sender, EventArgs e) {
WarpSourceData pointedData = warpSourceData.GetPointedWarp();
pointerSpinButton.Adjustment.Lower = 0;
pointerSpinButton.Adjustment.Upper = warpSourceData.GetPointedChainLength()-1;
if (pointerSpinButton.ValueAsInt > pointerSpinButton.Adjustment.Upper) {
pointerSpinButton.Value = pointerSpinButton.Adjustment.Upper;
}
int index = pointerSpinButton.ValueAsInt;
while (index > 0) {
pointedData = pointedData.GetNextWarp();
index--;
}
table.Remove(destEditor);
destEditor = new ValueReferenceEditor(Project, pointedData);
destEditor.AddDataModifiedHandler(delegate() {
SetDestIndex(pointedData.DestGroup, pointedData.DestIndex);
});
table.Attach(destEditor, 0, 2, 1, 2);
SetDestIndex(pointedData.DestGroup, pointedData.DestIndex);
};
pointerSpinButton.ValueChanged += valueChangedHandler;
// Button which, when clicked, adds a new PointedData to the
// "chain".
Gtk.Button addPointedWarpButton =
new Gtk.Button(new Gtk.Image(Gtk.Stock.Add, Gtk.IconSize.Button));
addPointedWarpButton.Clicked += delegate(object sender, EventArgs e) {
WarpSourceData pointedData = warpSourceData.GetPointedWarp();
while (pointedData.GetNextWarp() != null) {
pointedData = pointedData.GetNextWarp();
}
WarpSourceData nextData = new WarpSourceData(Project,
WarpSourceData.WarpCommands[(int)WarpSourceType.PointedWarp],
WarpSourceData.DefaultValues[(int)WarpSourceType.PointedWarp],
pointedData.FileParser,
new List<int>{-1});
pointedData.SetNextWarp(nextData);
pointerSpinButton.Adjustment.Upper++;
pointerSpinButton.Value = warpSourceData.GetPointedChainLength()-1;
valueChangedHandler(null, null);
};
// Button which removes a PointedData from the "chain", unless
// there is only one remaining.
Gtk.Button removePointedWarpButton =
new Gtk.Button(new Gtk.Image(Gtk.Stock.Remove, Gtk.IconSize.Button));
removePointedWarpButton.Clicked += delegate(object sender, EventArgs e) {
int index = pointerSpinButton.ValueAsInt;
WarpSourceData pointedData = warpSourceData.GetPointedWarp();
if (pointedData.GetPointedChainLength() <= 1) // Don't delete the last one
return;
while (index > 0) {
pointedData = pointedData.GetNextWarp();
index--;
}
pointedData.FileParser.RemoveFileComponent(pointedData);
valueChangedHandler(null, null);
};
table.Attach(new Gtk.Label("Pointer index"), 0, 1, 0, 1);
table.Attach(pointerSpinButton, 1, 2, 0, 1);
table.Attach(addPointedWarpButton, 2, 3, 0, 1);
table.Attach(removePointedWarpButton, 3, 4, 0, 1);
// Invoke handler
valueChangedHandler(pointerSpinButton, null);
Frame frame = new Frame(warpSourceData.PointerString);
frame.Add(table);
hbox.Add(frame);
}
else { // Not pointerWarp
sourceEditor.AddDataModifiedHandler(delegate() {
SetDestIndex(warpSourceData.DestGroup, warpSourceData.DestIndex);
});
}
valueEditorContainer.Add(hbox);
valueEditorContainer.ShowAll();
}