2015-08-15 03:08:32 -04:00
|
|
|
|
//
|
|
|
|
|
// CoverViewController.m
|
|
|
|
|
// Play
|
|
|
|
|
//
|
|
|
|
|
// Created by Lounge Katt on 8/15/15.
|
|
|
|
|
// Copyright (c) 2015 Jean-Philip Desjardins. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "CoverViewController.h"
|
|
|
|
|
#import "EmulatorViewController.h"
|
|
|
|
|
#import "IosUtils.h"
|
|
|
|
|
#import "DiskUtils.h"
|
2015-08-17 12:48:29 -04:00
|
|
|
|
#import "BackgroundLayer.h"
|
2015-08-31 14:59:13 -04:00
|
|
|
|
#import "CoverViewCell.h"
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
|
|
|
|
@interface CoverViewController ()
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation CoverViewController
|
|
|
|
|
|
|
|
|
|
static NSString * const reuseIdentifier = @"coverCell";
|
|
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
|
{
|
2015-08-22 09:27:08 -04:00
|
|
|
|
self.coverView = [CollectionView getInstance];
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
2015-08-17 12:48:29 -04:00
|
|
|
|
|
|
|
|
|
CAGradientLayer *bgLayer = [BackgroundLayer blueGradient];
|
|
|
|
|
bgLayer.frame = self.view.bounds;
|
|
|
|
|
[self.view.layer insertSublayer:bgLayer atIndex:0];
|
2015-08-15 04:06:15 -04:00
|
|
|
|
|
|
|
|
|
// Uncomment the following line to preserve selection between presentations
|
|
|
|
|
// self.clearsSelectionOnViewWillAppear = NO;
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
2015-08-15 04:06:15 -04:00
|
|
|
|
self.collectionView.allowsMultipleSelection = NO;
|
2015-08-31 14:59:13 -04:00
|
|
|
|
|
2015-08-15 03:08:32 -04:00
|
|
|
|
self.database = [[SqliteDatabase alloc] init];
|
2015-08-15 12:44:56 -04:00
|
|
|
|
if (self.coverView.diskImages == nil)
|
2015-08-15 03:08:32 -04:00
|
|
|
|
{
|
2015-08-15 12:44:56 -04:00
|
|
|
|
self.coverView.diskImages = [self.coverView buildCollection];
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.collectionView reloadData];
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-17 12:48:29 -04:00
|
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
|
|
|
|
|
{
|
|
|
|
|
// resize your layers based on the view’s new bounds
|
|
|
|
|
[[[self.view.layer sublayers] objectAtIndex:0] setFrame:self.view.bounds];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)shouldAutorotate {
|
|
|
|
|
if ([self isViewLoaded] && self.view.window) {
|
|
|
|
|
return YES;
|
|
|
|
|
} else {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 03:08:32 -04:00
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
|
// Get the new view controller using [segue destinationViewController].
|
|
|
|
|
// Pass the selected object to the new view controller.
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma mark <UICollectionViewDataSource>
|
|
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 12:44:56 -04:00
|
|
|
|
- (NSString*)collectionView:(UICollectionView *)collectionView titleForHeaderInSection: (NSInteger)section
|
|
|
|
|
{
|
|
|
|
|
return @"";
|
|
|
|
|
}
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
2015-08-15 12:44:56 -04:00
|
|
|
|
return self.coverView.diskImages.count;
|
2015-08-15 03:08:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
2015-08-31 14:59:13 -04:00
|
|
|
|
CoverViewCell *cell = (CoverViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
2015-08-15 12:44:56 -04:00
|
|
|
|
NSDictionary *disk = [self.coverView.diskImages objectAtIndex: indexPath.row];
|
2015-08-15 03:08:32 -04:00
|
|
|
|
NSString* diskId = [disk objectForKey:@"serial"];
|
|
|
|
|
|
|
|
|
|
NSDictionary *game = [self.database getDiskInfo:diskId];
|
|
|
|
|
|
2016-04-13 01:48:16 -04:00
|
|
|
|
UIImage *placeholder = [UIImage imageNamed:@"boxart.png"];
|
|
|
|
|
cell.backgroundView = [[UIImageView alloc] initWithImage:placeholder];
|
2015-08-26 02:07:56 -04:00
|
|
|
|
if ([game objectForKey:@"boxart"] != nil && ![[game objectForKey:@"boxart"] isEqual:@"404"]) {
|
2018-05-24 05:39:27 +03:00
|
|
|
|
NSString *imageIcon = [[NSString alloc] initWithFormat:@"http://legacy.thegamesdb.net/banners/_gameviewcache/%@", [game objectForKey:@"boxart"]];
|
2016-04-13 01:48:16 -04:00
|
|
|
|
[(UIImageView *)cell.backgroundView sd_setImageWithURL:[NSURL URLWithString:imageIcon] placeholderImage:placeholder];
|
2015-08-31 14:59:13 -04:00
|
|
|
|
} else {
|
|
|
|
|
cell.nameLabel.text = [[[disk objectForKey:@"file"] lastPathComponent] stringByDeletingPathExtension];
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 03:08:32 -04:00
|
|
|
|
// Configure the cell
|
|
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark <UICollectionViewDelegate>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Uncomment this method to specify if the specified item should be highlighted during tracking
|
|
|
|
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Uncomment this method to specify if the specified item should be selected
|
|
|
|
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2015-08-15 04:06:15 -04:00
|
|
|
|
-(void)prepareForSegue: (UIStoryboardSegue*)segue sender: (id)sender
|
|
|
|
|
{
|
|
|
|
|
if ([segue.identifier isEqualToString:@"showEmulator"]) {
|
|
|
|
|
NSIndexPath* indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
|
2015-08-15 12:44:56 -04:00
|
|
|
|
NSString* filePath = [[self.coverView.diskImages objectAtIndex: indexPath.row] objectForKey:@"file"];
|
2016-05-01 16:58:55 -04:00
|
|
|
|
NSString* homeDirPath = [@"~/Documents" stringByExpandingTildeInPath];
|
2015-08-15 04:06:15 -04:00
|
|
|
|
NSString* absolutePath = [homeDirPath stringByAppendingPathComponent: filePath];
|
|
|
|
|
EmulatorViewController* emulatorViewController = segue.destinationViewController;
|
|
|
|
|
emulatorViewController.imagePath = absolutePath;
|
|
|
|
|
[self.collectionView deselectItemAtIndexPath:indexPath animated:NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-11 01:31:35 -04:00
|
|
|
|
/*
|
|
|
|
|
// Uncomment these methods to perform selection segue programatically
|
2015-08-15 04:06:15 -04:00
|
|
|
|
-(void)collectionView: (UICollectionView*)collectionView didSelectItemAtIndexPath: (NSIndexPath*)indexPath
|
2015-08-15 03:08:32 -04:00
|
|
|
|
{
|
|
|
|
|
[self performSegueWithIdentifier: @"showEmulator" sender: self];
|
|
|
|
|
}
|
2015-09-11 01:31:35 -04:00
|
|
|
|
*/
|
2015-08-15 03:08:32 -04:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
|
|
|
|
|
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2018-10-26 08:14:14 -04:00
|
|
|
|
-(IBAction)onExit: (id)sender
|
|
|
|
|
{
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-15 03:08:32 -04:00
|
|
|
|
@end
|