Exemplo n.º 1
0
        bool device_OnEvent(Event ev)
        {
            switch (ev.Type)
            {
                case EventType.MouseInputEvent:
                    if (ev.MouseInputEvent == MouseInputEvent.LMousePressedDown)
                        Ox.DataStore.Input.SetMKey(OxCore.Data.MouseType.LButton, true);
                    if (ev.MouseInputEvent == MouseInputEvent.MMousePressedDown)
                        Ox.DataStore.Input.SetMKey(OxCore.Data.MouseType.MButton, true);
                    if (ev.MouseInputEvent == MouseInputEvent.RMousePressedDown)
                        Ox.DataStore.Input.SetMKey(OxCore.Data.MouseType.RButton, true);
                    if (ev.MouseInputEvent == MouseInputEvent.LMouseLeftUp)
                        Ox.DataStore.Input.SetMKey(OxCore.Data.MouseType.LButton, false);
                    if (ev.MouseInputEvent == MouseInputEvent.MMouseLeftUp)
                        Ox.DataStore.Input.SetMKey(OxCore.Data.MouseType.MButton, false);
                    if (ev.MouseInputEvent == MouseInputEvent.RMouseLeftUp)
                        Ox.DataStore.Input.SetMKey(OxCore.Data.MouseType.RButton, false);

                    Ox.DataStore.Input.SetMPosition(ev.MousePosition.X, ev.MousePosition.Y);

                    if (ev.MouseInputEvent == MouseInputEvent.MouseWheel)
                        Ox.DataStore.Input.SetMDelta(ev.MouseWheelDelta);
                    break;

                case EventType.KeyInputEvent:
                    Ox.DataStore.Input.SetKey((OxCore.Data.KeyType)ev.KeyCode, ev.KeyPressedDown);
                    break;
            }

            return false;
        }
Exemplo n.º 2
0
 public static bool device_OnEvent(Event ev)
 {
     if (ev.Type == EventType.GUIEvent)
     {
         switch (ev.GUIEvent)
         {
             case GUIEventType.ScrollBarChanged:
             GUIScrollBar bar = (GUIScrollBar)ev.Caller;
             if (ev.Caller.ID == 1) // Torso
             {
                 // We can control each bone position&rotation
                 // like a normal scene node
                 bone1.Rotation = new Vector3D(0,90-bar.Pos, 0);
                 // This should be called after any modification done with the bone
                 // to let it update it's children
                 bone1.UpdateAbsolutePositionOfAllChildren();
             } else
             if (ev.Caller.ID == 2) // Head
             {
                 bone2.Rotation = new Vector3D(0, 80-bar.Pos, 0);
                 bone2.UpdateAbsolutePositionOfAllChildren();
             } else // Axe
             {
                 bone3.Rotation = new Vector3D(bar.Pos-30, 0, 0);
                 bone3.UpdateAbsolutePositionOfAllChildren();
             }
             break;
         default:
             return false;
         }
     }
     return false;
 }
Exemplo n.º 3
0
 public override bool OnEvent(Event ev)
 {
     if (ev.Type == EventType.MouseInputEvent)
     {
         if (ev.MouseInputEvent == MouseInputEvent.LMousePressedDown)
         {
                 text.Text = caption + "\n\n      I'm clicked!";
             clicked = true;
         } else {
                 text.Text = caption;
             clicked = false;
         }
     }
     return base.OnEvent(ev);
 }
Exemplo n.º 4
0
 public static bool device_OnEvent(Event p_event)
 {
     // check if user presses the key 'W' or 'D'
     if (p_event.Type == EventType.KeyInputEvent &&
         !p_event.KeyPressedDown)
     {
         switch (p_event.KeyCode)
         {
             case KeyCode.Key_W:
                 isWireframe = !isWireframe;
                 terrain.SetMaterialFlag(MaterialFlag.Wireframe, isWireframe);
                 break;
             case KeyCode.Key_D:
                 terrain.SetMaterialType(
                     terrain.GetMaterial(0).MaterialType== MaterialType.Solid ?
                     MaterialType.DetailMap : MaterialType.Solid);
                 return true;
         }
     }
     return false;
 }
Exemplo n.º 5
0
 public virtual bool OnEvent(Event customevent)
 {
     return GuiElem_OnEvent(_raw, customevent.Raw);
 }
