NodeControllerBookmarks.cs :  » Game » SokoSolve-Sokoban » SokoSolve » Core » UI » Nodes » Complex » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » SokoSolve Sokoban 
SokoSolve Sokoban » SokoSolve » Core » UI » Nodes » Complex » NodeControllerBookmarks.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using SokoSolve.Common.Math;
using SokoSolve.Core.Model;
using SokoSolve.Core.UI.Nodes.Effects;
using SokoSolve.Core.UI.Nodes.UINodes;
using SokoSolve.Core.UI.Paths;

namespace SokoSolve.Core.UI.Nodes.Complex{
    class NodeControllerBookmarks : NodeBase
    {
        public NodeControllerBookmarks(GameUI myGameUI, int myDepth) : base(myGameUI, myDepth)
        {
            VectorInt vi = myGameUI.GameCoords.PositionWayPoints.TopLeft;
            b1 = new NodeUIButton(myGameUI, myDepth + 1, vi, ResourceID.GameButtonBookmark1, "WP1");
            b1.ImageBack = null;
            b1.ToolTip = "Bookmark #1";
            b1.OnClick += new EventHandler<NotificationEvent>(OnButtonClick);
            b1.OnMouseOver += new EventHandler<NotificationEvent>(OnButtonMouseOver);
            myGameUI.Add(b1);

            vi = vi.Add(0, 40);
            b2 = new NodeUIButton(myGameUI, myDepth + 2, vi, ResourceID.GameButtonBookmark2, "WP2");
            b2.ImageBack = null;
            b2.ToolTip = "Bookmark #2";
            b2.OnClick += new EventHandler<NotificationEvent>(OnButtonClick);
            b2.OnMouseOver += new EventHandler<NotificationEvent>(OnButtonMouseOver);
            myGameUI.Add(b2);

            vi = vi.Add(0, 40);
            b3 = new NodeUIButton(myGameUI, myDepth + 3, vi, ResourceID.GameButtonBookmark3, "WP3");
            b3.ImageBack = null;
            b3.ToolTip = "Bookmark #3";
            b3.OnClick += new EventHandler<NotificationEvent>(OnButtonClick);
            b3.OnMouseOver += new EventHandler<NotificationEvent>(OnButtonMouseOver);
            myGameUI.Add(b3);

            vi = vi.Add(0, 40);
            b4 = new NodeUIButton(myGameUI, myDepth + 4, vi, ResourceID.GameButtonBookmark4, "WP4");
            b4.ImageBack = null;
            b4.ToolTip = "Bookmark #4";
            b4.OnClick += new EventHandler<NotificationEvent>(OnButtonClick);
            b4.OnMouseOver += new EventHandler<NotificationEvent>(OnButtonMouseOver);
            myGameUI.Add(b4);

            vi = vi.Add(0, 40);
            b5 = new NodeUIButton(myGameUI, myDepth + 5, vi, ResourceID.GameButtonBookmark5, "WP5");
            b5.ImageBack = null;
            b5.ToolTip = "Bookmark #5";
            b5.OnClick += new EventHandler<NotificationEvent>(OnButtonClick);
            b5.OnMouseOver += new EventHandler<NotificationEvent>(OnButtonMouseOver);
            myGameUI.Add(b5);

            brushBookmarkOn = null;
            brushBookmarkOff = new SolidBrush(Color.FromArgb(120, Color.Black));

            staticImageRender = new StaticImage(ResourceController.Singleton.GetInstance("Default.Tiles"), new VectorInt(16, 16));
        }

        public override void doStep()
        {
            // Update bookmark enabled
            b1.MaskEffect = (GameUI.Bookmarks.Count > 0 && GameUI.Bookmarks[0] != null) ? brushBookmarkOn : brushBookmarkOff;
            b2.MaskEffect = (GameUI.Bookmarks.Count > 1 && GameUI.Bookmarks[1] != null) ? brushBookmarkOn : brushBookmarkOff;
            b3.MaskEffect = (GameUI.Bookmarks.Count > 2 && GameUI.Bookmarks[2] != null) ? brushBookmarkOn : brushBookmarkOff;
            b4.MaskEffect = (GameUI.Bookmarks.Count > 3 && GameUI.Bookmarks[3] != null) ? brushBookmarkOn : brushBookmarkOff;
            b5.MaskEffect = (GameUI.Bookmarks.Count > 4 && GameUI.Bookmarks[4] != null) ? brushBookmarkOn : brushBookmarkOff;
        }

        private void OnButtonClick(object sender, NotificationEvent e)
        {
            if (e.Command == "WP1")
            {
                StartBookmark(e, 0);
                return;
            }

            if (e.Command == "WP2")
            {
                StartBookmark(e, 1);
                return;
            }

            if (e.Command == "WP3")
            {
                StartBookmark(e,2);
                return;
            }

            if (e.Command == "WP4")
            {
                StartBookmark(e, 3);
                return;
            }


            if (e.Command == "WP5")
            {
                StartBookmark(e, 4);
                return;
            }
        }

        private void StartBookmark(NotificationEvent e, int idx)
        {
            NodeCursorEventArgs cursor = e.Tag as NodeCursorEventArgs;
            // Set if either empty or right-click
            if (GameUI.Bookmarks[idx] == null || (cursor != null && cursor.Button == UI.GameUI.MouseButtons.Right))
            {
                // Set it from current
                GameUI.Bookmarks[idx] = GameUI.MakeBookmark();
            }
            else
            {
                // Already set, reset the game to this
                GameUI.Reset(GameUI.Bookmarks[idx]);
            }
        }

        private void OnButtonMouseOver(object sender, NotificationEvent e)
        {
            if (sender == b1 && GameUI.Bookmarks[0] != null)
            {
                ShowMouseOverImage(0, b1);
                return;
            }

            if (sender == b2 && GameUI.Bookmarks[1] != null)
            {
                ShowMouseOverImage(1, b2);
                return;
            }

            if (sender == b3 && GameUI.Bookmarks[2] != null)
            {
                ShowMouseOverImage(2, b3);
                return;
            }

            if (sender == b4 && GameUI.Bookmarks[3] != null)
            {
                ShowMouseOverImage(3, b4);
                return;
            }

            if (sender == b5 && GameUI.Bookmarks[4] != null)
            {
                ShowMouseOverImage(4, b5);
                return;
            }
        }

        private void ShowMouseOverImage(int idx, NodeUIButton button)
        {
            if (mouseOverImage != null && !mouseOverImage.IsRemoved  && idx != currentMouseOver)
            {
                mouseOverImage.Remove();
            }

            SokobanMap map = GameUI.Bookmarks[idx].Current;
            if (mouseOverImage == null || mouseOverImage.IsRemoved)
            {
                mouseOverImage = new NodeEffectImage(GameUI, Depth + 1, staticImageRender.Draw(map));
                mouseOverImage.CurrentAbsolute = button.CurrentAbsolute.Add(60, 0);
                mouseOverImage.Path = new StaticPath(mouseOverImage.CurrentAbsolute, 40);
                GameUI.Add(mouseOverImage);
                currentMouseOver = idx;
            }
        }

        private NodeEffectImage mouseOverImage;
        private int currentMouseOver;

        private StaticImage staticImageRender;
        private NodeUIButton b1, b2, b3, b4, b5;
        private Brush brushBookmarkOn;
        private Brush brushBookmarkOff;
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.