Inheritance: GUIElement
Esempio n. 1
0
        static void Main(string[] args)
        {
            //We choosed OpenGL because it is cross-platform and GUI does not need
            //Amazing performances...
            IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL,
                                                    new Dimension2D(640, 480),
                                                    16, false, false, false, false);
            //Delegate that will catch our events
            device.OnEvent += new OnEventDelegate(device_OnEvent);

            //Does not seem to work on Linux but well...
            device.Resizeable = false;

            //We set a basic caption
            device.WindowCaption = "Irrlicht .NET CP General User Interface Example";

            //We set our handlers
            driver = device.VideoDriver;
            guienv = device.GUIEnvironment;

            //We set the skin as a metallic windows skin
            guienv.Skin = guienv.CreateSkin(GUISkinTypes.WindowsMetallic);
            guienv.Skin.SetColor(GuiDefaultColor.ButtonText, Color.White);

            TTFont font = new TTFont(device.VideoDriver);
            font.Antialias = true;
            TTFace face = new TTFace();
            face.Load("../../medias/FreeSans.ttf");
            font.Attach(face, 14);
            guienv.Skin.Font = font;

            //Our fader. We set it as first because we don't want him to hide our buttons.
            guienv.AddInOutFader(null, (int)GUIItems.Fader);
            //We add several buttons with the IDs we defined downwards
            guienv.AddButton(new Rect(new Position2D(250, 0), new Dimension2D(140, 100)),
                             null, (int)GUIItems.ClickMe, "Click me !");
            guienv.AddButton(new Rect(new Position2D(250, 380), new Dimension2D(140, 100)),
                             null, (int)GUIItems.DontClickMe, "Don't click me !");
            guienv.AddButton(new Rect(new Position2D(0, 190), new Dimension2D(140, 100)),
                             null, (int)GUIItems.FadeMe, "Fade me !");
            guienv.AddButton(new Rect(new Position2D(500, 190), new Dimension2D(140, 100)),
                             null, (int)GUIItems.FunnyEffect, "Funny effect !");

            guienv.AddStaticText ("Move this scrollbar and you'll see the miracle !", new Rect(new Position2D(220, 240), new Dimension2D(240, 30)),
                                  false, true, null, -1, false);

            guienv.AddSpinBox ("", new Rect(new Position2D (220, 270), new Dimension2D (120, 30)), null, -1);
            guienv.AddEditBox ("", new Rect(new Position2D (220, 300), new Dimension2D (120, 30)), true, null, -1);

            listbox = guienv.AddListBox(new Rect(new Position2D(400, 20), new Dimension2D(220, 150)), null, -1, true);
            //Our logo
            guienv.AddImage(driver.GetTexture("../../medias/NETCPlogo.png"), new Position2D(0, 0), true, null, -1, "");

            //And now the scrollbar
            GUIScrollBar scroll = guienv.AddScrollBar(true, new Rect(new Position2D(220, 220), new Dimension2D(240, 20)), null,
                                (int)GUIItems.ScrollBar);

            el = new CustomElement(guienv, null, -1, new Rect(new Position2D(220, 120), new Dimension2D(160, 100)));

            //Var for the funny effects
            int toAdd = 1;
            //While the device is running and we don't want him to exit
            while (device.Run() && !Exit)
            {
                //If our funny effect is enabled, we just scroll the scrollbar
                //It may seems strange but the "ScrollBarChanged" event is NOT fired
                //When we manually change the position... It's a gift and a cursed, depending on the situation.
                if (FunnyEffectEnabled)
                {
                    scroll.Pos += toAdd;
                    if(scroll.Pos >= 100 || scroll.Pos <= 0)
                        toAdd = -toAdd;
                    BackColor = Color.From(255, 255-scroll.Pos * 5 / 2, 255 - (scroll.Pos * 5 / 2), scroll.Pos * 5 / 2);
                }
                //Here we are, we begin the scene
                //Notice that we DO NOT use the ZBuffer because we have only two dimensions
                driver.BeginScene(true, false, BackColor);
                //We draw all the GUI
                guienv.DrawAll();
                //And we end
                driver.EndScene();
            }
            //As in the first example, we need to release main resources
            device.DumpElements();
            device.Close();
        }