Exemplo n.º 6
0
        //Fired when an event occurs
        static bool device_OnEvent(Event ev)
        {
            //If the event is a GUI one

            /*if (ev.Type == EventType.KeyInputEvent)
            {
                Console.WriteLine("From net "+ev.Key);
                return false;
            }*/
            if (ev.Type == EventType.GUIEvent)
            {

                switch (ev.GUIEvent)
                {
                    //Has a button been clicked ?
                    case GUIEventType.ButtonClicked:
                        if (ev.Caller.ID == (int)GUIItems.DontClickMe)
                        {
                            listbox.AddItem("Clicked on dontclickme");
                            //We just add a stupid message box... with a stupid text

                            guienv.AddMessageBox("Why have you clicked ?", "I told you not to do this !\nI need now to hack your computer !\nYahahahahahahahaha !\nDo you agree ?",
                                                 true, MessageBoxFlag.Yes | MessageBoxFlag.No, null, (int)GUIItems.StupidMessageBox);
                            return true;
                        }
                        else if (ev.Caller.ID == (int)GUIItems.FadeMe)
                        {
                        listbox.AddItem("Clicked on fademe");
                            //We get the fader and fade the back screen.
                            GUIInOutFader fader = (GUIInOutFader)guienv.RootElement.GetElementFromID((int)GUIItems.Fader, true);
                            fader.FadeIn(4000);
                        }
                        else if (ev.Caller.ID == (int)GUIItems.FunnyEffect)
                        {
                        listbox.AddItem("Clicked on funnyeffect");
                            //We enable/disable the funny effect
                            FunnyEffectEnabled = !FunnyEffectEnabled;
                        }
                        else if (ev.Caller.ID == (int)GUIItems.ClickMe)
                        {
                        listbox.AddItem("Clicked on clickme");
                            //We just write a text on the console
                            Console.WriteLine("Clicked on Click Me !");
                        }
                        return false;

                    case GUIEventType.MessageBoxYes:
                        if (ev.Caller.ID == (int)GUIItems.StupidMessageBox)
                        {
                            //Again a stupid text
                            guienv.AddMessageBox("Good choice !", "I see you are reasonable !\nNow I will proceed !",
                                                 true, MessageBoxFlag.OK, null, -1);
                            return true;
                        }
                        return false;

                    case GUIEventType.MessageBoxNo:
                        if (ev.Caller.ID == (int)GUIItems.StupidMessageBox)
                        {
                            //Another pointless text
                            guienv.AddMessageBox("Doesn't matter", "Why would a great hacker need your agreement ?!",
                                                 true, MessageBoxFlag.No, null, -1);
                            return true;
                        }
                        return false;

                    //Our scrollbar has been scrolled by the user
                    case GUIEventType.ScrollBarChanged:
                        if (ev.Caller.ID == (int)GUIItems.ScrollBar)
                        {
                            //We define anew BackColor
                            GUIScrollBar caller = ev.Caller as GUIScrollBar;
                            BackColor = Color.From(255, 255-caller.Pos * 5 / 2, 255-(caller.Pos * 5 / 2), caller.Pos * 5 / 2);
                            return true;
                        }
                        return false;

                    default:
                        return false;
                }
            }
            //The event wasn't handled
            return false;
        }
Exemplo n.º 7
0
		public override bool OnEvent (Event ev)
		{
			return CGE_PINT_METHODS(_raw, CGE_INT_METHOD.ON_EVENT, ev.Raw, 0, 0, null) == 0? false : true;
		}
