Skip to content

Commit

Permalink
CardIdle v2.5
Browse files Browse the repository at this point in the history
+ card prices
+ size settings
* views refactoring
  • Loading branch information
AlexanderSharykin committed May 27, 2018
1 parent 5c047f1 commit eda3e89
Show file tree
Hide file tree
Showing 38 changed files with 1,432 additions and 902 deletions.
Binary file modified Install/CardIdleRemastered.exe
Binary file not shown.
Binary file modified Install/ru-Ru/CardIdleRemastered.resources.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ OS Windows 7 and higher

.Net Framework 4.5

Stable Internet connection

You should be logged into your Steam account via Steam client to start idling.

---
Expand Down
97 changes: 76 additions & 21 deletions SourceCode/CardIdleRemastered/AccountModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
using CardIdleRemastered.Converters;
using CardIdleRemastered.Commands;
using CardIdleRemastered.ViewModels;

Expand All @@ -21,6 +22,7 @@ public class AccountModel : ObservableModel, IDisposable
{
#region Fields
private readonly AccountUpdater _updater;
private readonly PricesUpdater _pricesUpdater;
private readonly IdleManager _idler;
private readonly ShowcaseManager _showcaseManager;

Expand All @@ -36,6 +38,7 @@ public class AccountModel : ObservableModel, IDisposable

private bool _isAuthorized;
private bool _showInTaskbar = true;
private bool _showBackground = true;
private int _activeProcessCount;
private int _totalCards;
private int _totalGames;
Expand All @@ -59,7 +62,8 @@ public class AccountModel : ObservableModel, IDisposable

public AccountModel()
{
_updater = new AccountUpdater(this);
_pricesUpdater = new PricesUpdater();
_updater = new AccountUpdater(this, _pricesUpdater);
_idler = new IdleManager(this);
_showcaseManager = new ShowcaseManager();
_updater.BadgeListSync += SyncShowcases;
Expand Down Expand Up @@ -165,6 +169,17 @@ public bool ShowInTaskbar
}
}

public bool ShowBackground
{
get { return _showBackground; }
set
{
_showBackground = value;
OnPropertyChanged();
OnPropertyChanged("BackgroundUrl");
}
}

public IdleManager Idler
{
get { return _idler; }
Expand Down Expand Up @@ -206,6 +221,8 @@ public string BackgroundUrl
{
get
{
if (false == ShowBackground)
return null;
if (String.IsNullOrWhiteSpace(_customBackgroundUrl) == false)
return _customBackgroundUrl;
return _backgroundUrl;
Expand Down Expand Up @@ -292,24 +309,6 @@ public string SyncTime

#endregion

/// <summary>
/// Initialize timer to regularly check Steam client status
/// </summary>
public void InitSteamTimer()
{
_tmSteamStatus = new DispatcherTimer();
_tmSteamStatus.Interval = new TimeSpan(0, 0, 5);
bool steamRunning = false;
_tmSteamStatus.Tick += (sender, args) =>
{
bool connected = IsSteamRunning;
if (steamRunning != connected)
OnPropertyChanged("IsSteamRunning");
steamRunning = connected;
};
_tmSteamStatus.Start();
}

public void AddBadge(BadgeModel badge)
{
AllBadges.Add(badge);
Expand Down Expand Up @@ -388,6 +387,54 @@ public async void LoadCardIdleProfile()
CardIdleProfile = await new SteamParser().LoadCardIdleProfileAsync();
}

public FileStorage PricesStorage
{
get { return _pricesUpdater.Storage; }
set { _pricesUpdater.Storage = value; }
}

public void Startup()
{
InitSteamTimer();
CheckLatestRelease();
LoadCardIdleProfile();
DownloadPricesCatalog();
LoadAccount();
}

/// <summary>
/// Initialize timer to regularly check Steam client status
/// </summary>
public void InitSteamTimer()
{
_tmSteamStatus = new DispatcherTimer();
_tmSteamStatus.Interval = new TimeSpan(0, 0, 5);
bool steamRunning = false;
_tmSteamStatus.Tick += (sender, args) =>
{
bool connected = IsSteamRunning;
if (steamRunning != connected)
OnPropertyChanged("IsSteamRunning");
steamRunning = connected;
};
_tmSteamStatus.Start();
}

public async void DownloadPricesCatalog()
{
var dt = DateTime.Today;
int dayNum = dt.Year * 10000 + dt.Month * 100 + dt.Day;
if (dayNum > Storage.PricesCatalogDate)
{
bool success = await _pricesUpdater.DownloadCatalog();
if (success)
{
Storage.PricesCatalogDate = dayNum;
Storage.Save();
}
}
}

/// <summary>
/// Load account when application starts
/// </summary>
Expand All @@ -400,7 +447,7 @@ public async void LoadAccount()
Level = Storage.SteamLevel;

AvatarUrl = Storage.SteamAvatarUrl;
CustomBackgroundUrl = Storage.CustomBackgroundUrl;

BackgroundUrl = Storage.SteamBackgroundUrl;

FavoriteBadge = new BadgeLevelData
Expand All @@ -410,6 +457,7 @@ public async void LoadAccount()
};
}

CustomBackgroundUrl = Storage.CustomBackgroundUrl;
BadgePropertiesFilters.Deserialize<BadgeProperty>(Storage.BadgeFilter);
ShowcasePropertiesFilters.Deserialize<ShowcaseProperty>(Storage.ShowcaseFilter);

Expand All @@ -434,6 +482,7 @@ public async void LoadAccount()

AllowShowcaseSync = Storage.AllowShowcaseSync;
ShowInTaskbar = Storage.ShowInTaskbar;
ShowBackground = Storage.ShowBackground;

PropertyChanged += SaveConfiguration;
Idler.PropertyChanged += SaveConfiguration;
Expand All @@ -459,6 +508,7 @@ public async void LoadAccount()
foreach (var id in games)
{
var game = await new SteamParser().GetGameInfo(id);
game.PropertyChanged += BadgeIdleStatusChanged;
Games.Insert(idx, game);
idx++;
}
Expand Down Expand Up @@ -918,7 +968,7 @@ private void SaveConfiguration(object sender, PropertyChangedEventArgs e)
}
else if (e.PropertyName == "BackgroundUrl")
{
Storage.SteamBackgroundUrl = account.BackgroundUrl ?? string.Empty;
Storage.SteamBackgroundUrl = account._backgroundUrl ?? string.Empty;
save = true;
}

