Resolution du dernier(?) problème de Drag And Drop

master
cldupland 5 years ago
parent 9840165d90
commit 16043a30c0

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.uca.thegameextreme" android:installLocation="auto"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.1" package="com.uca.thegameextreme" android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" /> <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="TheGameExtreme.Android" android:icon="@drawable/iconpique"></application> <application android:label="TheGameExtreme.Android" android:icon="@drawable/iconpique"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

@ -68,10 +68,6 @@
HeightRequest="45" HeightRequest="45"
BackgroundColor="{DynamicResource BlackColor}" BackgroundColor="{DynamicResource BlackColor}"
Clicked="PlayToHome"/> Clicked="PlayToHome"/>
<Label Text="↑" TextColor="White"
FontSize="64"
Grid.Column="0" Grid.Row="1" Margin="120,0,0,10"/>
</StackLayout> </StackLayout>
@ -88,9 +84,6 @@
BackgroundColor="{DynamicResource SkyBlueColor}" BackgroundColor="{DynamicResource SkyBlueColor}"
HeightRequest="35" HeightRequest="35"
Clicked="EndTurn"/> Clicked="EndTurn"/>
<Label Text="↓" TextColor="White"
FontSize="64" Grid.Column="2" Grid.Row="1" Margin="0,0,120,10"/>
</StackLayout> </StackLayout>

@ -122,6 +122,8 @@ namespace TheGameExtreme.view
if (textDictionary.ContainsKey(args.Id)) if (textDictionary.ContainsKey(args.Id))
{ {
TouchManipulationBitmap bitmap = textDictionary[args.Id]; TouchManipulationBitmap bitmap = textDictionary[args.Id];
point.Y -= 120;
point.X -= 50;
bitmap.ProcessTouchEvent(args.Id, args.Type, point); bitmap.ProcessTouchEvent(args.Id, args.Type, point);
canvasView.InvalidateSurface(); canvasView.InvalidateSurface();
} }
@ -137,7 +139,8 @@ namespace TheGameExtreme.view
bool find = false; bool find = false;
foreach (TouchManipulationBitmap stack in stackCollection) foreach (TouchManipulationBitmap stack in stackCollection)
{ {
if (stack.HitTest(point)) SKPoint pointVisuCard = new SKPoint(point.X, point.Y - 120);
if (stack.HitTest(point) || stack.HitTest(pointVisuCard))
{ {
int indexPile = stackCollection.IndexOf(stack); int indexPile = stackCollection.IndexOf(stack);
if (played(indexPile, decimal.Parse(bitmap.Value))) if (played(indexPile, decimal.Parse(bitmap.Value)))
@ -190,6 +193,7 @@ namespace TheGameExtreme.view
stackCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.getListOrderedStacks()[i].Peek().Value) stackCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.getListOrderedStacks()[i].Peek().Value)
{ {
Matrix = SKMatrix.MakeTranslation(position.X, position.Y), Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialPoint = position InitialPoint = position
}); });
@ -213,6 +217,7 @@ namespace TheGameExtreme.view
textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value) textCollection.Add(new TouchManipulationBitmap(textPaint, viewmodel.CurrentHand[i].Value)
{ {
Matrix = SKMatrix.MakeTranslation(position.X, position.Y), Matrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialMatrix = SKMatrix.MakeTranslation(position.X, position.Y),
InitialPoint = position InitialPoint = position
}); });