Exemplo n.º 8
0
 /// <summary>
 /// Posts an input event to the environment. Usefull for new created SceneManagers
 /// </summary>
 /// <param name="ev">
 /// An event struct from the EventReceiver <see cref="Event"/>
 /// </param>
 /// <returns>
 /// A result of the scenemanager's internal routine <see cref="System.Boolean"/>
 /// </returns>
 public bool PostEventFromUser(Event ev)
 {
     if (ev == null) return false;
     return SceneManager_PostEventFromUser(_raw, ev.Raw);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Event handlers for the Irrlicht device
        /// DIRECT UPDATES MUST NOT HAPPEN TO THE SCENE WITHIN THE SCOPE OF THIS FUNCTION
        /// </summary>
        /// <param name="p_event"></param>
        /// <returns></returns>
        public bool device_OnEvent(Event p_event)
        {
            if (p_event.Type == EventType.GUIEvent)
            {
                // Dispatch to GUI Manager
                if (guiManager != null)
                {
                    bool flag = (guiManager.HandleEvent(p_event));

                    if (guiManager.Focused)
                    {
                        avatarManager.UserPushForward(false);
                        avatarManager.UserPushBackward(false);
                    }

                    return flag;
                }
            }

            if (p_event.Type == EventType.KeyInputEvent)
            {
                return KeyInputEventProcessor(p_event);
            }

            if (p_event.Type == EventType.MouseInputEvent)
            {
                return MouseEventProcessor(p_event);
            }
            return false;
        }
Exemplo n.º 10
0
 //Our function that will handle every event irrlicht casts
 //If we handled the event we must return true, else false !
 static bool device_OnEvent(Event ev)
 {
     //A log has been sent, we just draw it on the window...
     //Here you could for instance store this on a text file or send it to your girlfriend...
     if (ev.Type == EventType.LogTextEvent)
     {
         Console.WriteLine(ev.LogText);
         return true;
     }
     //If the user has pressed Escape, we end the application.
     //I advice to add such a line on EVERY CROSS-PLATFORM APPLICATION
     //Because on many Linux systems, you won't be able to leave the application if you started
     //it as fullscreen... Your friend is CTRL + ALT + BACKSPACE.
     if (ev.Type == EventType.KeyInputEvent && ev.KeyPressedDown && ev.KeyCode == KeyCode.Escape)
     {
         Exit = true;
         return true;
     }
     //And another great features added in 0.4 (Irrlicht 1.1) :
     //Making screenshots and saving them !
     //For now, Irrlicht only supports saving to bmp but Irrlicht .NET CP
     //Supports a lot of format such as jpeg, gif, png...
     if (ev.Type == EventType.KeyInputEvent && ev.KeyPressedDown && ev.KeyCode == KeyCode.Return)
     {
         driver.WriteImageIntoFile(driver.CreateScreenShot(), "screenshot.jpg");
         return true;
     }
     //The event wasn't handled.
     return false;
 }
Exemplo n.º 11
0
 public bool PostEventFromUser(Event ev)
 {
     return GuiEnv_PostEventFromUser(_raw, ev.Raw);
 }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
 public bool OnEvent(Event ev)
 {
     return Camera_OnEvent(_raw, ev.Raw);
 }
Exemplo n.º 14
0
        public bool MouseEventProcessor(Event p_event)
        {
            if (p_event.MouseInputEvent == MouseInputEvent.MouseWheel)
            {
                if (camera.CameraMode != ECameraMode.Build)
                {
                    camera.SwitchMode(ECameraMode.Build);
                }

                //KeyCode.RButton
                if (guiManager.Focused == false)
                    camera.MouseWheelAction(p_event.MouseWheelDelta);
            }

            if (p_event.MouseInputEvent == MouseInputEvent.LMouseLeftUp)
            {
                LMheld = false;
                if (menuManager == null && menuManager.Click(Device.CursorControl.Position))
                {
                    return (false);
                }
                if (stateManager.State == State.INITIALIZED)
                {
                    if (LoginMode == "click")
                    {
                        LoginRequest();
                    }

                    return (false);
                }

                if (stateManager.State == State.CONNECTED)
                {
                    if (guiManager.Focused)
                        return (false);

                    if (menuManager != null && menuManager.Visible)
                    {
                        menuManager.Click(Device.CursorControl.Position);
                        return (false);
                    }

                    // start touch code
                    Cursors currentCursor = guiManager.GetCursor();
                    if (currentCursor == Cursors.HAND && entityManager.PrimitiveUnderMouse != null)
                    {
                        string uuid = entityManager.GetUUIDFromLocalID(entityManager.PrimitiveUnderMouse.LocalID);
                        if (uuid != string.Empty)
                            adapter.CallTouchTo(uuid);

                        // FIXME: this only handles "Touch" actions. Other possible ClickAction values include Buy, Pay, OpenTask, PlayMedia, OpenMedia
                    }
                    else if (currentCursor == Cursors.CHAIR && entityManager.PrimitiveUnderMouse != null)
                    {
                        protocolManager.SitOn(entityManager.PrimitiveUnderMouse.ID.ToString());
                    }
                    // end touch code
                }

                avatarManager.UserPushForward(false);
                avatarManager.AvatarPickRequest();
            }
            if (p_event.MouseInputEvent == MouseInputEvent.LMousePressedDown)
            {
                if (stateManager.State == State.CONNECTED)
                {
                    if (menuManager.Visible || guiManager.Focused)
                    {
                        return (false);
                    }

                    // start touch code
                    Cursors currentCursor = guiManager.GetCursor();
                    if (currentCursor == Cursors.NORMAL)
                    {
                        if (camera.CameraMode != ECameraMode.Build)
                        {
                            camera.SwitchMode(ECameraMode.Build);
                        }

                        if (protocolManager.AvatarConnection.SittingOn() == 0)
                        {
                            avatarManager.UserUpdateMousePosition(p_event.MousePosition);
                        }
                        else
                        {
                            if (!IsStandUpIcon)
                                protocolManager.StandUp();
                        }
                    }
                }

                LMheld = true;
            }
            if (p_event.MouseInputEvent == MouseInputEvent.RMouseLeftUp)
            {
                RMheld = false;
            }
            if (p_event.MouseInputEvent == MouseInputEvent.RMousePressedDown)
            {
                RMheld = true;

                if (camera.CameraMode != ECameraMode.Build)
                {
                    camera.SwitchMode(ECameraMode.Build);
                }
            }
            if (p_event.MouseInputEvent == MouseInputEvent.MouseMoved)
            {
                Cursors currentCursor = guiManager.GetCursor();
                if (LMheld)
                {
                    if (currentCursor == Cursors.NORMAL)
                    {
                        avatarManager.UserUpdateMousePosition(p_event.MousePosition);
                    }
                }

                if (RMheld)
                {
                    int deltaX = p_event.MousePosition.X - OldMouseX;
                    int deltaY = p_event.MousePosition.Y - OldMouseY;

                    camera.SetDeltaFromMouse(deltaX, deltaY);
                }
                else if (MMheld)
                {
                    float deltaY = (float)(p_event.MousePosition.Y - OldMouseY) * -0.1f; // negate and scale it

                    // TODO: copied from MouseEventProcessor, should refactor common code
                    if (camera.CameraMode != ECameraMode.Build)
                    {
                        camera.SwitchMode(ECameraMode.Build);
                    }
                    //KeyCode.RButton
                    camera.MouseWheelAction(deltaY);
                }

                OldMouseX = p_event.MousePosition.X;
                OldMouseY = p_event.MousePosition.Y;
            }
            return false;
        }
Exemplo n.º 15
0
        public bool KeyInputEventProcessor(Event p_event)
        {
            if (guiManager.Focused)
                return false;

            if (p_event.KeyPressedDown)
            {
                bool isAvatarControl = false;

                switch (p_event.KeyCode)
                {
                    case KeyCode.Up:
                        avatarManager.UserPushForward(true);
                        isAvatarControl = true;
                        break;
                    case KeyCode.Down:
                        avatarManager.UserPushBackward(true);
                        isAvatarControl = true;
                        break;
                    case KeyCode.Left:
                        avatarManager.UserPushLeft();
                        isAvatarControl = true;
                        break;
                    case KeyCode.Right:
                        avatarManager.UserPushRight();
                        isAvatarControl = true;
                        break;
            #if DEBUG
                    // camera up / dn
                    case KeyCode.Numpad_7:
                        camera.MoveDown();
                        break;
                    case KeyCode.Numpad_9:
                        camera.MoveUp();
                        break;

                    // camera f / b / l / r
                    case KeyCode.Numpad_8:
                        camera.MoveForward();
                        break;
                    case KeyCode.Numpad_2:
                        camera.MoveBackward();
                        break;
                    case KeyCode.Numpad_1:
                        camera.MoveLeft();
                        break;
                    case KeyCode.Numpad_3:
                        camera.MoveRight();
                        break;

                    // camera turn l / r
                    case KeyCode.Numpad_4:
                        camera.MoveTurnLeft();
                        break;
                    case KeyCode.Numpad_6:
                        camera.MoveTurnRight();
                        break;

                    // camera move speed.
                    case KeyCode.Numpad_5:
                        camera.MoveSwitchSpeed();
                        break;
            #endif
                }

                if (isAvatarControl)
                {
                    camera.SwitchMode(ECameraMode.Third);
                }
            }
            else
            {
                switch (p_event.KeyCode)
                {
                    case KeyCode.Up:
                        avatarManager.UserPushForward(false);
                        break;
                    case KeyCode.Down:
                        avatarManager.UserPushBackward(false);
                        break;
                    case KeyCode.F11:
                        guiManager.ShowDebugWindow();
                        break;
            #if DEBUG
            #if ENABLE_ELEMENT_DUMPING
                    case KeyCode.F9:
                        NativeElement.DumpElements(@"c:\memlog_snapshot.txt");
                        break;
            #endif
                    case KeyCode.F1:
                        adapter.CallAvatarCustomizeAnimation(0);
                        break;
                    case KeyCode.F2:
                        adapter.CallAvatarCustomizeAnimation(1);
                        break;
            #if DEBUG
                    case KeyCode.F3:
                        debug_on = !debug_on;
                        break;
            #endif
                    case KeyCode.F5:
                        break;
                    case KeyCode.F6:
                        break;
                    case KeyCode.F7:
                        throw new Exception("Dead!!");
                        break;
                    case KeyCode.F10:
                        Shaders.AdvancedSea sea = (Shaders.AdvancedSea)shaderManager.GetShaderObject(ShaderManager.ShaderType.AdvancedSea);
                        sea.SaveMaps();
                        break;
                    case KeyCode.F12:
                        SetWorldTime("2009-02-20 10:00:00");
                        break;
            #endif
                }
            }

            return false;
        }
Exemplo n.º 16
0
        /// <summary>
        /// The Irrlicht window has had an event.
        /// </summary>
        /// <param name="p_event"></param>
        /// <returns></returns>
        public override bool OnDeviceEvent(Event p_event)
        {

            //m_log.Warn(p_event.Type.ToString());
            if (p_event.Type == EventType.LogTextEvent)
            {
                string eventype = p_event.LogText;
                if (eventype.Contains("Resizing window"))
                {
                    int pos = eventype.IndexOf('(');
                    int pos2 = eventype.IndexOf(')');
                    //
                    string resizeto = eventype.Substring(pos + 1, pos2 - (pos + 1));
                    string[] xy = resizeto.Split(' ');

                    WindowWidth = Convert.ToInt32(xy[0]);
                    WindowHeight = Convert.ToInt32(xy[1]);
                    WindowAspect = (float)WindowWidth / WindowHeight;
                }
            }

            if (p_event.Type == EventType.GUIEvent)
            {
                int id = p_event.Caller.ID;
                GUIEnvironment env = Renderer.Device.GUIEnvironment;

               

                //m_log.InfoFormat("{0} {1} {2} {3}", p_event.Type, p_event.Caller, p_event.GUIEvent, p_event.Caller.ID);
                switch (p_event.GUIEvent)
                {
                    case GUIEventType.ElementFocused:
                        this.UserInterface.FocusedElement = p_event.Caller as GUIElement;
                        break;
                    case GUIEventType.ElementFocusLost:
                        this.UserInterface.FocusedElement = null;
                        break;
                    case GUIEventType.MenuItemSelected:
                        // a menu item was clicked
                        GUIContextMenu menu = ((GUIContextMenu)p_event.Caller);
                        id = menu.GetItemCommandID(menu.SelectedItem);
                        switch (id)
                        {
                            case (int)MenuItems.FileOpen:
                                env.AddFileOpenDialog("Please select a model file to open", false, Renderer.Device.GUIEnvironment.RootElement, 0);
                                break;
                            case (int)MenuItems.FileQuit: // File -> Quit
                                Shutdown();
                                break;
                            case (int)MenuItems.ShowChat:
                                UserInterface.ShowChatWindow();
                                break;
                            case (int)MenuItems.ShowPrimcount:
                                {
                                    uint texcount = 0;
                                    if (TextureManager != null)
                                        texcount = TextureManager.TextureCacheCount;
                                    m_log.DebugFormat("FullUpdateCount:{0}, PrimCount:{1}, TextureCount:{2}, UniquePrim:{3}", SceneGraph.PrimitiveCount, SceneGraph.Objects.Count, texcount, MeshManager.UniqueObjects);
                                }
                                break;
                            case (int)MenuItems.ClearCache:
                                {
                                    if (TextureManager != null)
                                    {
                                        TextureManager.ClearMemoryCache();

                                    }
                                }
                                break;
                            case (int)MenuItems.ViewModeOne: // View -> Material -> Solid
                                //CFK nothing yet, circa Thanksgiving eve 08
                                //CFK                                if (Model != null)
                                //CFK                                    Model.SetMaterialType(MaterialType.Solid);
                                break;
                            case (int)MenuItems.ViewModeTwo: // View -> Material -> Transparent
                                //CFK nothing yet, circa Thanksgiving eve 08
                                //CFK                                if (Model != null)
                                //CFK                                    Model.SetMaterialType(MaterialType.TransparentAddColor);
                                break;
                            case (int)MenuItems.ViewModeThree: // View -> Material -> Reflection
                                //CFK nothing yet, circa Thanksgiving eve 08
                                //CFK                                if (Model != null)
                                //CFK                                    Model.SetMaterialType(MaterialType.SphereMap);
                                break;
                            default:
                                UserInterface.HandleMenuAction(id);
                                break;
                        }
                        break;//case GUIEventType.MenuItemSelected:

                    case GUIEventType.FileSelected:
                        //CFK nothing yet, circa Thanksgiving eve 08
                        // load the model file, selected in the file open dialog
                        //CFK GUIFileOpenDialog dialog = ((GUIFileOpenDialog)p_event.Caller);
                        //CFK                        loadModel(dialog.Filename);
                        break;
                    case GUIEventType.EditBoxEnter:
                        if (p_event.Caller == UserInterface.ChatBoxInput)
                        {
                            lock (UserInterface.OutboundChatMessages)
                                UserInterface.OutboundChatMessages.Enqueue(UserInterface.ChatBoxInput.Text);

                            lock (UserInterface.MessageHistory)
                            {
                                UserInterface.MessageHistory.Add("You: " + UserInterface.ChatBoxInput.Text);
                                UserInterface.NewChat = true;
                            }

                            UserInterface.ChatBoxInput.Text = "";
                        }
                        break;
                }
            }


            // !Mouse event  (we do this so that we don't process the rest of this each mouse move
            if (p_event.Type != EventType.MouseInputEvent)
            {
                
                //Keyboard event
                if (p_event.Type == EventType.KeyInputEvent)
                {
                    //If we have focus on the 3d screen and not a control
                    if (UserInterface.FocusedElement == null)
                    {
                        
                        switch (p_event.KeyCode)
                        {

                            case KeyCode.Control:
                                m_ctrlPressed = p_event.KeyPressedDown;
                                if (m_ctrlPressed)
                                {

                                    CameraController.ResetMouseOffsets();
                                }
                                else
                                {
                                    CameraController.ApplyMouseOffsets();
                                }
                                break;
                            case KeyCode.Shift:
                                m_shiftPressed = p_event.KeyPressedDown;
                                break;
                            case KeyCode.Up:
                            case KeyCode.Down:
                            case KeyCode.Left:
                            case KeyCode.Right:
                            case KeyCode.Prior:
                            case KeyCode.Next:
                            case KeyCode.Key_W:
                            case KeyCode.Key_S:
                            case KeyCode.Key_A:
                            case KeyCode.Key_D:
                            case KeyCode.Home:
                            case KeyCode.Key_F:
                                if (!m_ctrlPressed)
                                    ProcessPressedKey(p_event.KeyCode, p_event.KeyPressedDown, false);

                                UpdateKeyPressState(p_event.KeyCode, p_event.KeyPressedDown);
                                break;

                            case KeyCode.Key_P:
                                if (p_event.KeyPressedDown)
                                {
                                    uint texcount = 0;
                                    if (TextureManager != null)
                                        texcount = TextureManager.TextureCacheCount;
                                    m_log.DebugFormat("FullUpdateCount:{0}, PrimCount:{1}, TextureCount:{2}, UniquePrim:{3}", SceneGraph.PrimitiveCount, SceneGraph.Objects.Count, texcount, MeshManager.UniqueObjects);
                                }
                                break;

                            case KeyCode.Key_C:
                                if (p_event.KeyPressedDown)
                                {
                                    if (TextureManager != null)
                                    {
                                        TextureManager.ClearMemoryCache();

                                    }
                                }
                                break;
                        }  
                    }
                }
                UpdatePressedKeys();
            }

            if (p_event.Type == EventType.MouseInputEvent)
            {
                return OnMouseEvent(p_event);
            }

            return false;
        }
Exemplo n.º 17
0
        public override bool OnMouseEvent(Event p_event)
        {
            if (p_event.MouseInputEvent == MouseInputEvent.MouseWheel)
            {
                CameraController.MouseWheelAction(p_event.MouseWheelDelta);
            }
            if (p_event.MouseInputEvent == MouseInputEvent.LMouseLeftUp)
            {
                if (m_ctrlPressed)
                {
                    CameraController.ApplyMouseOffsets();
                }
                m_leftMousePressed = false;
            }
            if (p_event.MouseInputEvent == MouseInputEvent.LMousePressedDown)
            {

                m_leftMousePressed = true;
                if (m_ctrlPressed)
                {
                    CameraController.SwitchMode(ECameraMode.Build);
                    // Pick!

                    CameraController.ResetMouseOffsets();
                    Vector3D[] projection = CameraController.ProjectRayPoints(p_event.MousePosition, WindowWidth/2, WindowHeight/2, WindowAspect);
                    Line3D projectedray = new Line3D(projection[0], projection[1]);

                    Vector3D collisionpoint = new Vector3D(0, 0, 0);
                    Triangle3D tri = new Triangle3D(0, 0, 0, 0, 0, 0, 0, 0, 0);

                    // Check if we have a node under the mouse
                    SceneNode node = SceneGraph.TrianglePicker.GetSceneNodeFromRay(projectedray, 0x0128, true, CameraController.CameraNode.Position); //smgr.CollisionManager.GetSceneNodeFromScreenCoordinates(new Position2D(p_event.MousePosition.X, p_event.MousePosition.Y), 0, false);
                    if (node == null)
                    {
                        if (SceneGraph.TriangleSelector != null)
                        {
                            // Collide test against the terrain
                            if (Renderer.SceneManager.CollisionManager.GetCollisionPoint(projectedray, SceneGraph.TriangleSelector, out collisionpoint, out tri))
                            {
                                if (CameraController.CameraMode == ECameraMode.Build)
                                {
                                    CameraController.SetTarget(collisionpoint);
                                    CameraController.TargetNode = null;
                                }
                            }
                        }
                    }
                    else
                    {
                        // Sometimes the terrain picker returns weird values.
                        // If it's weird try the general 'everything' triangle picker.
                        m_log.WarnFormat("[PICK]: Picked <{0},{1},{2}>", node.Position.X, node.Position.Y, node.Position.Z);
                        if (node.Position.X == 0 && node.Position.Z == 0)
                        {
                            if (SceneGraph.TriangleSelector != null)
                            {
                                if (Renderer.SceneManager.CollisionManager.GetCollisionPoint(projectedray, SceneGraph.TriangleSelector, out collisionpoint, out tri))
                                {
                                    if (CameraController.CameraMode == ECameraMode.Build)
                                    {
                                        CameraController.SetTarget(collisionpoint);
                                        CameraController.TargetNode = null;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Target the node
                            if (CameraController.CameraMode == ECameraMode.Build)
                            {
                                CameraController.SetTarget(node.Position);
                                CameraController.TargetNode = node;
                            }
                        }
                    }
                }
            }
            if (p_event.MouseInputEvent == MouseInputEvent.RMouseLeftUp)
            {
                m_rightMousePressed = false;
            }
            if (p_event.MouseInputEvent == MouseInputEvent.RMousePressedDown)
            {
                m_rightMousePressed = true;
            }

            if (p_event.MouseInputEvent == MouseInputEvent.MouseMoved)
            {
                if (m_leftMousePressed && m_ctrlPressed)
                {
                    int deltaX = p_event.MousePosition.X - m_oldMouseX;
                    int deltaY = p_event.MousePosition.Y - m_oldMouseY;

                    CameraController.SetDeltaFromMouse(deltaX, deltaY);
                }

                if (m_rightMousePressed)
                {

                    int deltaX = p_event.MousePosition.X - m_oldMouseX;
                    int deltaY = p_event.MousePosition.Y - m_oldMouseY;

                    CameraController.SetRotationDelta(deltaX, deltaY);
                }

                m_oldMouseX = p_event.MousePosition.X;
                m_oldMouseY = p_event.MousePosition.Y;
            }
            return false;
        }
Exemplo n.º 18
0
 static bool device_OnEvent(Event ev)
 {
     if (ev.KeyPressedDown && ev.KeyCode == KeyCode.Escape)
         Exit = true;
     return false;
 }