private void connection_OnFogUpdateReceived(FogUpdate fogUpdate)
 {
     lock (fogUpdatesLock)
     {
         fogUpdates.Add(fogUpdate);
         gameState.ConsumeFogUpdates = true;
     }
 }
示例#2
0
        public override void FogOrRevealAll(bool fogAll)
        {
            var fogAllFogUpdate = new FogUpdate(!fogAll);
            fogAllFogUpdate.Add(new SimplePoint(0, 0));
            fogAllFogUpdate.Add(new SimplePoint(base.LoadedMapSize.Width, 0));
            fogAllFogUpdate.Add(new SimplePoint(base.LoadedMapSize.Width, base.LoadedMapSize.Height));
            fogAllFogUpdate.Add(new SimplePoint(0, base.LoadedMapSize.Height));

            this.SetFogUpdateAsync(fogAllFogUpdate, true);
        }
示例#3
0
        public void SetFogUpdateAsync(FogUpdate fogUpdate, bool ignoreFogAlphaEffect = false)
        {
            Bitmap fogImageToUpdate;
            var isNewFogImage = (this.Fog == null);
            if (isNewFogImage)
            {
                fogImageToUpdate = new Bitmap(base.LoadedMapSize.Width, base.LoadedMapSize.Height);
                using (var g = Graphics.FromImage(fogImageToUpdate))
                {
                    g.FillRectangle(DnDMapConstants.FOG_BRUSH, 0, 0, fogImageToUpdate.Width, fogImageToUpdate.Height);
                }
            }
            else
            {
                fogImageToUpdate = this.Fog;
            }

            var doAction = new Action(() =>
                    {
                        if (!ignoreFogAlphaEffect && this.UseFogAlphaEffect)
                        {
                            ImageProcessing.ApplyFogInwards(fogImageToUpdate, fogUpdate);
                        }
                        else
                        {
                            ImageProcessing.ApplyFogDirect(fogImageToUpdate, fogUpdate);
                        }
                    });

            // For new images, it's not tied to the control in any way so we can perform the update on the thread. Otherwise, we need
            // to sync up to the main thread to draw on the image.
            if (isNewFogImage || !this.InvokeRequired)
            {
                doAction();
                if (isNewFogImage)
                    this.Fog = fogImageToUpdate;
            }
            else
                this.Invoke(doAction);

            RefreshAll();
        }
示例#4
0
        private void ctlDnDMap_OnOneFogUpdatesChanged(FogUpdate fogUpdate)
        {
            anyFogChanges = true;

            undoLastFogAction.Enabled = this.ctlDnDMap.AnyUndoFogUpdates;
            redoLastFogAction.Enabled = this.ctlDnDMap.AnyRedoFogUpdates;

            if (this.ctlControlPanel.RealTimeFogUpdates)
                connection.WriteFogUpdate(fogUpdate);
        }
示例#5
0
        private void UpdateFogImage(FogUpdate[] fogUpdates, bool ignoreFogAlphaEffect = false, bool ignoreEvents = false)
        {
            if (!ignoreFogAlphaEffect && UseFogAlphaEffect)
            {
                if (!ImageProcessing.ApplyFogInwards(this.Fog, fogUpdates))
                    return;
            }
            else
            {
                if (!ImageProcessing.ApplyFogDirect(this.Fog, fogUpdates))
                    return;
                this.RefreshAll(true);
            }

            allFogUpdates.AddRange(fogUpdates);

            if (!ignoreEvents)
            {
                if (fogUpdates.Length == 1 && OnOneFogUpdatesChanged != null)
                    OnOneFogUpdatesChanged(fogUpdates[0]);
                if (fogUpdates.Length > 1 && OnManyFogUpdatesChanged != null)
                    OnManyFogUpdatesChanged();
            }
        }
        private void connection_OnFogUpdateReceived(FogUpdate fogUpdate)
        {
            var fogImageToUpdate = this.fog;
            var isNewFogImage = (fogImageToUpdate == null);
            if (isNewFogImage)
                fogImageToUpdate = new Bitmap(this.receivedMapWidth, this.receivedMapHeight);

            using (var g = Graphics.FromImage(fogImageToUpdate))
            {
                if (isNewFogImage)
                    g.FillRectangle(fogBrush, 0, 0, fog.Width, fog.Height);
                g.FillPolygon((fogUpdate.IsClearing) ? fogClearBrush : fogBrush, fogUpdate.Points.Select(p => p.ToPoint()).ToArray());
            }

            if (isNewFogImage)
                this.fog = fogImageToUpdate;

            if (isBlackoutOn)
                return;

            RefreshMapPictureBox();
        }
