mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-09-12 21:25:20 -05:00
Labels draft
This commit is contained in:
@@ -258,7 +258,9 @@
|
||||
<Compile Include="ROMFiles\SafariZoneObjectRequirement.cs" />
|
||||
<Compile Include="ROMFiles\ScriptAction.cs" />
|
||||
<Compile Include="ROMFiles\ScriptActionContainer.cs" />
|
||||
<Compile Include="ROMFiles\ScriptCommandContainer.cs" />
|
||||
<Compile Include="ROMFiles\ScriptCommandPosition.cs" />
|
||||
<Compile Include="ROMFiles\ScriptLabeledSection.cs" />
|
||||
<Compile Include="ROMFiles\ScriptParameter.cs" />
|
||||
<Compile Include="ROMFiles\ScriptReference.cs" />
|
||||
<Compile Include="ROMFiles\SpeciesFile.cs" />
|
||||
<Compile Include="ROMFiles\TrainerFile.cs" />
|
||||
|
||||
1423
DS_Map/Editors/ScriptEditor.Designer.cs
generated
1423
DS_Map/Editors/ScriptEditor.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@@ -13,14 +13,8 @@ using System.Globalization;
|
||||
namespace DSPRE.Editors {
|
||||
public partial class ScriptEditor : UserControl {
|
||||
public bool scriptEditorIsReady { get; set; } = false;
|
||||
private Scintilla ScriptTextArea;
|
||||
private Scintilla FunctionTextArea;
|
||||
private Scintilla ActionTextArea;
|
||||
private SearchManager scriptSearchManager;
|
||||
private SearchManager functionSearchManager;
|
||||
private SearchManager actionSearchManager;
|
||||
private Scintilla currentScintillaEditor;
|
||||
private SearchManager currentSearchManager;
|
||||
private Scintilla ScriptTextArea;
|
||||
private bool scriptsDirty = false;
|
||||
private bool functionsDirty = false;
|
||||
private bool actionsDirty = false;
|
||||
@@ -118,7 +112,6 @@ namespace DSPRE.Editors {
|
||||
public void OpenScriptEditor(MainProgram parent, int scriptFileID) {
|
||||
SetupScriptEditor(parent);
|
||||
|
||||
scriptEditorTabControl.SelectedIndex = 0;
|
||||
selectScriptFileComboBox.SelectedIndex = scriptFileID;
|
||||
EditorPanels.mainTabControl.SelectedTab = EditorPanels.scriptEditorTabPage;
|
||||
}
|
||||
@@ -132,9 +125,6 @@ namespace DSPRE.Editors {
|
||||
secondaryKeyWords = String.Join(" ", RomInfo.ScriptComparisonOperatorsDict.Values) +
|
||||
" " + String.Join(" ", ScriptDatabase.specialOverworlds.Values) +
|
||||
" " + String.Join(" ", ScriptDatabase.overworldDirections.Values) +
|
||||
" " + ScriptFile.ContainerTypes.Script.ToString() +
|
||||
" " + ScriptFile.ContainerTypes.Function.ToString() +
|
||||
" " + ScriptFile.ContainerTypes.Action.ToString() +
|
||||
" " + Event.EventType.Overworld +
|
||||
" " + Overworld.MovementCodeKW;
|
||||
secondaryKeyWords += " " + secondaryKeyWords.ToUpper() + " " + secondaryKeyWords.ToLower();
|
||||
@@ -145,52 +135,25 @@ namespace DSPRE.Editors {
|
||||
scintillaScriptsPanel.Controls.Clear();
|
||||
scintillaScriptsPanel.Controls.Add(ScriptTextArea);
|
||||
|
||||
FunctionTextArea = new Scintilla();
|
||||
functionSearchManager = new SearchManager(EditorPanels.MainProgram, FunctionTextArea, panelFindFunctionTextBox, PanelSearchFunctions);
|
||||
scintillaFunctionsPanel.Controls.Clear();
|
||||
scintillaFunctionsPanel.Controls.Add(FunctionTextArea);
|
||||
|
||||
ActionTextArea = new Scintilla();
|
||||
actionSearchManager = new SearchManager(EditorPanels.MainProgram, ActionTextArea, panelFindActionTextBox, PanelSearchActions);
|
||||
scintillaActionsPanel.Controls.Clear();
|
||||
scintillaActionsPanel.Controls.Add(ActionTextArea);
|
||||
|
||||
currentScintillaEditor = ScriptTextArea;
|
||||
currentSearchManager = scriptSearchManager;
|
||||
|
||||
// BASIC CONFIG
|
||||
ScriptTextArea.TextChanged += (OnTextChangedScript);
|
||||
FunctionTextArea.TextChanged += (OnTextChangedFunction);
|
||||
ActionTextArea.TextChanged += (OnTextChangedAction);
|
||||
|
||||
// INITIAL VIEW CONFIG
|
||||
InitialViewConfig(ScriptTextArea);
|
||||
InitialViewConfig(FunctionTextArea);
|
||||
InitialViewConfig(ActionTextArea);
|
||||
|
||||
InitSyntaxColoring(ScriptTextArea);
|
||||
InitSyntaxColoring(FunctionTextArea);
|
||||
InitSyntaxColoring(ActionTextArea);
|
||||
|
||||
// NUMBER MARGIN
|
||||
InitNumberMargin(ScriptTextArea, ScriptTextArea_MarginClick);
|
||||
InitNumberMargin(FunctionTextArea, FunctionTextArea_MarginClick);
|
||||
InitNumberMargin(ActionTextArea, ActionTextArea_MarginClick);
|
||||
|
||||
// BOOKMARK MARGIN
|
||||
InitBookmarkMargin(ScriptTextArea);
|
||||
InitBookmarkMargin(FunctionTextArea);
|
||||
InitBookmarkMargin(ActionTextArea);
|
||||
|
||||
// CODE FOLDING MARGIN
|
||||
InitCodeFolding(ScriptTextArea);
|
||||
InitCodeFolding(FunctionTextArea);
|
||||
InitCodeFolding(ActionTextArea);
|
||||
|
||||
// INIT HOTKEYS
|
||||
InitHotkeys(ScriptTextArea, scriptSearchManager);
|
||||
InitHotkeys(FunctionTextArea, functionSearchManager);
|
||||
InitHotkeys(ActionTextArea, actionSearchManager);
|
||||
|
||||
// INIT TOOLTIPS DWELLING
|
||||
/*
|
||||
@@ -202,6 +165,8 @@ namespace DSPRE.Editors {
|
||||
FunctionTextArea.DwellEnd += TextArea_DwellEnd;
|
||||
FunctionTextArea.DwellStart += TextArea_DwellStart;
|
||||
*/
|
||||
|
||||
// Style for prefixed words (label_*, script_*)
|
||||
}
|
||||
|
||||
private void populate_selectScriptFileComboBox(int selectedIndex = 0) {
|
||||
@@ -227,7 +192,6 @@ namespace DSPRE.Editors {
|
||||
}
|
||||
|
||||
private void InitSyntaxColoring(Scintilla textArea) {
|
||||
// Configure the default style
|
||||
textArea.StyleResetDefault();
|
||||
textArea.Styles[Style.Default].Font = "Consolas";
|
||||
textArea.Styles[Style.Default].Size = 12;
|
||||
@@ -245,10 +209,62 @@ namespace DSPRE.Editors {
|
||||
textArea.Styles[Style.Python.Word].ForeColor = Color.FromArgb(0x48A8EE);
|
||||
textArea.Styles[Style.Python.Word2].ForeColor = Color.FromArgb(0xF98906);
|
||||
|
||||
// Set the lexer and keywords
|
||||
textArea.Lexer = Lexer.Python;
|
||||
|
||||
textArea.SetKeywords(0, cmdKeyWords);
|
||||
textArea.SetKeywords(1, secondaryKeyWords);
|
||||
|
||||
// Configure indicators for prefix highlighting
|
||||
textArea.Indicators[0].Style = IndicatorStyle.TextFore;
|
||||
textArea.Indicators[0].ForeColor = Color.FromArgb(0x8A2BE2); // Purple for label_*
|
||||
|
||||
textArea.Indicators[1].Style = IndicatorStyle.TextFore;
|
||||
textArea.Indicators[1].ForeColor = Color.FromArgb(0x00CED1); // Cyan for script_*
|
||||
|
||||
// Apply the highlighting
|
||||
textArea.TextChanged += (sender, e) => HighlightPrefixedWords(textArea);
|
||||
|
||||
// Initial highlighting
|
||||
HighlightPrefixedWords(textArea);
|
||||
}
|
||||
|
||||
private void HighlightPrefixedWords(Scintilla textArea) {
|
||||
// Clear existing indicators
|
||||
textArea.IndicatorCurrent = 0;
|
||||
textArea.IndicatorClearRange(0, textArea.TextLength);
|
||||
textArea.IndicatorCurrent = 1;
|
||||
textArea.IndicatorClearRange(0, textArea.TextLength);
|
||||
|
||||
// Use Scintilla-specific regex syntax
|
||||
// Enable regex mode
|
||||
textArea.SearchFlags = SearchFlags.Regex;
|
||||
|
||||
// Search for label_* words
|
||||
textArea.IndicatorCurrent = 0;
|
||||
textArea.TargetStart = 0;
|
||||
textArea.TargetEnd = textArea.TextLength;
|
||||
|
||||
// Using \< and \> for word boundaries in Scintilla
|
||||
string labelPattern = "\\<label_[a-zA-Z0-9_]+\\>";
|
||||
|
||||
while (textArea.SearchInTarget(labelPattern) != -1) {
|
||||
textArea.IndicatorFillRange(textArea.TargetStart, textArea.TargetEnd - textArea.TargetStart);
|
||||
textArea.TargetStart = textArea.TargetEnd;
|
||||
textArea.TargetEnd = textArea.TextLength;
|
||||
}
|
||||
|
||||
// Search for script_* words
|
||||
textArea.IndicatorCurrent = 1;
|
||||
textArea.TargetStart = 0;
|
||||
textArea.TargetEnd = textArea.TextLength;
|
||||
|
||||
string scriptPattern = "\\<script_[a-zA-Z0-9_]+\\>";
|
||||
|
||||
while (textArea.SearchInTarget(scriptPattern) != -1) {
|
||||
textArea.IndicatorFillRange(textArea.TargetStart, textArea.TargetEnd - textArea.TargetStart);
|
||||
textArea.TargetStart = textArea.TargetEnd;
|
||||
textArea.TargetEnd = textArea.TextLength;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitNumberMargin(Scintilla textArea, EventHandler<MarginClickEventArgs> textArea_MarginClick) {
|
||||
@@ -372,10 +388,8 @@ namespace DSPRE.Editors {
|
||||
private void ScriptEditorSetClean() {
|
||||
Helpers.DisableHandlers();
|
||||
|
||||
scriptsTabPage.Text = ScriptFile.ContainerTypes.Script.ToString() + "s";
|
||||
functionsTabPage.Text = ScriptFile.ContainerTypes.Function.ToString() + "s";
|
||||
actionsTabPage.Text = ScriptFile.ContainerTypes.Action.ToString() + "s";
|
||||
scriptsDirty = functionsDirty = actionsDirty = false;
|
||||
//scriptsTabPage.Text = ScriptFile.ContainerTypes.Script.ToString() + "s";
|
||||
scriptsDirty = false;
|
||||
|
||||
Helpers.EnableHandlers();
|
||||
}
|
||||
@@ -383,33 +397,13 @@ namespace DSPRE.Editors {
|
||||
private void OnTextChangedScript(object sender, EventArgs e) {
|
||||
ScriptTextArea.Margins[NUMBER_MARGIN].Width = ScriptTextArea.Lines.Count.ToString().Length * 13;
|
||||
scriptsDirty = true;
|
||||
scriptsTabPage.Text = ScriptFile.ContainerTypes.Script.ToString() + "s" + "*";
|
||||
}
|
||||
|
||||
private void OnTextChangedFunction(object sender, EventArgs e) {
|
||||
FunctionTextArea.Margins[NUMBER_MARGIN].Width = FunctionTextArea.Lines.Count.ToString().Length * 13;
|
||||
functionsDirty = true;
|
||||
functionsTabPage.Text = ScriptFile.ContainerTypes.Function.ToString() + "s" + "*";
|
||||
}
|
||||
|
||||
private void OnTextChangedAction(object sender, EventArgs e) {
|
||||
ActionTextArea.Margins[NUMBER_MARGIN].Width = ActionTextArea.Lines.Count.ToString().Length * 13;
|
||||
actionsDirty = true;
|
||||
actionsTabPage.Text = ScriptFile.ContainerTypes.Action.ToString() + "s" + "*";
|
||||
//scriptsTabPage.Text = ScriptFile.ContainerTypes.Script.ToString() + "s" + "*";
|
||||
}
|
||||
|
||||
private void ScriptTextArea_MarginClick(object sender, MarginClickEventArgs e) {
|
||||
MarginClick(ScriptTextArea, e);
|
||||
}
|
||||
|
||||
private void FunctionTextArea_MarginClick(object sender, MarginClickEventArgs e) {
|
||||
MarginClick(FunctionTextArea, e);
|
||||
}
|
||||
|
||||
private void ActionTextArea_MarginClick(object sender, MarginClickEventArgs e) {
|
||||
MarginClick(ActionTextArea, e);
|
||||
}
|
||||
|
||||
private void MarginClick(Scintilla textArea, MarginClickEventArgs e) {
|
||||
if (e.Margin == BOOKMARK_MARGIN) {
|
||||
// Do we have a marker for this line?
|
||||
@@ -480,12 +474,12 @@ namespace DSPRE.Editors {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Keep all the code that handles unsaved changes
|
||||
if (scriptsDirty || functionsDirty || actionsDirty) {
|
||||
DialogResult d = MessageBox.Show("There are unsaved changes in this Script File.\nDo you wish to discard them?", "Unsaved work", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
||||
|
||||
if (!d.Equals(DialogResult.Yes)) {
|
||||
Helpers.DisableHandlers();
|
||||
// selectScriptFileComboBox.SelectedItem = currentScriptFile;
|
||||
selectScriptFileComboBox.SelectedIndex = (int)currentScriptFile.fileID;
|
||||
Helpers.EnableHandlers();
|
||||
return false;
|
||||
@@ -495,18 +489,13 @@ namespace DSPRE.Editors {
|
||||
Helpers.DisableHandlers();
|
||||
|
||||
ScriptFile lastScriptFile = currentScriptFile;
|
||||
// currentScriptFile = (ScriptFile)selectScriptFileComboBox.SelectedItem;
|
||||
currentScriptFile = new ScriptFile(selectScriptFileComboBox.SelectedIndex); // Load script file
|
||||
// Load the script file using our new label-based constructor
|
||||
currentScriptFile = new ScriptFile(selectScriptFileComboBox.SelectedIndex);
|
||||
|
||||
// Clear only the script text area and nav listbox
|
||||
ScriptTextArea.ClearAll();
|
||||
FunctionTextArea.ClearAll();
|
||||
ActionTextArea.ClearAll();
|
||||
|
||||
scriptsNavListbox.Items.Clear();
|
||||
functionsNavListbox.Items.Clear();
|
||||
actionsNavListbox.Items.Clear();
|
||||
|
||||
//prevent buttons from flickering when the combobox selection changes
|
||||
bool typeChanged = true;
|
||||
if (lastScriptFile != null) {
|
||||
typeChanged = lastScriptFile.isLevelScript != currentScriptFile.isLevelScript;
|
||||
@@ -545,9 +534,7 @@ namespace DSPRE.Editors {
|
||||
}
|
||||
|
||||
if (!currentScriptFile.isLevelScript) {
|
||||
displayScriptFile(ScriptFile.ContainerTypes.Script, currentScriptFile.allScripts, scriptsNavListbox, ScriptTextArea);
|
||||
displayScriptFile(ScriptFile.ContainerTypes.Function, currentScriptFile.allFunctions, functionsNavListbox, FunctionTextArea);
|
||||
displayScriptFileActions(ScriptFile.ContainerTypes.Action, currentScriptFile.allActions, actionsNavListbox, ActionTextArea);
|
||||
displayScriptFile(scriptsNavListbox, ScriptTextArea);
|
||||
}
|
||||
|
||||
ScriptEditorSetClean();
|
||||
@@ -558,84 +545,35 @@ namespace DSPRE.Editors {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void displayScriptFile(ScriptFile.ContainerTypes containerType, List<ScriptCommandContainer> commandList, ListBox navListBox, Scintilla textArea) {
|
||||
string buffer = "";
|
||||
/* Add commands */
|
||||
for (int i = 0; i < commandList.Count; i++) {
|
||||
ScriptCommandContainer scriptCommandContainer = commandList[i];
|
||||
|
||||
/* Write header */
|
||||
string header = containerType + " " + (i + 1);
|
||||
buffer += header + ':' + Environment.NewLine;
|
||||
navListBox.Items.Add(header);
|
||||
|
||||
/* If current command is identical to another, print UseScript instead of commands */
|
||||
if (scriptCommandContainer.usedScriptID < 0) {
|
||||
for (int j = 0; j < scriptCommandContainer.commands.Count; j++) {
|
||||
ScriptCommand command = scriptCommandContainer.commands[j];
|
||||
if (!ScriptDatabase.endCodes.Contains(command.id)) {
|
||||
buffer += '\t';
|
||||
}
|
||||
|
||||
buffer += command.name + Environment.NewLine;
|
||||
}
|
||||
} else {
|
||||
buffer += '\t' + "UseScript_#" + scriptCommandContainer.usedScriptID + Environment.NewLine;
|
||||
}
|
||||
|
||||
textArea.AppendText(buffer + Environment.NewLine);
|
||||
buffer = "";
|
||||
private void displayScriptFile(ListBox navListBox, Scintilla textArea) {
|
||||
if (currentScriptFile.CommandSequence == null || currentScriptFile.CommandSequence.Count == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void displayScriptFileActions(ScriptFile.ContainerTypes containerType, List<ScriptActionContainer> commandList, ListBox navListBox, Scintilla textArea) {
|
||||
/* Add movements */
|
||||
string buffer = "";
|
||||
for (int i = 0; i < commandList.Count; i++) {
|
||||
ScriptActionContainer currentCommand = commandList[i];
|
||||
|
||||
string header = containerType + " " + (i + 1);
|
||||
buffer += header + ':' + Environment.NewLine;
|
||||
navListBox.Items.Add(header);
|
||||
|
||||
for (int j = 0; j < currentCommand.commands.Count; j++) {
|
||||
ScriptAction command = currentCommand.commands[j];
|
||||
if (!ScriptDatabase.movementEndCodes.Contains(command.id)) {
|
||||
buffer += '\t';
|
||||
}
|
||||
|
||||
buffer += command.name + Environment.NewLine;
|
||||
// First add all labels to the nav listbox
|
||||
HashSet<string> addedLabels = new HashSet<string>();
|
||||
foreach (var cmdPos in currentScriptFile.CommandSequence) {
|
||||
if (!string.IsNullOrEmpty(cmdPos.Label) && !addedLabels.Contains(cmdPos.Label)) {
|
||||
navListBox.Items.Add(cmdPos.Label);
|
||||
addedLabels.Add(cmdPos.Label);
|
||||
}
|
||||
|
||||
textArea.AppendText(buffer + Environment.NewLine);
|
||||
buffer = "";
|
||||
}
|
||||
|
||||
// Generate the script text
|
||||
string scriptText = currentScriptFile.ToText();
|
||||
textArea.Text = scriptText;
|
||||
}
|
||||
|
||||
private void scriptEditorZoomInButton_Click(object sender, EventArgs e) {
|
||||
ZoomIn(currentScintillaEditor);
|
||||
ZoomIn(ScriptTextArea);
|
||||
}
|
||||
|
||||
private void scriptEditorZoomOutButton_Click(object sender, EventArgs e) {
|
||||
ZoomOut(currentScintillaEditor);
|
||||
ZoomOut(ScriptTextArea);
|
||||
}
|
||||
|
||||
private void scriptEditorZoomResetButton_Click(object sender, EventArgs e) {
|
||||
ZoomDefault(currentScintillaEditor);
|
||||
}
|
||||
|
||||
private void scriptEditorTabControl_TabIndexChanged(object sender, EventArgs e) {
|
||||
if (scriptEditorTabControl.SelectedTab == scriptsTabPage) {
|
||||
currentSearchManager = scriptSearchManager;
|
||||
currentScintillaEditor = ScriptTextArea;
|
||||
} else if (scriptEditorTabControl.SelectedTab == functionsTabPage) {
|
||||
currentSearchManager = functionSearchManager;
|
||||
currentScintillaEditor = FunctionTextArea;
|
||||
} else {
|
||||
//Actions
|
||||
currentSearchManager = actionSearchManager;
|
||||
currentScintillaEditor = ActionTextArea;
|
||||
}
|
||||
ZoomDefault(ScriptTextArea);
|
||||
}
|
||||
|
||||
private void removeScriptFileButton_Click(object sender, EventArgs e) {
|
||||
@@ -660,18 +598,20 @@ namespace DSPRE.Editors {
|
||||
/* Add new event file to event folder */
|
||||
int fileID = selectScriptFileComboBox.Items.Count;
|
||||
|
||||
ScriptFile scriptFile = new ScriptFile(
|
||||
scriptLines: new Scintilla { Text = "Script 1:\nEnd" }.Lines.ToStringsList(trim: true),
|
||||
functionLines: null,
|
||||
actionLines: null,
|
||||
fileID
|
||||
);
|
||||
// Create a simple script with one labeled section
|
||||
List<string> scriptLines = new List<string> {
|
||||
"script_0:",
|
||||
"\tEnd"
|
||||
};
|
||||
|
||||
//check if ScriptFile instance was created successfully
|
||||
// Use the new constructor that just takes script lines
|
||||
ScriptFile scriptFile = new ScriptFile(scriptLines, fileID);
|
||||
|
||||
// Check if ScriptFile instance was created successfully
|
||||
if (scriptFile.SaveToFileDefaultDir(fileID, showSuccessMessage: false)) {
|
||||
/* Update ComboBox and select new file */
|
||||
selectScriptFileComboBox.Items.Add(scriptFile);
|
||||
selectScriptFileComboBox.SelectedItem = scriptFile;
|
||||
selectScriptFileComboBox.Items.Add($"Script File {fileID}");
|
||||
selectScriptFileComboBox.SelectedIndex = selectScriptFileComboBox.Items.Count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,19 +619,13 @@ namespace DSPRE.Editors {
|
||||
/* Create new ScriptFile object using the values in the script editor */
|
||||
int fileID = currentScriptFile.fileID;
|
||||
|
||||
// We only need the script text area now, not function or action areas
|
||||
ScriptFile userEdited = new ScriptFile(
|
||||
scriptLines: ScriptTextArea.Lines.ToStringsList(trim: true),
|
||||
functionLines: FunctionTextArea.Lines.ToStringsList(trim: true),
|
||||
actionLines: ActionTextArea.Lines.ToStringsList(trim: true),
|
||||
fileID
|
||||
ScriptTextArea.Lines.ToStringsList(trim: true),
|
||||
fileID
|
||||
);
|
||||
|
||||
if (userEdited.hasNoScripts) {
|
||||
MessageBox.Show("This " + nameof(ScriptFile) + " couldn't be saved. A minimum of one script is required.", "Can't save", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
//check if ScriptFile instance was created successfully
|
||||
// Check if ScriptFile instance was created successfully
|
||||
if (userEdited.SaveToFileDefaultDir(fileID)) {
|
||||
currentScriptFile = userEdited;
|
||||
ScriptEditorSetClean();
|
||||
@@ -779,98 +713,54 @@ namespace DSPRE.Editors {
|
||||
scriptSearchManager.CloseSearch();
|
||||
}
|
||||
|
||||
private void BtnNextFindFunc_Click(object sender, EventArgs e) {
|
||||
findNext(functionSearchManager);
|
||||
}
|
||||
|
||||
private void BtnPrevFindFunc_Click(object sender, EventArgs e) {
|
||||
findNext(functionSearchManager);
|
||||
}
|
||||
|
||||
private void panelFindFunctionTextBox_TextChanged(object sender, EventArgs e) {
|
||||
findNext(functionSearchManager);
|
||||
}
|
||||
|
||||
private void functionTxtFind_KeyDown(object sender, KeyEventArgs e) {
|
||||
TxtFindKeyDown(functionSearchManager, e);
|
||||
}
|
||||
|
||||
private void BtnCloseFindFunc_Click(object sender, EventArgs e) {
|
||||
functionSearchManager.CloseSearch();
|
||||
}
|
||||
|
||||
private void BtnNextFindActions_Click(object sender, EventArgs e) {
|
||||
findNext(actionSearchManager);
|
||||
}
|
||||
|
||||
private void BtnPrevFindActions_Click(object sender, EventArgs e) {
|
||||
findNext(actionSearchManager);
|
||||
}
|
||||
|
||||
private void panelFindActionTextBox_TextChanged(object sender, EventArgs e) {
|
||||
findNext(actionSearchManager);
|
||||
}
|
||||
|
||||
private void actionTxtFind_KeyDown(object sender, KeyEventArgs e) {
|
||||
TxtFindKeyDown(actionSearchManager, e);
|
||||
}
|
||||
|
||||
private void BtnCloseFindActions_Click(object sender, EventArgs e) {
|
||||
actionSearchManager.CloseSearch();
|
||||
}
|
||||
|
||||
void scrollResultToTop(SearchManager searchManager) {
|
||||
int resultStart = searchManager.textAreaScintilla.CurrentLine - ScriptEditorSearchResult.ResultsPadding;
|
||||
searchManager.textAreaScintilla.FirstVisibleLine = resultStart;
|
||||
}
|
||||
|
||||
private void NavigatorGoTo(ListBox listBox, TabPage tabPage, SearchManager searchManager, ScriptFile.ContainerTypes containerType) {
|
||||
private void NavigatorGoTo(ListBox listBox, ScriptFile.ContainerTypes containerType) {
|
||||
if (listBox.SelectedIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
scriptEditorTabControl.SelectedTab = tabPage;
|
||||
int commandNumber = listBox.SelectedIndex + 1;
|
||||
string CommandBlockOpen = $"{containerType} {commandNumber}:";
|
||||
searchManager.Find(true, false, CommandBlockOpen);
|
||||
scriptSearchManager.Find(true, false, CommandBlockOpen);
|
||||
|
||||
scrollResultToTop(searchManager);
|
||||
scrollResultToTop(scriptSearchManager);
|
||||
}
|
||||
|
||||
private void scriptsNavListbox_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
NavigatorGoTo((ListBox)sender, scriptsTabPage, scriptSearchManager, ScriptFile.ContainerTypes.Script);
|
||||
NavigatorGoTo((ListBox)sender, ScriptFile.ContainerTypes.Script);
|
||||
}
|
||||
|
||||
private void functionsNavListbox_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
NavigatorGoTo((ListBox)sender, functionsTabPage, functionSearchManager, ScriptFile.ContainerTypes.Function);
|
||||
//NavigatorGoTo((ListBox)sender, functionsTabPage, functionSearchManager, ScriptFile.ContainerTypes.Function);
|
||||
}
|
||||
|
||||
private void actionsNavListbox_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
NavigatorGoTo((ListBox)sender, actionsTabPage, actionSearchManager, ScriptFile.ContainerTypes.Action);
|
||||
//NavigatorGoTo((ListBox)sender, actionsTabPage, actionSearchManager, ScriptFile.ContainerTypes.Action);
|
||||
}
|
||||
|
||||
private void openFindScriptEditorButton_Click(object sender, EventArgs e) {
|
||||
currentSearchManager.OpenSearch();
|
||||
scriptSearchManager.OpenSearch();
|
||||
}
|
||||
|
||||
private void ScriptEditorExpandButton_Click(object sender, EventArgs e) {
|
||||
currentScintillaEditor.FoldAll(FoldAction.Expand);
|
||||
ScriptTextArea.FoldAll(FoldAction.Expand);
|
||||
}
|
||||
|
||||
private void ScriptEditorCollapseButton_Click(object sender, EventArgs e) {
|
||||
currentScintillaEditor.FoldAll(FoldAction.Contract);
|
||||
ScriptTextArea.FoldAll(FoldAction.Contract);
|
||||
}
|
||||
|
||||
private void scriptEditorWordWrapCheckbox_CheckedChanged(object sender, EventArgs e) {
|
||||
ScriptTextArea.WrapMode = scriptEditorWordWrapCheckbox.Checked ? WrapMode.Word : WrapMode.None;
|
||||
FunctionTextArea.WrapMode = scriptEditorWordWrapCheckbox.Checked ? WrapMode.Word : WrapMode.None;
|
||||
ActionTextArea.WrapMode = scriptEditorWordWrapCheckbox.Checked ? WrapMode.Word : WrapMode.None;
|
||||
}
|
||||
|
||||
private void viewWhiteSpacesButton_Click(object sender, EventArgs e) {
|
||||
ScriptTextArea.ViewWhitespace = scriptEditorWhitespacesCheckbox.Checked ? WhitespaceMode.VisibleAlways : WhitespaceMode.Invisible;
|
||||
FunctionTextArea.ViewWhitespace = scriptEditorWhitespacesCheckbox.Checked ? WhitespaceMode.VisibleAlways : WhitespaceMode.Invisible;
|
||||
ActionTextArea.ViewWhitespace = scriptEditorWhitespacesCheckbox.Checked ? WhitespaceMode.VisibleAlways : WhitespaceMode.Invisible;
|
||||
}
|
||||
|
||||
private void searchInScriptsTextBox_KeyDown(object sender, KeyEventArgs e) {
|
||||
@@ -925,17 +815,20 @@ namespace DSPRE.Editors {
|
||||
List<ScriptFile> scriptsToSearch = getScriptsToSearch();
|
||||
|
||||
string searchString = searchInScriptsTextBox.Text;
|
||||
Func<string, bool> searchCriteriaCS = (string s) => s.IndexOf(searchString, StringComparison.InvariantCulture) >= 0;
|
||||
Func<string, bool> searchCriteriaCI = (string s) => s.IndexOf(searchString, StringComparison.InvariantCultureIgnoreCase) >= 0;
|
||||
Func<string, bool> searchCriteria = scriptSearchCaseSensitiveCheckBox.Checked ? searchCriteriaCS : searchCriteriaCI;
|
||||
bool searchCriteriaCS(string s) => s.IndexOf(searchString, StringComparison.InvariantCulture) >= 0;
|
||||
bool searchCriteriaCI(string s) => s.IndexOf(searchString, StringComparison.InvariantCultureIgnoreCase) >= 0;
|
||||
|
||||
Func<string, bool> searchCriteria;
|
||||
if (scriptSearchCaseSensitiveCheckBox.Checked) {
|
||||
searchCriteria = searchCriteriaCS;
|
||||
} else {
|
||||
searchCriteria = searchCriteriaCI;
|
||||
}
|
||||
|
||||
List<ScriptEditorSearchResult> results = new List<ScriptEditorSearchResult>();
|
||||
foreach (ScriptFile scriptFile in scriptsToSearch) {
|
||||
List<ScriptEditorSearchResult> scriptResults = SearchInScripts(scriptFile, scriptFile.allScripts, searchCriteria);
|
||||
List<ScriptEditorSearchResult> functionResults = SearchInScripts(scriptFile, scriptFile.allFunctions, searchCriteria);
|
||||
// List<ScriptEditorSearchResult> actionResults = SearchInScripts(scriptFile, scriptFile.allActions, searchCriteria);
|
||||
List<ScriptEditorSearchResult> scriptResults = SearchInScripts(scriptFile, searchCriteria);
|
||||
results.AddRange(scriptResults);
|
||||
results.AddRange(functionResults);
|
||||
// results.AddRange(actionResults);
|
||||
}
|
||||
|
||||
@@ -948,21 +841,9 @@ namespace DSPRE.Editors {
|
||||
bw.RunWorkerAsync();
|
||||
}
|
||||
|
||||
private List<ScriptEditorSearchResult> SearchInScripts(ScriptFile scriptFile, List<ScriptCommandContainer> commandContainers, Func<string, bool> criteria) {
|
||||
private List<ScriptEditorSearchResult> SearchInScripts(ScriptFile scriptFile, Func<string, bool> criteria) {
|
||||
List<ScriptEditorSearchResult> results = new List<ScriptEditorSearchResult>();
|
||||
|
||||
for (int j = 0; j < commandContainers.Count; j++) {
|
||||
if (commandContainers[j].commands is null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ScriptCommandContainer scriptCommandContainer = commandContainers[j];
|
||||
foreach (ScriptCommand scriptCommand in scriptCommandContainer.commands) {
|
||||
if (criteria(scriptCommand.name)) {
|
||||
results.Add(new ScriptEditorSearchResult(scriptFile, scriptCommandContainer.containerType, j + 1, scriptCommand));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
@@ -987,19 +868,11 @@ namespace DSPRE.Editors {
|
||||
selectScriptFileComboBox.SelectedIndex = scriptFile.fileID;
|
||||
|
||||
if (containerType == ScriptFile.ContainerTypes.Script) {
|
||||
displaySearchResult(scriptsTabPage, scriptSearchManager, searchResult);
|
||||
} else if (containerType == ScriptFile.ContainerTypes.Function) {
|
||||
displaySearchResult(functionsTabPage, functionSearchManager, searchResult);
|
||||
} else if (containerType == ScriptFile.ContainerTypes.Action) {
|
||||
displaySearchResult(actionsTabPage, actionSearchManager, searchResult);
|
||||
displaySearchResult(scriptSearchManager, searchResult);
|
||||
}
|
||||
}
|
||||
|
||||
private void displaySearchResult(TabPage tabPage, SearchManager searchManager, ScriptEditorSearchResult searchResult) {
|
||||
if (scriptEditorTabControl.SelectedTab != tabPage) {
|
||||
scriptEditorTabControl.SelectedTab = tabPage;
|
||||
}
|
||||
|
||||
private void displaySearchResult(SearchManager searchManager, ScriptEditorSearchResult searchResult) {
|
||||
searchManager.Find(true, false, searchResult.CommandBlockOpen);
|
||||
int blockStart = searchManager.textAreaScintilla.CurrentLine - ScriptEditorSearchResult.ResultsPadding;
|
||||
|
||||
|
||||
@@ -5422,12 +5422,12 @@ namespace DSPRE {
|
||||
} else {
|
||||
ScriptFile itemScript = new ScriptFile(RomInfo.itemScriptFileNumber);
|
||||
owItemComboBox.Items.Clear();
|
||||
foreach (ScriptCommandContainer cont in itemScript.allScripts) {
|
||||
if (cont.commands.Count > 4) {
|
||||
continue;
|
||||
}
|
||||
owItemComboBox.Items.Add(BitConverter.ToUInt16(cont.commands[1].cmdParams[1], 0) + "x " + itemNames[BitConverter.ToUInt16(cont.commands[0].cmdParams[1], 0)]);
|
||||
}
|
||||
//foreach (ScriptCommandContainer cont in itemScript.allScripts) {
|
||||
// if (cont.commands.Count > 4) {
|
||||
// continue;
|
||||
// }
|
||||
// owItemComboBox.Items.Add(BitConverter.ToUInt16(cont.commands[1].Parameters[1].RawData, 0) + "x " + itemNames[BitConverter.ToUInt16(cont.commands[0].Parameters[1].RawData, 0)]);
|
||||
//}
|
||||
}
|
||||
|
||||
/* Add ow movement list to box */
|
||||
|
||||
@@ -258,18 +258,18 @@ namespace DSPRE
|
||||
public static bool CheckScriptsStandardizedItemNumbers()
|
||||
{
|
||||
ScriptFile itemScript = new ScriptFile(RomInfo.itemScriptFileNumber);
|
||||
if (itemScript.allScripts.Count - 1 < new TextArchive(RomInfo.itemNamesTextNumber).messages.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//if (itemScript.allScripts.Count - 1 < new TextArchive(RomInfo.itemNamesTextNumber).messages.Count)
|
||||
//{
|
||||
// return false;
|
||||
//}
|
||||
|
||||
for (ushort i = 0; i < itemScript.allScripts.Count - 1; i++)
|
||||
{
|
||||
if (BitConverter.ToUInt16(itemScript.allScripts[i].commands[0].cmdParams[1], 0) != i || BitConverter.ToUInt16(itemScript.allScripts[i].commands[1].cmdParams[1], 0) != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//for (ushort i = 0; i < itemScript.allScripts.Count - 1; i++)
|
||||
//{
|
||||
// if (BitConverter.ToUInt16(itemScript.allScripts[i].commands[0].Parameters[1].RawData, 0) != i || BitConverter.ToUInt16(itemScript.allScripts[i].commands[1].Parameters[1].RawData, 0) != 1)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -590,12 +590,12 @@ namespace DSPRE
|
||||
ScriptFile itemScriptFile = new ScriptFile(RomInfo.itemScriptFileNumber);
|
||||
|
||||
// Create map for: script no. -> vanilla item
|
||||
int[] vanillaItemsArray = new int[itemScriptFile.allScripts.Count - 1];
|
||||
|
||||
for (int i = 0; i < itemScriptFile.allScripts.Count - 1; i++)
|
||||
{
|
||||
vanillaItemsArray[i] = BitConverter.ToInt16(itemScriptFile.allScripts[i].commands[0].cmdParams[1], 0);
|
||||
};
|
||||
//int[] vanillaItemsArray = new int[itemScriptFile.allScripts.Count - 1];
|
||||
//
|
||||
//for (int i = 0; i < itemScriptFile.allScripts.Count - 1; i++)
|
||||
//{
|
||||
// vanillaItemsArray[i] = BitConverter.ToInt16(itemScriptFile.allScripts[i].commands[0].Parameters[1].RawData, 0);
|
||||
//};
|
||||
|
||||
// Parse all event files and fix instances of ground items according to the new order
|
||||
int cnt = Filesystem.GetEventFileCount();
|
||||
@@ -617,7 +617,7 @@ namespace DSPRE
|
||||
if (isItem)
|
||||
{
|
||||
int itemScriptID = eventFile.overworlds[j].scriptNumber - (itemScrMin - 1);
|
||||
eventFile.overworlds[j].scriptNumber = (ushort)(itemScrMin + vanillaItemsArray[itemScriptID - 1]);
|
||||
//eventFile.overworlds[j].scriptNumber = (ushort)(itemScrMin + vanillaItemsArray[itemScriptID - 1]);
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
@@ -644,29 +644,29 @@ namespace DSPRE
|
||||
|
||||
using (DSUtils.EasyWriter ewr = new DSUtils.EasyWriter(ow9path, ow9offs))
|
||||
{
|
||||
ewr.Write((ushort)(itemScrMin + vanillaItemsArray[itemScriptID - 1]));
|
||||
//ewr.Write((ushort)(itemScrMin + vanillaItemsArray[itemScriptID - 1]));
|
||||
}
|
||||
}
|
||||
|
||||
// Sort scripts in the Script File according to item indices
|
||||
int itemCount = new TextArchive(RomInfo.itemNamesTextNumber).messages.Count;
|
||||
ScriptCommandContainer executeGive = new ScriptCommandContainer((uint)itemCount + 1, itemScriptFile.allScripts[itemScriptFile.allScripts.Count - 1]);
|
||||
//ScriptCommandContainer executeGive = new ScriptCommandContainer((uint)itemCount + 1, itemScriptFile.allScripts[itemScriptFile.allScripts.Count - 1]);
|
||||
|
||||
itemScriptFile.allScripts.Clear();
|
||||
//itemScriptFile.allScripts.Clear();
|
||||
|
||||
for (ushort i = 0; i < itemCount; i++)
|
||||
{
|
||||
List<ScriptCommand> cmdList = new List<ScriptCommand> {
|
||||
new ScriptCommand("SetVar 0x8008 " + i),
|
||||
new ScriptCommand("SetVar 0x8009 0x1"),
|
||||
new ScriptCommand("Jump Function_#1")
|
||||
};
|
||||
|
||||
itemScriptFile.allScripts.Add(new ScriptCommandContainer((ushort)(i + 1), ScriptFile.ContainerTypes.Script, commandList: cmdList));
|
||||
}
|
||||
|
||||
itemScriptFile.allScripts.Add(executeGive);
|
||||
itemScriptFile.allFunctions[0].usedScriptID = itemCount + 1;
|
||||
//for (ushort i = 0; i < itemCount; i++)
|
||||
//{
|
||||
// List<ScriptCommand> cmdList = new List<ScriptCommand> {
|
||||
// new ScriptCommand("SetVar 0x8008 " + i),
|
||||
// new ScriptCommand("SetVar 0x8009 0x1"),
|
||||
// new ScriptCommand("Jump Function_#1")
|
||||
// };
|
||||
//
|
||||
// itemScriptFile.allScripts.Add(new ScriptCommandContainer((ushort)(i + 1), ScriptFile.ContainerTypes.Script, commandList: cmdList));
|
||||
//}
|
||||
//
|
||||
//itemScriptFile.allScripts.Add(executeGive);
|
||||
//itemScriptFile.allFunctions[0].usedScriptID = itemCount + 1;
|
||||
|
||||
itemScriptFile.SaveToFileDefaultDir(RomInfo.itemScriptFileNumber, showSuccessMessage: false);
|
||||
MessageBox.Show("Operation successful.", "Process completed.", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DSPRE.ROMFiles {
|
||||
@@ -16,15 +17,17 @@ namespace DSPRE.ROMFiles {
|
||||
OW_DIRECTION,
|
||||
FUNCTION_ID,
|
||||
ACTION_ID,
|
||||
CMD_NUMBER
|
||||
CMD_NUMBER,
|
||||
LABEL_REF
|
||||
};
|
||||
|
||||
public ushort? id;
|
||||
public List<byte[]> cmdParams;
|
||||
public List<ScriptParameter> Parameters { get; set; } = new List<ScriptParameter>();
|
||||
public string name;
|
||||
|
||||
public ScriptCommand(ushort id, List<byte[]> parametersList) {
|
||||
if (parametersList is null) {
|
||||
// CHANGE: Update the constructor to use ScriptParameter
|
||||
public ScriptCommand(ushort id, List<ScriptParameter> parameters) {
|
||||
if (parameters is null) {
|
||||
this.id = null;
|
||||
return;
|
||||
}
|
||||
@@ -36,47 +39,48 @@ namespace DSPRE.ROMFiles {
|
||||
switch (id) {
|
||||
case 0x0016: // Jump
|
||||
case 0x001A: // Call
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.FUNCTION_ID)}";
|
||||
name += $" {FormatParameter(parameters[0], ParamTypeEnum.FUNCTION_ID)}";
|
||||
break;
|
||||
case 0x0017: // JumpIfObjID
|
||||
case 0x0018: // JumpIfEventID
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1])}";
|
||||
name += $" {FormatParameter(parameters[0], ParamTypeEnum.OW_ID)} {FormatParameter(parameters[1])}";
|
||||
break;
|
||||
case 0x0019: // JumpIfPlayerDir
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_DIRECTION)} {FormatNumber(parametersList[1], ParamTypeEnum.FUNCTION_ID)}";
|
||||
name += $" {FormatParameter(parameters[0], ParamTypeEnum.OW_DIRECTION)} {FormatParameter(parameters[1], ParamTypeEnum.FUNCTION_ID)}";
|
||||
break;
|
||||
case 0x001C: // JumpIf
|
||||
case 0x001D: // CallIf
|
||||
{
|
||||
string number = FormatNumber(parametersList[1], ParamTypeEnum.FUNCTION_ID);
|
||||
string number = FormatParameter(parameters[1], ParamTypeEnum.FUNCTION_ID);
|
||||
|
||||
if (RomInfo.ScriptComparisonOperatorsDict.TryGetValue(parametersList[0][0], out string v)) {
|
||||
// Access the byte value from the parameter's raw data
|
||||
if (RomInfo.ScriptComparisonOperatorsDict.TryGetValue(parameters[0].RawData[0], out string v)) {
|
||||
name += $" {v} {number}";
|
||||
} else {
|
||||
name += $" {parametersList[0][0]} {number}";
|
||||
name += $" {parameters[0].RawData[0]} {number}";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x005E: // Movement
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1], ParamTypeEnum.ACTION_ID)}";
|
||||
name += $" {FormatParameter(parameters[0], ParamTypeEnum.OW_ID)} {FormatParameter(parameters[1], ParamTypeEnum.ACTION_ID)}";
|
||||
break;
|
||||
case 0x006A: // GetOverworldPosition
|
||||
name += FormatCmd_Overworld_TwoParams(parametersList);
|
||||
name += FormatCmd_Overworld_TwoParams(parameters);
|
||||
break;
|
||||
case 0x0062: // Lock
|
||||
case 0x0063: // Release
|
||||
case 0x0064: // AddOW
|
||||
case 0x0065: // RemoveOW
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)}";
|
||||
name += $" {FormatParameter(parameters[0], ParamTypeEnum.OW_ID)}";
|
||||
break;
|
||||
case 0x006D: // SetOverworldMovement
|
||||
name += FormatCmd_Overworld_Move(parametersList);
|
||||
name += FormatCmd_Overworld_Move(parameters);
|
||||
break;
|
||||
|
||||
case 0x00B0: // Warp [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Warp(parametersList);
|
||||
name += FormatCmd_Warp(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -84,7 +88,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0152: // SetOverworldDefaultPosition [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_TwoParams(parametersList);
|
||||
name += FormatCmd_Overworld_TwoParams(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -92,7 +96,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0153: // SetOverworldPosition [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_3Coords_Dir(parametersList);
|
||||
name += FormatCmd_Overworld_3Coords_Dir(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -100,7 +104,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0154: // SetOverworldDefaultMovement [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_Move(parametersList);
|
||||
name += FormatCmd_Overworld_Move(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -108,7 +112,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0155: // SetOverworldDefaultDirection [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_Dir(parametersList);
|
||||
name += FormatCmd_Overworld_Dir(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -116,7 +120,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0158: // SetOverworldDirection [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_Dir(parametersList);
|
||||
name += FormatCmd_Overworld_Dir(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -125,7 +129,7 @@ namespace DSPRE.ROMFiles {
|
||||
|
||||
case 0x00BE: // Warp [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Warp(parametersList);
|
||||
name += FormatCmd_Warp(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -133,7 +137,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0186: // SetOverworldDefaultPosition [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_TwoParams(parametersList);
|
||||
name += FormatCmd_Overworld_TwoParams(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -141,7 +145,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0187: // SetOverworldPosition [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_3Coords_Dir(parametersList);
|
||||
name += FormatCmd_Overworld_3Coords_Dir(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -149,7 +153,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0188: // SetOverworldDefaultMovement [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_Move(parametersList);
|
||||
name += FormatCmd_Overworld_Move(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -157,7 +161,7 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x0189: // SetOverworldDefaultDirection [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_Dir(parametersList);
|
||||
name += FormatCmd_Overworld_Dir(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
@@ -165,47 +169,47 @@ namespace DSPRE.ROMFiles {
|
||||
break;
|
||||
case 0x018C: // SetOverworldDirection [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_Dir(parametersList);
|
||||
name += FormatCmd_Overworld_Dir(parameters);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
for (int i = 0; i < parametersList.Count; i++) {
|
||||
name += $" {FormatNumber(parametersList[i])}";
|
||||
for (int i = 0; i < parameters.Count; i++) {
|
||||
name += $" {FormatParameter(parameters[i])}";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
this.cmdParams = parametersList;
|
||||
this.Parameters = parameters;
|
||||
}
|
||||
|
||||
private string FormatCmd_Warp(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])} {FormatNumber(parametersList[3])} {FormatNumber(parametersList[4], ParamTypeEnum.OW_DIRECTION)}";
|
||||
private string FormatCmd_Warp(List<ScriptParameter> parameters) {
|
||||
return $" {FormatParameter(parameters[0])} {FormatParameter(parameters[1])} {FormatParameter(parameters[2])} {FormatParameter(parameters[3])} {FormatParameter(parameters[4], ParamTypeEnum.OW_DIRECTION)}";
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_TwoParams(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])}";
|
||||
private string FormatCmd_Overworld_TwoParams(List<ScriptParameter> parameters) {
|
||||
return $" {FormatParameter(parameters[0], ParamTypeEnum.OW_ID)} {FormatParameter(parameters[1])} {FormatParameter(parameters[2])}";
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_Move(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1], ParamTypeEnum.OW_MOVEMENT_TYPE)}";
|
||||
private string FormatCmd_Overworld_Move(List<ScriptParameter> parameters) {
|
||||
return $" {FormatParameter(parameters[0], ParamTypeEnum.OW_ID)} {FormatParameter(parameters[1], ParamTypeEnum.OW_MOVEMENT_TYPE)}";
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_3Coords_Dir(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])} {FormatNumber(parametersList[3])} {FormatNumber(parametersList[4], ParamTypeEnum.OW_DIRECTION)}";
|
||||
private string FormatCmd_Overworld_3Coords_Dir(List<ScriptParameter> parameters) {
|
||||
return $" {FormatParameter(parameters[0], ParamTypeEnum.OW_ID)} {FormatParameter(parameters[1])} {FormatParameter(parameters[2])} {FormatParameter(parameters[3])} {FormatParameter(parameters[4], ParamTypeEnum.OW_DIRECTION)}";
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_Dir(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1], ParamTypeEnum.OW_DIRECTION)}";
|
||||
private string FormatCmd_Overworld_Dir(List<ScriptParameter> parameters) {
|
||||
return $" {FormatParameter(parameters[0], ParamTypeEnum.OW_ID)} {FormatParameter(parameters[1], ParamTypeEnum.OW_DIRECTION)}";
|
||||
}
|
||||
|
||||
public ScriptCommand(string wholeLine, int lineNumber = 0) {
|
||||
name = wholeLine;
|
||||
cmdParams = new List<byte[]>();
|
||||
Parameters = new List<ScriptParameter>();
|
||||
|
||||
string[] nameParts = wholeLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Separate command code from parameters
|
||||
/* Get command id, which is always first in the description */
|
||||
@@ -229,9 +233,8 @@ namespace DSPRE.ROMFiles {
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* Read parameters from remainder of the description */
|
||||
//Console.WriteLine("ID = " + ((ushort)id).ToString("X4"));
|
||||
|
||||
/* Read parameters from remainder of the description */
|
||||
byte[] parametersSizeArr = RomInfo.ScriptCommandParametersDict[(ushort)id];
|
||||
|
||||
int paramLength = 0;
|
||||
@@ -241,7 +244,7 @@ namespace DSPRE.ROMFiles {
|
||||
int firstParamValue = int.Parse(nameParts[1].PurgeSpecial(ScriptFile.specialChars), nameParts[1].GetNumberStyle());
|
||||
byte firstParamSize = parametersSizeArr[1];
|
||||
|
||||
cmdParams.Add(firstParamValue.ToByteArrayChooseSize(firstParamSize));
|
||||
Parameters.Add(new ScriptParameter(firstParamValue.ToByteArrayChooseSize(firstParamSize)));
|
||||
paramsProcessed++;
|
||||
|
||||
int i = 2;
|
||||
@@ -303,7 +306,8 @@ namespace DSPRE.ROMFiles {
|
||||
Console.WriteLine($"Parameter #{i}: {nameParts[i + 1]}");
|
||||
|
||||
if (RomInfo.ScriptComparisonOperatorsReverseDict.TryGetValue(nameParts[i + 1].ToLower(), out cmdID)) { //Check succeeds when command is like "asdfg LESS" or "asdfg DIFFERENT"
|
||||
cmdParams.Add(new byte[] { (byte)cmdID });
|
||||
// Create parameter with byte array
|
||||
Parameters.Add(new ScriptParameter(new byte[] { (byte)cmdID }));
|
||||
} else { //Not a comparison
|
||||
/* Convert strings of parameters to the correct datatypes */
|
||||
NumberStyles numStyle = nameParts[i + 1].GetNumberStyle();
|
||||
@@ -312,6 +316,16 @@ namespace DSPRE.ROMFiles {
|
||||
int result = 0;
|
||||
|
||||
try {
|
||||
// Check if this is a label reference
|
||||
if (nameParts[i + 1].StartsWith("label") || nameParts[i + 1].StartsWith("script")) {
|
||||
// This is a label reference
|
||||
ScriptParameter labelParam = new ScriptParameter(0, nameParts[i + 1]) {
|
||||
Type = ScriptParameter.ParameterType.RelativeJump
|
||||
};
|
||||
Parameters.Add(labelParam);
|
||||
continue;
|
||||
}
|
||||
|
||||
result = int.Parse(nameParts[i + 1], numStyle);
|
||||
} catch {
|
||||
if (string.IsNullOrWhiteSpace(nameParts[i + 1])) {
|
||||
@@ -338,7 +352,8 @@ namespace DSPRE.ROMFiles {
|
||||
}
|
||||
|
||||
try {
|
||||
cmdParams.Add(result.ToByteArrayChooseSize(parametersSizeArr[i]));
|
||||
byte[] paramData = result.ToByteArrayChooseSize(parametersSizeArr[i]);
|
||||
Parameters.Add(new ScriptParameter(paramData));
|
||||
} catch (OverflowException) {
|
||||
MessageBox.Show($"Argument {nameParts[i + 1]} at line {lineNumber} is not in the range [0, {Math.Pow(2, 8 * parametersSizeArr[i]) - 1}].", "Argument error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
id = null;
|
||||
@@ -354,6 +369,10 @@ namespace DSPRE.ROMFiles {
|
||||
}
|
||||
|
||||
private string FormatNumber(byte[] par, ParamTypeEnum paramType = ParamTypeEnum.INTEGER) {
|
||||
if (paramType == ParamTypeEnum.LABEL_REF && par.Length > 0) {
|
||||
return FormatLabelReference(Encoding.ASCII.GetString(par));
|
||||
}
|
||||
|
||||
//number acquisition
|
||||
uint num;
|
||||
if (par.Length == 0) {
|
||||
@@ -390,9 +409,6 @@ namespace DSPRE.ROMFiles {
|
||||
case ParamTypeEnum.CMD_NUMBER:
|
||||
return "CMD_" + prefix + num.ToString(formatOverride + '3');
|
||||
|
||||
case ParamTypeEnum.FUNCTION_ID:
|
||||
return ScriptFile.ContainerTypes.Function.ToString() + "#" + num;
|
||||
|
||||
case ParamTypeEnum.ACTION_ID:
|
||||
return ScriptFile.ContainerTypes.Action.ToString() + "#" + num;
|
||||
|
||||
@@ -440,8 +456,21 @@ namespace DSPRE.ROMFiles {
|
||||
return outp;
|
||||
}
|
||||
|
||||
private string FormatParameter(ScriptParameter param, ParamTypeEnum paramType = ParamTypeEnum.INTEGER) {
|
||||
// For jump-to-label parameters, return the label name
|
||||
if (param.Type == ScriptParameter.ParameterType.RelativeJump && !string.IsNullOrEmpty(param.TargetLabel)) {
|
||||
return param.TargetLabel;
|
||||
}
|
||||
|
||||
// Otherwise handle the numeric value
|
||||
return FormatNumber(param.RawData, paramType);
|
||||
}
|
||||
public override string ToString() {
|
||||
return name + " (" + ((ushort)id).ToString("X") + ")";
|
||||
}
|
||||
|
||||
private string FormatLabelReference(string labelName) {
|
||||
return labelName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DSPRE.ROMFiles {
|
||||
public class ScriptCommandContainer {
|
||||
public List<ScriptCommand> commands;
|
||||
public uint manualUserID;
|
||||
public int usedScriptID; //useScript ID referenced by this Script/Function
|
||||
public ScriptFile.ContainerTypes containerType;
|
||||
internal static readonly string functionStart;
|
||||
|
||||
public ScriptCommandContainer(uint scriptNumber, ScriptFile.ContainerTypes containerType, int usedScriptID = -1, List<ScriptCommand> commandList = null) {
|
||||
manualUserID = scriptNumber;
|
||||
this.usedScriptID = usedScriptID;
|
||||
this.containerType = containerType;
|
||||
commands = commandList;
|
||||
}
|
||||
|
||||
public ScriptCommandContainer(uint newID, ScriptCommandContainer toCopy) {
|
||||
manualUserID = newID;
|
||||
usedScriptID = toCopy.usedScriptID;
|
||||
containerType = toCopy.containerType;
|
||||
commands = new List<ScriptCommand>(toCopy.commands); //command parameters need to be copied recursively
|
||||
}
|
||||
}
|
||||
}
|
||||
20
DS_Map/ROMFiles/ScriptCommandPosition.cs
Normal file
20
DS_Map/ROMFiles/ScriptCommandPosition.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
// ScriptCommandPosition.cs
|
||||
using System;
|
||||
|
||||
namespace DSPRE.ROMFiles {
|
||||
public class ScriptCommandPosition {
|
||||
public ScriptCommand Command { get; set; }
|
||||
public int Offset { get; set; }
|
||||
public string Label { get; set; } // null if no label needed
|
||||
public bool IsEntryPoint { get; set; }
|
||||
public int EntryPointIndex { get; set; } // -1 if not an entry point
|
||||
|
||||
public ScriptCommandPosition(ScriptCommand cmd, int offset, string label = null, bool isEntryPoint = false, int entryPointIndex = -1) {
|
||||
Command = cmd;
|
||||
Offset = offset;
|
||||
Label = label;
|
||||
IsEntryPoint = isEntryPoint;
|
||||
EntryPointIndex = entryPointIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
21
DS_Map/ROMFiles/ScriptLabeledSection.cs
Normal file
21
DS_Map/ROMFiles/ScriptLabeledSection.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// Create this as a new file: ScriptLabeledSection.cs
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DSPRE.ROMFiles {
|
||||
public class ScriptLabeledSection {
|
||||
public string LabelName { get; set; }
|
||||
public List<ScriptCommand> Commands { get; set; }
|
||||
public uint OffsetInFile { get; set; }
|
||||
public bool IsReferenced { get; set; } = false;
|
||||
|
||||
public ScriptLabeledSection(string labelName, List<ScriptCommand> commands = null) {
|
||||
LabelName = labelName;
|
||||
Commands = commands ?? new List<ScriptCommand>();
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return LabelName;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
DS_Map/ROMFiles/ScriptParameter.cs
Normal file
45
DS_Map/ROMFiles/ScriptParameter.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
|
||||
public class ScriptParameter {
|
||||
public enum ParameterType {
|
||||
Integer,
|
||||
RelativeJump,
|
||||
Byte,
|
||||
Variable
|
||||
}
|
||||
|
||||
public ParameterType Type { get; set; } = ParameterType.Integer;
|
||||
public byte[] RawData { get; set; }
|
||||
public string TargetLabel { get; set; } // For RelativeJump type
|
||||
public int TargetOffset { get; set; } // For RelativeJump type
|
||||
|
||||
// Constructor for regular parameters
|
||||
public ScriptParameter(byte[] data) {
|
||||
Type = ParameterType.Integer;
|
||||
RawData = data;
|
||||
}
|
||||
|
||||
// Constructor for relative jumps
|
||||
public ScriptParameter(int targetOffset, string targetLabel) {
|
||||
Type = ParameterType.RelativeJump;
|
||||
TargetOffset = targetOffset;
|
||||
TargetLabel = targetLabel;
|
||||
// Store raw bytes only for display purposes
|
||||
RawData = BitConverter.GetBytes(targetOffset);
|
||||
}
|
||||
|
||||
// Get display representation
|
||||
public string GetFormattedValue() {
|
||||
if (Type == ParameterType.RelativeJump && !string.IsNullOrEmpty(TargetLabel)) {
|
||||
return TargetLabel;
|
||||
}
|
||||
|
||||
// Default formatting for other types
|
||||
if (RawData.Length == 0) return "";
|
||||
if (RawData.Length == 1) return RawData[0].ToString("X2");
|
||||
if (RawData.Length == 2) return BitConverter.ToUInt16(RawData, 0).ToString("X4");
|
||||
if (RawData.Length == 4) return BitConverter.ToUInt32(RawData, 0).ToString("X8");
|
||||
|
||||
return BitConverter.ToString(RawData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user