mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 21:27:01 -04:00
Game settings loading is now deferred until the game is fully loading.
This allows auto replaces to be properly loaded from the game file. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1295 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -81,7 +81,11 @@ GameSettings::GameSettings()
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
void GameSettings::initDefaults(const Game& game) {
|
void GameSettings::initDefaults(const Game& game) {
|
||||||
if (initialized) return;
|
// Defer initialization until the game is fully loaded.
|
||||||
|
// This prevents data that needs to be initialized from
|
||||||
|
// being accessed from the new set window, but removes
|
||||||
|
// the need to load the entire file, which takes too long.
|
||||||
|
if (initialized || !game.isFullyLoaded()) return;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
// init auto_replaces, copy from game file
|
// init auto_replaces, copy from game file
|
||||||
FOR_EACH_CONST(ar, game.auto_replaces) {
|
FOR_EACH_CONST(ar, game.auto_replaces) {
|
||||||
|
|||||||
@@ -23,15 +23,15 @@ DECLARE_POINTER_TYPE(AutoReplace);
|
|||||||
class WordListWord : public IntrusivePtrBase<WordListWord> {
|
class WordListWord : public IntrusivePtrBase<WordListWord> {
|
||||||
public:
|
public:
|
||||||
WordListWord();
|
WordListWord();
|
||||||
|
|
||||||
String name; ///< Name of the list / the word
|
String name; ///< Name of the list / the word
|
||||||
bool line_below; ///< Line below in the list?
|
bool line_below; ///< Line below in the list?
|
||||||
bool is_prefix; ///< Is this a prefix before other words?
|
bool is_prefix; ///< Is this a prefix before other words?
|
||||||
vector<WordListWordP> words; ///< Sublist
|
vector<WordListWordP> words; ///< Sublist
|
||||||
OptionalScript script; ///< Generate words using a script
|
OptionalScript script; ///< Generate words using a script
|
||||||
|
|
||||||
inline bool isGroup() const { return !words.empty(); }
|
inline bool isGroup() const { return !words.empty(); }
|
||||||
|
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,15 +47,15 @@ class WordList : public WordListWord {
|
|||||||
class AutoReplace : public IntrusivePtrVirtualBase {
|
class AutoReplace : public IntrusivePtrVirtualBase {
|
||||||
public:
|
public:
|
||||||
AutoReplace();
|
AutoReplace();
|
||||||
|
|
||||||
bool enabled;
|
bool enabled;
|
||||||
bool whole_word;
|
bool whole_word;
|
||||||
bool custom; ///< Is this a custom auto replace?
|
bool custom; ///< Is this a custom auto replace?
|
||||||
String match;
|
String match;
|
||||||
String replace;
|
String replace;
|
||||||
|
|
||||||
inline AutoReplaceP clone() const { return new_intrusive1<AutoReplace>(*this); }
|
inline AutoReplaceP clone() const { return new_intrusive1<AutoReplace>(*this); }
|
||||||
|
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -27,38 +27,38 @@ DEFINE_EVENT_TYPE(EVENT_ITEM_SELECT);
|
|||||||
class AutoReplaceList : public ItemList {
|
class AutoReplaceList : public ItemList {
|
||||||
public:
|
public:
|
||||||
AutoReplaceList(Window* parent, int id, const Game& game);
|
AutoReplaceList(Window* parent, int id, const Game& game);
|
||||||
|
|
||||||
/// The items
|
/// The items
|
||||||
vector<AutoReplaceP> items;
|
vector<AutoReplaceP> items;
|
||||||
/// Settings we are edditing
|
/// Settings we are edditing
|
||||||
const Game& game;
|
const Game& game;
|
||||||
GameSettings& gs;
|
GameSettings& gs;
|
||||||
|
|
||||||
/// The current item
|
/// The current item
|
||||||
inline AutoReplaceP getSelected() const { return static_pointer_cast<AutoReplace>(selected_item); }
|
inline AutoReplaceP getSelected() const { return static_pointer_cast<AutoReplace>(selected_item); }
|
||||||
|
|
||||||
/// Add an item
|
/// Add an item
|
||||||
void addItem(const AutoReplaceP& item);
|
void addItem(const AutoReplaceP& item);
|
||||||
/// Remove the selected item
|
/// Remove the selected item
|
||||||
void removeSelected();
|
void removeSelected();
|
||||||
|
|
||||||
/// Reset the list to the default
|
/// Reset the list to the default
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
using ItemList::refreshList;
|
using ItemList::refreshList;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Get all items
|
/// Get all items
|
||||||
virtual void getItems(vector<VoidP>& out) const;
|
virtual void getItems(vector<VoidP>& out) const;
|
||||||
/// Return the AutoReplace at the given position in the sorted list
|
/// Return the AutoReplace at the given position in the sorted list
|
||||||
inline AutoReplaceP getAR(long pos) const { return static_pointer_cast<AutoReplace>(getItem(pos)); }
|
inline AutoReplaceP getAR(long pos) const { return static_pointer_cast<AutoReplace>(getItem(pos)); }
|
||||||
|
|
||||||
/// Send an 'item selected' event for the currently selected item (selected_item)
|
/// Send an 'item selected' event for the currently selected item (selected_item)
|
||||||
virtual void sendEvent();
|
virtual void sendEvent();
|
||||||
/// Compare items
|
/// Compare items
|
||||||
virtual bool compareItems(void* a, void* b) const;
|
virtual bool compareItems(void* a, void* b) const;
|
||||||
virtual bool mustSort() const { return true; }
|
virtual bool mustSort() const { return true; }
|
||||||
|
|
||||||
/// Get the text of an item in a specific column
|
/// Get the text of an item in a specific column
|
||||||
/** Overrides a function from wxListCtrl */
|
/** Overrides a function from wxListCtrl */
|
||||||
virtual String OnGetItemText (long pos, long col) const;
|
virtual String OnGetItemText (long pos, long col) const;
|
||||||
@@ -67,7 +67,7 @@ class AutoReplaceList : public ItemList {
|
|||||||
virtual int OnGetItemImage(long pos) const;
|
virtual int OnGetItemImage(long pos) const;
|
||||||
/// Get the color for an item
|
/// Get the color for an item
|
||||||
virtual wxListItemAttr* OnGetItemAttr(long pos) const;
|
virtual wxListItemAttr* OnGetItemAttr(long pos) const;
|
||||||
|
|
||||||
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ AutoReplaceList::AutoReplaceList(Window* parent, int id, const Game& game)
|
|||||||
items.push_back(ar->clone());
|
items.push_back(ar->clone());
|
||||||
}
|
}
|
||||||
// Add columns
|
// Add columns
|
||||||
InsertColumn(0, _LABEL_(""), wxLIST_FORMAT_LEFT, 0); // dummy, prevent the image from taking up space
|
InsertColumn(0, _(""), wxLIST_FORMAT_LEFT, 0); // dummy, prevent the image from taking up space
|
||||||
InsertColumn(1, _LABEL_("auto match"), wxLIST_FORMAT_LEFT, 100);
|
InsertColumn(1, _LABEL_("auto match"), wxLIST_FORMAT_LEFT, 100);
|
||||||
InsertColumn(2, _LABEL_("auto replace"), wxLIST_FORMAT_LEFT, 200);
|
InsertColumn(2, _LABEL_("auto replace"), wxLIST_FORMAT_LEFT, 200);
|
||||||
// grey for disabled items
|
// grey for disabled items
|
||||||
@@ -143,7 +143,7 @@ String AutoReplaceList::OnGetItemText (long pos, long col) const {
|
|||||||
if (col == 0) return ar->match;
|
if (col == 0) return ar->match;
|
||||||
if (col == 1) return ar->match;
|
if (col == 1) return ar->match;
|
||||||
if (col == 2) return ar->replace;
|
if (col == 2) return ar->replace;
|
||||||
throw InternalError(_("too mana columns"));
|
throw InternalError(_("too many columns"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int AutoReplaceList::OnGetItemImage(long pos) const {
|
int AutoReplaceList::OnGetItemImage(long pos) const {
|
||||||
|
|||||||
+35
-31
@@ -38,7 +38,7 @@ DECLARE_DYNAMIC_ARG(Package*, clipboard_package);
|
|||||||
*
|
*
|
||||||
* Zip files are accessed using wxZip(Input|Output)Stream.
|
* Zip files are accessed using wxZip(Input|Output)Stream.
|
||||||
* The zip input stream appears to only allow one file at a time, since the stream itself maintains
|
* The zip input stream appears to only allow one file at a time, since the stream itself maintains
|
||||||
* state about what file we are reading.
|
* state about what file we are reading.
|
||||||
* There are multiple solutions:
|
* There are multiple solutions:
|
||||||
* 1. (currently used) Open a new ZipInputStream for each file
|
* 1. (currently used) Open a new ZipInputStream for each file
|
||||||
* 2. (may be faster) First read the file into a memory buffer,
|
* 2. (may be faster) First read the file into a memory buffer,
|
||||||
@@ -49,11 +49,11 @@ DECLARE_DYNAMIC_ARG(Package*, clipboard_package);
|
|||||||
class Package : public IntrusivePtrVirtualBase {
|
class Package : public IntrusivePtrVirtualBase {
|
||||||
public:
|
public:
|
||||||
// --------------------------------------------------- : Managing the outside of the package
|
// --------------------------------------------------- : Managing the outside of the package
|
||||||
|
|
||||||
/// Creates a new package
|
/// Creates a new package
|
||||||
Package();
|
Package();
|
||||||
virtual ~Package();
|
virtual ~Package();
|
||||||
|
|
||||||
/// Is a file opened?
|
/// Is a file opened?
|
||||||
bool isOpened() const;
|
bool isOpened() const;
|
||||||
/// Must the package be saved with saveAs()?
|
/// Must the package be saved with saveAs()?
|
||||||
@@ -67,11 +67,11 @@ class Package : public IntrusivePtrVirtualBase {
|
|||||||
const String& absoluteFilename() const;
|
const String& absoluteFilename() const;
|
||||||
/// The time this package was last modified
|
/// The time this package was last modified
|
||||||
inline wxDateTime lastModified() const { return modified; }
|
inline wxDateTime lastModified() const { return modified; }
|
||||||
|
|
||||||
/// Open a package, should only be called when the package is constructed using the default constructor!
|
/// Open a package, should only be called when the package is constructed using the default constructor!
|
||||||
/// @pre open not called before [TODO]
|
/// @pre open not called before [TODO]
|
||||||
void open(const String& package);
|
void open(const String& package);
|
||||||
|
|
||||||
/// Saves the package, by default saves as a zip file, unless
|
/// Saves the package, by default saves as a zip file, unless
|
||||||
/// it was already a directory
|
/// it was already a directory
|
||||||
/** If remove_unused=true all files that were in the file and
|
/** If remove_unused=true all files that were in the file and
|
||||||
@@ -79,46 +79,46 @@ class Package : public IntrusivePtrVirtualBase {
|
|||||||
* This is a form of garbage collection, to get rid of old picture files for example.
|
* This is a form of garbage collection, to get rid of old picture files for example.
|
||||||
*/
|
*/
|
||||||
void save(bool remove_unused = true);
|
void save(bool remove_unused = true);
|
||||||
|
|
||||||
/// Saves the package under a different filename
|
/// Saves the package under a different filename
|
||||||
void saveAs(const String& package, bool remove_unused = true);
|
void saveAs(const String& package, bool remove_unused = true);
|
||||||
|
|
||||||
/// Saves the package under a different filename, but keep the old one open
|
/// Saves the package under a different filename, but keep the old one open
|
||||||
void saveCopy(const String& package);
|
void saveCopy(const String& package);
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------- : Managing the inside of the package
|
// --------------------------------------------------- : Managing the inside of the package
|
||||||
|
|
||||||
/// Open an input stream for a file in the package.
|
/// Open an input stream for a file in the package.
|
||||||
InputStreamP openIn(const String& file);
|
InputStreamP openIn(const String& file);
|
||||||
|
|
||||||
/// Open an output stream for a file in the package.
|
/// Open an output stream for a file in the package.
|
||||||
/// (changes are only committed with save())
|
/// (changes are only committed with save())
|
||||||
OutputStreamP openOut(const String& file);
|
OutputStreamP openOut(const String& file);
|
||||||
|
|
||||||
/// Get a filename that can be written to to modfify a file in the package
|
/// Get a filename that can be written to to modfify a file in the package
|
||||||
/// (changes are only committed with save())
|
/// (changes are only committed with save())
|
||||||
String nameOut(const String& file);
|
String nameOut(const String& file);
|
||||||
|
|
||||||
/// Creates a new, unique, filename with the specified prefix and suffix
|
/// Creates a new, unique, filename with the specified prefix and suffix
|
||||||
/// for example newFileName("image/",".jpg") -> "image/1.jpg"
|
/// for example newFileName("image/",".jpg") -> "image/1.jpg"
|
||||||
/// Returns the name of a temporary file that can be written to.
|
/// Returns the name of a temporary file that can be written to.
|
||||||
FileName newFileName(const String& prefix, const String& suffix);
|
FileName newFileName(const String& prefix, const String& suffix);
|
||||||
|
|
||||||
/// Signal that a file is still used by this package.
|
/// Signal that a file is still used by this package.
|
||||||
/// Must be called for files not opened using openOut/nameOut
|
/// Must be called for files not opened using openOut/nameOut
|
||||||
/// If they are to be kept in the package.
|
/// If they are to be kept in the package.
|
||||||
void referenceFile(const String& file);
|
void referenceFile(const String& file);
|
||||||
|
|
||||||
/// Get an 'absolute filename' for a file in the package.
|
/// Get an 'absolute filename' for a file in the package.
|
||||||
/// This file can later be opened from anywhere (other process) using openAbsoluteFile()
|
/// This file can later be opened from anywhere (other process) using openAbsoluteFile()
|
||||||
String absoluteName(const String& file);
|
String absoluteName(const String& file);
|
||||||
|
|
||||||
/// Open a file given an absolute filename
|
/// Open a file given an absolute filename
|
||||||
static InputStreamP openAbsoluteFile(const String& name);
|
static InputStreamP openAbsoluteFile(const String& name);
|
||||||
|
|
||||||
// --------------------------------------------------- : Managing the inside of the package : Reader/writer
|
// --------------------------------------------------- : Managing the inside of the package : Reader/writer
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void readFile(const String& file, T& obj) {
|
void readFile(const String& file, T& obj) {
|
||||||
Reader reader(openIn(file), dynamic_cast<Packaged*>(this), absoluteFilename() + _("/") + file);
|
Reader reader(openIn(file), dynamic_cast<Packaged*>(this), absoluteFilename() + _("/") + file);
|
||||||
@@ -134,16 +134,16 @@ class Package : public IntrusivePtrVirtualBase {
|
|||||||
readFile(file, obj);
|
readFile(file, obj);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void writeFile(const String& file, const T& obj, Version file_version) {
|
void writeFile(const String& file, const T& obj, Version file_version) {
|
||||||
Writer writer(openOut(file), file_version);
|
Writer writer(openOut(file), file_version);
|
||||||
writer.handle(obj);
|
writer.handle(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------- : Private stuff
|
// --------------------------------------------------- : Private stuff
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Information about a file in the package
|
/// Information about a file in the package
|
||||||
struct FileInfo {
|
struct FileInfo {
|
||||||
FileInfo();
|
FileInfo();
|
||||||
@@ -154,7 +154,7 @@ class Package : public IntrusivePtrVirtualBase {
|
|||||||
/// Is this file changed, and therefore written to a temporary file?
|
/// Is this file changed, and therefore written to a temporary file?
|
||||||
inline bool wasWritten() const { return !tempName.empty(); }
|
inline bool wasWritten() const { return !tempName.empty(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Filename of the package
|
/// Filename of the package
|
||||||
String filename;
|
String filename;
|
||||||
/// Last modified time
|
/// Last modified time
|
||||||
@@ -173,7 +173,7 @@ class Package : public IntrusivePtrVirtualBase {
|
|||||||
wxFileInputStream* fileStream;
|
wxFileInputStream* fileStream;
|
||||||
/// Filestream for reading zip files
|
/// Filestream for reading zip files
|
||||||
wxZipInputStream* zipStream;
|
wxZipInputStream* zipStream;
|
||||||
|
|
||||||
void loadZipStream();
|
void loadZipStream();
|
||||||
void openDirectory();
|
void openDirectory();
|
||||||
void openSubdir(const String&);
|
void openSubdir(const String&);
|
||||||
@@ -193,7 +193,7 @@ class PackageDependency : public IntrusivePtrBase<PackageDependency> {
|
|||||||
public:
|
public:
|
||||||
String package; ///< Name of the package someone depends on
|
String package; ///< Name of the package someone depends on
|
||||||
Version version; ///< Minimal required version of that package
|
Version version; ///< Minimal required version of that package
|
||||||
|
|
||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ class Packaged : public Package {
|
|||||||
public:
|
public:
|
||||||
Packaged();
|
Packaged();
|
||||||
virtual ~Packaged() {}
|
virtual ~Packaged() {}
|
||||||
|
|
||||||
Version version; ///< Version number of this package
|
Version version; ///< Version number of this package
|
||||||
Version compatible_version; ///< Earliest version number this package is compatible with
|
Version compatible_version; ///< Earliest version number this package is compatible with
|
||||||
String installer_group; ///< Group to place this package in in the installer
|
String installer_group; ///< Group to place this package in in the installer
|
||||||
@@ -213,10 +213,10 @@ class Packaged : public Package {
|
|||||||
String icon_filename; ///< Filename of icon to use in package lists
|
String icon_filename; ///< Filename of icon to use in package lists
|
||||||
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
|
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
|
||||||
int position_hint; ///< A hint for the package list
|
int position_hint; ///< A hint for the package list
|
||||||
|
|
||||||
/// Get an input stream for the package icon, if there is any
|
/// Get an input stream for the package icon, if there is any
|
||||||
InputStreamP openIconFile();
|
InputStreamP openIconFile();
|
||||||
|
|
||||||
/// Open a package, and read the data
|
/// Open a package, and read the data
|
||||||
/** if just_header is true, then the package is not fully parsed.
|
/** if just_header is true, then the package is not fully parsed.
|
||||||
*/
|
*/
|
||||||
@@ -226,11 +226,15 @@ class Packaged : public Package {
|
|||||||
void save();
|
void save();
|
||||||
void saveAs(const String& package, bool remove_unused = true);
|
void saveAs(const String& package, bool remove_unused = true);
|
||||||
void saveCopy(const String& package);
|
void saveCopy(const String& package);
|
||||||
|
|
||||||
/// Check if this package lists a dependency on the given package
|
/// Check if this package lists a dependency on the given package
|
||||||
/** This is done to force people to fill in the dependencies */
|
/** This is done to force people to fill in the dependencies */
|
||||||
void requireDependency(Packaged* package);
|
void requireDependency(Packaged* package);
|
||||||
|
|
||||||
|
inline bool isFullyLoaded () const {
|
||||||
|
return fully_loaded;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// filename of the data file, and extension of the package file
|
/// filename of the data file, and extension of the package file
|
||||||
virtual String typeName() const = 0;
|
virtual String typeName() const = 0;
|
||||||
@@ -238,9 +242,9 @@ class Packaged : public Package {
|
|||||||
virtual void validate(Version file_app_version);
|
virtual void validate(Version file_app_version);
|
||||||
/// What file version should be used for writing files?
|
/// What file version should be used for writing files?
|
||||||
virtual Version fileVersion() const = 0;
|
virtual Version fileVersion() const = 0;
|
||||||
|
|
||||||
DECLARE_REFLECTION_VIRTUAL();
|
DECLARE_REFLECTION_VIRTUAL();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool fully_loaded; ///< Is the package fully loaded?
|
bool fully_loaded; ///< Is the package fully loaded?
|
||||||
friend struct JustAsPackageProxy;
|
friend struct JustAsPackageProxy;
|
||||||
|
|||||||
Reference in New Issue
Block a user