示例#7
0
        protected override void HandleMouseUp(MouseEventArgs e)
        {
            // If we're currently dealing with drawing New Fog, we'll suck all Mouse Up events into oblivion that aren't Left Click.
            if (newFogUpdatePoints.Count > 0 && e.Button != System.Windows.Forms.MouseButtons.Left)
                return;

            // Anything this override cannot handle will delegate to the base implementation.
            if (base.LoadedMap == null ||
                IsZoomFactorInProgress ||
                newFogUpdatePoints.Count == 0
                || e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                base.HandleMouseUp(e);
                return;
            }

            if (IsToolFogAddOrRemove)
            {
                // Commit the last point onto the main Fog Image. Note that if we don't have at least 3 points, then we don't have a shape that can be used.
                newFogUpdatePoints.Add(e.Location.Translate(this.ScrollPosition));
                if (newFogUpdatePoints.Count >= 3)
                {
                    var fogUpdate = new FogUpdate(newFogUpdatePoints.Select(p => p.ToSimplePoint()), isNewFogClearing);
                    undoFogUpdates.AddLast(fogUpdate);
                    UpdateFogImage(fogUpdate);
                }
                newFogUpdatePoints.Clear();
                base.SuppressScroll = false;
                UseHighQuality = true;
                base.RefreshAll();
            }
            else
            {
                base.HandleMouseUp(e);
            }
        }
示例#8
0
 private void UpdateFogImage(FogUpdate fogUpdate, bool ignoreFogAlphaEffect = false, bool ignoreEvents = false)
 {
     UpdateFogImage(new[] { fogUpdate }, ignoreFogAlphaEffect, ignoreEvents);
 }
示例#9
0
        public override void FogOrRevealAll(bool fogAll)
        {
            var fogAllFogUpdate = new FogUpdate(!fogAll);
            fogAllFogUpdate.Add(new SimplePoint(0, 0));
            fogAllFogUpdate.Add(new SimplePoint(this.Fog.Width, 0));
            fogAllFogUpdate.Add(new SimplePoint(this.Fog.Width, this.Fog.Height));
            fogAllFogUpdate.Add(new SimplePoint(0, this.Fog.Height));

            UpdateFogImage(fogAllFogUpdate, true, true);
            undoFogUpdates.Clear();
            redoFogUpdates.Clear();
            this.RefreshAll();
        }
示例#10
0
        public void SetFogUpdates(FogUpdate[] fogUpdates)
        {
            using (var g = Graphics.FromImage(this.Fog))
                g.Clear(DnDMapConstants.FOG_BRUSH_COLOR);

            this.allFogUpdates.Clear();
            UpdateFogImage(fogUpdates);
            base.RefreshAll();
        }
示例#11
0
        private void pbxMap_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != System.Windows.Forms.MouseButtons.Left && e.Button != System.Windows.Forms.MouseButtons.Right)
                return;

            pbxMap.MouseMove += new MouseEventHandler(pbxMap_MouseMove);
            pbxMap.MouseUp += new MouseEventHandler(pbxMap_MouseUp);

            newFog = new Bitmap(fog.Width, fog.Height);

            currentFogUpdate = new FogUpdate((e.Button == System.Windows.Forms.MouseButtons.Left));
            currentFogUpdate.Add(ConvertPointToStretchedImage(e.Location));
        }
