-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacterPage - Copier.xaml.cs
449 lines (392 loc) · 17.3 KB
/
CharacterPage - Copier.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.ComponentModel;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Input;
namespace BushidoApp
{
public partial class CharacterPage : PhoneApplicationPage, INotifyPropertyChanged
{
int charIndex { get; set; }
int factIndex { get; set; }
private System.Windows.Media.SolidColorBrush color;
public System.Windows.Media.SolidColorBrush Color
{
get { return color; }
set
{
if (value == color) return;
color = value;
NotifyPropertyChanged("Color");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string nomPropriete) {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(nomPropriete));
}
public void loadImage()
{
//MiniImage.Source = FactionList.Factions()[factIndex].Characters[charIndex].MinisImage;
MiniImage.Source = Image.Get(FactionList.Factions()[factIndex].Characters[charIndex].MinisPath);
int cnt = 1;
BitmapImage img;
// foreach (BitmapImage img in FactionList.Factions()[factIndex].Characters[charIndex].ProfileImage)
foreach (string path in FactionList.Factions()[factIndex].Characters[charIndex].ProfilePaths)
{
img = Image.Get(path);
switch(cnt)
{
case 1: ProfileImageFirst_1.Source = img;
ProfileImageBack_1.Source = img;
break;
case 2: ProfileImageFirst_2.Source = img;
ProfileImageBack_2.Source = img;
break;
case 3: ProfileImageFirst_3.Source = img;
ProfileImageBack_3.Source = img;
break;
case 4: ProfileImageFirst_4.Source = img;
ProfileImageBack_4.Source = img;
break;
case 5: ProfileImageFirst_5.Source = img;
ProfileImageBack_5.Source = img;
break;
}
cnt += 1;
}
cnt *= 2;
cnt -= 1;
int max = Pivot.Items.Count;
for (int i = cnt; i < max; i++)
{
Pivot.Items.RemoveAt(Pivot.Items.Count-1);
}
//if (FactionList.Factions()[factIndex].Characters[charIndex].MinisImage == null)
if (MiniImage.Source == null)
{
Pivot.Items.RemoveAt(0);
}
}
public CharacterPage()
{
InitializeComponent();
//ResizeImage(false);
DataContext = this;
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string charIndexStr, factIndexStr;
if (NavigationContext.QueryString.TryGetValue("charIndex", out charIndexStr) &&
NavigationContext.QueryString.TryGetValue("factIndex", out factIndexStr)) {
charIndex = int.Parse(charIndexStr);
factIndex = int.Parse(factIndexStr);
ChangeColor(FactionList.Factions()[factIndex].Name);
loadImage();
}
base.OnNavigatedTo(e);
}
protected void ChangeColor(string factionName){
ApplicationTitle.Foreground = Faction.GetColor(factionName);
Color = Faction.GetColor(factionName);
//miniHeader.Foreground = Faction.GetColor(factionName);
/*
HeaderF1.Foreground = Faction.GetColor(factionName);
HeaderF2.Foreground = Faction.GetColor(factionName);
HeaderF3.Foreground = Faction.GetColor(factionName);
HeaderF4.Foreground = Faction.GetColor(factionName);
HeaderF5.Foreground = Faction.GetColor(factionName);
HeaderB1.Foreground = Faction.GetColor(factionName);
HeaderB2.Foreground = Faction.GetColor(factionName);
HeaderB3.Foreground = Faction.GetColor(factionName);
HeaderB4.Foreground = Faction.GetColor(factionName);
HeaderB5.Foreground = Faction.GetColor(factionName);
//*/
}
// these two fully define the zoom state:
//private double TotalImageScale = 1d;
//private Point ImagePosition = new Point(0, 0);
//private Point _oldFinger1;
//private Point _oldFinger2;
//private double _oldScaleFactor;
//private System.Windows.Controls.Image getImageToZoom()
//{
// // If there is no image, the number of card is even
// // Hence, we need an offset
// int offset = (Pivot.Items.Count % 2 == 0) ? 1 : 0;
// switch (Pivot.SelectedIndex + offset)
// {
// case 0: return MiniImage;
// case 1: return ProfileImageFirst_1;
// case 2: return ProfileImageBack_1;
// case 3: return ProfileImageFirst_2;
// case 4: return ProfileImageBack_2;
// case 5: return ProfileImageFirst_3;
// case 6: return ProfileImageBack_3;
// case 7: return ProfileImageFirst_4;
// case 8: return ProfileImageBack_4;
// case 9: return ProfileImageFirst_5;
// case 10: return ProfileImageBack_5;
// }
// return MiniImage;
//}
//private System.Windows.Media.ScaleTransform getXform()
//{
// // If there is no image, the number of card is even
// // Hence, we need an offset
// int offset = (Pivot.Items.Count % 2 == 0) ? 1 : 0;
// switch (Pivot.SelectedIndex + offset)
// {
// case 0: return xformMini;
// case 1: return xformFirst_1;/*
// case 2: return ProfileImageBack_1;
// case 3: return ProfileImageFirst_2;
// case 4: return ProfileImageBack_2;
// case 5: return ProfileImageFirst_3;
// case 6: return ProfileImageBack_3;
// case 7: return ProfileImageFirst_4;
// case 8: return ProfileImageBack_4;
// case 9: return ProfileImageFirst_5;
// case 10: return ProfileImageBack_5;*/
// }
// return xformMini;
//}
//private System.Windows.Controls.Primitives.ViewportControl getViewport()
//{
// // If there is no image, the number of card is even
// // Hence, we need an offset
// int offset = (Pivot.Items.Count % 2 == 0) ? 1 : 0;
// switch (Pivot.SelectedIndex + offset)
// {
// case 0: return viewportMini;
// case 1: return viewportFirst_1;/*
// case 2: return ProfileImageBack_1;
// case 3: return ProfileImageFirst_2;
// case 4: return ProfileImageBack_2;
// case 5: return ProfileImageFirst_3;
// case 6: return ProfileImageBack_3;
// case 7: return ProfileImageFirst_4;
// case 8: return ProfileImageBack_4;
// case 9: return ProfileImageFirst_5;
// case 10: return ProfileImageBack_5;*/
// }
// return viewportMini;
//}
//private System.Windows.Controls.Canvas getCanvas()
//{
// // If there is no image, the number of card is even
// // Hence, we need an offset
// int offset = (Pivot.Items.Count % 2 == 0) ? 1 : 0;
// switch (Pivot.SelectedIndex + offset)
// {
// case 0: return canvasMini;
// case 1: return canvasFirst_1;/*
// case 2: return ProfileImageBack_1;
// case 3: return ProfileImageFirst_2;
// case 4: return ProfileImageBack_2;
// case 5: return ProfileImageFirst_3;
// case 6: return ProfileImageBack_3;
// case 7: return ProfileImageFirst_4;
// case 8: return ProfileImageBack_4;
// case 9: return ProfileImageFirst_5;
// case 10: return ProfileImageBack_5;*/
// }
// return canvasMini;
//}
//const double MaxScale = 5;
//static double optimalScale = 0.54;
//double _scale;
//double _minScale;
//double _coercedScale;
//double _originalScale;
//Size _viewportSize;
//bool _pinching;
//Point _screenMidpoint;
//Point _relativeMidpoint;
//BitmapImage _bitmap;
/// <summary>
/// Either the user has manipulated the image or the size of the viewport has changed. We only
/// care about the size.
/// </summary>
//void viewport_ViewportChanged(object sender, System.Windows.Controls.Primitives.ViewportChangedEventArgs e)
//{
// Size newSize = new Size(getViewport().Viewport.Width, getViewport().Viewport.Height);
// if (newSize != _viewportSize)
// {
// _viewportSize = newSize;
// CoerceScale(true);
// ResizeImage(false);
// }
//}
/// <summary>
/// Handler for the ManipulationStarted event. Set initial state in case
/// it becomes a pinch later.
/// </summary>
//void OnManipulationStarted(object sender, ManipulationStartedEventArgs e)
//{
// _pinching = false;
// _originalScale = _scale;
//}
/// <summary>
/// Handler for the ManipulationDelta event. It may or may not be a pinch. If it is not a
/// pinch, the getViewport()Control will take care of it.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//void OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
//{
// if (e.PinchManipulation != null)
// {
// e.Handled = true;
// if (!_pinching)
// {
// _pinching = true;
// Point center = e.PinchManipulation.Original.Center;
// _relativeMidpoint = new Point(center.X / getImageToZoom().ActualWidth, center.Y / getImageToZoom().ActualHeight);
// var xform = getImageToZoom().TransformToVisual(getViewport());
// _screenMidpoint = xform.Transform(center);
// }
// _scale = _originalScale * e.PinchManipulation.CumulativeScale;
// CoerceScale(false);
// ResizeImage(false);
// }
// else if (_pinching)
// {
// _pinching = false;
// _originalScale = _scale = _coercedScale;
// }
// // REMOVE
// ApplicationTitle.Text = _originalScale.ToString();
//}
/// <summary>
/// The manipulation has completed (no touch points anymore) so reset state.
/// </summary>
//void OnManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
//{
// _pinching = false;
// _scale = _coercedScale;
// // REMOVE
// ApplicationTitle.Text = _originalScale.ToString();
//}
/// <summary>
/// When a new image is opened, set its initial scale.
/// </summary>
//void OnImageOpened(object sender, RoutedEventArgs e)
//{
// _bitmap = (BitmapImage)getImageToZoom().Source;
// // Set scale to the minimum, and then save it.
// _scale = 0;
// CoerceScale(true);
// _scale = _coercedScale;
// ResizeImage(true);
//}
/// <summary>
/// Adjust the size of the image according to the coerced scale factor. Optionally
/// center the image, otherwise, try to keep the original midpoint of the pinch
/// in the same spot on the screen regardless of the scale.
/// </summary>
/// <param name="center"></param>
//void ResizeImage(bool center)
//{
// if (_coercedScale != 0 && _bitmap != null)
// {
// double newWidth = getCanvas().Width = Math.Round(_bitmap.PixelWidth * _coercedScale);
// double newHeight = getCanvas().Height = Math.Round(_bitmap.PixelHeight * _coercedScale);
// getXform().ScaleX = getXform().ScaleY = _coercedScale;
// getViewport().Bounds = new Rect(0, 0, newWidth, newHeight);
// if (center)
// {
// getViewport().SetViewportOrigin(
// new Point(
// Math.Round((newWidth - getViewport().ActualWidth) / 2),
// Math.Round((newHeight - getViewport().ActualHeight) / 2)
// ));
// }
// else
// {
// Point newImgMid = new Point(newWidth * _relativeMidpoint.X, newHeight * _relativeMidpoint.Y);
// Point origin = new Point(newImgMid.X - _screenMidpoint.X, newImgMid.Y - _screenMidpoint.Y);
// getViewport().SetViewportOrigin(origin);
// }
// }
//}
/// <summary>
/// Coerce the scale into being within the proper range. Optionally compute the constraints
/// on the scale so that it will always fill the entire screen and will never get too big
/// to be contained in a hardware surface.
/// </summary>
/// <param name="recompute">Will recompute the min max scale if true.</param>
//void CoerceScale(bool recompute)
//{
// if (recompute && _bitmap != null && getViewport() != null)
// {
// ApplicationTitle.Text = getViewport().ActualHeight.ToString() + " " + getViewport().ActualWidth.ToString();
// // Calculate the minimum scale to fit the viewport
// double minX = getViewport().ActualWidth / _bitmap.PixelWidth;
// double minY = getViewport().ActualHeight / _bitmap.PixelHeight;
// _minScale = Math.Min(minX, minY);
// }
// _coercedScale = Math.Min(MaxScale, Math.Max(_scale, _minScale));
// //_coercedScale = optimalScale;
//}
//private void OnPinchStarted(object s, PinchStartedGestureEventArgs e)
//{
// _oldFinger1 = e.GetPosition(getImageToZoom(), 0);
// _oldFinger2 = e.GetPosition(getImageToZoom(), 1);
// _oldScaleFactor = 1;
//}
//private void OnPinchDelta(object s, PinchGestureEventArgs e)
//{
// var scaleFactor = e.DistanceRatio / _oldScaleFactor;
// var currentFinger1 = e.GetPosition(getImageToZoom(), 0);
// var currentFinger2 = e.GetPosition(getImageToZoom(), 1);
// var translationDelta = GetTranslationDelta(
// currentFinger1,
// currentFinger2,
// _oldFinger1,
// _oldFinger2,
// ImagePosition,
// scaleFactor);
// _oldFinger1 = currentFinger1;
// _oldFinger2 = currentFinger2;
// _oldScaleFactor = e.DistanceRatio;
// UpdateImage(scaleFactor, translationDelta);
//}
//private void UpdateImage(double scaleFactor, Point delta)
//{
// TotalImageScale *= scaleFactor;
// ImagePosition = new Point(ImagePosition.X + delta.X, ImagePosition.Y + delta.Y);
// var transform = (CompositeTransform)getImageToZoom().RenderTransform;
// transform.ScaleX = TotalImageScale;
// transform.ScaleY = TotalImageScale;
// transform.TranslateX = ImagePosition.X;
// transform.TranslateY = ImagePosition.Y;
//}
//private Point GetTranslationDelta(
// Point currentFinger1, Point currentFinger2,
// Point oldFinger1, Point oldFinger2,
// Point currentPosition, double scaleFactor)
//{
// var newPos1 = new Point(
// currentFinger1.X + (currentPosition.X - oldFinger1.X) * scaleFactor,
// currentFinger1.Y + (currentPosition.Y - oldFinger1.Y) * scaleFactor);
// var newPos2 = new Point(
// currentFinger2.X + (currentPosition.X - oldFinger2.X) * scaleFactor,
// currentFinger2.Y + (currentPosition.Y - oldFinger2.Y) * scaleFactor);
// var newPos = new Point(
// (newPos1.X + newPos2.X) / 2,
// (newPos1.Y + newPos2.Y) / 2);
// return new Point(
// newPos.X - currentPosition.X,
// newPos.Y - currentPosition.Y);
//}
}
}