Skip to content

Commit

Permalink
Fix trying to get nonexistent platform from Steam game info
Browse files Browse the repository at this point in the history
Show default icons for games in list and details
  • Loading branch information
tkashkin committed Jun 22, 2019
1 parent b19073e commit 603316b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/data/sources/steam/SteamGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ namespace GameHub.Data.Sources.Steam

foreach(var p in Platform.PLATFORMS)
{
if(platforms_json.get_boolean_member(p.id()))
if(platforms_json.has_member(p.id()) && platforms_json.get_boolean_member(p.id()))
{
platforms.add(p);
}
Expand All @@ -212,7 +212,7 @@ namespace GameHub.Data.Sources.Steam
save();

update_status();

game_info_updated = true;
game_info_updating = false;
}
Expand Down
21 changes: 18 additions & 3 deletions src/ui/views/GameDetailsView/GameDetailsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace GameHub.UI.Views.GameDetailsView
private Label status;
private ProgressBar download_progress;
private AutoSizeImage icon;
private Image no_icon_indicator;
private Image src_icon;

private Box platform_icons;
Expand Down Expand Up @@ -107,10 +108,23 @@ namespace GameHub.UI.Views.GameDetailsView

var title_hbox = new Box(Orientation.HORIZONTAL, 15);

var icon_overlay = new Overlay();
icon_overlay.set_size_request(48, 48);
icon_overlay.valign = Align.START;

no_icon_indicator = new Image.from_icon_name("gamehub-symbolic", IconSize.DND);
no_icon_indicator.get_style_context().add_class("no-icon-indicator");
no_icon_indicator.halign = Align.CENTER;
no_icon_indicator.valign = Align.CENTER;
no_icon_indicator.opacity = 0.8;

icon = new AutoSizeImage();
icon.valign = Align.START;
icon.halign = Align.CENTER;
icon.valign = Align.CENTER;
icon.set_constraint(48, 48, 1);
icon.set_size_request(48, 48);

icon_overlay.add(no_icon_indicator);
icon_overlay.add_overlay(icon);

title = new Label(null);
title.halign = Align.START;
Expand Down Expand Up @@ -174,7 +188,7 @@ namespace GameHub.UI.Views.GameDetailsView
title_vbox.add(hbox_inner);
title_vbox.add(download_progress);

title_hbox.add(icon);
title_hbox.add(icon_overlay);
title_hbox.add(title_vbox);

title_icons.add(platform_icons);
Expand Down Expand Up @@ -358,6 +372,7 @@ namespace GameHub.UI.Views.GameDetailsView
set_visible_widgets(game.status);

icon.load(game.icon, "icon");
no_icon_indicator.visible = game.icon == null || icon.source == null;

stack.set_visible_child(content_scrolled);
}
Expand Down
43 changes: 33 additions & 10 deletions src/ui/views/GamesView/GameListRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ namespace GameHub.UI.Views.GamesView

public signal void update_tags();

private AutoSizeImage image;
private Overlay icon_overlay;
private AutoSizeImage icon;
private Image no_icon_indicator;

private Label label;
private Label state_label;
private Image favorite_icon;
Expand All @@ -71,10 +74,23 @@ namespace GameHub.UI.Views.GamesView
var vbox = new Box(Orientation.VERTICAL, 0);
vbox.valign = Align.CENTER;

image = new AutoSizeImage();
image.valign = Align.CENTER;
icon_overlay = new Overlay();

no_icon_indicator = new Image.from_icon_name("gamehub-symbolic", IconSize.BUTTON);
no_icon_indicator.get_style_context().add_class("no-icon-indicator");
no_icon_indicator.halign = Align.CENTER;
no_icon_indicator.valign = Align.CENTER;
no_icon_indicator.opacity = 0.8;

icon = new AutoSizeImage();
icon.halign = Align.CENTER;
icon.valign = Align.CENTER;
icon.scale = true;

icon_overlay.add(no_icon_indicator);
icon_overlay.add_overlay(icon);

hbox.add(image);
hbox.add(icon_overlay);

var label_hbox = new Box(Orientation.HORIZONTAL, 4);

Expand Down Expand Up @@ -126,7 +142,7 @@ namespace GameHub.UI.Views.GamesView
break;

case 3:
new GameContextMenu(game, image).open(e, true);
new GameContextMenu(game, icon).open(e, true);
break;
}
return true;
Expand Down Expand Up @@ -220,18 +236,25 @@ namespace GameHub.UI.Views.GamesView
public void update_compact_view()
{
var compact = ui_settings.list_compact;
var image_size = compact ? 16 : 36;
image.set_constraint(image_size, image_size, 1);
image.set_size_request(image_size, image_size);
var is_gog_game = game is GameHub.Data.Sources.GOG.GOGGame;

// GOG icons are rounded, make them bigger to compensate visual difference
var image_size = compact ? (is_gog_game ? 18 : 16) : (is_gog_game ? 38 : 32);
var overlay_size = compact ? 18 : 38;

icon.set_constraint(image_size, image_size, 1);
icon_overlay.set_size_request(overlay_size, overlay_size);

state_label.visible = !compact;
}

private void update_icon()
{
image.queue_draw();
icon.queue_draw();
if(game.icon == old_icon) return;
old_icon = game.icon;
image.load(game.icon, "icon");
icon.load(game.icon, "icon");
no_icon_indicator.visible = game.icon == null || icon.source == null;
}
}
}
36 changes: 25 additions & 11 deletions src/ui/widgets/AutoSizeImage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,29 @@ namespace GameHub.UI.Widgets
private float ratio = 1;
private Orientation constraint = Orientation.HORIZONTAL;

public bool? scale = null;
private bool _scale = true;

public int corner_radius = 4;

public Pixbuf? source
{
get
{
return src;
}
set
{
src = value;
scaled = src;
if(src != null && src.width > 0 && src.height > 0)
{
_scale = scale ?? (src.width > cmin || src.height > cmin || src.width != src.height);
}
queue_draw();
}
}

public void set_constraint(int min, int max, float ratio = 1, Orientation orientation = Orientation.HORIZONTAL)
{
this.constraint = orientation;
Expand All @@ -52,22 +73,15 @@ namespace GameHub.UI.Widgets
}
}

public void set_source(Pixbuf? buf)
{
src = buf;
scaled = src;
queue_draw();
}

public void load(string? url, string cache_prefix=ImageCache.DEFAULT_CACHED_FILE_PREFIX)
{
if(url == null || url == "")
{
set_source(null);
source = null;
return;
}
ImageCache.load.begin(url, cache_prefix, (obj, res) => {
set_source(ImageCache.load.end(res));
source = ImageCache.load.end(res);
});
}

Expand Down Expand Up @@ -114,7 +128,7 @@ namespace GameHub.UI.Widgets

if(src != null && src.width > 0 && src.height > 0)
{
if(src.width > cmin || src.height > cmin || src.width != src.height)
if(_scale)
{
var ratio = float.min((float) width / src.width, (float) height / src.height);
var new_width = (int) (src.width * ratio);
Expand All @@ -132,7 +146,7 @@ namespace GameHub.UI.Widgets
new_height = height;
}

if(scaled.width != new_width && scaled.height != new_height)
if(scaled.width != new_width || scaled.height != new_height)
{
scaled = src.scale_simple(new_width, new_height, InterpType.BILINEAR);
}
Expand Down

0 comments on commit 603316b

Please sign in to comment.