@ -15,8 +15,6 @@ extern vi2d WINDOW_SIZE;
typedef Attribute A ;
Menu : : Menu ( ) { }
Menu : : Menu ( vf2d pos , vf2d size )
: pos ( pos = = CENTERED ? WINDOW_SIZE / 2 - size / 2 : vi2d { pos } ) , size ( size ) {
r . Create ( size . x , size . y ) ;
@ -25,19 +23,28 @@ Menu::Menu(vf2d pos,vf2d size)
void Menu : : InitializeMenus ( ) {
stack . reserve ( 32 ) ;
menus [ TEST ] = InitializeTestMenu ( ) ;
menus [ TEST_2 ] = InitializeTestSubMenu ( ) ;
menus [ INVENTORY ] = InitializeInventoryWindow ( ) ;
InitializeTestMenu ( ) ;
InitializeTestSubMenu ( ) ;
InitializeInventoryWindow ( ) ;
for ( MenuType type = TEST ; type < MenuType : : ENUM_END ; type = MenuType ( int ( type + 1 ) ) ) {
if ( menus . count ( type ) = = 0 ) {
std : : cout < < " WARNING! Menu Type " < < type < < " does not exist! " < < std : : endl ;
throw ;
}
for ( auto & key : menus [ type ] - > components ) {
MenuComponent * component = key . second ;
component - > AfterCreate ( ) ;
}
menus [ type ] - > components . SetInitialized ( ) ; //Lock all known components to prevent invalid access.
}
}
Menu * Menu : : CreateMenu ( MenuType type , vf2d pos , vf2d size ) {
menus [ type ] = new Menu ( pos , size ) ;
return menus . at ( type ) ;
}
void Menu : : AddComponent ( std : : string key , MenuComponent * button ) {
if ( button - > selectable ) {
buttons [ button - > rect . pos . y ] . push_back ( button ) ;
@ -59,13 +66,16 @@ void Menu::CheckClickAndPerformMenuSelect(Crawler*game){
void Menu : : HoverMenuSelect ( Crawler * game ) {
if ( selection = = vi2d { - 1 , - 1 } | | buttons [ selection . y ] [ selection . x ] - > disabled ) return ;
if ( buttons [ selection . y ] [ selection . x ] - > draggable )
if ( buttonHoldTime < " ThemeGlobal.MenuHoldTime " _F ) CheckClickAndPerformMenuSelect ( game ) ;
else {
if ( buttons [ selection . y ] [ selection . x ] - > draggable ) {
if ( buttonHoldTime < " ThemeGlobal.MenuHoldTime " _F ) {
CheckClickAndPerformMenuSelect ( game ) ;
} else {
draggingComponent = buttons [ selection . y ] [ selection . x ] - > PickUpDraggableItem ( ) ;
buttonHoldTime = 0 ;
}
else CheckClickAndPerformMenuSelect ( game ) ;
} else {
CheckClickAndPerformMenuSelect ( game ) ;
}
}
void Menu : : MenuSelect ( Crawler * game ) {
@ -110,8 +120,8 @@ void Menu::Update(Crawler*game){
selection . y = key . first ;
selection . x = index ;
}
index + + ;
}
index + + ;
}
}
}
@ -161,6 +171,11 @@ void Menu::Draw(Crawler*game){
Pixel : : Mode prevMode = game - > GetPixelMode ( ) ;
game - > SetPixelMode ( Pixel : : MASK ) ;
game - > Clear ( BLANK ) ;
for ( auto & component : displayComponents ) {
if ( component - > renderInMain ) {
component - > _Draw ( game , { 0 , 0 } , this = = Menu : : stack . back ( ) ) ;
}
}
for ( auto & key : buttons ) {
for ( auto & button : key . second ) {
if ( button - > renderInMain ) {
@ -168,15 +183,15 @@ void Menu::Draw(Crawler*game){
}
}
}
for ( auto & component : displayComponents ) {
if ( component - > renderInMain ) {
component - > _Draw ( game , { 0 , 0 } , this = = Menu : : stack . back ( ) ) ;
}
}
game - > SetPixelMode ( prevMode ) ;
game - > SetDrawTarget ( nullptr ) ;
r . Decal ( ) - > Update ( ) ;
game - > DrawDecal ( pos , r . Decal ( ) ) ;
for ( auto & component : displayComponents ) {
if ( component - > renderInMain ) {
component - > _DrawDecal ( game , pos , this = = Menu : : stack . back ( ) ) ;
}
}
for ( auto & key : buttons ) {
for ( auto & button : key . second ) {
if ( button - > renderInMain ) {
@ -184,11 +199,6 @@ void Menu::Draw(Crawler*game){
}
}
}
for ( auto & component : displayComponents ) {
if ( component - > renderInMain ) {
component - > _DrawDecal ( game , pos , this = = Menu : : stack . back ( ) ) ;
}
}
if ( GetCurrentTheme ( ) . IsScaled ( ) ) {
DrawScaledWindowBorder ( game , pos ) ;
@ -364,7 +374,9 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
}
}
if ( prevSelection ! = selection ) {
if ( selection ! = vi2d { - 1 , - 1 } & & buttons [ selection . y ] [ selection . x ] - > disabled ) selection = prevSelection ;
if ( selection ! = vi2d { - 1 , - 1 } & & buttons [ selection . y ] [ selection . x ] - > disabled ) {
selection = prevSelection ;
}
// If the new selection of a button on this frame is disabled for some reason, we need to go back to what we had selected before.
}
}