Exemplo n.º 1
0
        private static WObject CreateItemRenderer(WObject parent, out Model model, out Label amount)
        {
            WObject itemRenderer = new WObject("Item")
            {
                Parent = parent,
                Layer  = (ulong)Layers.UI,
            };


            model = itemRenderer.AddModule <Model>();
            model.Renderer.Material = ItemCache.AtlasMaterial;
            model.KeepRatio         = true;

            WObject labelRender = new WObject("Amount")
            {
                Parent = itemRenderer,
                Layer  = (ulong)Layers.UI
            };

            amount           = labelRender.AddModule <Label>();
            amount.Text      = "";
            amount.AutoSize  = true;
            amount.Aligns    = TextAligns.Down | TextAligns.Right;
            amount.MinAnchor = new Vector2D(0.05, -0.3);
            amount.MaxAnchor = new Vector2D(1.0, 0.3);

            return(itemRenderer);
        }
Exemplo n.º 2
0
        private void UpdateItem(ContainerItem item, int index)
        {
            Item aitem = item.Item;

            WObject itemRenderer = InventoryItemsRenders[index];
            Model   mod          = null;
            Label   amount       = null;

            if (itemRenderer == null)
            {
            }
            else
            {
                mod    = itemRenderer.GetModule <Model>();
                amount = InventoryItemsAmount[index];
            }

            itemRenderer.LocalRotation = aitem.InventoryRotation;
            itemRenderer.LocalScale    = aitem.InventoryScale;

            if (aitem.Identifier == "winecrash:air")
            {
                mod.Renderer.Mesh = null;
                amount.Text       = "";
            }
            else
            {
                mod.Renderer.Mesh = aitem.Model;
                amount.Text       = item.Amount > 1 ? item.Amount.ToString() : "";
            }



            amount.WObject.Rotation = Quaternion.Identity;
        }
Exemplo n.º 3
0
        private static void CreateMenu()
        {
            MenuWobject    = new WObject("Main Menu");
            MenuCameraWobj = new WObject("Main Menu Camera Wobject")
            {
                Parent = MenuWobject
            };
            Camera MainMenuCamera = MenuCameraWobj.AddModule <Camera>();

            MenuBGWObject        = new WObject("Main Menu Background Object");
            MenuBGWObject.Parent = MenuWobject;
            MainMenuCamera.FOV   = 80.0D;
            MainMenuCamera.WObject.LocalRotation = new Quaternion(25, 0, 0);

            MenuBGWObject.AddModule <MenuBackgroundControler>();

            WObject bgPanel = new WObject("Background Panel")
            {
                Parent = MenuWobject
            };

            bgPanel.Parent = MenuWobject;

            LocalizedLabel lbVersion = bgPanel.AddModule <LocalizedLabel>();

            lbVersion.LocalizationArgs = new object[] { Winecrash.Version };
            lbVersion.Localization     = "#winecrash:ui.mainmenu.gameversion";
            lbVersion.Aligns           = TextAligns.Down | TextAligns.Left;
            lbVersion.AutoSize         = true;
            lbVersion.MinAnchor        = new Vector2F(0.0F, 0.0F);
            lbVersion.MaxAnchor        = new Vector2F(1.0F, 0.05F);
            lbVersion.Color            = Color256.White;
            lbVersion.Left             = 20.0D;

            Label lbCopyright = bgPanel.AddModule <Label>();

            lbCopyright.Text      = "Copyright Arekva 2020\nAll Rights Reserved";
            lbCopyright.Aligns    = TextAligns.Down | TextAligns.Right;
            lbCopyright.AutoSize  = true;
            lbCopyright.MinAnchor = new Vector2F(0.0F, 0.0F);
            lbCopyright.MaxAnchor = new Vector2F(1.0F, 0.1F);
            lbCopyright.Color     = Color256.White;
            lbCopyright.Right     = 20.0D;


            CreateMain();
            CreateOptions();
            CreateMultiplayer();
        }
