Add dark icon property

This commit is contained in:
GenevensiS
2025-12-05 13:36:09 +01:00
parent 039a9c5b34
commit 04a3289755
10 changed files with 118 additions and 84 deletions
+1
View File
@@ -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);
+1
View File
@@ -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
View File
@@ -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);
+11 -10
View File
@@ -60,16 +60,17 @@ public:
PackageDescription();
PackageDescription(const Packaged& package);
String name; ///< Filename of the package
Version version; ///< Version number of this package
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
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
String description; ///< Changelog/description
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
String name; ///< Filename of the package
Version version; ///< Version number of this package
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
String description; ///< Changelog/description
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
/// Merge two descriptions a package. This package takes precedence
/** Usually one of the descriptions will refer to the locally installed one, the other to the new one */
+28 -24
View File
@@ -16,23 +16,24 @@ extern ScriptValueP script_primary_choice;
// ----------------------------------------------------------------------------- : Statistics dimension
StatsDimension::StatsDimension()
: automatic (false)
, position_hint(0)
, numeric (false)
, bin_size (0)
, show_empty (false)
, split_list (false)
: automatic (false)
, position_hint (0)
, numeric (false)
, bin_size (0)
, show_empty (false)
, split_list (false)
{}
StatsDimension::StatsDimension(const Field& field)
: automatic (true)
, name (field.name)
, description (field.description)
, position_hint(field.position_hint)
, icon_filename(field.icon_filename)
, numeric (false)
, show_empty (false)
, split_list (false)
: automatic (true)
, name (field.name)
, description (field.description)
, 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)
{
// choice field?
const ChoiceField* choice_field = dynamic_cast<const ChoiceField*>(&field);
@@ -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)
, name (dim->name)
, description (dim->description)
, position_hint(dim->position_hint)
, icon_filename(dim->icon_filename)
, dimensions(1, dim)
, type(GRAPH_TYPE_BAR)
: automatic (true)
, name (dim->name)
, description (dim->description)
, 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);
}
+25 -23
View File
@@ -27,20 +27,21 @@ public:
StatsDimension();
StatsDimension(const Field&);
const bool automatic; ///< Based on a card field?
String name; ///< Name of this dimension
LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists
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
bool numeric; ///< Are the values numeric? If so, they require special sorting
double bin_size; ///< Bin adjecent numbers?
bool show_empty; ///< Should "" be shown?
bool split_list; ///< Split values into multiple ones separated by commas
map<String,Color> colors; ///< Colors for the categories
vector<String> groups; ///< Order of the items
const bool automatic; ///< Based on a card field?
String name; ///< Name of this dimension
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
bool numeric; ///< Are the values numeric? If so, they require special sorting
double bin_size; ///< Bin adjecent numbers?
bool show_empty; ///< Should "" be shown?
bool split_list; ///< Split values into multiple ones separated by commas
map<String,Color> colors; ///< Colors for the categories
vector<String> groups; ///< Order of the items
DECLARE_REFLECTION();
};
@@ -54,15 +55,16 @@ public:
StatsCategory();
StatsCategory(const StatsDimensionP&);
const bool automatic; ///< Automatically generated?
String name; ///< Name/label
LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists
Bitmap icon; ///< The loaded icon (optional of course)
vector<String> dimension_names; ///< Names of the dimensions to use
vector<StatsDimensionP> dimensions; ///< Actual dimensions
GraphType type; ///< Type of graph to use
const bool automatic; ///< Automatically generated?
String name; ///< Name/label
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
GraphType type; ///< Type of graph to use
/// Initialize dimensions from dimension_names
void find_dimensions(const vector<StatsDimensionP>& available);
+4 -3
View File
@@ -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));
}
+13 -7
View File
@@ -228,13 +228,19 @@ 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);
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()) {
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
View File
@@ -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>();
}
+10 -9
View File
@@ -305,15 +305,16 @@ public:
Packaged();
virtual ~Packaged() {}
Version version; ///< Version number of this package
Version compatible_version; ///< Earliest version number this package is compatible with
String installer_group; ///< Group to place this package in in the installer
String short_name; ///< Short name of this package
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
vector<PackageDependencyP> dependencies; ///< Dependencies of this package
int position_hint; ///< A hint for the package list
Version version; ///< Version number of this package
Version compatible_version; ///< Earliest version number this package is compatible with
String installer_group; ///< Group to place this package in in the installer
String short_name; ///< Short name of this package
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
/// Get an input stream for the package icon, if there is any
unique_ptr<wxInputStream> openIconFile();