示例#1
0
        public override bool OnMouse(int button, int state, int x, int y)
        {
            if (button == Glut.GLUT_LEFT_BUTTON && (state == Glut.GLUT_DOWN || state == Glut.GLUT_UP))
            {
//                MouseWorld = RenderLayerGame.ConvertScreenToWorldCoordsNoDepth(x, y, Camera.ViewMatrix, projectionMatrix, Vector3.Zero);
                MouseWorld = RenderLayerGame.ConvertScreenToWorldCoordsNoDepth(x, y, Matrix4.Identity, projectionMatrix,
                                                                               Vector3.Zero, TheRenderStatus);

                foreach (ObjHudPanel aHudObject in theHudPanels)
                {
                    ObjObject tempObj = aHudObject.IsOn((int)MouseWorld.x, (int)MouseWorld.y);
                    if (tempObj != null)
                    {
                        if (tempObj is ObjHudButton)
                        {
                            Tile.TileIds tempTileId;
                            string       tempTileIdName = (string)((ObjHudButton)tempObj).Tag;
                            if (Tile.TileIds.TryParse(tempTileIdName, true, out tempTileId))
                            {
                                selectedTileId = tempTileId;
                                selectedObjHudButton.Material = TheResourceManager.Get("Tile_" + tempTileIdName);
                            }
                        }

                        GameCore.TheGameCore.RaiseMessage("Mouse: [" + x + "," + y + "] on HUD: " + tempObj + ".");
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#2
0
        public override void OnLoad()
        {
            GameCore.TheGameCore.TheGameEventHandler += TheGameCore_TheGameEventHandler;

            hudProgram = new ShaderProgram(VertexShader, FragmentShader);
//            hudProgram = new ShaderProgram(vertexShader2Source, fragmentShader2Source);

            hudProgram.Use();
            projectionMatrix = Matrix4.CreateOrthographic(Width, Height, 0, 10);
            hudProgram["projection_matrix"].SetValue(projectionMatrix);
            hudProgram["model_matrix"].SetValue(Matrix4.Identity);


            Dictionary <Tile.TileIds, PlainBmpTexture> tempTiletypeList =
                RenderObjects.RenderObjects.CreateTileTextures(new Size(20, 20), hudProgram);

            ObjHudPanel hudPanel = CreateHudPanel("HudPanelCreative.png",
                                                  ObjHudPanel.Anchors.TopRight);

            theHudPanels.Add(hudPanel);


            Size tempButtonSize = new Size(60, 60);

            Tile.TileIds tempTileKey      = tempTiletypeList.Keys.First();
            Vector2      tempMainButton   = new Vector2(70, 100);
            ObjHudButton tempObjHudButton =
                new ObjHudButton(ObjectPrimitives.CreateSquareWithNormalsYorZ(new Vector3(0, 0, 0),
                                                                              new Vector3(
                                                                                  tempButtonSize.Width,
                                                                                  tempButtonSize.Height, 0),
                                                                              true))
            {
                Anchor   = ObjHudButton.Anchors.TopRight,
                Position = tempMainButton,
                Size     = tempButtonSize
            };

            tempObjHudButton.Size = tempButtonSize;
            tempObjHudButton.UpdatePosition(Width, Height);
            tempObjHudButton.Material = tempTiletypeList[tempTileKey].Material;
            tempObjHudButton.Name    += ":" + tempTileKey;
            hudPanel.AddButton(tempObjHudButton);
            selectedObjHudButton = tempObjHudButton;


            int     counter     = 0;
            int     cellsPerRow = 2;
            Vector2 startLoc    = new Vector2(120, 200);
            int     rowOffset   = 100;

            foreach (KeyValuePair <Tile.TileIds, PlainBmpTexture> tempTile in tempTiletypeList)
            {
                int     row     = counter % cellsPerRow;
                int     col     = counter / cellsPerRow;
                Vector2 tempLoc = startLoc + new Vector2(-row * rowOffset, col * rowOffset);

                tempObjHudButton = new ObjHudButton(ObjectPrimitives.CreateSquareWithNormalsYorZ(new Vector3(0, 0, 0),
                                                                                                 new Vector3(
                                                                                                     tempButtonSize.Width,
                                                                                                     tempButtonSize.Height, 0),
                                                                                                 true))
                {
                    Anchor   = ObjHudButton.Anchors.TopRight,
                    Position = tempLoc,
                    Size     = tempButtonSize
                };
                tempObjHudButton.Size = tempButtonSize;
                tempObjHudButton.UpdatePosition(Width, Height);
                tempObjHudButton.Material = tempTiletypeList[tempTile.Key].Material;
                tempObjHudButton.Name    += ":" + tempTile.Key;
                tempObjHudButton.Tag      = tempTile.Key.ToString();
                hudPanel.AddButton(tempObjHudButton);

                counter++;
            }
        }