@ -16,31 +16,34 @@ namespace TheGameExtreme.view
{ {
this.textPaint = textPaint; this.textPaint = textPaint;
Value = value.ToString(); Value = value.ToString();
if (value < 0 && value > -10)
{ if (!Value.Contains(",") && !Value.Contains("."))
Value = "-0" + Math.Abs(value).ToString();
}
else if (value >= 0 && value < 10 && !(value > 0 && value < 1))
{
Value = "0" + value.ToString();
}
else
{ {
Value = value.ToString(); if (value < 0 && value > -10)
{
Value = "-0" + Math.Abs(value).ToString();
}
else if (value >= 0 && value < 10)
{
Value = "0" + value.ToString();
}
else
{
Value = value.ToString();
}
} }
Matrix = SKMatrix.MakeIdentity(); Matrix = SKMatrix.MakeIdentity();
TouchManager = new TouchManipulationManager Mode = TouchManipulationMode.PanOnly;
{
Mode = TouchManipulationMode.PanOnly
};
} }
public TouchManipulationManager TouchManager { set; get; } public TouchManipulationMode Mode { set; get; }
public SKMatrix Matrix { set; get; } public SKMatrix Matrix { set; get; }
public SKMatrix InitialMatrix { set; get; }
public void Paint(SKCanvas canvas, SKColor color) public void Paint(SKCanvas canvas, SKColor color)
{ {
canvas.Save(); canvas.Save();
@ -119,29 +122,11 @@ namespace TheGameExtreme.view
{ {
TouchManipulationInfo[] infos = new TouchManipulationInfo[touchDictionary.Count]; TouchManipulationInfo[] infos = new TouchManipulationInfo[touchDictionary.Count];
touchDictionary.Values.CopyTo(infos, 0); touchDictionary.Values.CopyTo(infos, 0);
SKMatrix touchMatrix = SKMatrix.MakeIdentity();
if (infos.Length == 1) if (Mode == TouchManipulationMode.PanOnly)
{ {
SKPoint prevPoint = infos[0].PreviousPoint; Matrix = SKMatrix.MakeTranslation(infos[0].NewPoint.X, infos[0].NewPoint.Y);
SKPoint newPoint = infos[0].NewPoint;
SKPoint pivotPoint = Matrix.MapPoint(textPaint.MeasureText(Value) / 2, textPaint.TextSize / 2);
touchMatrix = TouchManager.OneFingerManipulate(prevPoint, newPoint, pivotPoint);
} }
//else if (infos.Length >= 2)
//{
// int pivotIndex = infos[0].NewPoint == infos[0].PreviousPoint ? 0 : 1;
// SKPoint pivotPoint = infos[pivotIndex].NewPoint;
// SKPoint newPoint = infos[1 - pivotIndex].NewPoint;
// SKPoint prevPoint = infos[1 - pivotIndex].PreviousPoint;
// touchMatrix = TouchManager.TwoFingerManipulate(prevPoint, newPoint, pivotPoint);
//}
SKMatrix matrix = Matrix;
SKMatrix.PostConcat(ref matrix, touchMatrix);
Matrix = matrix;
} }
} }
} }

