Added taking of photos
This commit is contained in:
@@ -9,7 +9,6 @@ using Windows.UI.ViewManagement;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using YJMPD_UWP.Helpers;
|
||||
|
||||
namespace YJMPD_UWP
|
||||
{
|
||||
@@ -59,6 +58,15 @@ namespace YJMPD_UWP
|
||||
}
|
||||
}
|
||||
|
||||
private static PhotoHandler photohandler = new PhotoHandler();
|
||||
|
||||
public static PhotoHandler Photo
|
||||
{
|
||||
get
|
||||
{
|
||||
return photohandler;
|
||||
}
|
||||
}
|
||||
|
||||
// =========================
|
||||
// STATIC HELPER FUNCTIONS
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YJMPD_UWP.Model.Object;
|
||||
using YJMPD_UWP.Model.Object;
|
||||
|
||||
namespace YJMPD_UWP.Helpers.EventArgs
|
||||
{
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace YJMPD_UWP.Helpers.EventArgs
|
||||
{
|
||||
public class PhotoTakenEventArgs : System.EventArgs
|
||||
{
|
||||
public SoftwareBitmapSource Photo { get; private set; }
|
||||
|
||||
public PhotoTakenEventArgs(SoftwareBitmapSource photo)
|
||||
{
|
||||
Photo = photo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
using YJMPD_UWP.Model.Object;
|
||||
|
||||
|
||||
@@ -6,10 +6,8 @@ using System.Threading.Tasks;
|
||||
using Windows.Data.Xml.Dom;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.Services.Maps;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Notifications;
|
||||
using Windows.UI.Popups;
|
||||
using Windows.UI.Xaml.Controls.Maps;
|
||||
|
||||
namespace YJMPD_UWP.Helpers
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@ using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace YJMPD_UWP
|
||||
{
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using YJMPD_UWP.Helpers;
|
||||
using YJMPD_UWP.Helpers.EventArgs;
|
||||
using YJMPD_UWP.Model.Object;
|
||||
@@ -23,6 +22,8 @@ namespace YJMPD_UWP.Model
|
||||
|
||||
public List<Player> Players { get; private set; }
|
||||
|
||||
public bool Selected { get; private set; }
|
||||
|
||||
private void UpdateGameStatus(GameStatus status)
|
||||
{
|
||||
Status = status;
|
||||
@@ -95,7 +96,7 @@ namespace YJMPD_UWP.Model
|
||||
{
|
||||
|
||||
//Do stuff
|
||||
|
||||
/*
|
||||
UpdateGameStatus(GameStatus.SEARCHING);
|
||||
Search();
|
||||
|
||||
@@ -108,11 +109,12 @@ namespace YJMPD_UWP.Model
|
||||
Debug.WriteLine("Searching");
|
||||
Task.Delay(TimeSpan.FromMilliseconds(50));
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
|
||||
UpdateGameStatus(GameStatus.WAITING);
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
|
||||
UpdateGameStatus(GameStatus.STARTED);
|
||||
|
||||
@@ -143,7 +145,10 @@ namespace YJMPD_UWP.Model
|
||||
App.Navigate(typeof(WaitingView));
|
||||
break;
|
||||
case GameStatus.STARTED:
|
||||
App.Navigate(typeof(GameView));
|
||||
if (Selected && App.Photo.Photo == null)
|
||||
App.Navigate(typeof(PhotoView));
|
||||
else
|
||||
App.Navigate(typeof(GameView));
|
||||
break;
|
||||
case GameStatus.ENDED:
|
||||
App.Navigate(typeof(ScoreView));
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace YJMPD_UWP.Model
|
||||
StreamSocketControl controller = client.Control;
|
||||
controller.KeepAlive = true;
|
||||
|
||||
await client.ConnectAsync(new HostName("imegumii.space"), "3333");
|
||||
await client.ConnectAsync(new HostName(Settings.Values["hostname"] as string), Settings.Values["port"] as string);
|
||||
|
||||
|
||||
din = new StreamReader(client.InputStream.AsStreamForRead());
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YJMPD_UWP.Model.Object
|
||||
namespace YJMPD_UWP.Model.Object
|
||||
{
|
||||
public class Player
|
||||
{
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YJMPD_UWP.Model.Object
|
||||
{
|
||||
|
||||
@@ -1,13 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Media.Capture;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Streams;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using YJMPD_UWP.Helpers.EventArgs;
|
||||
|
||||
namespace YJMPD_UWP.Model
|
||||
{
|
||||
public class PhotoHandler
|
||||
{
|
||||
public delegate void OnPhotoTakenHandler(object sender, PhotoTakenEventArgs e);
|
||||
public event OnPhotoTakenHandler OnPhotoTaken;
|
||||
|
||||
public SoftwareBitmapSource Photo { get; private set; }
|
||||
|
||||
public PhotoHandler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void UpdatePhotoTaken(SoftwareBitmapSource photo)
|
||||
{
|
||||
Photo = photo;
|
||||
|
||||
if (OnPhotoTaken == null) return;
|
||||
|
||||
OnPhotoTaken(this, new PhotoTakenEventArgs(photo));
|
||||
}
|
||||
|
||||
public async void Take()
|
||||
{
|
||||
CameraCaptureUI captureUI = new CameraCaptureUI();
|
||||
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;
|
||||
captureUI.PhotoSettings.AllowCropping = false;
|
||||
captureUI.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.Large3M;
|
||||
|
||||
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
|
||||
|
||||
if (photo == null)
|
||||
{
|
||||
// User cancelled photo capture
|
||||
return;
|
||||
}
|
||||
|
||||
IRandomAccessStream stream = await photo.OpenAsync(FileAccessMode.Read);
|
||||
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
|
||||
SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync();
|
||||
|
||||
SoftwareBitmap softwareBitmapBGR8 = SoftwareBitmap.Convert(softwareBitmap,
|
||||
BitmapPixelFormat.Bgra8,
|
||||
BitmapAlphaMode.Premultiplied);
|
||||
|
||||
SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
|
||||
await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);
|
||||
|
||||
UpdatePhotoTaken(bitmapSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YJMPD_UWP.ViewModels
|
||||
namespace YJMPD_UWP.ViewModels
|
||||
{
|
||||
public class GameVM : TemplateVM
|
||||
{
|
||||
|
||||
@@ -1,16 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
||||
namespace YJMPD_UWP.ViewModels
|
||||
{
|
||||
public class PhotoVM : TemplateVM
|
||||
{
|
||||
private ImageSource photo;
|
||||
|
||||
public PhotoVM() : base("Photo")
|
||||
{
|
||||
App.Photo.OnPhotoTaken += Photo_OnPhotoTaken;
|
||||
}
|
||||
|
||||
private void Photo_OnPhotoTaken(object sender, Helpers.EventArgs.PhotoTakenEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
photo = e.Photo;
|
||||
NotifyPropertyChanged(nameof(Photo));
|
||||
NotifyPropertyChanged(nameof(PhotoVisible));
|
||||
NotifyPropertyChanged(nameof(ControlsVisible));
|
||||
});
|
||||
}
|
||||
|
||||
public bool PhotoVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return photo != null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ControlsVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return !PhotoVisible;
|
||||
}
|
||||
}
|
||||
|
||||
public string TimeOut
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Take a photo within 1 minute";
|
||||
}
|
||||
}
|
||||
|
||||
public ImageSource Photo
|
||||
{
|
||||
get
|
||||
{
|
||||
return photo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using YJMPD_UWP.Model.Object;
|
||||
|
||||
namespace YJMPD_UWP.ViewModels
|
||||
|
||||
@@ -1,17 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using YJMPD_UWP.ViewModels;
|
||||
|
||||
namespace YJMPD_UWP.Views
|
||||
|
||||
@@ -3,13 +3,22 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:YJMPD_UWP.Views"
|
||||
xmlns:convert="using:YJMPD_UWP.Helpers.Converter"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Page.Resources>
|
||||
<convert:BoolToVisibilityConverter x:Key="BoolToVisConverter" />
|
||||
</Page.Resources>
|
||||
|
||||
<ScrollViewer>
|
||||
<StackPanel Style="{StaticResource BaseStackPanel}">
|
||||
|
||||
</StackPanel>
|
||||
<Grid Style="{StaticResource BaseGrid}">
|
||||
<Image Name="Photo" Stretch="UniformToFill" Source="{Binding Photo}" Visibility="{Binding PhotoVisible, Converter={StaticResource BoolToVisConverter}}"/>
|
||||
<StackPanel Visibility="{Binding ControlsVisible, Converter={StaticResource BoolToVisConverter}}">
|
||||
<TextBlock Text="{Binding TimeOut}" />
|
||||
<Button Content="Take Photo" Style="{StaticResource Green}" Click="PhotoButton_Click" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Page>
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using Windows.UI.Xaml.Media.Imaging;
|
||||
using YJMPD_UWP.ViewModels;
|
||||
|
||||
namespace YJMPD_UWP.Views
|
||||
@@ -26,5 +16,10 @@ namespace YJMPD_UWP.Views
|
||||
this.DataContext = photovm;
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
private void PhotoButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.Photo.Take();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using YJMPD_UWP.ViewModels;
|
||||
|
||||
namespace YJMPD_UWP.Views
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.UI.Xaml;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace YJMPD_UWP.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class WaitingView : Page
|
||||
{
|
||||
public WaitingView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
StartWait();
|
||||
}
|
||||
|
||||
private async void StartWait()
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(2));
|
||||
App.Navigate(typeof(PhotoView));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,7 @@
|
||||
<Compile Include="Helpers\EventArgs\GameStatusUpdatedEventArgs.cs" />
|
||||
<Compile Include="Helpers\EventArgs\HeadingUpdatedEventArgs.cs" />
|
||||
<Compile Include="Helpers\EventArgs\NetworkStatusUpdatedEventArgs.cs" />
|
||||
<Compile Include="Helpers\EventArgs\PhotoTakenEventArgs.cs" />
|
||||
<Compile Include="Helpers\EventArgs\PositionStatusUpdatedEventArgs.cs" />
|
||||
<Compile Include="Helpers\EventArgs\PositionUpdatedEventArgs.cs" />
|
||||
<Compile Include="Helpers\Extensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user