Drag and Drop foireux

master
cldupland 6 years ago
parent 426a3ce6f8
commit 31749dd382

@ -11,7 +11,8 @@ namespace TheGameExtreme.model.card
public int Value
{
get { return value; }
set {
set
{
this.value = value;
//OnPropertyChange("Value");
}

@ -10,6 +10,7 @@ using System.Reflection;
using SkiaSharp.Views.Forms;
using TouchTracking;
using Xamarin.Essentials;
using TheGameExtreme.model.card;
namespace TheGameExtreme.view
{
@ -124,6 +125,15 @@ namespace TheGameExtreme.view
break;
case TouchActionType.Released:
if (textDictionary.ContainsKey(args.Id))
{
TouchManipulationBitmap bitmap = textDictionary[args.Id];
bitmap.ProcessTouchEvent(args.Id, args.Type, point, stackCollection);
canvasView.InvalidateSurface();
viewmodel.CurrentHand.RemoveAt((int)args.Id);
}
break;
case TouchActionType.Cancelled:
if (textDictionary.ContainsKey(args.Id))
{
@ -150,21 +160,29 @@ namespace TheGameExtreme.view
{
stackCollection.Clear();
SKPoint position = new SKPoint(150, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01));
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("01");
float textSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
SKPoint position = new SKPoint((float)((DeviceDisplay.MainDisplayInfo.Width * 0.05) - (textWidth * 0.5)), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.1) + (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.01 + 2 * textSize));
textPaint.TextSize = textSize;
stackCollection.Add(new TouchManipulationBitmap(textPaint, 1)
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialPoint = position
});
for (int i = 0; i < 5; i++)
for (int i = 0; i < 4; i++)
{
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("1");
textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
textPaint = new SKPaint();
textPaint.TextSize = textSize;
position.X += (float)(DeviceDisplay.MainDisplayInfo.Width * 0.2);
stackCollection.Add(new TouchManipulationBitmap(textPaint, "1")
stackCollection.Add(new TouchManipulationBitmap(textPaint, 1)
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y + textPaint.TextSize),
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialPoint = position
});
position.X += textPaint.MeasureText("1") + (float)(DeviceDisplay.MainDisplayInfo.Width * 0.15);
}
}
@ -172,21 +190,24 @@ namespace TheGameExtreme.view
{
textCollection.Clear();
SKPoint position = new SKPoint(100, (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.2));
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText("01");
float textSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
SKPoint position = new SKPoint((float)(DeviceDisplay.MainDisplayInfo.Width * 0.05), (float)((DeviceDisplay.MainDisplayInfo.Height * 0.9) - (DeviceDisplay.MainDisplayInfo.Height * 0.9) * 0.2 - textSize));
for (int i = 0; i < viewmodel.CurrentHand.Count; i++)
{
SKPaint textPaint = new SKPaint();
float textWidth = textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString());
textPaint.TextSize = 0.05f * (float)DeviceDisplay.MainDisplayInfo.Width * textPaint.TextSize / textWidth;
textPaint = new SKPaint();
textPaint.TextSize = textSize;
position.X -= (float)(textWidth * 0.5);
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value.ToString())
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value)
{
Matrix = SKMatrix.MakeTranslation(position.X, position.Y - textPaint.TextSize),
Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialPoint = position
});
position.X += textPaint.MeasureText(viewmodel.CurrentHand[i].Value.ToString()) + 50;
position.X += (float)((DeviceDisplay.MainDisplayInfo.Width * 0.9) / viewmodel.CurrentHand.Count);
}
}

@ -12,10 +12,18 @@ namespace TheGameExtreme.view
string value;
SKCanvas canvas;
public TouchManipulationBitmap(SKPaint textPaint, string value)
public TouchManipulationBitmap(SKPaint textPaint, int value)
{
this.textPaint = textPaint;
this.value = value;
if (value > 0 && value < 10)
{
this.value = "0" + value.ToString();
}
else
{
this.value = value.ToString();
}
Matrix = SKMatrix.MakeIdentity();
TouchManager = new TouchManipulationManager
@ -32,12 +40,24 @@ namespace TheGameExtreme.view
{
this.canvas = canvas;
canvas.Save();
SKMatrix matrix = Matrix;
canvas.Concat(ref matrix);
textPaint.Color = SKColors.Red;
textPaint.Color = SKColors.DarkRed;
textPaint.StrokeWidth = 5;
textPaint.Style = SKPaintStyle.Stroke;
SKRect textBounds = new SKRect();
textPaint.MeasureText(value, ref textBounds);
SKRoundRect card = new SKRoundRect(textBounds);
card.Inflate(35, 35);
canvas.DrawRoundRect(card, textPaint);
canvas.DrawText(value, 0, 0, textPaint);
canvas.Restore();
}
@ -83,7 +103,12 @@ namespace TheGameExtreme.view
{
if (stack.HitTest(location))
{
touchDictionary[id].NewPoint = stack.InitialPoint;
Manipulate();
touchDictionary[id].PreviousPoint = touchDictionary[id].NewPoint;
stackCollection[stackCollection.IndexOf(stack)] = this;
//canvas.Flush();
find = true;
break;
}
}
@ -92,7 +117,6 @@ namespace TheGameExtreme.view
touchDictionary[id].NewPoint = InitialPoint;
Manipulate();
touchDictionary[id].PreviousPoint = touchDictionary[id].NewPoint;
touchDictionary.Remove(id);
}
break;

@ -12,25 +12,14 @@ namespace TheGameExtreme.viewmodel
public event PropertyChangedEventHandler PropertyChanged;
public Card View { get; set; }
protected string image;
public string Image
{
get { return image; }
set
{
image = value;
OnPropertyChanged("Image");
}
}
protected int value;
private Image bmp;
public int Value {
get { return value; }
set
{
this.value = value;
View.Value = value;
OnPropertyChanged("Value");
}
}
@ -45,21 +34,6 @@ namespace TheGameExtreme.viewmodel
{
View = view;
Value = view.Value;
/*SKBitmap bit = new SKBitmap();
RectangleF rectangle = new RectangleF(50, 90, 90, 50);
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawString("yourText", new Font("Tahoma", 8), Brushes.Black, rectangle);
g.Flush();*/
}

@ -48,7 +48,7 @@ namespace TheGameExtreme.viewmodel
}
private GameManager gameManager;
public List<Card> CurrentHand { get; set; }
public List<CardVM> CurrentHand { get; set; } = new List<CardVM>();
//private ObservableCollection<Stack<Card>> ListOrderedStacks;
@ -63,7 +63,10 @@ namespace TheGameExtreme.viewmodel
gameManager.PlayerChanged += OnPlayerChanged;
CurrentHand = gameManager.CurrentHand;
gameManager.CurrentHand.ForEach( card =>
{
CurrentHand.Add(new CardVM(card));
});
Pseudo = players[0].Pseudo;
@ -72,7 +75,10 @@ namespace TheGameExtreme.viewmodel
protected internal void OnPlayerChanged(object source, PlayerChangedEventArgs args)
{
CurrentHand = args.NewCurrentHand;
args.NewCurrentHand.ForEach( card =>
{
CurrentHand.Add(new CardVM(card));
});
Pseudo = args.Pseudo;
//PlayerChanged?.Invoke(this, args);
}

Loading…
Cancel
Save