123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608 |
- //-----------------------------------------------------------------------------
- class UIMenuPanel: Managed
- {
- proto native UIMenuPanel GetSubMenu();
- proto native UIMenuPanel GetParentMenu();
- proto native UIMenuPanel GetVisibleMenu();
- proto native void SetSubMenu(UIMenuPanel submenu);
- proto native void SetParentMenu(UIMenuPanel parent);
- proto native bool CanClose();
- proto native bool CanCloseOnEscape();
- //! Create & open menu with specific id (see \ref MenuID) and set this menu as its parent
- proto native UIScriptedMenu EnterScriptedMenu(int id);
-
- proto native void DestroySubmenu();
- proto native bool IsAnyMenuVisible();
- proto native bool IsVisible();
- #ifdef FEATURE_CURSOR
- //! Signal when the menu is created through 'UIManager.CreateScriptedMenu'
- proto native bool IsCreatedHidden();
- #endif
-
- //! If visibility of application is changed. On console it is called when application is suspended or constrained.
- //! @param isVisible indicate if application is visible in foreground
- void OnVisibilityChanged(bool isVisible)
- {
- }
-
- //! Safe way to close window, using this function can even window safely close itself
- proto native void Close();
- bool UseMouse() {
- #ifdef PLATFORM_CONSOLE
- return GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
- #else
- return true;
- #endif
- }
- bool UseKeyboard() {
- #ifdef PLATFORM_CONSOLE
- return GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
- #else
- return true;
- #endif
- }
-
- bool UseGamepad() {
- return true;
- }
- //! Returns \ref MenuID
- int GetID() {
- return MENU_UNKNOWN;
- }
-
- //! Refresh request, called from anywhere
- void Refresh()
- {
- }
- };
- //-----------------------------------------------------------------------------
- //! Part of main menu hierarchy to create custom menus from script
- class UIScriptedMenu extends UIMenuPanel
- {
- int m_id;
- Widget layoutRoot;
- private Widget m_AnimAlphaWidget;
- private bool m_AnimAlphaIsIncreasing;
- private float m_AnimAlphaValue;
- Widget GetLayoutRoot()
- {
- return layoutRoot;
- }
-
- void LockControls()
- {
- #ifdef FEATURE_CURSOR
- if (IsCreatedHidden())
- return;
- #endif
- if (UseMouse())
- {
- GetGame().GetInput().ChangeGameFocus(1, INPUT_DEVICE_MOUSE);
- GetGame().GetUIManager().ShowUICursor(true);
- }
- if (UseKeyboard())
- {
- GetGame().GetInput().ChangeGameFocus(1, INPUT_DEVICE_KEYBOARD);
- }
-
- if (UseGamepad())
- {
- GetGame().GetInput().ChangeGameFocus(1, INPUT_DEVICE_GAMEPAD);
- }
- }
-
- void UnlockControls()
- {
- #ifdef FEATURE_CURSOR
- if (IsCreatedHidden())
- return;
- #endif
- if (UseMouse())
- {
- GetGame().GetInput().ChangeGameFocus(-1, INPUT_DEVICE_MOUSE);
- }
- if (GetParentMenu() && GetParentMenu().UseMouse())
- {
- GetGame().GetUIManager().ShowUICursor(true);
- }
- else
- {
- GetGame().GetUIManager().ShowUICursor(false);
- }
- if(UseKeyboard())
- {
- GetGame().GetInput().ChangeGameFocus(-1, INPUT_DEVICE_KEYBOARD);
- }
-
- if(UseGamepad())
- {
- GetGame().GetInput().ChangeGameFocus(-1, INPUT_DEVICE_GAMEPAD);
- }
- }
-
- void UIScriptedMenu()
- {
- m_id = MENU_UNKNOWN;
- }
-
- void ~UIScriptedMenu()
- {
- }
- //! Sets \ref MenuID
- void SetID(int id) {
- m_id = id;
- }
- //! Returns \ref MenuID
- override int GetID() {
- return m_id;
- }
- void SetWidgetAnimAlpha( Widget widget )
- {
- m_AnimAlphaValue = 0.3;
- m_AnimAlphaWidget = widget;
- }
-
- //create widgets here and return layout root Widget
- //widgets will be destroyed automatically by c++ side
- Widget Init()
- {
- return NULL;
- }
- void Cleanup()
- {
- }
- //after show
- void OnShow()
- {
- LockControls();
- if (IsHandlingPlayerDeathEvent() && g_Game && g_Game.GetPlayer())
- {
- g_Game.GetPlayer().GetOnDeathStart().Insert(OnPlayerDeath);
- }
- }
- //after hide
- void OnHide()
- {
- UnlockControls();
- if (IsHandlingPlayerDeathEvent() && g_Game && g_Game.GetPlayer())
- {
- g_Game.GetPlayer().GetOnDeathStart().Remove(OnPlayerDeath);
- }
- }
- //! Per frame update, called from engine
- void Update(float timeslice)
- {
- #ifdef PLATFORM_CONSOLE
- if ( m_AnimAlphaWidget )
- {
- float anim_speed = 1.2;
- float anim_value_max = 1.0;
- float anim_value_min = 0.3;
- if ( m_AnimAlphaIsIncreasing )
- {
- m_AnimAlphaValue += anim_speed * timeslice;
-
- if ( m_AnimAlphaValue >= anim_value_max )
- {
- m_AnimAlphaValue = anim_value_max;
- m_AnimAlphaIsIncreasing = false;
- }
- }
- else
- {
- m_AnimAlphaValue -= anim_speed * timeslice;
-
- if ( m_AnimAlphaValue <= anim_value_min )
- {
- m_AnimAlphaValue = anim_value_min;
- m_AnimAlphaIsIncreasing = true;
- }
- }
-
-
- m_AnimAlphaWidget.SetAlpha( m_AnimAlphaValue );
- }
- #endif
- }
- // Moved to parent
- //! Refresh request, called from anywhere
- //void Refresh()
- //{
- //}
- proto native void SetFadingPanels(Widget panel0, Widget panel1, Widget panel2, Widget panel3, Widget panel4);
-
- bool OnClick(Widget w, int x, int y, int button)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnClick( w, x, y, button ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnModalResult(Widget w, int x, int y, int code, int result)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnModalResult( w, x, y, code, result ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnDoubleClick(Widget w, int x, int y, int button)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDoubleClick( w, x, y, button ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnSelect(Widget w, int x, int y)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnSelect( w, x, y ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnItemSelected( w, x, y, row, column, oldRow, oldColumn ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnFocus(Widget w, int x, int y)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnFocus( w, x, y ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnFocusLost(Widget w, int x, int y)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnFocusLost( w, x, y ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnMouseEnter(Widget w, int x, int y)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseEnter( w, x, y ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseLeave( w, enterW, x, y ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnMouseButtonDown(Widget w, int x, int y, int button)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseButtonDown( w, x, y, button ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnMouseButtonUp(Widget w, int x, int y, int button)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseButtonUp( w, x, y, button ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnMouseWheel(Widget w, int x, int y, int wheel)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnMouseWheel( w, x, y, wheel ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnController(Widget w, int control, int value)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnController( w, control, value ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnKeyDown(Widget w, int x, int y, int key)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnKeyDown( w, x, y, key ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnKeyUp(Widget w, int x, int y, int key)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnKeyUp( w, x, y, key ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnKeyPress(Widget w, int x, int y, int key)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnKeyPress( w, x, y, key ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnChange(Widget w, int x, int y, bool finished)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnChange( w, x, y, finished ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnDrag(Widget w, int x, int y)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDrag( w, x, y ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnDragging(Widget w, int x, int y, Widget reciever)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDragging( w, x, y, reciever ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnDraggingOver(Widget w, int x, int y, Widget reciever)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDraggingOver( w, x, y, reciever ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnDrop(Widget w, int x, int y, Widget reciever)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDrop( w, x, y, reciever ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnDropReceived(Widget w, int x, int y, Widget reciever)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnDropReceived( w, x, y, reciever ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- bool OnEvent(EventType eventType, Widget target, int parameter0, int parameter1)
- {
- if ( UIScriptedWindow.GetActiveWindows() )
- {
- for ( int i = 0; i < UIScriptedWindow.GetActiveWindows().Count(); i++ )
- {
- if ( UIScriptedWindow.GetActiveWindows().GetElement( i ).OnEvent( eventType, target, parameter0, parameter1 ) )
- {
- return true;
- }
- }
- }
-
- return false;
- }
- ScriptedWidgetEventHandler GetContextMenu()
- {
- return null;
- }
-
- bool OnXboxEvent(int xboxEvent)
- {
- return true;
- }
-
- void OnRPC(ParamsReadContext ctx){}
- void OnRPCEx(int rpc_type, ParamsReadContext ctx){}
-
- void InitNoteWrite(EntityAI paper, EntityAI pen, string text = "") {}
- void InitNoteRead(string text = "") {}
- void InitMapItem(EntityAI item) {}
- void LoadMapMarkers() {}
-
- bool IsHandlingPlayerDeathEvent()
- {
- return true;
- }
-
- void OnPlayerDeath()
- {
- Close();
- }
- };
|