Exemplo n.º 4
0
        private void UpdateHotbarItem(ContainerItem item, int index)
        {
            Item aitem = item.Item;

            WObject itemRenderer = HotbarItemsRenders[index];
            Model   mod          = null;
            Label   amount       = null;

            if (itemRenderer == null)
            {
                itemRenderer             = HotbarItemsRenders[index] = CreateItemRenderer(Hotbar, out mod, out amount);
                itemRenderer.Name       += " (Hotbar)";
                mod.Depth                = 1000;
                amount.Depth             = 1000;
                HotbarItemsAmount[index] = amount;
            }
            else
            {
                mod    = itemRenderer.GetModule <Model>();
                amount = HotbarItemsAmount[index];
            }

            itemRenderer.LocalRotation = aitem.InventoryRotation;
            itemRenderer.LocalScale    = aitem.InventoryScale;

            if (aitem.Identifier == "winecrash:air")
            {
                mod.Renderer.Mesh = null;
                amount.Text       = "";
            }
            else
            {
                mod.Renderer.Mesh = aitem.Model;
                amount.Text       = item.Amount > 1 ? item.Amount.ToString() : "";
            }


            mod.MinAnchor = _ItemHotbarAnchors[index][0];
            mod.MaxAnchor = _ItemHotbarAnchors[index][1];


            amount.WObject.Rotation = Quaternion.Identity;

            if (index == Player.LocalPlayer.HotbarSelectedIndex)
            {
                UpdateHotbarSelected(item, index);
            }
        }
Exemplo n.º 5
0
        protected override void OnDelete()
        {
            if (Instance == this)
            {
                Instance = null;
            }
            Crosshair?.Delete();
            Crosshair = null;

            HotbarImage = null;
            HotbarSelector?.Delete();
            HotbarSelector = null;

            HotbarImage = null;
            Hotbar?.Delete();
            Hotbar = null;

            Inventory?.Delete();
            Inventory = null;

            GlobalInventoryBackground?.Delete();
            GlobalInventoryBackground = null;

            ItemNameLabel.WObject.Delete();
            ItemNameLabel = null;

            HotbarItemsAmount  = null;
            HotbarItemsRenders = null;

            HoveredTooltipWObject.Delete();
            HoveredTooltipWObject = null;
            HoveredTooltip        = null;

            Player.LocalPlayer.OnHotbarUpdate         -= UpdateHotbarItem;
            Player.LocalPlayer.OnHotbarSelectedChange -= UpdateHotbarSelected;
            Player.LocalPlayer.OnContainerToggle      -= TogglePlayerInventory;
            Player.LocalPlayer.OnContainerClose       -= PlayerCloseInventory;
            Player.LocalPlayer.OnContainerOpen        -= PlayerOpenInventory;
            Player.LocalPlayer.OnItemUpdate           -= UpdateItem;
        }
