Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumzhao committed Aug 24, 2020
1 parent 8d4f7f1 commit bc655bf
Show file tree
Hide file tree
Showing 17 changed files with 535 additions and 207 deletions.
3 changes: 1 addition & 2 deletions CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ static void Main(string[] args)
_ColorMap.Add('g', Colors.Green);
_ColorMap.Add('o', Colors.Orange);
_ColorMap.Add('p', Colors.Purple);
Func<bool?, char> boolMap = b => b == null ? 'N' : ((b ?? false) ? 'T' : 'F');
gamemanager.GameOver += b =>
{
if (b)
Expand All @@ -41,7 +40,7 @@ static void Main(string[] args)
gamemanager.Gameboard.Current.Balls[i] = _ColorMap[entry[i]];
}
gamemanager.SubmitCurrent();
Console.WriteLine($"{entry}: {new Func<IEnumerable<char>, string>(c => new string(c.ToArray(), 0, c.Count()))(gamemanager.Gameboard.Current.Correctness.Select(b => boolMap(b)))}");
Console.WriteLine($"{entry}: {new Func<IEnumerable<char>, string>(c => new string(c.ToArray(), 0, c.Count()))(gamemanager.Gameboard.Current.Correctness.Select(s => s.ToString()[0]))}");
gamemanager.Next();
}
}
Expand Down
58 changes: 43 additions & 15 deletions GUESS/App.axaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,84 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GUESS"
xmlns:ripple="clr-namespace:Ripple;assembly=Ripple"
x:Class="GUESS.App">
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<Style Selector="Ellipse.Red">
<Setter Property="Fill">
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="avares://Ripple/RippleEffect/RippleEffect.xaml" />
<Style Selector="Border.Red">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#ffe6317f"/>
</Setter.Value>
</Setter>
</Style>
<Style Selector="Ellipse.Yellow">
<Setter Property="Fill">
<Style Selector="Border.Yellow">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#ffffdb27"/>
</Setter.Value>
</Setter>
</Style>
<Style Selector="Ellipse.Blue">
<Setter Property="Fill">
<Style Selector="Border.Blue">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#ff5959ce"/>
</Setter.Value>
</Setter>
</Style>
<Style Selector="Ellipse.Green">
<Setter Property="Fill">
<Style Selector="Border.Green">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#ff53d348"/>
</Setter.Value>
</Setter>
</Style>
<Style Selector="Ellipse.Orange">
<Setter Property="Fill">
<Style Selector="Border.Orange">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#ffef9029"/>
</Setter.Value>
</Setter>
</Style>
<Style Selector="Ellipse.Purple">
<Setter Property="Fill">
<Style Selector="Border.Purple">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#ff7831aa"/>
</Setter.Value>
</Setter>
</Style>
<Style Selector="Border.None">
<Setter Property="Background" Value="#fff4f4f4"/>
</Style>
<Style Selector="Border[Tag=MainSection]">
<Setter Property="BoxShadow" Value="0 5 30 0 #33000000"/>
</Style>
<Style Selector="TextBlock.Comment">
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="#ff000000"/>
</Style>
<Style Selector="ripple|RippleEffect">
<Setter Property="RippleFill" Value="#fff0f0f0"/>
<Setter Property="RippleOpacity" Value="0.25"/>
</Style>
<Style Selector="Border.DockButton">
<Setter Property="Width" Value="30"/>
<Setter Property="Height" Value="30"/>
<Setter Property="CornerRadius" Value="15"/>
<Setter Property="Background" Value="#ffffffff"/>
<!--<Setter Property="BoxShadow" Value="3 3 28 0 #66494949"/>-->
</Style>
<Style Selector="Border.ButtonBackground:pointerover">
<Setter Property="Border.Background" Value="#fff4f4f4"/>
</Style>

</Application.Styles>

<Application.Resources>
Expand Down
50 changes: 50 additions & 0 deletions GUESS/Converters/BoolToPromptConverterConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.Media;
using GUESS.Views;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Text;

namespace GUESS.Converters
{
public class BoolToPromptConverter : IValueConverter
{
public static BoolToPromptConverter Singleton { get; } = new BoolToPromptConverter();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var doesWin = (bool)value;
var section = (string)parameter;
if (doesWin)
{
if (section == "Header")
{
return "That's a Win!";
}
else
{
return "Cool!";
}
}
else
{
if (section == "Header")
{
return "That's a Lose";
}
else
{
return "Alright";
}
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
46 changes: 0 additions & 46 deletions GUESS/Converters/NullableBoolToBrushConverter.cs

This file was deleted.

2 changes: 1 addition & 1 deletion GUESS/Converters/RemainingTrialsToBrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class RemainingTrialsToBrushConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var count = (int)value;
if (count <= 1)
if (count <= 2)
{
return new SolidColorBrush(Color.FromUInt32(0xfff26b6b));
}
Expand Down
32 changes: 32 additions & 0 deletions GUESS/Converters/StatusToBrushConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Avalonia;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.Media;
using GUESS.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace GUESS.Converters
{
public class StatusToBrushConverter : IValueConverter
{
public static StatusToBrushConverter Singleton { get; } = new StatusToBrushConverter();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> new SolidColorBrush(((Status)value) switch
{
Status.HalfHalf => Color.FromUInt32(0xffeae463),
Status.Correct => Color.FromUInt32(0xffade887),
Status.Wrong => Color.FromUInt32(0xfff26b6b),
Status.None => Color.FromUInt32(0xfff4f4f4),
_ => throw new NotSupportedException()
});

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return new BindingNotification(new NotSupportedException());
}
}
}
64 changes: 31 additions & 33 deletions GUESS/Converters/StdColorToBrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,48 @@ public class StdColorToBrushConverter : IValueConverter
{
public static StdColorToBrushConverter Singleton { get; } = new StdColorToBrushConverter();

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> new SolidColorBrush(((Colors)value) switch
{
var stdColor = (Colors)value;
Color rgbColor;
switch (stdColor)
Colors.None => Color.FromUInt32(0xfff4f4f4),
Colors.Red => Color.FromUInt32(0xffe6317f),
Colors.Yellow => Color.FromUInt32(0xffffdb27),
Colors.Blue => Color.FromUInt32(0xff5959ce),
Colors.Green => Color.FromUInt32(0xff53d348),
Colors.Orange => Color.FromUInt32(0xffef9029),
Colors.Purple => Color.FromUInt32(0xff7831aa),
_ => throw new NotSupportedException(),
});

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var rgbColor = (value as SolidColorBrush).Color;
switch (rgbColor.ToUint32())
{
case Colors.None:
rgbColor = Color.FromUInt32(0xfff4f4f4);
break;
case 0xfff4f4f4:
return Colors.None;

case Colors.Red:
rgbColor = Color.FromUInt32(0xffe6317f);
break;
case 0xffe6317f:
return Colors.Red;

case Colors.Yellow:
rgbColor = Color.FromUInt32(0xffffdb27);
break;
case 0xffffdb27:
return Colors.Yellow;

case Colors.Blue:
rgbColor = Color.FromUInt32(0xff5959ce);
break;
case 0xff5959ce:
return Colors.Blue;

case Colors.Green:
rgbColor = Color.FromUInt32(0xff53d348);
break;
case 0xff53d348:
return Colors.Green;

case Colors.Orange:
rgbColor = Color.FromUInt32(0xffef9029);
break;
case 0xffef9029:
return Colors.Orange;

case Colors.Purple:
rgbColor = Color.FromUInt32(0xff7831aa);
break;
case 0xff7831aa:
return Colors.Purple;

default:
throw new ArgumentException();
throw new NotSupportedException();
}

return new SolidColorBrush(rgbColor);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return new BindingNotification(new NotSupportedException());
}
}
}
3 changes: 3 additions & 0 deletions GUESS/GUESS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@
<ItemGroup>
<Folder Include="Fonts\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Ripple\Ripple.csproj" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions GUESS/Misc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Avalonia.Input;
using Avalonia.Media;
using System;
using System.Collections.Generic;
using System.Text;

namespace GUESS.Misc
{
public class BrushDataObject : DataObject
{
public BrushDataObject(IBrush brush) => Brush = brush;
public IBrush Brush { get; }
}
}
Loading

0 comments on commit bc655bf

Please sign in to comment.