@ -1,107 +1,107 @@
using System; //using System;
using SkiaSharp; //using SkiaSharp;
namespace TheGameExtreme.view //namespace TheGameExtreme.view
{ //{
public class TouchManipulationManager // public class TouchManipulationManager
{ // {
public TouchManipulationMode Mode { set; get; } // public TouchManipulationMode Mode { set; get; }
//float Magnitude(SKPoint point) // //float Magnitude(SKPoint point)
//{ // //{
// return (float)Math.Sqrt(Math.Pow(point.X, 2) + Math.Pow(point.Y, 2)); // // return (float)Math.Sqrt(Math.Pow(point.X, 2) + Math.Pow(point.Y, 2));
//} // //}
public SKMatrix OneFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint) // public SKMatrix OneFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
{ // {
if (Mode == TouchManipulationMode.None) // if (Mode == TouchManipulationMode.None)
{ // {
return SKMatrix.MakeIdentity(); // return SKMatrix.MakeIdentity();
} // }
SKMatrix touchMatrix = SKMatrix.MakeIdentity(); // SKMatrix touchMatrix = SKMatrix.MakeIdentity();
SKPoint delta = newPoint - prevPoint; // SKPoint delta = newPoint - prevPoint;
//if (Mode == TouchManipulationMode.ScaleDualRotate) // One-finger rotation // //if (Mode == TouchManipulationMode.ScaleDualRotate) // One-finger rotation
//{ // //{
// SKPoint oldVector = prevPoint - pivotPoint; // // SKPoint oldVector = prevPoint - pivotPoint;
// SKPoint newVector = newPoint - pivotPoint; // // SKPoint newVector = newPoint - pivotPoint;
// // Avoid rotation if fingers are too close to center // // // Avoid rotation if fingers are too close to center
// if (Magnitude(newVector) > 25 && Magnitude(oldVector) > 25) // // if (Magnitude(newVector) > 25 && Magnitude(oldVector) > 25)
// { // // {
// float prevAngle = (float)Math.Atan2(oldVector.Y, oldVector.X); // // float prevAngle = (float)Math.Atan2(oldVector.Y, oldVector.X);
// float newAngle = (float)Math.Atan2(newVector.Y, newVector.X); // // float newAngle = (float)Math.Atan2(newVector.Y, newVector.X);
// // Calculate rotation matrix // // // Calculate rotation matrix
// float angle = newAngle - prevAngle; // // float angle = newAngle - prevAngle;
// touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y); // // touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
// // Effectively rotate the old vector // // // Effectively rotate the old vector
// float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector); // // float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector);
// oldVector.X = magnitudeRatio * newVector.X; // // oldVector.X = magnitudeRatio * newVector.X;
// oldVector.Y = magnitudeRatio * newVector.Y; // // oldVector.Y = magnitudeRatio * newVector.Y;
// // Recalculate delta // // // Recalculate delta
// delta = newVector - oldVector; // // delta = newVector - oldVector;
// } // // }
//} // //}
// Multiply the rotation matrix by a translation matrix // // Multiply the rotation matrix by a translation matrix
SKMatrix.PostConcat(ref touchMatrix, SKMatrix.MakeTranslation(delta.X, delta.Y)); // SKMatrix.PostConcat(ref touchMatrix, SKMatrix.MakeTranslation(delta.X, delta.Y));
return touchMatrix; // return touchMatrix;
} // }
public SKMatrix TwoFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint) // public SKMatrix TwoFingerManipulate(SKPoint prevPoint, SKPoint newPoint, SKPoint pivotPoint)
{ // {
SKMatrix touchMatrix = SKMatrix.MakeIdentity(); // SKMatrix touchMatrix = SKMatrix.MakeIdentity();
//SKPoint oldVector = prevPoint - pivotPoint; // //SKPoint oldVector = prevPoint - pivotPoint;
//SKPoint newVector = newPoint - pivotPoint; // //SKPoint newVector = newPoint - pivotPoint;
//if (Mode == TouchManipulationMode.ScaleRotate || // //if (Mode == TouchManipulationMode.ScaleRotate ||
// Mode == TouchManipulationMode.ScaleDualRotate) // // Mode == TouchManipulationMode.ScaleDualRotate)
//{ // //{
// // Find angles from pivot point to touch points // // // Find angles from pivot point to touch points
// float oldAngle = (float)Math.Atan2(oldVector.Y, oldVector.X); // // float oldAngle = (float)Math.Atan2(oldVector.Y, oldVector.X);
// float newAngle = (float)Math.Atan2(newVector.Y, newVector.X); // // float newAngle = (float)Math.Atan2(newVector.Y, newVector.X);
// // Calculate rotation matrix // // // Calculate rotation matrix
// float angle = newAngle - oldAngle; // // float angle = newAngle - oldAngle;
// touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y); // // touchMatrix = SKMatrix.MakeRotation(angle, pivotPoint.X, pivotPoint.Y);
// // Effectively rotate the old vector // // // Effectively rotate the old vector
// float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector); // // float magnitudeRatio = Magnitude(oldVector) / Magnitude(newVector);
// oldVector.X = magnitudeRatio * newVector.X; // // oldVector.X = magnitudeRatio * newVector.X;
// oldVector.Y = magnitudeRatio * newVector.Y; // // oldVector.Y = magnitudeRatio * newVector.Y;
//} // //}
float scaleX = 1; // float scaleX = 1;
float scaleY = 1; // float scaleY = 1;
//if (Mode == TouchManipulationMode.AnisotropicScale) // //if (Mode == TouchManipulationMode.AnisotropicScale)
//{ // //{
// scaleX = newVector.X / oldVector.X; // // scaleX = newVector.X / oldVector.X;
// scaleY = newVector.Y / oldVector.Y; // // scaleY = newVector.Y / oldVector.Y;
//} // //}
//else if (Mode == TouchManipulationMode.IsotropicScale || // //else if (Mode == TouchManipulationMode.IsotropicScale ||
// Mode == TouchManipulationMode.ScaleRotate || // // Mode == TouchManipulationMode.ScaleRotate ||
// Mode == TouchManipulationMode.ScaleDualRotate) // // Mode == TouchManipulationMode.ScaleDualRotate)
//{ // //{
// scaleX = scaleY = Magnitude(newVector) / Magnitude(oldVector); // // scaleX = scaleY = Magnitude(newVector) / Magnitude(oldVector);
//} // //}
if (!float.IsNaN(scaleX) && !float.IsInfinity(scaleX) && // if (!float.IsNaN(scaleX) && !float.IsInfinity(scaleX) &&
!float.IsNaN(scaleY) && !float.IsInfinity(scaleY)) // !float.IsNaN(scaleY) && !float.IsInfinity(scaleY))
{ // {
SKMatrix.PostConcat(ref touchMatrix, // SKMatrix.PostConcat(ref touchMatrix,
SKMatrix.MakeScale(scaleX, scaleY, pivotPoint.X, pivotPoint.Y)); // SKMatrix.MakeScale(scaleX, scaleY, pivotPoint.X, pivotPoint.Y));
} // }
return touchMatrix; // return touchMatrix;
} // }
} // }
} //}

Binary file not shown.
Loading…
Cancel
Save