mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Add dark icon property
This commit is contained in:
@@ -52,6 +52,7 @@ IMPLEMENT_REFLECTION(Field) {
|
||||
REFLECT_LOCALIZED(caption);
|
||||
REFLECT_LOCALIZED(description); // FIXME: This field is both unused and uninitialized.
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT_N("dark_icon", dark_icon_filename);
|
||||
REFLECT(editable);
|
||||
REFLECT(save_value);
|
||||
REFLECT(show_statistics);
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
LocalizedString caption; ///< Caption for NativeLookEditor
|
||||
LocalizedString description; ///< Description, used in status bar
|
||||
String icon_filename; ///< Filename for an icon (for list of fields)
|
||||
String dark_icon_filename; ///< Filename for an icon (for list of fields) when a variant for dark mode is necessary
|
||||
bool editable; ///< Can values of this field be edited?
|
||||
bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields.
|
||||
bool show_statistics; ///< Should this field appear as a group by choice in the statistics panel?
|
||||
|
||||
+10
-3
@@ -38,15 +38,20 @@ void Installer::validate(Version file_app_version) {
|
||||
Packaged::validate(file_app_version);
|
||||
// load icons where possible
|
||||
FOR_EACH(p,packages) {
|
||||
if (!p->icon_url.empty() && !starts_with(p->icon_url,_("http:"))) {
|
||||
String url = p->icon_url;
|
||||
if (settings.darkMode() && !p->dark_icon_url.empty()) {
|
||||
url = p->dark_icon_url;
|
||||
}
|
||||
if (!url.empty() && !starts_with(url,_("http:"))) {
|
||||
// TODO: support absolute icon names
|
||||
try{
|
||||
String filename = p->name + _("/") + p->icon_url;
|
||||
auto img_stream = openIn(p->name + _("/") + p->icon_url);
|
||||
String filename = p->name + _("/") + url;
|
||||
auto img_stream = openIn(p->name + _("/") + url);
|
||||
image_load_file(p->icon, *img_stream);
|
||||
} catch (...) {
|
||||
// ignore errors, it's just an image
|
||||
p->icon_url.clear();
|
||||
p->dark_icon_url.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,6 +207,7 @@ PackageDescription::PackageDescription(const Packaged& package)
|
||||
, short_name(package.short_name)
|
||||
, full_name(package.full_name)
|
||||
, icon_url(package.icon_filename)
|
||||
, dark_icon_url(package.dark_icon_filename)
|
||||
, installer_group(package.installer_group)
|
||||
, position_hint(package.position_hint)
|
||||
//, description(package.description)
|
||||
@@ -237,6 +243,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(PackageDescription) {
|
||||
REFLECT(short_name);
|
||||
REFLECT(full_name);
|
||||
REFLECT(icon_url);
|
||||
REFLECT(dark_icon_url);
|
||||
REFLECT(installer_group);
|
||||
REFLECT(position_hint);
|
||||
REFLECT(description);
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
String short_name; ///< Short name of this package
|
||||
String full_name; ///< Name of this package, for menus etc.
|
||||
String icon_url; ///< Filename or URL of icon to use in package lists
|
||||
String dark_icon_url; ///< Filename or URL of icon to use in package lists
|
||||
Image icon; ///< Icon for the package
|
||||
String installer_group; ///< Where to put this package in the installer
|
||||
int position_hint; ///< A hint for the package list
|
||||
|
||||
+15
-11
@@ -17,7 +17,7 @@ extern ScriptValueP script_primary_choice;
|
||||
|
||||
StatsDimension::StatsDimension()
|
||||
: automatic (false)
|
||||
, position_hint(0)
|
||||
, position_hint (0)
|
||||
, numeric (false)
|
||||
, bin_size (0)
|
||||
, show_empty (false)
|
||||
@@ -28,8 +28,9 @@ StatsDimension::StatsDimension(const Field& field)
|
||||
: automatic (true)
|
||||
, name (field.name)
|
||||
, description (field.description)
|
||||
, position_hint(field.position_hint)
|
||||
, icon_filename(field.icon_filename)
|
||||
, position_hint (field.position_hint)
|
||||
, icon_filename (field.icon_filename)
|
||||
, dark_icon_filename (field.dark_icon_filename)
|
||||
, numeric (false)
|
||||
, show_empty (false)
|
||||
, split_list (false)
|
||||
@@ -67,6 +68,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
|
||||
REFLECT_LOCALIZED(description);
|
||||
REFLECT(position_hint);
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT_N("dark_icon", dark_icon_filename);
|
||||
REFLECT(script);
|
||||
REFLECT(global_script);
|
||||
REFLECT(numeric);
|
||||
@@ -81,19 +83,20 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
|
||||
// ----------------------------------------------------------------------------- : Statistics category
|
||||
|
||||
StatsCategory::StatsCategory()
|
||||
: automatic(false)
|
||||
, position_hint(0)
|
||||
, type(GRAPH_TYPE_BAR)
|
||||
: automatic (false)
|
||||
, position_hint (0)
|
||||
, type (GRAPH_TYPE_BAR)
|
||||
{}
|
||||
|
||||
StatsCategory::StatsCategory(const StatsDimensionP& dim)
|
||||
: automatic(true)
|
||||
: automatic (true)
|
||||
, name (dim->name)
|
||||
, description (dim->description)
|
||||
, position_hint(dim->position_hint)
|
||||
, icon_filename(dim->icon_filename)
|
||||
, dimensions(1, dim)
|
||||
, type(GRAPH_TYPE_BAR)
|
||||
, position_hint (dim->position_hint)
|
||||
, icon_filename (dim->icon_filename)
|
||||
, dark_icon_filename (dim->dark_icon_filename)
|
||||
, dimensions (1, dim)
|
||||
, type (GRAPH_TYPE_BAR)
|
||||
{}
|
||||
|
||||
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
|
||||
@@ -102,6 +105,7 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
|
||||
REFLECT_LOCALIZED(description);
|
||||
REFLECT(position_hint);
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT_N("dark_icon", dark_icon_filename);
|
||||
REFLECT(type);
|
||||
REFLECT_N("dimensions", dimension_names);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
LocalizedString description; ///< Description, used in status bar
|
||||
int position_hint; ///< Hint for the ordering
|
||||
String icon_filename; ///< Icon for lists
|
||||
String dark_icon_filename; ///< Icon for lists, if a variant for dark mode is needed
|
||||
Bitmap icon; ///< The loaded icon (optional of course)
|
||||
OptionalScript script; ///< Script that determines the value(s), ran on each card
|
||||
OptionalScript global_script; ///< Script that determines the value(s), ran only once at the start
|
||||
@@ -59,6 +60,7 @@ public:
|
||||
LocalizedString description; ///< Description, used in status bar
|
||||
int position_hint; ///< Hint for the ordering
|
||||
String icon_filename; ///< Icon for lists
|
||||
String dark_icon_filename; ///< Icon for lists when a variant for dark mode is needed
|
||||
Bitmap icon; ///< The loaded icon (optional of course)
|
||||
vector<String> dimension_names; ///< Names of the dimensions to use
|
||||
vector<StatsDimensionP> dimensions; ///< Actual dimensions
|
||||
|
||||
@@ -159,13 +159,13 @@ public:
|
||||
PackageIconRequest(PackageUpdateList* list, PackageUpdateList::TreeItem* ti)
|
||||
: ThumbnailRequest(
|
||||
list,
|
||||
_("package_") + ti->package->description->icon_url + _("_") + ti->package->description->version.toString(),
|
||||
_("package_") + (settings.darkMode() && !ti->package->description->dark_icon_url.empty() ? ti->package->description->dark_icon_url : ti->package->description->icon_url) + _("_") + ti->package->description->version.toString(),
|
||||
wxDateTime(1,wxDateTime::Jan,2000))
|
||||
, list(list), ti(ti)
|
||||
{}
|
||||
|
||||
Image generate() override {
|
||||
wxURL url(ti->package->description->icon_url);
|
||||
wxURL url(settings.darkMode() && !ti->package->description->dark_icon_url.empty() ? ti->package->description->dark_icon_url : ti->package->description->icon_url);
|
||||
unique_ptr<wxInputStream> isP(url.GetInputStream());
|
||||
if (!isP) return wxImage();
|
||||
SeekAtStartInputStream is2(*isP);
|
||||
@@ -220,7 +220,8 @@ void PackageUpdateList::initItems() {
|
||||
ti.setIcon(p->description->icon);
|
||||
} else if (p) { // it doesn't have an icon (yet)
|
||||
ti.setIcon(load_resource_image(_("installer_package")));
|
||||
if (!p->description->icon_url.empty()) {
|
||||
String icon_url = settings.darkMode() && !p->description->dark_icon_url.empty() ? p->description->dark_icon_url : p->description->icon_url;
|
||||
if (!icon_url.empty()) {
|
||||
// download icon
|
||||
thumbnail_thread.request(make_intrusive<PackageIconRequest>(this,&ti));
|
||||
}
|
||||
|
||||
@@ -228,14 +228,20 @@ void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item) {
|
||||
}
|
||||
StatsDimension& dim = *dimensions.at(item - show_empty);
|
||||
// draw icon
|
||||
if (!dim.icon_filename.empty() && !dim.icon.Ok()) {
|
||||
auto file = game->openIn(dim.icon_filename);
|
||||
if(!dim.icon.Ok()) {
|
||||
String filename = dim.icon_filename;
|
||||
if (settings.darkMode() && !dim.dark_icon_filename.empty()) {
|
||||
filename = dim.dark_icon_filename;
|
||||
}
|
||||
if (!filename.empty()) {
|
||||
auto file = game->openIn(filename);
|
||||
Image img(*file);
|
||||
if (img.HasMask()) img.InitAlpha(); // we can't handle masks
|
||||
Image resampled(21, 21);
|
||||
resample_preserve_aspect(img, resampled);
|
||||
if (img.Ok()) dim.icon = Bitmap(resampled);
|
||||
}
|
||||
}
|
||||
if (dim.icon.Ok()) {
|
||||
dc.DrawBitmap(dim.icon, x+1, y+1);
|
||||
}
|
||||
|
||||
+12
-2
@@ -572,6 +572,7 @@ IMPLEMENT_REFLECTION(Packaged) {
|
||||
REFLECT(full_name);
|
||||
REFLECT(folder_name);
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT_N("dark_icon", dark_icon_filename);
|
||||
REFLECT_NO_SCRIPT(position_hint);
|
||||
REFLECT(installer_group);
|
||||
REFLECT(version);
|
||||
@@ -585,8 +586,17 @@ Packaged::Packaged()
|
||||
{}
|
||||
|
||||
unique_ptr<wxInputStream> Packaged::openIconFile() {
|
||||
if (!icon_filename.empty()) {
|
||||
return openIn(icon_filename);
|
||||
String filename = icon_filename;
|
||||
if (!dark_icon_filename.empty()) {
|
||||
if (settings.darkMode()) {
|
||||
wxFileName fn (dark_icon_filename);
|
||||
String extension = fn.GetExt();
|
||||
filename = dark_icon_filename.Replace(extension, _("")) + "_dark" + extension;
|
||||
}
|
||||
else filename = dark_icon_filename;
|
||||
}
|
||||
if (!filename.empty()) {
|
||||
return openIn(filename);
|
||||
} else {
|
||||
return unique_ptr<wxInputStream>();
|
||||
}
|
||||
|
||||
@@ -312,6 +312,7 @@ public:
|
||||
String full_name; ///< Name of this package, for menus etc.
|
||||
String folder_name; ///< Name of the folder this package is loaded from.
|
||||
String icon_filename; ///< Filename of icon to use in package lists
|
||||
String dark_icon_filename; ///< Filename of icon to use in package lists, when a variant for dark mode is needed
|
||||
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
|
||||
int position_hint; ///< A hint for the package list
|
||||
|
||||
|
||||
Reference in New Issue
Block a user