Esempio n. 2
0
        public bool HandleEvent(Event evnt)
        {
            switch (evnt.GUIEvent)
            {
                case GUIEventType.ElementFocused:
                    if (evnt.Caller.Type != ElementType.Image)
                    {
                        focused = true;
                    }
                    break;

                case GUIEventType.ElementFocusLost:
                    focused = false;
                    break;

                case GUIEventType.EditBoxEnter:
                    // Login.
                    if (evnt.Caller.ID == (int)GUIElementIDS.LOGIN_SERVERURI
                        || evnt.Caller.ID == (int)GUIElementIDS.LOGIN_FIRSTNAME
                        || evnt.Caller.ID == (int)GUIElementIDS.LOGIN_LASTNAME
                        || evnt.Caller.ID == (int)GUIElementIDS.LOGIN_PASSWORD)
                    {
                        LoginRequest();
                    }

                    // Teleport.
                    if (evnt.Caller.ID == (int)GUIElementIDS.TELEPORT_REGIONNAME
                        || evnt.Caller.ID == (int)GUIElementIDS.TELEPORT_X
                        || evnt.Caller.ID == (int)GUIElementIDS.TELEPORT_Y
                        || evnt.Caller.ID == (int)GUIElementIDS.TELEPORT_Z)
                    {
                        TeleportRequest();
                    }

                    // Chat.
                    if (evnt.Caller.ID == (int)GUIElementIDS.CHAT_ENTERMSG)
                    {
                        RequestSendChatMessage();
                    }
                    break;

                case GUIEventType.ElementClosed:
                    focused = false;
                    if (evnt.Caller.ID == (int)GUIElementIDS.CHAT_WINDOW)
                    {
                        chatBoxMessageList = null;
                    }
                    break;

                case GUIEventType.TabChanged:
                    if (evnt.Caller.ID == (int)GUIElementIDS.DEBUG_DTAB_CONTROLLER)
                    {
                        Reference.Viewer.DebugManager.ChangeMode(debugTab.ActiveTab);
                    }
                    break;

                case GUIEventType.ButtonClicked:
                    if (evnt.Caller.ID == (int)GUIElementIDS.LOGIN_LOGINBUTTON)
                    {
                        LoginRequest();
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.GENERAL_MESSAGE_BUTTON00)
                    {
                        if (isChacheDeleteMessage)
                        {
                            SaveReserveChacheDelete();

                            ShowMessageWindow(DialogText.CacheDeleteMessage);
                        }
                        else
                        {
                            Remove((int)GUIElementIDS.GENERAL_MESSAGE_WINDOW);
                            Remove((int)GUIElementIDS.SETTING_WINDOW);

                            if (Reference.Viewer.StateManager.State == State.ERROR)
                            {
                                // Change login mode by now mode.
                                switch (loginInfo.LoginMode)
                                {
                                    case LoginType.AUTO:
                                        Reference.Viewer.LoginMode = "click";
                                        break;

                                    case LoginType.CLICK:
                                        Reference.Viewer.LoginMode = "click";
                                        break;

                                    case LoginType.MANUAL:
                                        Reference.Viewer.LoginMode = "manual";
                                        break;

                                    case LoginType.NONE:
                                        Reference.Viewer.LoginMode = "hide";
                                        break;
                                }

                                Reference.Viewer.LogoutRequest();
                            }
                        }

                        isChacheDeleteMessage = false;
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.GENERAL_MESSAGE_BUTTON01)
                    {
                        Remove((int)GUIElementIDS.GENERAL_MESSAGE_WINDOW);
                        Remove((int)GUIElementIDS.SETTING_WINDOW);

                        isChacheDeleteMessage = false;
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.TELEPORT_BACKBUTTON)
                    {
                        Remove((int)GUIElementIDS.TELEPORT_FAILED_WINDOW);
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.TELEPORT_TELEPORTBUTTON)
                    {
                        TeleportRequest();
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.CHAT_SENDBUTTON)
                    {
                        RequestSendChatMessage();
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.SETTING_TAB1_BUTTON00)
                    {
                        SaveIniFile();

                        ShowMessageWindow(DialogText.SettingMessage);
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.SETTING_TAB2_BUTTON00)
                    {
                        ShowMessageWindow(DialogText.CacheDeleteConfirm, true);
                        isChacheDeleteMessage = true;
                    }
                    else if (evnt.Caller.ID == (int)GUIElementIDS.STANDUP_BUTTON)
                    {
                        if (Reference.Viewer.IsStandUpIcon)
                        {
                            imageChair.Visible = false;
                            Reference.Viewer.Adapter.CallStandUp();
                        }
                    }
                    else
                    {
                        // Not default button click, see if we have a callback defined for it
                        if (buttonClickCallbacks.ContainsKey(evnt.Caller.ID))
                        {
                            buttonClickCallbacks[evnt.Caller.ID].Invoke();
                        }
                    }

                    timer.Enabled = true;

                    break;
            }
            return (false);
        }
