Commit 4722cdb2 authored by twanvl's avatar twanvl

separate short_name for packages, moved full_name,short_name and icon_filename to Packaged

parent faeb0888
...@@ -36,18 +36,8 @@ bool Game::isMagic() const { ...@@ -36,18 +36,8 @@ bool Game::isMagic() const {
String Game::typeNameStatic() { return _("game"); } String Game::typeNameStatic() { return _("game"); }
String Game::typeName() const { return _("game"); } String Game::typeName() const { return _("game"); }
String Game::fullName() const { return full_name; }
InputStreamP Game::openIconFile() {
if (!icon_filename.empty()) {
return openIn(icon_filename);
} else {
return InputStreamP();
}
}
IMPLEMENT_REFLECTION(Game) { IMPLEMENT_REFLECTION(Game) {
REFLECT(full_name); REFLECT_BASE(Packaged);
REFLECT_N("icon", icon_filename);
REFLECT(init_script); REFLECT(init_script);
REFLECT(set_fields); REFLECT(set_fields);
REFLECT(card_fields); REFLECT(card_fields);
...@@ -59,9 +49,8 @@ IMPLEMENT_REFLECTION(Game) { ...@@ -59,9 +49,8 @@ IMPLEMENT_REFLECTION(Game) {
// REFLECT(word_lists); // REFLECT(word_lists);
} }
void Game::validate(Version) { void Game::validate(Version v) {
// a default for the full name Packaged::validate(v);
if (full_name.empty()) full_name = name();
// automatic statistics dimensions // automatic statistics dimensions
{ {
vector<StatsDimensionP> dims; vector<StatsDimensionP> dims;
......
...@@ -33,8 +33,6 @@ class Game : public Packaged { ...@@ -33,8 +33,6 @@ class Game : public Packaged {
public: public:
Game(); Game();
String full_name; ///< Name of this game, for menus etc.
String icon_filename; ///< Filename of icon to use in NewWindow
OptionalScript init_script; ///< Script of variables available to other scripts in this game OptionalScript init_script; ///< Script of variables available to other scripts in this game
vector<FieldP> set_fields; ///< Fields for set information vector<FieldP> set_fields; ///< Fields for set information
vector<FieldP> card_fields; ///< Fields on each card vector<FieldP> card_fields; ///< Fields on each card
...@@ -57,8 +55,6 @@ class Game : public Packaged { ...@@ -57,8 +55,6 @@ class Game : public Packaged {
static String typeNameStatic(); static String typeNameStatic();
virtual String typeName() const; virtual String typeName() const;
virtual String fullName() const;
virtual InputStreamP openIconFile();
protected: protected:
virtual void validate(Version); virtual void validate(Version);
......
...@@ -21,7 +21,7 @@ LocaleP Locale::byName(const String& name) { ...@@ -21,7 +21,7 @@ LocaleP Locale::byName(const String& name) {
} }
IMPLEMENT_REFLECTION(Locale) { IMPLEMENT_REFLECTION(Locale) {
REFLECT(full_name); REFLECT_BASE(Packaged);
REFLECT_N("menu", translations[LOCALE_CAT_MENU]); REFLECT_N("menu", translations[LOCALE_CAT_MENU]);
REFLECT_N("help", translations[LOCALE_CAT_HELP]); REFLECT_N("help", translations[LOCALE_CAT_HELP]);
REFLECT_N("tool", translations[LOCALE_CAT_TOOL]); REFLECT_N("tool", translations[LOCALE_CAT_TOOL]);
......
...@@ -29,8 +29,6 @@ class GameLocale { ...@@ -29,8 +29,6 @@ class GameLocale {
/// A collection of translations of messages /// A collection of translations of messages
class Locale : public Packaged { class Locale : public Packaged {
public: public:
/// Name of this locale
String full_name;
/// Translations of UI strings in each category /// Translations of UI strings in each category
map<String,String> translations[LOCALE_CAT_MAX]; map<String,String> translations[LOCALE_CAT_MAX];
/// Translations of game specific texts, by game name /// Translations of game specific texts, by game name
......
...@@ -36,15 +36,6 @@ String StyleSheet::stylesheetName() const { ...@@ -36,15 +36,6 @@ String StyleSheet::stylesheetName() const {
String StyleSheet::typeNameStatic() { return _("style"); } String StyleSheet::typeNameStatic() { return _("style"); }
String StyleSheet::typeName() const { return _("style"); } String StyleSheet::typeName() const { return _("style"); }
String StyleSheet::fullName() const { return full_name; }
InputStreamP StyleSheet::openIconFile() {
if (!icon_filename.empty()) {
return openIn(icon_filename);
} else {
return game->openIconFile(); // use game icon by default
}
}
StyleP StyleSheet::styleFor(const FieldP& field) { StyleP StyleSheet::styleFor(const FieldP& field) {
if (card_style.containsKey(field)) { if (card_style.containsKey(field)) {
return card_style[field]; return card_style[field];
...@@ -70,8 +61,7 @@ IMPLEMENT_REFLECTION(StyleSheet) { ...@@ -70,8 +61,7 @@ IMPLEMENT_REFLECTION(StyleSheet) {
tag.addAlias(300, _("extra style"),_("styling style")); tag.addAlias(300, _("extra style"),_("styling style"));
REFLECT(game); REFLECT(game);
REFLECT(full_name); REFLECT_BASE(Packaged);
REFLECT_N("icon", icon_filename);
REFLECT(init_script); REFLECT(init_script);
REFLECT(card_width); REFLECT(card_width);
REFLECT(card_height); REFLECT(card_height);
...@@ -90,11 +80,6 @@ IMPLEMENT_REFLECTION(StyleSheet) { ...@@ -90,11 +80,6 @@ IMPLEMENT_REFLECTION(StyleSheet) {
REFLECT(styling_style); REFLECT(styling_style);
} }
void StyleSheet::validate(Version) {
// a default for the full name
if (full_name.empty()) full_name = name();
}
// special behaviour of reading/writing StyleSheetPs: only read/write the name // special behaviour of reading/writing StyleSheetPs: only read/write the name
......
...@@ -27,8 +27,6 @@ class StyleSheet : public Packaged { ...@@ -27,8 +27,6 @@ class StyleSheet : public Packaged {
StyleSheet(); StyleSheet();
GameP game; ///< The game this stylesheet is made for GameP game; ///< The game this stylesheet is made for
String full_name; ///< Name of this game, for menus etc.
String icon_filename; ///< Filename of icon to use in NewWindow
OptionalScript init_script; ///< Script of variables available to other scripts in this stylesheet OptionalScript init_script; ///< Script of variables available to other scripts in this stylesheet
double card_width; ///< The width of a card in pixels double card_width; ///< The width of a card in pixels
double card_height; ///< The height of a card in pixels double card_height; ///< The height of a card in pixels
...@@ -60,11 +58,8 @@ class StyleSheet : public Packaged { ...@@ -60,11 +58,8 @@ class StyleSheet : public Packaged {
static String typeNameStatic(); static String typeNameStatic();
virtual String typeName() const; virtual String typeName() const;
virtual String fullName() const;
virtual InputStreamP openIconFile();
protected: protected:
virtual void validate(Version);
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
......
...@@ -33,14 +33,14 @@ void PackageList::drawItem(DC& dc, int x, int y, size_t item, bool selected) { ...@@ -33,14 +33,14 @@ void PackageList::drawItem(DC& dc, int x, int y, size_t item, bool selected) {
} }
// draw short name // draw short name
dc.SetFont(wxFont(12,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial"))); dc.SetFont(wxFont(12,wxSWISS,wxNORMAL,wxBOLD,false,_("Arial")));
dc.GetTextExtent(capitalize(d.package->name()), &w, &h); dc.GetTextExtent(capitalize(d.package->short_name), &w, &h);
pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect); pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
dc.DrawText(capitalize(d.package->name()), pos.x, pos.y + 110); dc.DrawText(capitalize(d.package->short_name), pos.x, pos.y + 110);
// draw name // draw name
dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
dc.GetTextExtent(d.package->fullName(), &w, &h); dc.GetTextExtent(d.package->full_name, &w, &h);
RealPoint text_pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect); RealPoint text_pos = align_in_rect(ALIGN_CENTER, RealSize(w,h), rect);
dc.DrawText(d.package->fullName(), text_pos.x, text_pos.y + 130); dc.DrawText(d.package->full_name, text_pos.x, text_pos.y + 130);
} }
void PackageList::showData(const String& pattern) { void PackageList::showData(const String& pattern) {
...@@ -51,7 +51,7 @@ void PackageList::showData(const String& pattern) { ...@@ -51,7 +51,7 @@ void PackageList::showData(const String& pattern) {
while (!f.empty()) { while (!f.empty()) {
// try to open the package // try to open the package
// try { // try {
PackageP package = ::packages.openAny(f); PackagedP package = ::packages.openAny(f);
// open image // open image
InputStreamP stream = package->openIconFile(); InputStreamP stream = package->openIconFile();
Image img; Image img;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <gui/control/gallery_list.hpp> #include <gui/control/gallery_list.hpp>
DECLARE_POINTER_TYPE(Package); DECLARE_POINTER_TYPE(Packaged);
// ----------------------------------------------------------------------------- : PackageList // ----------------------------------------------------------------------------- : PackageList
...@@ -59,9 +59,9 @@ class PackageList : public GalleryList { ...@@ -59,9 +59,9 @@ class PackageList : public GalleryList {
// Information about a package // Information about a package
struct PackageData { struct PackageData {
PackageData() {} PackageData() {}
PackageData(const PackageP& package, const Bitmap& image) : package(package), image(image) {} PackageData(const PackagedP& package, const Bitmap& image) : package(package), image(image) {}
PackageP package; PackagedP package;
Bitmap image; Bitmap image;
}; };
/// The displayed packages /// The displayed packages
vector<PackageData> packages; vector<PackageData> packages;
......
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
BufferSecurityCheck="FALSE" BufferSecurityCheck="FALSE"
EnableFunctionLevelLinking="TRUE" EnableFunctionLevelLinking="TRUE"
RuntimeTypeInfo="TRUE" RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="2" UsePrecompiledHeader="0"
PrecompiledHeaderThrough="util/prec.hpp" PrecompiledHeaderThrough="util/prec.hpp"
PrecompiledHeaderFile="" PrecompiledHeaderFile=""
AssemblerListingLocation="$(OutDir)" AssemblerListingLocation="$(OutDir)"
......
...@@ -60,9 +60,6 @@ String Package::fullName() const { ...@@ -60,9 +60,6 @@ String Package::fullName() const {
const String& Package::absoluteFilename() const { const String& Package::absoluteFilename() const {
return filename; return filename;
} }
InputStreamP Package::openIconFile() {
return InputStreamP();
}
void Package::open(const String& n) { void Package::open(const String& n) {
...@@ -408,12 +405,21 @@ String Package::toStandardName(const String& name) { ...@@ -408,12 +405,21 @@ String Package::toStandardName(const String& name) {
// note: reflection must be declared before it is used // note: reflection must be declared before it is used
IMPLEMENT_REFLECTION(Packaged) { IMPLEMENT_REFLECTION(Packaged) {
// default does nothing REFLECT(short_name);
REFLECT(full_name);
REFLECT_N("icon", icon_filename);
} }
Packaged::Packaged() { Packaged::Packaged() {
} }
InputStreamP Packaged::openIconFile() {
if (!icon_filename.empty()) {
return openIn(icon_filename);
} else {
return InputStreamP();
}
}
void Packaged::open(const String& package) { void Packaged::open(const String& package) {
Package::open(package); Package::open(package);
Reader reader(openIn(typeName()), absoluteFilename() + _("/") + typeName()); Reader reader(openIn(typeName()), absoluteFilename() + _("/") + typeName());
...@@ -436,3 +442,8 @@ void Packaged::saveAs(const String& package) { ...@@ -436,3 +442,8 @@ void Packaged::saveAs(const String& package) {
referenceFile(typeName()); referenceFile(typeName());
Package::saveAs(package); Package::saveAs(package);
} }
void Packaged::validate(Version) {
// a default for the short name
if (short_name.empty()) short_name = name();
}
\ No newline at end of file
...@@ -64,10 +64,7 @@ class Package { ...@@ -64,10 +64,7 @@ class Package {
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; }
/// Get an input stream for the package icon, if there is any
virtual InputStreamP openIconFile();
/// 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);
...@@ -187,6 +184,13 @@ class Packaged : public Package { ...@@ -187,6 +184,13 @@ class Packaged : public Package {
Packaged(); Packaged();
virtual ~Packaged() {} virtual ~Packaged() {}
String short_name; ///< Short name of this package
String full_name; ///< Name of this package, for menus etc.
String icon_filename; ///< Filename of icon to use in package lists
/// Get an input stream for the package icon, if there is any
InputStreamP openIconFile();
/// Open a package, and read the data /// Open a package, and read the data
void open(const String& package); void open(const String& package);
void save(); void save();
...@@ -196,7 +200,7 @@ class Packaged : public Package { ...@@ -196,7 +200,7 @@ class Packaged : public Package {
/// 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;
/// Can be overloaded to do validation after loading /// Can be overloaded to do validation after loading
virtual void validate(Version file_app_version) {} virtual void validate(Version file_app_version);
DECLARE_REFLECTION_VIRTUAL(); DECLARE_REFLECTION_VIRTUAL();
}; };
......
...@@ -26,10 +26,10 @@ class IncludePackage : public Packaged { ...@@ -26,10 +26,10 @@ class IncludePackage : public Packaged {
String IncludePackage::typeName() const { return _("include"); } String IncludePackage::typeName() const { return _("include"); }
IMPLEMENT_REFLECTION(IncludePackage) { IMPLEMENT_REFLECTION(IncludePackage) {
REFLECT_BASE(Packaged);
if (tag.reading()) { if (tag.reading()) {
// ingore // ingore
String full_name, version; String version;
REFLECT(full_name);
REFLECT(version); REFLECT(version);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment