Пример #1
0
        public void HandleInput()
        {
            int pressedBox = -1;

            if (Input.OrthoMouseX <OrthoRenderEngine.GetCanvasWidth() - overscan& Input.OrthoMouseX> OrthoRenderEngine.GetCanvasWidth() - iconSize - overscan &
                Input.OrthoMouseY <OrthoRenderEngine.GetCanvasHeight() - overscan& Input.OrthoMouseY> OrthoRenderEngine.GetCanvasHeight() - iconSize * SIZE - overscan)
            {
                hoveredBox = (int)((OrthoRenderEngine.GetCanvasHeight() - Input.OrthoMouseY - overscan) / iconSize);
            }
            else
            {
                hoveredBox = -1;
            }

            if (Input.PressedItemKey != -1)
            {
                pressedBox = Input.PressedItemKey;
            }
            else if (Input.MousePressed && hoveredBox > -1)
            {
                pressedBox = hoveredBox;
            }

            int usedBox = pressedBox == -1 ? hoveredBox : pressedBox;

            if (usedBox == -1)
            {
                hoveredItem = -1;
                return;
            }

            uint box   = 0;
            int  index = 0;

            for (; index < GetItemAmount(); index++)
            {
                box += GetItem(index).GetSize();
                if (box > usedBox)
                {
                    break;
                }
            }
            int usedItem = (index < GetItemAmount()) ? index : -1;

            if (pressedBox != -1)
            {
                if (selectedItem == usedItem)
                {
                    selectedItem = -1;
                }
                else
                {
                    selectedItem = usedItem;
                }
            }
            else
            {
                hoveredItem = usedItem;
            }
        }
Пример #2
0
        public void RenderView(Matrix4 VP, Scene s)
        {
            if (PrevView != null)
            {
                PrevView.RenderView(VP, s);
            }
            OrthoRenderEngine.DrawColorOnEntireScreen(gradiantColor);
            OrthoRenderEngine.DrawColoredBox(Vector4.UnitW, barXPos, 0, barWidth, OrthoRenderEngine.GetCanvasHeight());
            float maxY = OrthoRenderEngine.GetCanvasHeight() * 0.55f;
            float x    = Input.OrthoMouseX - barXPos;
            float y    = maxY + optionHeight - Input.OrthoMouseY;

            if (x > 0 & x < barWidth & y > 0 & y < writers.Length * optionHeight)
            {
                hovering = (int)y / optionHeight;
            }
            else
            {
                hovering = -1;
            }
            for (int i = 0; i < writers.Length; i++)
            {
                OrthoRenderEngine.DrawColoredTexturedBox(hovering == i ? Util.White : Util.White60, writers[i].GetTextureID(), barXPos, maxY - optionHeight * i, writers[i].Width, writers[i].Height);
            }
        }
Пример #3
0
        public void Render(Smith2DGame game)
        {
            var cW = OrthoRenderEngine.GetCanvasWidth();
            var cH = OrthoRenderEngine.GetCanvasHeight();

            uint l = 0;

            for (int i = 0; i < GetItemAmount(); i++)
            {
                Item item = GetItem(i);

                Vector4 boxColor = i == selectedItem ? selected : Util.White;

                OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * (l + 0.5f) - overscan, iconSize, iconSize / 2, 0, 0, 1, 0.5f);
                OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Numbers, cW - iconSize - overscan + 2, cH - iconSize * l - overscan - 12, 10, 10, l / 4f, 0, 0.25f, 1);
                uint oldL = l;
                for (l++; l < oldL + item.GetSize(); l++)
                {
                    OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * l - overscan, iconSize, iconSize / 2, 0, 0.25f, 1, 0.5f);
                    OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * (l + 0.5f) - overscan, iconSize, iconSize / 2, 0, 0.25f, 1, 0.5f);
                }
                OrthoRenderEngine.DrawColoredTexturedBox(boxColor, TextureCollection.Button, cW - iconSize - overscan, cH - iconSize * l - overscan, iconSize, iconSize / 2, 0, 0.5f, 1, 0.5f);
                float bob = i == selectedItem ? (float)Math.Sin(Time.CurrentTime() * 5) * 4 + 2 : 0;
                item.RenderItem(cW - iconSize - overscan - bob, cH - iconSize * l - overscan - bob, iconSize + bob * 2, iconSize * item.GetSize() + bob * 2);
            }

            for (uint i = l; i < Inventory.SIZE; i++)
            {
                OrthoRenderEngine.DrawTexturedBox(TextureCollection.Button, cW - iconSize - 20, cH - iconSize * (i + 1) - 20, iconSize, iconSize, 0, 0, 1, 1);
                OrthoRenderEngine.DrawTexturedBox(TextureCollection.Numbers, cW - iconSize - 20 + 2, cH - iconSize * i - 20 - 12, 10, 10, i / 4f, 0, 0.25f, 1);
            }

            if (hoveredItem > -1 & hoveredItem < items.Count && items [hoveredItem] != null)
            {
                game.TooltipHelper.ClaimIfPossible(this);
                if (game.TooltipHelper.GetOwner() == this)
                {
                    game.TooltipHelper.RenderItemTooltip(items [hoveredItem], OrthoRenderEngine.GetCanvasWidth() - overscan - iconSize - 32, Input.OrthoMouseY);
                }
            }
            else if (game.TooltipHelper.GetOwner() == this)
            {
                game.TooltipHelper.UnClaim();
            }

            if (tooFull)
            {
                game.ErrortipHelper.ShowError(Localization.GetLocalization("ui.error.inventoryfull"), OrthoRenderEngine.GetCanvasWidth() - overscan, OrthoRenderEngine.GetCanvasHeight() - overscan - iconSize * SIZE - 32 - 30, 1.5f, true);
                tooFull = false;
            }
        }