Esempio n. 3
0
        public void ShowChatWindow()
        {
            // remove tool box if already there
            Remove((int)GUIElementIDS.CHAT_WINDOW);

            GUIWindow wnd = Reference.GUIEnvironment.AddWindowW(
                new Rect(new Position2D(Reference.Viewer.Width / 2 - 150, Reference.Viewer.Height / 2 - 110), new Dimension2D(300, 220)),
                false, "   " + DialogText.Chat, parentElement, (int)GUIElementIDS.CHAT_WINDOW);

            wnd.CloseButton.UseAlphaChannel = true;
            wnd.CloseButton.SetImage(closeButton);
            wnd.ToolTipText = string.Empty;
            wnd.ToolTipTextW = string.Empty;

            GUIListBox chatBoxMessageList_private = Reference.GUIEnvironment.AddListBox(new Rect(new Position2D(4, 24), new Dimension2D(290, 140)), wnd, (int)GUIElementIDS.CHAT_MSGLIST, true);

            Texture buttonTex = Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/gui/windows/button_chatenter.png");
            chatBoxInput = Reference.GUIEnvironment.AddEditBoxW("", new Rect(new Position2D(4, 172), new Dimension2D(276, 44)), true, wnd, (int)GUIElementIDS.CHAT_ENTERMSG);
            GUIButton btn = Reference.GUIEnvironment.AddButtonW(new Rect(new Position2D(284, 172), new Dimension2D(buttonTex.OriginalSize.Width, buttonTex.OriginalSize.Height)), wnd, (int)GUIElementIDS.CHAT_SENDBUTTON, "");
            btn.SetImage(buttonTex);
            //Reference.GUIEnvironment.AddImage(Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/gui/windows/button_chatenter.png"), new Position2D(0, 0), true, btn, -1, "");

            Reference.GUIEnvironment.AddImage(Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/gui/windows/window_chat.png"), new Position2D(5, 2), true, wnd, -1, "");

            // Get all chat history.
            for (int i = 0; i < Reference.Viewer.ChatManager.Messages.Length; i++)
            {
                chatBoxMessageList_private.AddItemW(Reference.Viewer.ChatManager.Messages[i]);
            }

            // Set last message.
            chatBoxMessageList_private.Selected = chatBoxMessageList_private.ItemCount - 1;
            chatBoxMessageList = chatBoxMessageList_private;
            // Set focus.
            Reference.GUIEnvironment.SetFocus(chatBoxInput);

            imageChat.Visible = false;
        }
Esempio n. 4
0
        public void ShowSettingWindow()
        {
            //----------------------------------------------------------------------
            // Remove window
            //----------------------------------------------------------------------
            Remove((int)GUIElementIDS.SETTING_WINDOW);

            //----------------------------------------------------------------------
            // Set window
            //----------------------------------------------------------------------
            Rect rect = new Rect(new Position2D(Reference.Viewer.Width / 2 - 150, Reference.Viewer.Height / 2 - 110), new Dimension2D(300, 220));
            GUIWindow wnd = Reference.GUIEnvironment.AddWindowW(rect, false, "   " + DialogText.Settings, parentElement, (int)GUIElementIDS.SETTING_WINDOW);

            Texture tex = Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/gui/windows/window_settings.png");
            if (tex != null)
                Reference.GUIEnvironment.AddImage(tex, new Position2D(5, 2), true, wnd, -1, "");

            wnd.CloseButton.UseAlphaChannel = true;
            wnd.CloseButton.SetImage(closeButton);

            //----------------------------------------------------------------------
            // Set tab
            //----------------------------------------------------------------------
            const int width = 4;
            const int height = 32;
            rect.X = width / 2;
            rect.Width = rect.Width - width;
            rect.Y = height;
            rect.Height = (int)(rect.Height * 2f) - (rect.Y / 2);
            GUITabControl tab = Reference.GUIEnvironment.AddTabControl(rect, wnd, true, true, -1);

            //----------------------------------------------------------------------
            // Graphic tab
            //----------------------------------------------------------------------
            GUITab t1 = tab.AddTabW(DialogText.General, -1);
            Rect t1Rect = new Rect();

            t1Rect.X = 8;
            t1Rect.Y = 24;
            t1Rect.Width = 80;
            t1Rect.Height = 20 * 1;
            Reference.GUIEnvironment.AddStaticTextW(DialogText.SeaShader+":", t1Rect, false, false, t1, -1, false);
            t1Rect.X = t1Rect.X + t1Rect.Width;
            t1Rect.Width = 48;
            t1Rect.Height = 20 * 2;
            settingTab1SeaQualityList = Reference.GUIEnvironment.AddListBox(t1Rect, t1, -1, false);
            settingTab1SeaQualityList.AddItemW(DialogText.High);
            settingTab1SeaQualityList.AddItemW(DialogText.Low);
            settingTab1SeaQualityList.Selected = (Reference.Viewer.SeaQuality == Viewer.ShaderLevelType.High ? 0 : 1);

            t1Rect.X = 16 + t1Rect.X + t1Rect.Width;
            t1Rect.Width = 80;
            t1Rect.Height = 20 * 1;
            Reference.GUIEnvironment.AddStaticTextW(DialogText.SkyShader+":", t1Rect, false, false, t1, -1, false);
            t1Rect.X = t1Rect.X + t1Rect.Width;
            t1Rect.Width = 48;
            t1Rect.Height = 20 * 2;
            settingTab1SkyQualityList = Reference.GUIEnvironment.AddListBox(t1Rect, t1, -1, false);
            settingTab1SkyQualityList.AddItemW(DialogText.High);
            settingTab1SkyQualityList.AddItemW(DialogText.Low);
            settingTab1SkyQualityList.Selected = (Reference.Viewer.SkyQuality == Viewer.ShaderLevelType.High ? 0 : 1);

            t1Rect.X = 8;
            t1Rect.Y = t1Rect.Y + t1Rect.Height + 6;
            t1Rect.Width = 80;
            t1Rect.Height = 20 * 1;
            Reference.GUIEnvironment.AddStaticTextW(DialogText.Locale+":", t1Rect, false, false, t1, -1, false);
            t1Rect.X = t1Rect.X + t1Rect.Width;
            t1Rect.Width = 192;
            t1Rect.Height = 16 * 2;
            settingTab1Locale = Reference.GUIEnvironment.AddListBox(t1Rect, t1, -1, false);
            settingTab1Locale.AddItemW(DialogText.EN);
            if (Reference.Viewer.JapaneseEnabled)
                settingTab1Locale.AddItemW(DialogText.JP);
            settingTab1Locale.Selected = (Reference.Viewer.Locale == "en" ? 0 : 1);

            t1Rect.X = 8;
            t1Rect.Y = t1Rect.Y + t1Rect.Height + 16;
            t1Rect.Width = 278;
            t1Rect.Height = BUTTON_DEFULT_HEIGHT;
            Reference.GUIEnvironment.AddButtonW(t1Rect, t1, (int)GUIElementIDS.SETTING_TAB1_BUTTON00, "OK");

            //----------------------------------------------------------------------
            // Cache tab
            //----------------------------------------------------------------------
            GUITab t2 = tab.AddTabW(DialogText.Cache, -1);

            Rect t2Rect = new Rect(new Position2D(8, 24), new Dimension2D(278, 64));
            Reference.GUIEnvironment.AddStaticTextW(DialogText.CacheInformationMessage, t2Rect, false, true, t2, -1, false);

            t2Rect = new Rect(new Position2D(112, 88), new Dimension2D(278, 32));
            Reference.GUIEnvironment.AddStaticTextW(DialogText.CacheUnitMessage, t2Rect, false, true, t2, -1, false);

            t2Rect = new Rect(new Position2D(224, 80), new Dimension2D(64, 32));
            long cacheMB = Reference.Viewer.CacheManager.CacheMaxSize / (1000 * 1000);
            settingTab2CacheSize = Reference.GUIEnvironment.AddEditBox(cacheMB.ToString(), t2Rect, true, t2, -1);

            t2Rect = new Rect(new Position2D(8, 118), new Dimension2D(278, BUTTON_DEFULT_HEIGHT));
            Reference.GUIEnvironment.AddButtonW(t2Rect, t2, (int)GUIElementIDS.SETTING_TAB2_BUTTON00, DialogText.Delete);

            //----------------------------------------------------------------------
            // Information tab
            //----------------------------------------------------------------------
            GUITab t3 = tab.AddTabW(DialogText.Information, -1);
            Reference.GUIEnvironment.AddImage(Reference.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"/media/gui/windows/logo.tga"), new Position2D(22, 24), false, t3, -1, string.Empty);
            Reference.GUIEnvironment.AddStaticTextW(DialogText.Version + ": " + Reference.Viewer.Version.ToString(), new Rect(new Position2D(22, 100), new Dimension2D(Reference.Viewer.Width - 8, 24)), false, true, t3, -1, false);
            Reference.GUIEnvironment.AddStaticTextW("Copyright (C) 2009 3Di, Inc.", new Rect(new Position2D(22, 120), new Dimension2D(Reference.Viewer.Width - 8, 24)), false, true, t3, -1, false);
        }