private void HandleRightClick(PointerEventData eventData) { switch (mouseMode) { case MouseMode.Select: { Ray clickWorldRay = Camera.main.ScreenPointToRay(eventData.position); if (Physics.Raycast(clickWorldRay, out clickCast)) { Vector3 target = clickCast.point; Vector2 pathTarget = new Vector2(target.x, target.z); MoveOp action = new MoveOp(); action.targets = new ulong[selected.Count]; for (int i = 0; i < selected.Count; i++) { action.targets[i] = selected[i].getID(); } action.targetPosition = pathTarget; RoundManager.INSTANCE.actionSystem.addAction(action); } break; } case MouseMode.Placement: { break; } } }
/// <summary> /// 玩家移动 /// </summary> /// <param name="id">玩家ID</param> /// <param name="dir">方向(用战斗中的Vector2类)</param> public static void Move(ulong id, Vector2 dir) { if (scene != null) { MoveOp op = new MoveOp(); op.Direction = dir; scene.AddPlayerOp(id, op); } }
private void TimePlot_MouseUp(object sender, MouseEventArgs e) { CurrentMoveOp = MoveOp.None; TentativeOp = MoveOp.None; if (MenuStripIsShowing == null) { HoverOver = null; } ScreenLoopOffset = new PointF(); }
private void TimePlot_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { CurrentMoveOp = TentativeOp; if (CurrentMoveOp == MoveOp.resetScale) { AutoScaleRequested = true; } if (CurrentMoveOp == MoveOp.goToZero) { if (TimeStamps.Count == 0) { xOffsetG = DrawPlotArea.Width; } else { xOffsetG = DrawPlotArea.Width - TimeStamps.Max() * XPPU; } needsRefresh = true; } if (CurrentMoveOp == MoveOp.xyPan) { Cursor = Cursors.NoMove2D; } else if (CurrentMoveOp == MoveOp.yZoom) { Cursor = Cursors.NoMove2D; } GAtMouseDown = e.Location; VAtMouseDown = GtoV(e.Location); } else if (e.Button == MouseButtons.Right) { if (TentativeOp == MoveOp.selectSeries) { ContextMenuStrip = HoverOver.ContextMenuStrip; ContextMenuStrip.Closed += ContextMenuStrip_Closed; MenuStripIsShowing = HoverOver; } else if (TentativeOp == MoveOp.yZoom) { ContextMenuStrip = yScaleConextMenuStrip; } else { ContextMenuStrip_bkp = ContextMenuStrip; ContextMenuStrip = null; } } MouseDownAt = LastMouse; }
public PaletteKMeans(List <UInt32> colors, int targetCount, int maxIterations) { MoveOp[] moveOps = new MoveOp[colors.Count * 2]; int moveCount = 1; targetCount = Math.Min(targetCount, colors.Count); _clusters = new List <Cluster>(); System.Random rng = new System.Random(); int n = colors.Count; while (n > 1) { n--; int k = rng.Next(n + 1); UInt32 value = colors[k]; colors[k] = colors[n]; colors[n] = value; } int i; for (i = 0; i < targetCount; i++) { Cluster cluster = new Cluster(); cluster.colors.Add(colors[i]); _clusters.Add(cluster); cluster.RecalcCentroid(); } colors.RemoveRange(0, targetCount); while (colors.Count > 0) { UInt32 color = colors[0]; colors.RemoveRange(0, 1); float distance = float.MaxValue; Cluster bestCluster = _clusters[0]; foreach (Cluster cluster in _clusters) { float newDistance = cluster.Distance(color); if (newDistance < distance) { distance = newDistance; bestCluster = cluster; } } bestCluster.colors.Add(color); } foreach (Cluster cluster in _clusters) { cluster.RecalcCentroid(); } i = 0; while (i < maxIterations && moveCount > 0) { moveCount = 0; foreach (Cluster cluster in _clusters) { if (cluster.colors.Count <= 1) { continue; } foreach (UInt32 color in cluster.colors) { float currentDistance = cluster.Distance(color); foreach (Cluster compareCluster in _clusters) { if (cluster == compareCluster) { continue; } float newDistance = compareCluster.Distance(color); if (newDistance < currentDistance) { moveOps[moveCount].color = color; moveOps[moveCount].from = cluster; moveOps[moveCount].to = compareCluster; moveCount++; } } } } for (int j = 0; j < moveCount; j++) { moveOps[j].Execute(); } foreach (Cluster cluster in _clusters) { cluster.RecalcCentroid(); } i++; } palette = CreatePalette(); }
public void ForceHighlight(TimeSeries series) { HoverOver = series; TentativeOp = series == null ? MoveOp.None : MoveOp.selectSeries; MenuStripIsShowing = series; }
private void TimePlot_MouseMove(object sender, MouseEventArgs e) { CursorG = e.Location; Point eLocForSaving = e.Location; Point eLoc = new Point(e.Location.X + (int)ScreenLoopOffset.X, e.Location.Y + (int)ScreenLoopOffset.Y); showCursorX = false; showCursorY = false; if (CurrentMoveOp == MoveOp.None) { if ( (MaxValueOvershootInDisplay() && UpLimitImage.Contains(eLoc)) || (MinValueOvershootInDisplay() && DownLimitImage.Contains(eLoc)) ) { Cursor = Cursors.Hand; TentativeOp = MoveOp.resetScale; needsRefresh = true; HoverOver = null; } else if (TimeUndershootInDisplay() && RightLimitImage.Contains(eLoc)) { Cursor = Cursors.Hand; TentativeOp = MoveOp.goToZero; needsRefresh = true; HoverOver = null; } else if (eLoc.Y > DrawPlotArea.Height) { Cursor = Cursors.SizeWE; TentativeOp = MoveOp.xZoom; needsRefresh = true; showCursorX = true; HoverOver = null; } else if (eLoc.X > DrawPlotArea.Width) { Cursor = Cursors.SizeNS; TentativeOp = MoveOp.yZoom; needsRefresh = true; showCursorY = true; HoverOver = null; } else { Cursor = Cursors.Default; TentativeOp = MoveOp.xyPan; var bkp = HoverOver; HoverOver = CheckHover(GtoV(eLoc, xOffsetG, XPPU, yOffsetG, YPPU, Height - XLabelHeight), 10 / XPPU, 10 / YPPU); if (HoverOver != null) { TentativeOp = MoveOp.selectSeries; } if (HoverOver != bkp) { needsRefresh = true; if (HoverOver != null) { Cursor = Cursors.Help; } } } } else if (CurrentMoveOp == MoveOp.xZoom) { float totalShownV = Width / XPPU; float changeV = -(eLoc.X - LastMouse.X) / XPPU; float newTotalV = totalShownV + changeV; if (newTotalV < 0) { return; } XPPU = Width / newTotalV; xOffsetG = GAtMouseDown.X - VAtMouseDown.X * XPPU; needsRefresh = true; } else if (CurrentMoveOp == MoveOp.yZoom) { float totalShownV = (Height - XLabelHeight) / YPPU; float changeV = (eLoc.Y - LastMouse.Y) / YPPU; float newTotalV = totalShownV + changeV; YPPU = (Height - XLabelHeight) / newTotalV; yOffsetG = ((Height - XLabelHeight) - GAtMouseDown.Y) - VAtMouseDown.Y * YPPU; needsRefresh = true; } else if (CurrentMoveOp == MoveOp.xyPan || CurrentMoveOp == MoveOp.selectSeries) { xOffsetG += (eLoc.X - LastMouse.X); yOffsetG += -(eLoc.Y - LastMouse.Y); needsRefresh = true; } if (CurrentMoveOp == MoveOp.xyPan || CurrentMoveOp == MoveOp.yZoom || CurrentMoveOp == MoveOp.xZoom || CurrentMoveOp == MoveOp.selectSeries) { int x = Cursor.Position.X; if (x + 1 >= Screen.PrimaryScreen.Bounds.Width) { Cursor.Position = new Point(1, MousePosition.Y); ScreenLoopOffset = new PointF(ScreenLoopOffset.X + Screen.PrimaryScreen.Bounds.Width, ScreenLoopOffset.Y); eLocForSaving.X -= Screen.PrimaryScreen.Bounds.Width; } else if (x == 0) { Cursor.Position = new Point(Screen.PrimaryScreen.Bounds.Width - 2, MousePosition.Y); ScreenLoopOffset = new PointF(ScreenLoopOffset.X - Screen.PrimaryScreen.Bounds.Width, ScreenLoopOffset.Y); eLocForSaving.X += Screen.PrimaryScreen.Bounds.Width; } int y = Cursor.Position.Y; if (y + 1 >= Screen.PrimaryScreen.Bounds.Height) { Cursor.Position = new Point(MousePosition.X, 1); ScreenLoopOffset = new PointF(ScreenLoopOffset.X, ScreenLoopOffset.Y + Screen.PrimaryScreen.Bounds.Height); eLocForSaving.Y -= Screen.PrimaryScreen.Bounds.Height; } else if (y == 0) { Cursor.Position = new Point(MousePosition.X, Screen.PrimaryScreen.Bounds.Height - 2); ScreenLoopOffset = new PointF(ScreenLoopOffset.Y, ScreenLoopOffset.Y - Screen.PrimaryScreen.Bounds.Height); eLocForSaving.Y += Screen.PrimaryScreen.Bounds.Height; } } LastMouse = new Point(eLocForSaving.X + (int)ScreenLoopOffset.X, eLocForSaving.Y + (int)ScreenLoopOffset.Y); }
private void ProcessDuplicates(MoveOp op, string srcFolder, string dstRoot) { int progress = 0; foreach (Dir directory in _found.Values) { string dest = directory.GetDirectory(srcFolder).TrimStart('\\'); string destFolder = Path.Combine(dstRoot, dest); if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } foreach (Duplicate dupe in directory.Dupes) { foreach (FileInfo file in dupe.DuplicateFiles) { string destFile = Path.Combine(destFolder, file.Name); switch(op) { case MoveOp.Test: using (StreamWriter wrt = File.AppendText(destFile)) { wrt.Write(""); } break; case MoveOp.Move: File.Copy(file.FullName, destFile); file.Delete(); break; case MoveOp.Copy: File.Copy(file.FullName, destFile); break; } UpdateProgress(++progress); } } } }