Exemplo n.º 6
0
        private static void CreateMain()
        {
            WObject mainPanel = MainMenuPanel = new WObject("Main UI Panel")
            {
                Parent = MenuWobject
            };
            Image mainPanelImg = mainPanel.AddModule <Image>();

            mainPanelImg.Color     = new Color256(1.0, 0.0, 1.0, 0.0);
            mainPanelImg.MinAnchor = new Vector2F(0.225F, 0.10F);
            mainPanelImg.MaxAnchor = new Vector2F(0.775F, 0.95F);
            mainPanelImg.MinSize   = new Vector3F(400.0F, 400.0F, Single.PositiveInfinity);
            mainPanelImg.MaxSize   = new Vector3F(800.0F, 800.0F, Single.PositiveInfinity);
            mainPanelImg.KeepRatio = true;

            WObject logo = new WObject("Game Text Logo")
            {
                Parent = mainPanel
            };
            Image logoImage = logo.AddModule <Image>();

            logoImage.Picture   = new Texture("assets/textures/logo.png");
            logoImage.MinAnchor = new Vector2F(0.0F, 0.8F);
            logoImage.MaxAnchor = new Vector2F(1.0F, 1.0F);
            logoImage.KeepRatio = true;

            Label lbTip = mainPanel.AddModule <Label>();

            lbTip.ParentGUI = logoImage;
            lbTip.Text      = "Minecraft";
            lbTip.Color     = new Color256(1.0, 1.0, 0.0, 1.0);
            lbTip.Aligns    = TextAligns.Middle;
            lbTip.AutoSize  = true;
            lbTip.MinAnchor = new Vector2F(0.7F, 0.0F);
            lbTip.MaxAnchor = new Vector2F(1.1F, 0.4F);
            lbTip.Rotation  = -20.0D;


            MenuTip tip = MenuWobject.AddModule <MenuTip>();

            tip.ReferenceLabel = lbTip;
            lbTip.Text         = tip.SelectRandom();


            WObject btnPanel = new WObject("Main UI Button Panel")
            {
                Parent = mainPanel
            };
            Image btnPanelImg = btnPanel.AddModule <Image>();

            btnPanelImg.Color     = new Color256(1.0, 0.0, 1.0, 0.0);
            btnPanelImg.MinAnchor = new Vector2F(0.075F, 0.0F);
            btnPanelImg.MaxAnchor = new Vector2F(0.925F, 0.6F);

            WObject single = new WObject("Singleplayer Button")
            {
                Parent = btnPanel
            };

            GUI.LargeButton btnSingle = single.AddModule <GUI.LargeButton>();
            btnSingle.Button.MinAnchor   = new Vector2F(0.0F, 0.9F);
            btnSingle.Button.MaxAnchor   = new Vector2F(1.0F, 1.0F);
            btnSingle.Label.Localization = "#winecrash:ui.mainmenu.singleplayer";
            btnSingle.Button.Locked      = false;
            //btnSingle.Button.OnClick += () => { Graphics.Window.InvokeUpdate(() => Program.RunGameDebug()); };
            btnSingle.Button.OnClick += () =>
            {
                Game.InvokePartyJoined(PartyType.Singleplayer);
                Task.Run(() =>
                {
                    //Parallel.ForEach()
                    //IntegratedServer server = IntegratedServer.CurrentIntegratedServer = new IntegratedServer(new Player("Arthur"));
                    //server.Run();
                });
            };

            WObject mult = new WObject("Multiplayer Button")
            {
                Parent = btnPanel
            };

            GUI.LargeButton btnMult = mult.AddModule <GUI.LargeButton>();
            btnMult.Button.MinAnchor   = new Vector2F(0.0F, 0.7F);
            btnMult.Button.MaxAnchor   = new Vector2F(1.0F, 0.8F);
            btnMult.Label.Localization = "#winecrash:ui.mainmenu.multiplayer";
            btnMult.Button.Locked      = true;
            btnMult.Button.OnClick    += () =>
            {
                ShowMulti();
            };

            WObject mods = new WObject("Mods Button")
            {
                Parent = btnPanel
            };

            GUI.LargeButton btnMods = mods.AddModule <GUI.LargeButton>();
            btnMods.Button.MinAnchor   = new Vector2F(0.0F, 0.5F);
            btnMods.Button.MaxAnchor   = new Vector2F(1.0F, 0.6F);
            btnMods.Label.Localization = "#winecrash:ui.mainmenu.addons";
            btnMods.Button.Locked      = true;

            WObject options = new WObject("Options Button")
            {
                Parent = btnPanel
            };

            GUI.SmallButton btnOptions = options.AddModule <GUI.SmallButton>();
            btnOptions.Button.MinAnchor   = new Vector2F(0.0F, 0.2F);
            btnOptions.Button.MaxAnchor   = new Vector2F(0.45F, 0.3F);
            btnOptions.Label.Localization = "#winecrash:ui.mainmenu.settings";
            btnOptions.Button.OnClick    += () => ShowOptions();
            btnOptions.Button.Locked      = false;

            WObject quit = new WObject("Quit Button")
            {
                Parent = btnPanel
            };

            GUI.SmallButton btnQuit = quit.AddModule <GUI.SmallButton>();
            btnQuit.Button.MinAnchor   = new Vector2F(0.55F, 0.2F);
            btnQuit.Button.MaxAnchor   = new Vector2F(1.0F, 0.3F);
            btnQuit.Label.Localization = "#winecrash:ui.mainmenu.quit";
            btnQuit.Button.OnClick    += () => Engine.Stop();
        }