Пример #4
0
        public static void AddToWindow(GameWindow window)
        {
            window.KeyDown += (sender, e) => {
                if (e.IsRepeat)
                {
                    return;
                }

                switch (e.Key)
                {
                case CLOSEKEY:
                    closeKeyBuffered = true;
                    break;

                case LEFTKEY:
                    LeftKey = true;
                    break;

                case RIGHTKEY:
                    RightKey = true;
                    break;

                case UPKEY:
                    UpKey         = true;
                    upKeyBuffered = true;
                    break;

                case DOWNKEY:
                    DownKey         = true;
                    downKeyBuffered = true;
                    break;

                case INTERACTKEY:
                    interactKeyBuffered = true;
                    break;

                case POURKEY:
                    pourKeyBuffered = true;
                    break;
                }

                for (int i = 0; i < ITEMKEYS.Length; i++)
                {
                    if (e.Key == ITEMKEYS[i])
                    {
                        bufferedItemKey = i;
                        break;
                    }
                }
            };

            window.Keyboard.KeyUp += (sender, e) => {
                switch (e.Key)
                {
                case LEFTKEY:
                    LeftKey = false;
                    break;

                case RIGHTKEY:
                    RightKey = false;
                    break;

                case UPKEY:
                    UpKey = false;
                    break;

                case DOWNKEY:
                    DownKey = false;
                    break;

                default:
                    break;
                }
            };

            window.Mouse.ButtonDown += (sender, e) => {
                if (e.Button == MouseButton.Left)
                {
                    MouseDown          = true;
                    mousePressBuffered = true;
                }
                else if (e.Button == MouseButton.Right)
                {
                    interactKeyBuffered = true;
                }
            };

            window.Mouse.ButtonUp += (sender, e) => {
                if (e.Button == MouseButton.Left)
                {
                    MouseDown = false;
                }
            };

            window.Mouse.Move += (sender, e) => {
                RelativeMouseX = e.X * 2f / window.Width - 1;
                RelativeMouseY = e.Y * 2f / window.Height - 1;
                OrthoMouseX    = (float)e.X / window.Width * OrthoRenderEngine.GetCanvasWidth();
                OrthoMouseY    = (1 - (float)e.Y / window.Height) * OrthoRenderEngine.GetCanvasHeight();
            };
        }
Пример #5
0
        public void UpdateView(Scene s)
        {
            transition.UpdateTransition(Time.Delta() * 2);

            if (Input.CloseKeyPressed)
            {
                OnAnvilNotUsed();
                game.SetView(parentView);
                return;
            }
            if (Input.InteractKeyPressed | Input.MousePressed & Input.OrthoMouseX > 50 & Input.OrthoMouseX < 300 & Input.OrthoMouseY > 50 & Input.OrthoMouseY < 300)
            {
                game.SetView(table);
                table.OnTableUsed(heat, blade);
                OnAnvilNotUsed();
                return;
            }

            for (int i = 0; i < heat.Length; i++)
            {
                if (heat[i] > 25)
                {
                    heat [i] -= Time.Delta() * (i == diamond? 100 : 200);
                }
            }

            if (!hammerDown && Input.MousePressed & hammerMove <0.3f& Input.OrthoMouseX> OrthoRenderEngine.GetCanvasWidth() / 2 - 100 & Input.OrthoMouseX <OrthoRenderEngine.GetCanvasWidth() / 2 + 100 &
                                                                                                                                                           Input.OrthoMouseY> OrthoRenderEngine.GetCanvasHeight() / 2 - 70 & Input.OrthoMouseY < OrthoRenderEngine.GetCanvasHeight() / 2 + 70)
            {
                hammerDown = true;
                hammerX    = Util.NextFloat() - 0.5f;
                hammerY    = Util.NextFloat() - 0.5f;
            }

            if (hammerDown)
            {
                if (hammerMove < 1)
                {
                    hammerMove += Time.Delta() * 10;
                    if (hammerMove >= 1)
                    {
                        hammerDown = false;
                        hammerMove = 1;
                        if (diamond >= 0)
                        {
                            blade.Sharpness [diamond] = Math.Min(1, blade.Sharpness [diamond] + KnownMetal.GetRedEmmission(blade.Metal, heat[diamond]) * 0.01f * (1 - blade.Sharpness [diamond]));
                            blade.UpdateSharpnessMap();
                        }
                    }
                }
            }
            else if (hammerMove > 0)
            {
                hammerMove = Math.Max(0, hammerMove - Time.Delta() * 4);
            }

            if (Input.LeftKey)
            {
                panAngle -= (panAngle + 0.6f) * Time.Delta() * 3;
            }
            else if (Input.RightKey)
            {
                panAngle -= (panAngle - 0.6f) * Time.Delta() * 3;
            }
            else
            {
                panAngle -= panAngle * Time.Delta() * 3;
            }

            if (Input.DownKey)
            {
                panAngleY -= (panAngleY + 0.3f) * Time.Delta() * 3;
            }
            else if (Input.UpKey)
            {
                panAngleY -= (panAngleY - 0.28f) * Time.Delta() * 3;
            }
            else
            {
                panAngleY -= panAngleY * Time.Delta() * 3;
            }
        }