Skip to content

Commit

Permalink
Merge pull request #2221 from ivan-mogilko/361--fiximportoldproject2
Browse files Browse the repository at this point in the history
Editor: recreate GeneralSettings and DefaultSetup documents when a new game is opened
  • Loading branch information
ivan-mogilko authored Nov 12, 2023
2 parents d653232 + b29c68b commit fd491b6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
4 changes: 1 addition & 3 deletions Editor/AGS.Editor/ApplicationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ private void _events_GameLoad(XmlNode rootNode)
DataFileWriter.TextEncoding = _agsEditor.CurrentGame.TextEncoding;
}

private void _events_GamePostLoad()
private void _events_GamePostLoad(Game game)
{
Game game = Factory.AGSEditor.CurrentGame;

// TODO: this may be noticably slow especially for sprites. Display some kind of
// progress window to notify user.
// Convert absolute paths to relative paths. This is an automatic fixup from when the
Expand Down
16 changes: 13 additions & 3 deletions Editor/AGS.Editor/Components/DefaultSetupComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ class DefaultSetupComponent : BaseComponent
public DefaultSetupComponent(GUIController guiController, AGSEditor agsEditor)
: base(guiController, agsEditor)
{
_settingsPane = new DefaultRuntimeSetupPane();
_document = new ContentDocument(_settingsPane, "Default Setup", this, ICON_KEY);
RecreateDocument();
_guiController.RegisterIcon(ICON_KEY, Resources.ResourceManager.GetIcon("iconsett.ico"));
_guiController.ProjectTree.AddTreeRoot(this, ComponentID, "Default Setup", ICON_KEY);
}

private void RecreateDocument()
{
if (_document != null)
{
_guiController.RemovePaneIfExists(_document);
_document.Dispose();
}
_settingsPane = new DefaultRuntimeSetupPane();
_document = new ContentDocument(_settingsPane, "Default Setup", this, ICON_KEY);
}

public override string ComponentID
{
get { return ComponentIDs.DefaultSetup; }
Expand All @@ -38,7 +48,7 @@ public override void GameSettingsChanged()

public override void RefreshDataFromGame()
{
_settingsPane.RefreshData();
RecreateDocument();
}
}
}
5 changes: 2 additions & 3 deletions Editor/AGS.Editor/Components/ScriptsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,17 +654,16 @@ protected override IList<ScriptAndHeader> GetFlatList()
return null;
}

private void Events_GamePostLoad()
private void Events_GamePostLoad(Game game)
{
var game = _agsEditor.CurrentGame;
if (game.SavedXmlVersionIndex >= 3060110)
return; // no upgrade necessary

// < 3060110 - SetRestartPoint() has to be added to Global Script's game_start,
// emulate legacy behavior where its call was hardcoded in the engine.
if (game.SavedXmlVersionIndex < 3060110)
{
Script script = AGSEditor.Instance.CurrentGame.RootScriptFolder.GetScriptByFileName(Script.GLOBAL_SCRIPT_FILE_NAME, true);
Script script = game.RootScriptFolder.GetScriptByFileName(Script.GLOBAL_SCRIPT_FILE_NAME, true);
if (script != null)
{
script.Text =
Expand Down
17 changes: 13 additions & 4 deletions Editor/AGS.Editor/Components/SettingsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ class SettingsComponent : BaseComponent
public SettingsComponent(GUIController guiController, AGSEditor agsEditor)
: base(guiController, agsEditor)
{
_settingsPane = new GeneralSettingsPane();
_document = new ContentDocument(_settingsPane, "General Settings", this, ICON_KEY);
RecreateDocument();
_guiController.RegisterIcon(ICON_KEY, Resources.ResourceManager.GetIcon("iconsett.ico"));
_guiController.ProjectTree.AddTreeRoot(this, "GeneralSettings", "General Settings", ICON_KEY);
}

private void RecreateDocument()
{
if (_document != null)
{
_guiController.RemovePaneIfExists(_document);
_document.Dispose();
}
_settingsPane = new GeneralSettingsPane();
_document = new ContentDocument(_settingsPane, "General Settings", this, ICON_KEY);
}

public override string ComponentID
{
get { return ComponentIDs.GeneralSettings; }
Expand All @@ -37,13 +47,12 @@ public override void CommandClick(string controlID)

public override void RefreshDataFromGame()
{
_settingsPane.RefreshData();
RecreateDocument();

if (Factory.AGSEditor.Settings.StartupPane == StartupPane.GeneralSettings)
{
_guiController.AddOrShowPane(_document);
}
}

}
}
6 changes: 3 additions & 3 deletions Editor/AGS.Editor/EditorEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class EditorEvents
public event ParameterlessDelegate RefreshAllComponentsFromGame;
public delegate void GameLoadHandler(XmlNode rootNode);
public event GameLoadHandler GameLoad;
public delegate void GamePostLoadHandler();
public delegate void GamePostLoadHandler(Game game);
public event GamePostLoadHandler GamePostLoad;
public delegate void SavingGameHandler(XmlTextWriter writer);
public event SavingGameHandler SavingGame;
Expand Down Expand Up @@ -56,11 +56,11 @@ public void OnGameLoad(XmlNode rootNode)
}
}

public void OnGamePostLoad()
public void OnGamePostLoad(Game game)
{
if (GamePostLoad != null)
{
GamePostLoad();
GamePostLoad(game);
}
}

Expand Down
4 changes: 3 additions & 1 deletion Editor/AGS.Editor/Tasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ public bool LoadGameFromDisk(string gameToLoad, bool interactive)
}
Factory.AGSEditor.Settings.RecentGames.Insert(0, recentGame);

Factory.Events.OnGamePostLoad();
Factory.Events.OnGamePostLoad(game);

// WARNING: this is where the "global" Factory.AGSEditor.CurrentGame is set;
// any tasks and events that expect to reference it must be called after!
Factory.AGSEditor.RefreshEditorAfterGameLoad(game, errors);
if (needToSave)
{
Expand Down

0 comments on commit fd491b6

Please sign in to comment.