示例#12
0
        private void FogOrRevealAll(bool revealAll)
        {
            var message = (revealAll) ? "This will reveal the entire map. Are you sure? This cannot be undone." : "This will fog the entire map. Are you sure? This cannot be undone.";
            var title = (revealAll) ? "Reveal Entire Map?" : "Fog Entire Map?";
            if (MessageBox.Show(this, message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                var fogAllFogUpdate = new FogUpdate(revealAll);
                fogAllFogUpdate.Add(new SimplePoint(0, 0));
                fogAllFogUpdate.Add(new SimplePoint(fog.Width, 0));
                fogAllFogUpdate.Add(new SimplePoint(fog.Width, fog.Height));
                fogAllFogUpdate.Add(new SimplePoint(0, fog.Height));

                UpdateFogImage(fogAllFogUpdate);
                undoFogUpdates.Clear();
                redoFogUpdates.Clear();
                undoLastFogAction.Enabled = redoLastFogAction.Enabled = false;
                pbxMap.Refresh();

                if (realTimeFogUpdates)
                    connection.WriteFog(fog);
            }
        }
示例#13
0
        public void WriteFogUpdate(FogUpdate fogUpdate)
        {
            if (ClientsCount == 0)
                return;

            if (fogUpdate != null && fogUpdate.Length != 0)
                EnqueueWrite(new FogUpdateSocketObject(SocketConstants.SocketAction.FogUpdate, fogUpdate));
        }
示例#14
0
 private void UpdateNewFogImage(FogUpdate fogUpdate)
 {
     using (var g = Graphics.FromImage(newFog))
     {
         g.FillPolygon((fogUpdate.IsClearing) ? newFogClearBrush : newFogBrush, fogUpdate.Points.Select(p => p.ToPoint()).ToArray());
     }
 }
示例#15
0
        private void UpdateFogImage(FogUpdate[] fogUpdates, bool persistFogUpdatesToFile)
        {
            using (var g = Graphics.FromImage(fog))
            {
                foreach (var fogUpdate in fogUpdates)
                {
                    g.FillPolygon((fogUpdate.IsClearing) ? fogClearBrush : FOG_BRUSH, fogUpdate.Points.Select(p => p.ToPoint()).ToArray());
                }
            }

            allFogUpdates.AddRange(fogUpdates);

            if (persistFogUpdatesToFile)
            {
                Persistence.SaveServerFogData(this.mapUrl, new ServerFogData() { Data = allFogUpdates.ToFogData() });
            }
        }
示例#16
0
 private void UpdateFogImage(FogUpdate fogUpdate)
 {
     UpdateFogImage(new[] { fogUpdate }, true);
 }
示例#17
0
        private void pbxMap_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != System.Windows.Forms.MouseButtons.Left && e.Button != System.Windows.Forms.MouseButtons.Right)
                return;

            pbxMap.MouseMove -= new MouseEventHandler(pbxMap_MouseMove);
            pbxMap.MouseUp -= new MouseEventHandler(pbxMap_MouseUp);

            var toBeDisposedFog = newFog;
            newFog = null;
            if (toBeDisposedFog != null)
                toBeDisposedFog.Dispose();

            // Commit the last point onto the main Fog Image then clear out the 'New Fog' temporary image altogether. Note that if we don't have
            // at least 3 points, then we don't have a shape that can be used.

            currentFogUpdate.Add(ConvertPointToStretchedImage(e.Location));
            if (currentFogUpdate.Length >= 3)
            {
                UpdateFogImage(currentFogUpdate);
                undoFogUpdates.AddLast(currentFogUpdate);
                undoLastFogAction.Enabled = true;
                redoFogUpdates.Clear();
                redoLastFogAction.Enabled = false;

                pbxMap.Refresh();

                if (realTimeFogUpdates)
                    connection.WriteFogUpdate(currentFogUpdate);

                currentFogUpdate = null;
            }
        }
示例#18
0
 public FogUpdateSocketObject(SocketConstants.SocketAction action, FogUpdate fogUpdate)
     : base(SocketConstants.SocketAction.FogUpdate)
 {
     FogUpdateInstance = new FogUpdate(fogUpdate.Points, fogUpdate.IsClearing);
 }
示例#19
0
 private void connection_OnFogUpdateReceived(FogUpdate fogUpdate)
 {
     this.ctlDnDMap.SetFogUpdateAsync(fogUpdate);
 }