Exemplo n.º 7
0
        protected override void Creation()
        {
            if (Instance)
            {
                this.Delete();
                return;
            }

            Instance = this;

            Crosshair = new WObject("Crosshair")
            {
                Parent = Canvas.Main.WObject,
                Layer  = (ulong)Layers.UI
            };
            Image img = Crosshair.AddModule <Image>();

            img.Picture   = new Texture("assets/textures/gui/crosshair.png");
            img.KeepRatio = true;
            img.MinAnchor = new Vector2D(0.49D, 0.49D);
            img.MaxAnchor = new Vector2D(0.51D, 0.51D);
            img.Material.SourceColorBlending = BlendingFactorSrc.OneMinusDstColor;


            Hotbar = new WObject("Hotbar")
            {
                Parent = Canvas.Main.WObject,
                Layer  = (ulong)Layers.UI
            };
            HotbarImage   = img = Hotbar.AddModule <Image>();
            img.Picture   = new Texture("assets/textures/gui/hotbar.png");
            img.KeepRatio = true;
            img.Depth     = 2000;
            img.Renderer.Material.RenderOrder = -10;

            HotbarSelector = new WObject("Hotbar Selector")
            {
                Parent = Hotbar,
                Layer  = (ulong)Layers.UI
            };
            HotbarSelectorImage = img = HotbarSelector.AddModule <Image>();
            img.Picture         = new Texture("assets/textures/gui/hotbar_selector.png");
            img.KeepRatio       = true;
            img.MinAnchor       = new Vector2D(-0.0055D, 0.01D);
            img.MaxAnchor       = new Vector2D(0.1265, 1.0725D);
            img.Depth           = 1999;

            DebugPanel = new WObject("Debug Panel")
            {
                Parent = Canvas.Main.WObject,
                Layer  = (ulong)Layers.UI
            };
            img       = DebugPanel.AddModule <Image>();
            img.Color = Color256.Transparent;

            WObject inamewobj = new WObject("Item Name Display")
            {
                Parent = Canvas.Main.WObject,
                Layer  = (ulong)Layers.UI
            };

            ItemNameLabel           = inamewobj.AddModule <LocalizedLabel>();
            ItemNameLabel.AutoSize  = true;
            ItemNameLabel.MinAnchor = new Vector2D(0.33, 0.15);
            ItemNameLabel.MaxAnchor = new Vector2D(0.66, 0.20);
            ItemNameLabel.Aligns    = TextAligns.Middle;
            ItemNameLabel.Enabled   = false;
            ItemNameLabel.Depth     = 1000;

            WObject positionTextObj = new WObject("Global Position")
            {
                Parent = DebugPanel
            };

            DebugPosition           = positionTextObj.AddModule <Label>();
            DebugPosition.MinAnchor = new Vector2D(0.3, 0.95);
            DebugPosition.MaxAnchor = new Vector2D(0.7, 1.0);
            DebugPosition.AutoSize  = true;
            DebugPosition.Aligns    = TextAligns.Up | TextAligns.Middle;
            DebugPosition.Color     = Color256.White;
            DebugPosition.Text      = "XYZ: ?/?/?";

            CreateInventoryFocus();
            CreatePlayerInventory();

            Player.LocalPlayer.OnHotbarUpdate         += UpdateHotbarItem;
            Player.LocalPlayer.OnHotbarSelectedChange += UpdateHotbarSelected;
            Player.LocalPlayer.OnContainerToggle      += TogglePlayerInventory;
            Player.LocalPlayer.OnContainerClose       += PlayerCloseInventory;
            Player.LocalPlayer.OnContainerOpen        += PlayerOpenInventory;
            Player.LocalPlayer.OnItemUpdate           += UpdateItem;

            Player.LocalPlayer.OnCraftUpdate += UpdateCraft;


            HoveredTooltipWObject = new WObject("Item Tooltip")
            {
                Parent  = Canvas.Main.WObject,
                Layer   = (ulong)Layers.UI,
                Enabled = false
            };
            HoveredTooltip           = HoveredTooltipWObject.AddModule <ToolTip>();
            HoveredTooltip.MinAnchor = new Vector2D(0);
            HoveredTooltip.MaxAnchor = new Vector2D(0.2, 0.05);

            CreateInventoryRenders();
        }