/// <summary>
        /// Gets the action based on a window key combination
        /// </summary>
        /// <param name="wWindow">The window id.</param>
        /// <param name="key">The key.</param>
        /// <returns>The action if it is found in the map, 0 if not.</returns>
        private static int GetActionCode(int wWindow, Key key, out string strSoundFile)
        {
            strSoundFile = "";
            if (key == null)
            {
                return(0);
            }
            for (int iw = 0; iw < mapWindows.Count; ++iw)
            {
                WindowMap window = (WindowMap)mapWindows[iw];
                if (window.iWindow == wWindow)
                {
                    for (int ib = 0; ib < window.mapButtons.Count; ib++)
                    {
                        button but = (button)window.mapButtons[ib];

                        if (but.eKeyChar == key.KeyChar && key.KeyChar > 0)
                        {
                            strSoundFile = but.m_strSoundFile;
                            return((int)but.eAction);
                        }
                        if (but.eKeyCode == key.KeyCode && key.KeyCode > 0)
                        {
                            strSoundFile = but.m_strSoundFile;
                            return((int)but.eAction);
                        }
                    }
                    return(0);
                }
            }
            return(0);
        }
        /// <summary>
        /// Update action with soundfilename based on a window id and action id
        /// </summary>
        /// <param name="wWindow">The window id.</param>
        /// <param name="action">The action</param>
        /// <returns>True if it is found in the map, fales if not.</returns>
        public static bool GetActionDetail(int wWindow, Action action)
        {
            if (action.wID == 0)
            {
                return(false);
            }
            for (int iw = 0; iw < mapWindows.Count; ++iw)
            {
                WindowMap window = (WindowMap)mapWindows[iw];
                if (window.iWindow == wWindow)
                {
                    for (int ib = 0; ib < window.mapButtons.Count; ib++)
                    {
                        button but = (button)window.mapButtons[ib];

                        if (but.eAction == (Action.ActionType)action.wID)
                        {
                            action.SoundFileName = but.m_strSoundFile;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Loads a supplementary keymap file and adds it to the map previously built from keymap.xml
        /// </summary>
        /// <returns>True if the load was successfull, false if it failed.</returns>
        public static bool Load(string strFilename)
        {
            //mapWindows.Clear();
            //string strFilename = Config.GetFile(Config.Dir.Config, "keymap.xml");
            Log.Info("  Load supplementary key mapping from {0}", strFilename);
            try
            {
                // Load the XML file
                XmlDocument doc = new XmlDocument();
                doc.Load(strFilename);
                // Check if it is a keymap
                if (doc.DocumentElement == null)
                {
                    return(false);
                }
                string strRoot = doc.DocumentElement.Name;
                if (strRoot != "keymap")
                {
                    return(false);
                }

                // Create a new windowmap
                WindowMap map;

                // For each window
                XmlNodeList listWindows = doc.DocumentElement.SelectNodes("/keymap/window");
                foreach (XmlNode nodeWindow in listWindows)
                {
                    XmlNode nodeWindowId = nodeWindow.SelectSingleNodeFast("id");
                    if (null != nodeWindowId)
                    {
                        map         = new WindowMap();
                        map.iWindow = Int32.Parse(nodeWindowId.InnerText);
                        XmlNodeList listNodes = nodeWindow.SelectNodes("action");
                        // Create a list of key/actiontype mappings
                        foreach (XmlNode node in listNodes)
                        {
                            XmlNode nodeId      = node.SelectSingleNodeFast("id");
                            XmlNode nodeGamepad = node.SelectSingleNodeFast("key");
                            XmlNode nodeSound   = node.SelectSingleNodeFast("sound");
                            MapAction(ref map, nodeId, nodeGamepad, nodeSound);
                        }
                        if (map.mapButtons.Count > 0)
                        {
                            mapWindows.Add(map);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Warn("exception loading supplementary keymap {0} err:{1} stack:{2}", strFilename, ex.Message, ex.StackTrace);
            }
            return(false);
        }
Example #4
0
    private void constructorSetupWindow(WindowMap _windowMap, SimpleRange startDisRange, int startX, int startZ)
    {
        this.m_windowMap = _windowMap;
        Trapezoid atrapezoid = new Trapezoid(startDisRange, startZ);

        this.lightLevelTrapezoid = new LightLevelTrapezoid(TrapLight.MediumLightQuad(), atrapezoid);

//		this.heights.Add(startDisRange);

        this.xLevel = startX;
    }
Example #5
0
//	public List<Window> windowsAdjacentToWindowEitherSide(Window window)
//	{
//		List<Window> xNegWindows = windowsXNegAdjacentToWindow(window);
//		List<Window> xPosWindows = windowsXPosAdjacentToWindow(window);
//		xNegWindows.AddRange(xPosWindows);
//		return xNegWindows;
//	}
//
//	public List<Window> windowsXPosAdjacentToWindow(Window window)
//	{
//		return windowsAdjacentToWindow(window, true);
//	}
//
//	public List<Window> windowsXNegAdjacentToWindow(Window window)
//	{
//		return windowsAdjacentToWindow(window, false);
//	}
//
//	private List<Window> windowsAdjacentToWindow(Window window, bool wantXPos)
//	{
//		return null;
//	}

//	public List<Window> windowsAdjacentToStartOfWindow(Window window)
//	{
//		return windowsAdjacentToEndWindow(window, false);
//	}
//
//	public List<Window> windowsAdjacentToExtentOfWindow(Window window)
//	{
//		return windowsAdjacentToEndWindow(window, true);
//	}
//
//	private List<Window> windowsAdjacentToEndWindow(Window window, bool wantExtent)
//	{
//		return null;
//	}

    #endregion

    #region talk to other windows

    /*
     * 'introduce' (share data with) windows from neighbor noise patches
     *
     */

    public void introduceFlushWindowsWithWindowInNeighborDirection(WindowMap other, NeighborDirection ndir)
    {
        return;

        Direction dir = NeighborDirectionUtils.DirecionFourForNeighborDirection(ndir);

        Axis axis = DirectionUtil.AxisForDirection(dir);

        if (axis == Axis.X)
        {
            introduceFlushWithWindowMapInNeighborDirectionX(other, ndir);
            return;
        }

        introduceFlushWithWindowMapInNeighborDirectionZ(other, ndir);
    }
Example #6
0
    public Window(WindowMap _windowMap, SimpleRange startDisRange, int startX, int startZ)
    {
//		this.m_windowMap = _windowMap;
//		Trapezoid atrapezoid = new Trapezoid(startDisRange, startZ);
//		this.lightLevelTrapezoid = new LightLevelTrapezoid(TrapLight.MediumLightQuad(), atrapezoid);
//
//		heights.Add(startDisRange);
//
//		xLevel = startX;

        this.constructorSetupWindow(_windowMap, startDisRange, startX, startZ);
        // TODO: make a new class that inventories the locations of discontinuities
        // probably 2 lists of height/span offset values
        // plus 2 height values on either end.

        checkAdjacentToSurfaceFourDirectionsAt(0);
    }
Example #7
0
    /*
     * Z introductions
     *
     * */
    private void introduceFlushWithWindowMapInNeighborDirectionZ(WindowMap other, NeighborDirection ndir)
    {
        Direction dir    = NeighborDirectionUtils.DirecionFourForNeighborDirection(ndir);
        Direction oppDir = NeighborDirectionUtils.DirecionFourForNeighborDirection(NeighborDirectionUtils.oppositeNeighborDirection(ndir));

        //want windows flush with a given z value (0 or max)
        List <Window>[] thisWinListArrayAtEdge      = this.windowsTouchingEdgeOfNoisePatchNeighborInDirection(dir);
        List <Window>[] winListArrayAtAnEdgeOfOther = other.windowsTouchingEdgeOfNoisePatchNeighborInDirection(oppDir);

        AssertUtil.Assert(thisWinListArrayAtEdge.Length == winListArrayAtAnEdgeOfOther.Length, "confusing. and not what we expected. lists should be the same length");

        bool wantExtentForThis = DirectionUtil.IsPosDirection(dir);

//		this.testSetAllMaxLight(); //TEST
//		other.testSetAllMaxLight();
//
//		return;

        for (int i = 0; i < thisWinListArrayAtEdge.Length; ++i)
        {
            List <Window> wins = thisWinListArrayAtEdge[i];
            foreach (Window win in wins)
            {
                //TEST
//				win.testSetMaxLight(null);
                win.updateWithWindowsFlushWithAnEdge(winListArrayAtAnEdgeOfOther[i], wantExtentForThis);
            }
        }

        for (int i = 0; i < winListArrayAtAnEdgeOfOther.Length; ++i)
        {
            List <Window> wins = winListArrayAtAnEdgeOfOther[i];
            foreach (Window win in wins)
            {
                //TEST
//				win.testSetMaxLight(null);
                win.updateWithWindowsFlushWithAnEdge(thisWinListArrayAtEdge[i], !wantExtentForThis);
            }
        }
    }
Example #8
0
    /*
     * X AXIS NEIGHBOR INTRODUCTIONS
     *
     */
    private void introduceFlushWithWindowMapInNeighborDirectionX(WindowMap other, NeighborDirection ndir)
    {
        return;         // !!!!

        Direction dir    = NeighborDirectionUtils.DirecionFourForNeighborDirection(ndir);
        Direction oppDir = NeighborDirectionUtils.DirecionFourForNeighborDirection(NeighborDirectionUtils.oppositeNeighborDirection(ndir));

        //want windows along a z on a given x val (0 or max)
        List <Window>[] thisWinListArrayAtEdge      = this.windowsTouchingEdgeOfNoisePatchNeighborInDirection(dir);
        List <Window>[] winListArrayAtAnEdgeOfOther = other.windowsTouchingEdgeOfNoisePatchNeighborInDirection(oppDir);

        if (thisWinListArrayAtEdge.Length == 0 || winListArrayAtAnEdgeOfOther.Length == 0)
        {
            AssertUtil.Assert(false, "??? 0 length arrays");
            return;
        }

        AssertUtil.Assert(thisWinListArrayAtEdge.Length == 1 && winListArrayAtAnEdgeOfOther.Length == 1, "Confusing. dealing with x edge right? length was: " + thisWinListArrayAtEdge.Length);

        foreach (Window win in thisWinListArrayAtEdge[0])        // when world was flat this was null!
        {
//			win.testSetAllValuesTo(4f);
            //TEST
            win.setMaxLight();
//			win.updateWithAdjacentWindowsReturnAddedLightRating(winListArrayAtAnEdgeOfOther[0]);
        }


        foreach (Window othersWin in winListArrayAtAnEdgeOfOther[0])
        {
//			othersWin.testSetAllValuesTo(4f);
            othersWin.setMaxLight();             //TEST

//			othersWin.updateWithAdjacentWindowsReturnAddedLightRating(thisWinListArrayAtEdge[0]);
        }
    }
 /// <summary>
 /// Loads the keymap file and creates the mapping.
 /// </summary>
 /// <returns>True if the load was successfull, false if it failed.</returns>
 public static bool Load()
 {
   mapWindows.Clear();
   string strFilename = Config.GetFile(Config.Dir.Config, "keymap.xml");
   Log.Info("  Load key mapping from {0}", strFilename);
   try
   {
     // Load the XML file
     XmlDocument doc = new XmlDocument();
     doc.Load(strFilename);
     // Check if it is a keymap
     if (doc.DocumentElement == null)
     {
       return false;
     }
     string strRoot = doc.DocumentElement.Name;
     if (strRoot != "keymap")
     {
       return false;
     }
     // Create a new windowmap and fill it with the global actions
     WindowMap map = new WindowMap();
     map.iWindow = -1;
     XmlNodeList list = doc.DocumentElement.SelectNodes("/keymap/global/action");
     foreach (XmlNode node in list)
     {
       XmlNode nodeId = node.SelectSingleNodeFast("id");
       XmlNode nodeGamepad = node.SelectSingleNodeFast("key");
       XmlNode nodeSound = node.SelectSingleNodeFast("sound");
       MapAction(ref map, nodeId, nodeGamepad, nodeSound);
     }
     if (map.mapButtons.Count > 0)
     {
       mapWindows.Add(map);
     }
     // For each window
     XmlNodeList listWindows = doc.DocumentElement.SelectNodes("/keymap/window");
     foreach (XmlNode nodeWindow in listWindows)
     {
       XmlNode nodeWindowId = nodeWindow.SelectSingleNodeFast("id");
       if (null != nodeWindowId)
       {
         map = new WindowMap();
         map.iWindow = Int32.Parse(nodeWindowId.InnerText);
         XmlNodeList listNodes = nodeWindow.SelectNodes("action");
         // Create a list of key/actiontype mappings
         foreach (XmlNode node in listNodes)
         {
           XmlNode nodeId = node.SelectSingleNodeFast("id");
           XmlNode nodeGamepad = node.SelectSingleNodeFast("key");
           XmlNode nodeSound = node.SelectSingleNodeFast("sound");
           MapAction(ref map, nodeId, nodeGamepad, nodeSound);
         }
         if (map.mapButtons.Count > 0)
         {
           mapWindows.Add(map);
         }
       }
     }
   }
   catch (Exception ex)
   {
     Log.Warn("exception loading keymap {0} err:{1} stack:{2}", strFilename, ex.Message, ex.StackTrace);
   }
   return false;
 }
    /// <summary>
    /// Map an action in a windowmap based on the id and key xml nodes. 
    /// </summary>
    /// <param name="map">The windowmap that needs to be filled in.</param>
    /// <param name="nodeId">The id of the action</param>
    /// <param name="nodeGamepad">The key corresponding to the mapping.</param>
    private static void MapAction(ref WindowMap map, XmlNode nodeId, XmlNode nodeGamepad, XmlNode nodeSound)
    {
      if (null == nodeId)
      {
        return;
      }
      button but = new button();
      but.eAction = (Action.ActionType)Int32.Parse(nodeId.InnerText);
      but.m_strSoundFile = "";

      if (nodeSound != null && nodeSound.InnerText != null)
      {
        but.m_strSoundFile = nodeSound.InnerText;
      }

      if (nodeGamepad != null)
      {
        string strButton = nodeGamepad.InnerText.ToLower();
        if (strButton.Length == 1)
        {
          but.eKeyChar = (int)strButton[0];
          but.eKeyCode = 0;
        }
        else
        {
          but.eKeyChar = 0;
          strButton = strButton.ToLower();

          switch (strButton)
          {
            case "f1":
              but.eKeyCode = (int)Keys.F1;
              break;
            case "f2":
              but.eKeyCode = (int)Keys.F2;
              break;
            case "f3":
              but.eKeyCode = (int)Keys.F3;
              break;
            case "f4":
              but.eKeyCode = (int)Keys.F4;
              break;
            case "f5":
              but.eKeyCode = (int)Keys.F5;
              break;
            case "f6":
              but.eKeyCode = (int)Keys.F6;
              break;
            case "f7":
              but.eKeyCode = (int)Keys.F7;
              break;
            case "f8":
              but.eKeyCode = (int)Keys.F8;
              break;
            case "f9":
              but.eKeyCode = (int)Keys.F9;
              break;
            case "f10":
              but.eKeyCode = (int)Keys.F10;
              break;
            case "f11":
              but.eKeyCode = (int)Keys.F11;
              break;
            case "f12":
              but.eKeyCode = (int)Keys.F12;
              break;
            case "backspace":
              but.eKeyCode = (int)Keys.Back;
              break;
            case "tab":
              but.eKeyCode = (int)Keys.Tab;
              break;
            case "end":
              but.eKeyCode = (int)Keys.End;
              break;
            case "insert":
              but.eKeyCode = (int)Keys.Insert;
              break;
            case "home":
              but.eKeyCode = (int)Keys.Home;
              break;
            case "pageup":
              but.eKeyCode = (int)Keys.PageUp;
              break;
            case "pagedown":
              but.eKeyCode = (int)Keys.PageDown;
              break;
            case "left":
              but.eKeyCode = (int)Keys.Left;
              break;
            case "right":
              but.eKeyCode = (int)Keys.Right;
              break;
            case "up":
              but.eKeyCode = (int)Keys.Up;
              break;
            case "down":
              but.eKeyCode = (int)Keys.Down;
              break;
            case "enter":
              but.eKeyCode = (int)Keys.Enter;
              break;
            case "delete":
              but.eKeyCode = (int)Keys.Delete;
              break;
            case "pause":
              but.eKeyCode = (int)Keys.Pause;
              break;
            case "print":
              but.eKeyCode = (int)Keys.PrintScreen;
              break;
            case "escape":
              but.eKeyCode = (int)Keys.Escape;
              break;
            case "esc":
              but.eKeyCode = (int)Keys.Escape;
              break;
            case "apps":
              but.eKeyCode = (int)Keys.Apps;
              break;
            case "win":
              but.eKeyCode = (int)Keys.LWin;
              break;
            case "space":
              but.eKeyCode = 0;
              but.eKeyChar = 32;
              break;
          }
        }
      }

      map.mapButtons.Add(but);
    }
Example #11
0
 public Window(WindowMap _windowMap, SimpleRange startDisRange, int startX, int startZ, bool noSurfaceCheck)
 {
     this.constructorSetupWindow(_windowMap, startDisRange, startX, startZ);
 }
        /// <summary>
        /// Map an action in a windowmap based on the id and key xml nodes.
        /// </summary>
        /// <param name="map">The windowmap that needs to be filled in.</param>
        /// <param name="nodeId">The id of the action</param>
        /// <param name="nodeGamepad">The key corresponding to the mapping.</param>
        private static void MapAction(ref WindowMap map, XmlNode nodeId, XmlNode nodeGamepad, XmlNode nodeSound)
        {
            if (null == nodeId)
            {
                return;
            }
            button but = new button();

            but.eAction        = (Action.ActionType)Int32.Parse(nodeId.InnerText);
            but.m_strSoundFile = "";

            if (nodeSound != null && nodeSound.InnerText != null)
            {
                but.m_strSoundFile = nodeSound.InnerText;
            }

            if (nodeGamepad != null)
            {
                string strButton = nodeGamepad.InnerText.ToLower();
                if (strButton.Length == 1)
                {
                    but.eKeyChar = (int)strButton[0];
                    but.eKeyCode = 0;
                }
                else
                {
                    but.eKeyChar = 0;
                    strButton    = strButton.ToLower();

                    switch (strButton)
                    {
                    case "f1":
                        but.eKeyCode = (int)Keys.F1;
                        break;

                    case "f2":
                        but.eKeyCode = (int)Keys.F2;
                        break;

                    case "f3":
                        but.eKeyCode = (int)Keys.F3;
                        break;

                    case "f4":
                        but.eKeyCode = (int)Keys.F4;
                        break;

                    case "f5":
                        but.eKeyCode = (int)Keys.F5;
                        break;

                    case "f6":
                        but.eKeyCode = (int)Keys.F6;
                        break;

                    case "f7":
                        but.eKeyCode = (int)Keys.F7;
                        break;

                    case "f8":
                        but.eKeyCode = (int)Keys.F8;
                        break;

                    case "f9":
                        but.eKeyCode = (int)Keys.F9;
                        break;

                    case "f10":
                        but.eKeyCode = (int)Keys.F10;
                        break;

                    case "f11":
                        but.eKeyCode = (int)Keys.F11;
                        break;

                    case "f12":
                        but.eKeyCode = (int)Keys.F12;
                        break;

                    case "backspace":
                        but.eKeyCode = (int)Keys.Back;
                        break;

                    case "tab":
                        but.eKeyCode = (int)Keys.Tab;
                        break;

                    case "end":
                        but.eKeyCode = (int)Keys.End;
                        break;

                    case "insert":
                        but.eKeyCode = (int)Keys.Insert;
                        break;

                    case "home":
                        but.eKeyCode = (int)Keys.Home;
                        break;

                    case "pageup":
                        but.eKeyCode = (int)Keys.PageUp;
                        break;

                    case "pagedown":
                        but.eKeyCode = (int)Keys.PageDown;
                        break;

                    case "left":
                        but.eKeyCode = (int)Keys.Left;
                        break;

                    case "right":
                        but.eKeyCode = (int)Keys.Right;
                        break;

                    case "up":
                        but.eKeyCode = (int)Keys.Up;
                        break;

                    case "down":
                        but.eKeyCode = (int)Keys.Down;
                        break;

                    case "enter":
                        but.eKeyCode = (int)Keys.Enter;
                        break;

                    case "delete":
                        but.eKeyCode = (int)Keys.Delete;
                        break;

                    case "pause":
                        but.eKeyCode = (int)Keys.Pause;
                        break;

                    case "print":
                        but.eKeyCode = (int)Keys.PrintScreen;
                        break;

                    case "escape":
                        but.eKeyCode = (int)Keys.Escape;
                        break;

                    case "esc":
                        but.eKeyCode = (int)Keys.Escape;
                        break;

                    case "apps":
                        but.eKeyCode = (int)Keys.Apps;
                        break;

                    case "win":
                        but.eKeyCode = (int)Keys.LWin;
                        break;

                    case "space":
                        but.eKeyCode = 0;
                        but.eKeyChar = 32;
                        break;
                    }
                }
            }

            map.mapButtons.Add(but);
        }