Expand Down Expand Up @@ -952,6 +1002,11 @@ private void SaveConfiguration(object sender, PropertyChangedEventArgs e)
Storage.ShowInTaskbar = account.ShowInTaskbar;
save = true;
}
else if (e.PropertyName == "ShowBackground")
{
Storage.ShowBackground = account.ShowBackground;
save = true;
}
else if (e.PropertyName == "FavoriteBadge")
{
if (account.FavoriteBadge != null)
Expand Down
7 changes: 6 additions & 1 deletion SourceCode/CardIdleRemastered/AccountUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ namespace CardIdleRemastered
public class AccountUpdater
{
private AccountModel _account;
private PricesUpdater _pricesUpdater;
private DispatcherTimer _tmSync;
private DispatcherTimer _tmCounter;
private TimeSpan _interval;
private int _counter;

public AccountUpdater(AccountModel account)
public AccountUpdater(AccountModel account, PricesUpdater pricesUpdater)
{
_account = account;
_pricesUpdater = pricesUpdater;

_tmSync = new DispatcherTimer();
_tmSync.Tick += SyncBanges;
Expand Down Expand Up @@ -135,7 +137,9 @@ private async Task<IEnumerable<BadgeModel>> LoadBadgesAsync()
if (badge.RemainingCard > 0)
{
if (b == null)
{
_account.AddBadge(badge);
}
else
{
b.RemainingCard = badge.RemainingCard;
Expand All @@ -148,6 +152,7 @@ private async Task<IEnumerable<BadgeModel>> LoadBadgesAsync()
if (b != null)
_account.RemoveBadge(b);
}
badge.CardPrice = _pricesUpdater.GetCardPrice(badge.AppId);
}

_account.UpdateTotalValues();
Expand Down
6 changes: 2 additions & 4 deletions SourceCode/CardIdleRemastered/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private void LaunchCardIdle(object sender, StartupEventArgs e)
_account = new AccountModel();
_account.Storage = storage;
_account.ShowcaseStorage = new FileStorage("ShowcaseDb.txt");
_account.PricesStorage = new FileStorage(Path.Combine(appFolder, "PricesDb.txt"));

Palette = PaletteItemsCollection.Create();
if (storage.AppBrushes != null)
Expand All @@ -55,10 +56,7 @@ private void LaunchCardIdle(object sender, StartupEventArgs e)
var w = new BadgesWindow { DataContext = _account };
w.Show();

_account.InitSteamTimer();
_account.CheckLatestRelease();
_account.LoadCardIdleProfile();
_account.LoadAccount();
_account.Startup();
}

private void LogTaskSchedulerUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs arg)
Expand Down
11 changes: 11 additions & 0 deletions SourceCode/CardIdleRemastered/Badges/BadgeIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace CardIdleRemastered
public abstract class BadgeIdentity : ObservableModel
{
private bool _canCraft;
double? _cardPrice;

protected BadgeIdentity()
{
Expand All @@ -25,6 +26,16 @@ protected BadgeIdentity(string appId, string title)
/// </summary>
public string UnlockedBadge { get; set; }

public double? CardPrice
{
get { return _cardPrice; }
set
{
_cardPrice = value;
OnPropertyChanged();
}
}

/// <summary>
/// Indication of a badge which can be crafted
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions SourceCode/CardIdleRemastered/Badges/BadgeStockModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace CardIdleRemastered.Badges
{
public class BadgeStockModel
{
public string Name { get; set; }

public string CardRelease { get; set; }

public int Count { get; set; }

public double Normal { get; set; }

public double Foil { get; set; }

public int NormalStock { get; set; }

public int FoilStock { get; set; }
}
}
46 changes: 46 additions & 0 deletions SourceCode/CardIdleRemastered/CardIdleRemastered.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
Expand All @@ -90,7 +91,10 @@
</ApplicationDefinition>
<Compile Include="AccountModel.cs" />
<Compile Include="AccountUpdater.cs" />
<Compile Include="Badges\BadgeStockModel.cs" />
<Compile Include="Converters\BooleanToLengthConverter.cs" />
<Compile Include="Info\ProfileInfo.cs" />
<Compile Include="PricesUpdater.cs" />
<Compile Include="ViewModels\PaletteItemsCollection.cs" />
<Compile Include="ViewModels\PaletteItemVm.cs" />
<Compile Include="Badges\BadgeIdentity.cs" />
Expand All @@ -105,6 +109,12 @@
<Compile Include="ShowcaseManager.cs" />
<Compile Include="ViewModels\FilterStatesCollection.cs" />
<Compile Include="ViewModels\SelectionItemVm.cs" />
<Compile Include="Views\AboutPage.xaml.cs">
<DependentUpon>AboutPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\BadgesPage.xaml.cs">
<DependentUpon>BadgesPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\BadgesWindow.xaml.cs">
<DependentUpon>BadgesWindow.xaml</DependentUpon>
</Compile>
Expand All @@ -130,9 +140,21 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Views\QueuePage.xaml.cs">
<DependentUpon>QueuePage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SearchPopup.cs" />
<Compile Include="Converters\TranslationConverter.cs" />
<Compile Include="SteamParser.cs" />
<Compile Include="Views\SettingsPage.xaml.cs">
<DependentUpon>SettingsPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ShowcasesPage.xaml.cs">
<DependentUpon>ShowcasesPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\TimeIdlePage.xaml.cs">
<DependentUpon>TimeIdlePage.xaml</DependentUpon>
</Compile>
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -141,6 +163,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\AboutPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\BadgesPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\BadgesWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -165,6 +195,22 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\QueuePage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\SettingsPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ShowcasesPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\TimeIdlePage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down
Loading

0 comments on commit eda3e89

Please sign in to comment.