Ejemplo n.º 1
0
    public void ClearAndReset()
    {
        var clearAction = new BrushAction()
        {
            type     = BrushActionType.Clear,
            drawerId = Player.Local.netId
        };

        //We apply a brush action to clear all clients
        //and predict a brush action to clear the server
        ApplyBrushAction(clearAction);
        PredictBrushAction(clearAction);

        //We also send preview actions to everybody so that
        //things get cleared out
        foreach (var player in Player.All)
        {
            ApplyBrushAction(new BrushAction()
            {
                type      = BrushActionType.Line,
                position0 = new Vector2Int(-100, -100),
                position1 = new Vector2Int(-100, -100),
                size      = 0,
                drawerId  = player.netId,
                isPreview = true
            });
        }
    }
Ejemplo n.º 2
0
 public void SubmitBrush(Player player, BrushAction brush)
 {
     if (CanPlayerDraw(player))
     {
         _drawingBoard.ApplyBrushAction(brush);
     }
 }
Ejemplo n.º 3
0
            public BrushAction Dequeue()
            {
                BrushAction ba = list.Last.Value;

                list.RemoveLast();
                return(ba);
            }
Ejemplo n.º 4
0
        private void btnBrush_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;

            BrushType            = button?.Name;
            sizeTrackBar.Enabled = false;
            BrushAction?.Invoke();
            ToolAction?.Invoke();
        }
Ejemplo n.º 5
0
    private void OnDraw(BrushAction brush)
    {
        brush.drawerId = Player.Local.netId;

        if (CanPlayerDraw(Player.Local))
        {
            _drawingBoard.PredictBrushAction(brush);
            Player.Local.CmdDraw(brush);
        }
    }
Ejemplo n.º 6
0
    private void deserializeBrushActions(NetworkReader reader)
    {
        int count = (int)reader.ReadPackedUInt32();

        for (int i = 0; i < count; i++)
        {
            BrushAction action = new BrushAction();
            action.Deserialize(reader);
            _toDrawQueue.Enqueue(action);
        }
    }
Ejemplo n.º 7
0
    private void drawBrushActionToCanvases(BrushAction action)
    {
        var previewCanvas = getPreviewCanvas(action.drawerId);

        previewCanvas.Clear(new Color32(0, 0, 0, 0));
        if (action.isPreview)
        {
            previewCanvas.ApplyBrushAction(action);
        }
        else
        {
            _boardCanvas.ApplyBrushAction(action);
        }
    }
Ejemplo n.º 8
0
    public void ApplyBrushAction(BrushAction action)
    {
        action.time = GameCoordinator.instance.GameTime;
        SetDirtyBit(1);

        //We add the brush action to the send queue so that
        //when we serialize this board, the actions get serialized
        //and sent out
        _toSendQueue.Enqueue(action);

        //Serialized stuff never gets sent to the server (it's the
        //thing being serialized) so we also want to add the action
        //to the servers toDraw queue so that it gets drawn
        _toDrawQueue.Enqueue(action);
    }
Ejemplo n.º 9
0
 private void Redo()
 {
     if (redoQueue.Count > 0)
     {
         BrushAction redoAction = redoQueue.Dequeue();
         //Set all of the values in the affected area to what they were before the undo action took place.
         HeightRender render   = Document.SelectedRender;
         BrushAction  opposite = new BrushAction(redoAction.Selection, redoAction.Data);
         for (int x = redoAction.Selection.Left; x < redoAction.Selection.Right; x++)
         {
             for (int y = redoAction.Selection.Top; y < redoAction.Selection.Bottom; y++)
             {
                 float oldSample;
                 if (render.HeightField.TryGetHeight(x, y, out oldSample))
                 {
                     int i = (y - redoAction.Selection.Top) * redoAction.Selection.Width + (x - redoAction.Selection.Left);
                     render.HeightField[x, y] = redoAction.Data[i];
                     opposite.Data[i]         = oldSample;
                 }
             }
         }
         PhotonGradient gradient = Document.SelectedGradient;
         IEnumerable <HeightRender.Effect> effects;
         if (paintEffectsBox.Checked)
         {
             effects = Document.SelectedEffects;
         }
         else
         {
             effects = null;                 //Don't worry about effects if we're not painting with them.
         }
         //Update each section of the selection when wrapping has been accounted for.
         foreach (FieldSelection fs in redoAction.Selection.SubSelectionsOf(render.HeightField))
         {
             //Omit any parts that have a width or height of zero.
             if (!fs.IsEmpty)
             {
                 //Update the corresponding part of the render.
                 render.UpdateArea(fs.Left, fs.Top, fs.Width, fs.Height, gradient, effects);
                 //Invalidate the corresponding part of the image panel so that it redraws itself in realtime.
                 Point start = Numerics.ToPoint(renderArea.ImageToClient(new Vector2(fs.Left, fs.Top)));
                 Point end   = Numerics.ToPoint(renderArea.ImageToClient(new Vector2(fs.Right, fs.Bottom)));
                 renderArea.Invalidate(new Rectangle(Numerics.Max(start.X, 0), Numerics.Max(start.Y, 0), Numerics.Max(end.X, 0), Numerics.Max(end.Y, 0)));
             }
         }
         undoQueue.Enqueue(opposite);
     }
 }
Ejemplo n.º 10
0
 public void CmdDraw(BrushAction brush)
 {
     GameCoordinator.instance.SubmitBrush(this, brush);
 }
Ejemplo n.º 11
0
 public void PredictBrushAction(BrushAction action)
 {
     Assert.AreEqual(action.drawerId, Player.Local.netId);
     drawBrushActionToCanvases(action);
 }
Ejemplo n.º 12
0
 public void Enqueue(BrushAction action)
 {
     list.AddLast(action);
     Trim();
 }