diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.cpp index 90525f5d0..7ba874f78 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.cpp @@ -12,1627 +12,1509 @@ #ifdef __ORBIS__ #include #endif -IUIScene_AbstractContainerMenu::IUIScene_AbstractContainerMenu() -{ - m_menu = NULL; - m_autoDeleteMenu = false; - m_lastPointerLabelSlot = NULL; - - m_pointerPos.x = 0.0f; - m_pointerPos.y = 0.0f; +IUIScene_AbstractContainerMenu::IUIScene_AbstractContainerMenu() { + m_menu = NULL; + m_autoDeleteMenu = false; + m_lastPointerLabelSlot = NULL; + m_pointerPos.x = 0.0f; + m_pointerPos.y = 0.0f; } -IUIScene_AbstractContainerMenu::~IUIScene_AbstractContainerMenu() -{ - // Delete associated menu if we were requested to on initialisation. Most menus are - // created just before calling CXuiSceneAbstractContainer::Initialize, but the player's inventorymenu - // is also passed directly and we don't want to go deleting that - if( m_autoDeleteMenu ) delete m_menu; +IUIScene_AbstractContainerMenu::~IUIScene_AbstractContainerMenu() { + // Delete associated menu if we were requested to on initialisation. Most + // menus are created just before calling + // CXuiSceneAbstractContainer::Initialize, but the player's inventorymenu is + // also passed directly and we don't want to go deleting that + if (m_autoDeleteMenu) delete m_menu; } -void IUIScene_AbstractContainerMenu::Initialize(int iPad, AbstractContainerMenu* menu, bool autoDeleteMenu, int startIndex,ESceneSection firstSection,ESceneSection maxSection, bool bNavigateBack) -{ - assert( menu != NULL ); +void IUIScene_AbstractContainerMenu::Initialize( + int iPad, AbstractContainerMenu* menu, bool autoDeleteMenu, int startIndex, + ESceneSection firstSection, ESceneSection maxSection, bool bNavigateBack) { + assert(menu != NULL); - m_menu = menu; - m_autoDeleteMenu = autoDeleteMenu; + m_menu = menu; + m_autoDeleteMenu = autoDeleteMenu; - Minecraft::GetInstance()->localplayers[iPad]->containerMenu = menu; + Minecraft::GetInstance()->localplayers[iPad]->containerMenu = menu; - // 4J WESTY - New tool tips to support pointer prototype. - //UpdateTooltips(); - // Default tooltips. - for ( int i = 0; i < eToolTipNumButtons; ++i ) - { - m_aeToolTipSettings[ i ] = eToolTipNone; - } - // 4J-PB - don't set the eToolTipPickupPlace_OLD here - let the timer do it. - /*SetToolTip( eToolTipButtonA, eToolTipPickupPlace_OLD );*/ - SetToolTip( eToolTipButtonB, eToolTipExit ); - SetToolTip( eToolTipButtonA, eToolTipNone ); - SetToolTip( eToolTipButtonX, eToolTipNone ); - SetToolTip( eToolTipButtonY, eToolTipNone ); + // 4J WESTY - New tool tips to support pointer prototype. + // UpdateTooltips(); + // Default tooltips. + for (int i = 0; i < eToolTipNumButtons; ++i) { + m_aeToolTipSettings[i] = eToolTipNone; + } + // 4J-PB - don't set the eToolTipPickupPlace_OLD here - let the timer do it. + /*SetToolTip( eToolTipButtonA, eToolTipPickupPlace_OLD );*/ + SetToolTip(eToolTipButtonB, eToolTipExit); + SetToolTip(eToolTipButtonA, eToolTipNone); + SetToolTip(eToolTipButtonX, eToolTipNone); + SetToolTip(eToolTipButtonY, eToolTipNone); - // 4J WESTY : To indicate if pointer has left menu window area. - m_bPointerOutsideMenu = false; + // 4J WESTY : To indicate if pointer has left menu window area. + m_bPointerOutsideMenu = false; - // 4J Stu - Store the enum range for the current scene - m_eFirstSection = firstSection; - m_eMaxSection = maxSection; + // 4J Stu - Store the enum range for the current scene + m_eFirstSection = firstSection; + m_eMaxSection = maxSection; - m_iConsectiveInputTicks = 0; + m_iConsectiveInputTicks = 0; - m_bNavigateBack = bNavigateBack; + m_bNavigateBack = bNavigateBack; - // Put the pointer over first item in use row to start with. + // Put the pointer over first item in use row to start with. #ifdef TAP_DETECTION - m_eCurrSection = firstSection; - m_eCurrTapState = eTapStateNoInput; - m_iCurrSlotX = 0; - m_iCurrSlotY = 0; -#endif // TAP_DETECTION - // - // for(int i=0;i= columns) - { - *piTargetX = columns - 1; - } - else - { - *piTargetX = offsetX; - } - } - else - { - // Update X - int offsetX = (*piTargetX) - xOffset; - if( offsetX < 0 ) - { - *piTargetX = columns - 1; - } - else if (offsetX >= columns) - { - *piTargetX = 0; - } - else - { - *piTargetX = offsetX; - } - } + // Update X + int offsetX = (*piTargetX) - xOffset; + if (offsetX < 0) { + *piTargetX = 0; + } else if (offsetX >= columns) { + *piTargetX = columns - 1; + } else { + *piTargetX = offsetX; + } + } else { + // Update X + int offsetX = (*piTargetX) - xOffset; + if (offsetX < 0) { + *piTargetX = columns - 1; + } else if (offsetX >= columns) { + *piTargetX = 0; + } else { + *piTargetX = offsetX; + } + } } #ifdef TAP_DETECTION -IUIScene_AbstractContainerMenu::ETapState IUIScene_AbstractContainerMenu::GetTapInputType( float fInputX, float fInputY ) -{ - if ( ( fabs( fInputX ) < 0.3f ) && ( fabs( fInputY ) < 0.3f ) ) - { - return eTapStateNoInput; - } - else if ( ( fInputX < -0.3f ) && ( fabs( fInputY ) < 0.3f ) ) - { - return eTapStateLeft; - } - else if ( ( fInputX > 0.3f ) && ( fabs( fInputY ) < 0.3f ) ) - { - return eTapStateRight; - } - else if ( ( fInputY < -0.3f ) && ( fabs( fInputX ) < 0.3f ) ) - { - return eTapStateDown; - } - else if ( ( fInputY > 0.3f ) && ( fabs( fInputX ) < 0.3f ) ) - { - return eTapStateUp; - } - else - { - return eTapNone; - } +IUIScene_AbstractContainerMenu::ETapState +IUIScene_AbstractContainerMenu::GetTapInputType(float fInputX, float fInputY) { + if ((fabs(fInputX) < 0.3f) && (fabs(fInputY) < 0.3f)) { + return eTapStateNoInput; + } else if ((fInputX < -0.3f) && (fabs(fInputY) < 0.3f)) { + return eTapStateLeft; + } else if ((fInputX > 0.3f) && (fabs(fInputY) < 0.3f)) { + return eTapStateRight; + } else if ((fInputY < -0.3f) && (fabs(fInputX) < 0.3f)) { + return eTapStateDown; + } else if ((fInputY > 0.3f) && (fabs(fInputX) < 0.3f)) { + return eTapStateUp; + } else { + return eTapNone; + } } -#endif // TAP_DETECTION +#endif // TAP_DETECTION -void IUIScene_AbstractContainerMenu::SetToolTip( EToolTipButton eButton, EToolTipItem eItem ) -{ - if ( m_aeToolTipSettings[ eButton ] != eItem ) - { - m_aeToolTipSettings[ eButton ] = eItem; - UpdateTooltips(); - } +void IUIScene_AbstractContainerMenu::SetToolTip(EToolTipButton eButton, + EToolTipItem eItem) { + if (m_aeToolTipSettings[eButton] != eItem) { + m_aeToolTipSettings[eButton] = eItem; + UpdateTooltips(); + } } -void IUIScene_AbstractContainerMenu::UpdateTooltips() -{ - // Table gives us text id for tooltip. - static const int kaToolTipextIds[ eNumToolTips ] = - { - IDS_TOOLTIPS_PICKUPPLACE, //eToolTipPickupPlace_OLD - IDS_TOOLTIPS_EXIT, // eToolTipExit - IDS_TOOLTIPS_PICKUP_GENERIC, // eToolTipPickUpGeneric - IDS_TOOLTIPS_PICKUP_ALL, // eToolTipPickUpAll - IDS_TOOLTIPS_PICKUP_HALF, // eToolTipPickUpHalf - IDS_TOOLTIPS_PLACE_GENERIC, // eToolTipPlaceGeneric - IDS_TOOLTIPS_PLACE_ONE, // eToolTipPlaceOne - IDS_TOOLTIPS_PLACE_ALL, // eToolTipPlaceAll - IDS_TOOLTIPS_DROP_GENERIC, // eToolTipDropGeneric - IDS_TOOLTIPS_DROP_ONE, // eToolTipDropOne - IDS_TOOLTIPS_DROP_ALL, // eToolTipDropAll - IDS_TOOLTIPS_SWAP, // eToolTipSwap - IDS_TOOLTIPS_QUICK_MOVE, // eToolTipQuickMove - IDS_TOOLTIPS_QUICK_MOVE_INGREDIENT, // eToolTipQuickMoveIngredient - IDS_TOOLTIPS_QUICK_MOVE_FUEL, // eToolTipQuickMoveTool - IDS_TOOLTIPS_WHAT_IS_THIS, // eToolTipWhatIsThis - IDS_TOOLTIPS_EQUIP, // eToolTipEquip - IDS_TOOLTIPS_CLEAR_QUICK_SELECT, // eToolTipClearQuickSelect - IDS_TOOLTIPS_QUICK_MOVE_TOOL, // eToolTipQuickMoveTool - IDS_TOOLTIPS_QUICK_MOVE_ARMOR, // eToolTipQuickMoveTool - IDS_TOOLTIPS_QUICK_MOVE_WEAPON, // eToolTipQuickMoveTool - IDS_TOOLTIPS_DYE, // eToolTipDye - IDS_TOOLTIPS_REPAIR, // eToolTipRepair - }; +void IUIScene_AbstractContainerMenu::UpdateTooltips() { + // Table gives us text id for tooltip. + static const int kaToolTipextIds[eNumToolTips] = { + IDS_TOOLTIPS_PICKUPPLACE, // eToolTipPickupPlace_OLD + IDS_TOOLTIPS_EXIT, // eToolTipExit + IDS_TOOLTIPS_PICKUP_GENERIC, // eToolTipPickUpGeneric + IDS_TOOLTIPS_PICKUP_ALL, // eToolTipPickUpAll + IDS_TOOLTIPS_PICKUP_HALF, // eToolTipPickUpHalf + IDS_TOOLTIPS_PLACE_GENERIC, // eToolTipPlaceGeneric + IDS_TOOLTIPS_PLACE_ONE, // eToolTipPlaceOne + IDS_TOOLTIPS_PLACE_ALL, // eToolTipPlaceAll + IDS_TOOLTIPS_DROP_GENERIC, // eToolTipDropGeneric + IDS_TOOLTIPS_DROP_ONE, // eToolTipDropOne + IDS_TOOLTIPS_DROP_ALL, // eToolTipDropAll + IDS_TOOLTIPS_SWAP, // eToolTipSwap + IDS_TOOLTIPS_QUICK_MOVE, // eToolTipQuickMove + IDS_TOOLTIPS_QUICK_MOVE_INGREDIENT, // eToolTipQuickMoveIngredient + IDS_TOOLTIPS_QUICK_MOVE_FUEL, // eToolTipQuickMoveTool + IDS_TOOLTIPS_WHAT_IS_THIS, // eToolTipWhatIsThis + IDS_TOOLTIPS_EQUIP, // eToolTipEquip + IDS_TOOLTIPS_CLEAR_QUICK_SELECT, // eToolTipClearQuickSelect + IDS_TOOLTIPS_QUICK_MOVE_TOOL, // eToolTipQuickMoveTool + IDS_TOOLTIPS_QUICK_MOVE_ARMOR, // eToolTipQuickMoveTool + IDS_TOOLTIPS_QUICK_MOVE_WEAPON, // eToolTipQuickMoveTool + IDS_TOOLTIPS_DYE, // eToolTipDye + IDS_TOOLTIPS_REPAIR, // eToolTipRepair + }; - int focusUser = getPad(); + int focusUser = getPad(); - for ( int i = 0; i < eToolTipNumButtons; ++i ) - { - if ( m_aeToolTipSettings[ i ] == eToolTipNone ) - { - ui.ShowTooltip( focusUser, i, false ); - } - else - { - ui.SetTooltipText( focusUser, i, kaToolTipextIds[ m_aeToolTipSettings[ i ] ] ); - ui.ShowTooltip( focusUser, i, true ); - } - } + for (int i = 0; i < eToolTipNumButtons; ++i) { + if (m_aeToolTipSettings[i] == eToolTipNone) { + ui.ShowTooltip(focusUser, i, false); + } else { + ui.SetTooltipText(focusUser, i, + kaToolTipextIds[m_aeToolTipSettings[i]]); + ui.ShowTooltip(focusUser, i, true); + } + } } -void IUIScene_AbstractContainerMenu::onMouseTick() -{ - Minecraft *pMinecraft = Minecraft::GetInstance(); - if( pMinecraft->localgameModes[getPad()] != NULL) - { - Tutorial *tutorial = pMinecraft->localgameModes[getPad()]->getTutorial(); - if(tutorial != NULL) - { - if(ui.IsTutorialVisible(getPad()) && !tutorial->isInputAllowed(ACTION_MENU_UP)) - { - return; - } - } - } +void IUIScene_AbstractContainerMenu::onMouseTick() { + Minecraft* pMinecraft = Minecraft::GetInstance(); + if (pMinecraft->localgameModes[getPad()] != NULL) { + Tutorial* tutorial = + pMinecraft->localgameModes[getPad()]->getTutorial(); + if (tutorial != NULL) { + if (ui.IsTutorialVisible(getPad()) && + !tutorial->isInputAllowed(ACTION_MENU_UP)) { + return; + } + } + } - // Offset to display carried item attached to pointer. - // static const float kfCarriedItemOffsetX = -5.0f; - // static const float kfCarriedItemOffsetY = -5.0f; - float fInputDirX=0.0f; - float fInputDirY=0.0f; + // Offset to display carried item attached to pointer. + // static const float kfCarriedItemOffsetX = -5.0f; + // static const float kfCarriedItemOffsetY = -5.0f; + float fInputDirX = 0.0f; + float fInputDirY = 0.0f; - // Get current pointer position. - UIVec2D vPointerPos = m_pointerPos; + // Get current pointer position. + UIVec2D vPointerPos = m_pointerPos; - // Offset to image centre. - vPointerPos.x += m_fPointerImageOffsetX; - vPointerPos.y += m_fPointerImageOffsetY; + // Offset to image centre. + vPointerPos.x += m_fPointerImageOffsetX; + vPointerPos.y += m_fPointerImageOffsetY; - // Get stick input. - int iPad = getPad(); + // Get stick input. + int iPad = getPad(); - bool bStickInput = false; - float fInputX = InputManager.GetJoypadStick_LX( iPad, false )*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f); // apply the sensitivity - float fInputY = InputManager.GetJoypadStick_LY( iPad, false )*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f); // apply the sensitivity + bool bStickInput = false; + float fInputX = + InputManager.GetJoypadStick_LX(iPad, false) * + ((float)app.GetGameSettings(iPad, eGameSetting_Sensitivity_InMenu) / + 100.0f); // apply the sensitivity + float fInputY = + InputManager.GetJoypadStick_LY(iPad, false) * + ((float)app.GetGameSettings(iPad, eGameSetting_Sensitivity_InMenu) / + 100.0f); // apply the sensitivity #ifdef __ORBIS__ - // should have sensitivity for the touchpad - //(float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_TouchPadInMenu)/100.0f + // should have sensitivity for the touchpad + //(float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_TouchPadInMenu)/100.0f - // get the touchpad input and treat it as a map to the window - ScePadTouchData *pTouchPadData=InputManager.GetTouchPadData(iPad); + // get the touchpad input and treat it as a map to the window + ScePadTouchData* pTouchPadData = InputManager.GetTouchPadData(iPad); - // make sure the touchpad button isn't down (it's the pausemenu) + // make sure the touchpad button isn't down (it's the pausemenu) - if((!InputManager.ButtonDown(iPad, ACTION_MENU_TOUCHPAD_PRESS)) && (pTouchPadData->touchNum>0)) - { - if(m_bFirstTouchStored[iPad]==false) - { - m_oldvTouchPos.x=(float)pTouchPadData->touch[0].x; - m_oldvTouchPos.y=(float)pTouchPadData->touch[0].y; - m_oldvPointerPos.x=vPointerPos.x; - m_oldvPointerPos.y=vPointerPos.y; - m_bFirstTouchStored[iPad]=true; - } + if ((!InputManager.ButtonDown(iPad, ACTION_MENU_TOUCHPAD_PRESS)) && + (pTouchPadData->touchNum > 0)) { + if (m_bFirstTouchStored[iPad] == false) { + m_oldvTouchPos.x = (float)pTouchPadData->touch[0].x; + m_oldvTouchPos.y = (float)pTouchPadData->touch[0].y; + m_oldvPointerPos.x = vPointerPos.x; + m_oldvPointerPos.y = vPointerPos.y; + m_bFirstTouchStored[iPad] = true; + } - // should take the average of multiple touch points + // should take the average of multiple touch points - float fNewX=(((float)pTouchPadData->touch[0].x)-m_oldvTouchPos.x) * m_fTouchPadMulX; - float fNewY=(((float)pTouchPadData->touch[0].y)-m_oldvTouchPos.y) * m_fTouchPadMulY; - // relative positions - needs a deadzone + float fNewX = (((float)pTouchPadData->touch[0].x) - m_oldvTouchPos.x) * + m_fTouchPadMulX; + float fNewY = (((float)pTouchPadData->touch[0].y) - m_oldvTouchPos.y) * + m_fTouchPadMulY; + // relative positions - needs a deadzone - if(fNewX>m_fTouchPadDeadZoneX) - { - vPointerPos.x=m_oldvPointerPos.x+((fNewX-m_fTouchPadDeadZoneX)*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f)); - } - else if(fNewX<-m_fTouchPadDeadZoneX) - { - vPointerPos.x=m_oldvPointerPos.x+((fNewX+m_fTouchPadDeadZoneX)*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f)); - } + if (fNewX > m_fTouchPadDeadZoneX) { + vPointerPos.x = m_oldvPointerPos.x + + ((fNewX - m_fTouchPadDeadZoneX) * + ((float)app.GetGameSettings( + iPad, eGameSetting_Sensitivity_InMenu) / + 100.0f)); + } else if (fNewX < -m_fTouchPadDeadZoneX) { + vPointerPos.x = m_oldvPointerPos.x + + ((fNewX + m_fTouchPadDeadZoneX) * + ((float)app.GetGameSettings( + iPad, eGameSetting_Sensitivity_InMenu) / + 100.0f)); + } - if(fNewY>m_fTouchPadDeadZoneY) - { - vPointerPos.y=m_oldvPointerPos.y+((fNewY-m_fTouchPadDeadZoneY)*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f)); - } - else if(fNewY<-m_fTouchPadDeadZoneY) - { - vPointerPos.y=m_oldvPointerPos.y+((fNewY+m_fTouchPadDeadZoneY)*((float)app.GetGameSettings(iPad,eGameSetting_Sensitivity_InMenu)/100.0f)); - } + if (fNewY > m_fTouchPadDeadZoneY) { + vPointerPos.y = m_oldvPointerPos.y + + ((fNewY - m_fTouchPadDeadZoneY) * + ((float)app.GetGameSettings( + iPad, eGameSetting_Sensitivity_InMenu) / + 100.0f)); + } else if (fNewY < -m_fTouchPadDeadZoneY) { + vPointerPos.y = m_oldvPointerPos.y + + ((fNewY + m_fTouchPadDeadZoneY) * + ((float)app.GetGameSettings( + iPad, eGameSetting_Sensitivity_InMenu) / + 100.0f)); + } - // Clamp to pointer extents. - if ( vPointerPos.x < m_fPointerMinX ) vPointerPos.x = m_fPointerMinX; - else if ( vPointerPos.x > m_fPointerMaxX ) vPointerPos.x = m_fPointerMaxX; - if ( vPointerPos.y < m_fPointerMinY ) vPointerPos.y = m_fPointerMinY; - else if ( vPointerPos.y > m_fPointerMaxY ) vPointerPos.y = m_fPointerMaxY; + // Clamp to pointer extents. + if (vPointerPos.x < m_fPointerMinX) + vPointerPos.x = m_fPointerMinX; + else if (vPointerPos.x > m_fPointerMaxX) + vPointerPos.x = m_fPointerMaxX; + if (vPointerPos.y < m_fPointerMinY) + vPointerPos.y = m_fPointerMinY; + else if (vPointerPos.y > m_fPointerMaxY) + vPointerPos.y = m_fPointerMaxY; - bStickInput = true; - m_eCurrTapState=eTapStateNoInput; - } - else - { - // reset the touch flag - m_bFirstTouchStored[iPad]=false; + bStickInput = true; + m_eCurrTapState = eTapStateNoInput; + } else { + // reset the touch flag + m_bFirstTouchStored[iPad] = false; #endif - - - // If there is any input on sticks, move the pointer. - if ( ( fabs( fInputX ) >= 0.01f ) || ( fabs( fInputY ) >= 0.01f ) ) - { - fInputDirX = ( fInputX > 0.0f ) ? 1.0f : ( fInputX < 0.0f )?-1.0f : 0.0f; - fInputDirY = ( fInputY > 0.0f ) ? 1.0f : ( fInputY < 0.0f )?-1.0f : 0.0f; + // If there is any input on sticks, move the pointer. + if ((fabs(fInputX) >= 0.01f) || (fabs(fInputY) >= 0.01f)) { + fInputDirX = (fInputX > 0.0f) ? 1.0f + : (fInputX < 0.0f) ? -1.0f + : 0.0f; + fInputDirY = (fInputY > 0.0f) ? 1.0f + : (fInputY < 0.0f) ? -1.0f + : 0.0f; #ifdef TAP_DETECTION - // Check for potential tap input to jump slot. - ETapState eNewTapInput = GetTapInputType( fInputX, fInputY ); + // Check for potential tap input to jump slot. + ETapState eNewTapInput = GetTapInputType(fInputX, fInputY); - switch( m_eCurrTapState ) - { - case eTapStateNoInput: - m_eCurrTapState = eNewTapInput; - break; + switch (m_eCurrTapState) { + case eTapStateNoInput: + m_eCurrTapState = eNewTapInput; + break; - case eTapStateUp: - case eTapStateDown: - case eTapStateLeft: - case eTapStateRight: - if ( ( eNewTapInput != m_eCurrTapState ) && ( eNewTapInput != eTapStateNoInput ) ) - { - // Input is no longer suitable for tap. - m_eCurrTapState = eTapNone; - } - break; + case eTapStateUp: + case eTapStateDown: + case eTapStateLeft: + case eTapStateRight: + if ((eNewTapInput != m_eCurrTapState) && + (eNewTapInput != eTapStateNoInput)) { + // Input is no longer suitable for tap. + m_eCurrTapState = eTapNone; + } + break; - case eTapNone: - /// Nothing to do, input is not a tap. - break; - default: - break; - } -#endif // TAP_DETECTION + case eTapNone: + /// Nothing to do, input is not a tap. + break; + default: + break; + } +#endif // TAP_DETECTION - // Square it so we get more precision for small inputs. - fInputX = fInputX * fInputX * fInputDirX * POINTER_SPEED_FACTOR; - fInputY = fInputY * fInputY * fInputDirY * POINTER_SPEED_FACTOR; - //fInputX = fInputX * POINTER_SPEED_FACTOR; - //fInputY = fInputY * POINTER_SPEED_FACTOR; - float fInputScale = 1.0f; + // Square it so we get more precision for small inputs. + fInputX = fInputX * fInputX * fInputDirX * POINTER_SPEED_FACTOR; + fInputY = fInputY * fInputY * fInputDirY * POINTER_SPEED_FACTOR; + // fInputX = fInputX * POINTER_SPEED_FACTOR; + // fInputY = fInputY * POINTER_SPEED_FACTOR; + float fInputScale = 1.0f; - // Ramp up input from zero when new input is recieved over INPUT_TICKS_FOR_SCALING ticks. This is to try to improve tapping stick to move 1 box. - if ( m_iConsectiveInputTicks < MAX_INPUT_TICKS_FOR_SCALING ) - { - ++m_iConsectiveInputTicks; - fInputScale = ( (float)( m_iConsectiveInputTicks) / (float)(MAX_INPUT_TICKS_FOR_SCALING) ); - } + // Ramp up input from zero when new input is recieved over + // INPUT_TICKS_FOR_SCALING ticks. This is to try to improve tapping + // stick to move 1 box. + if (m_iConsectiveInputTicks < MAX_INPUT_TICKS_FOR_SCALING) { + ++m_iConsectiveInputTicks; + fInputScale = ((float)(m_iConsectiveInputTicks) / + (float)(MAX_INPUT_TICKS_FOR_SCALING)); + } #ifdef TAP_DETECTION - else if ( m_iConsectiveInputTicks < MAX_INPUT_TICKS_FOR_TAPPING ) - { - ++m_iConsectiveInputTicks; - } - else - { - m_eCurrTapState = eTapNone; - } + else if (m_iConsectiveInputTicks < MAX_INPUT_TICKS_FOR_TAPPING) { + ++m_iConsectiveInputTicks; + } else { + m_eCurrTapState = eTapNone; + } #endif - // 4J Stu - The cursor moves too fast in SD mode - // The SD/splitscreen scenes are approximately 0.6 times the size of the fullscreen on - if(!RenderManager.IsHiDef() || app.GetLocalPlayerCount() > 1) fInputScale *= 0.6f; + // 4J Stu - The cursor moves too fast in SD mode + // The SD/splitscreen scenes are approximately 0.6 times the size of + // the fullscreen on + if (!RenderManager.IsHiDef() || app.GetLocalPlayerCount() > 1) + fInputScale *= 0.6f; - fInputX *= fInputScale; - fInputY *= fInputScale; + fInputX *= fInputScale; + fInputY *= fInputScale; -#ifdef USE_POINTER_ACCEL - m_fPointerAccelX += fInputX / 50.0f; - m_fPointerAccelY += fInputY / 50.0f; +#ifdef USE_POINTER_ACCEL + m_fPointerAccelX += fInputX / 50.0f; + m_fPointerAccelY += fInputY / 50.0f; - if ( fabsf( fInputX ) > fabsf( m_fPointerVelX + m_fPointerAccelX ) ) - { - m_fPointerVelX += m_fPointerAccelX; - } - else - { - m_fPointerAccelX = fInputX - m_fPointerVelX; - m_fPointerVelX = fInputX; - } + if (fabsf(fInputX) > fabsf(m_fPointerVelX + m_fPointerAccelX)) { + m_fPointerVelX += m_fPointerAccelX; + } else { + m_fPointerAccelX = fInputX - m_fPointerVelX; + m_fPointerVelX = fInputX; + } - if ( fabsf( fInputY ) > fabsf( m_fPointerVelY + m_fPointerAccelY ) ) - { - m_fPointerVelY += m_fPointerAccelY; - } - else - { - m_fPointerAccelY = fInputY - m_fPointerVelY; - m_fPointerVelY = fInputY; - } - //printf( "IN %.2f VEL %.2f ACC %.2f\n", fInputY, m_fPointerVelY, m_fPointerAccelY ); + if (fabsf(fInputY) > fabsf(m_fPointerVelY + m_fPointerAccelY)) { + m_fPointerVelY += m_fPointerAccelY; + } else { + m_fPointerAccelY = fInputY - m_fPointerVelY; + m_fPointerVelY = fInputY; + } + // printf( "IN %.2f VEL %.2f ACC %.2f\n", fInputY, m_fPointerVelY, + // m_fPointerAccelY ); - vPointerPos.x += m_fPointerVelX; - vPointerPos.y -= m_fPointerVelY; + vPointerPos.x += m_fPointerVelX; + vPointerPos.y -= m_fPointerVelY; #else - // Add input to pointer position. - vPointerPos.x += fInputX; - vPointerPos.y -= fInputY; + // Add input to pointer position. + vPointerPos.x += fInputX; + vPointerPos.y -= fInputY; #endif - // Clamp to pointer extents. - if ( vPointerPos.x < m_fPointerMinX ) vPointerPos.x = m_fPointerMinX; - else if ( vPointerPos.x > m_fPointerMaxX ) vPointerPos.x = m_fPointerMaxX; - if ( vPointerPos.y < m_fPointerMinY ) vPointerPos.y = m_fPointerMinY; - else if ( vPointerPos.y > m_fPointerMaxY ) vPointerPos.y = m_fPointerMaxY; + // Clamp to pointer extents. + if (vPointerPos.x < m_fPointerMinX) + vPointerPos.x = m_fPointerMinX; + else if (vPointerPos.x > m_fPointerMaxX) + vPointerPos.x = m_fPointerMaxX; + if (vPointerPos.y < m_fPointerMinY) + vPointerPos.y = m_fPointerMinY; + else if (vPointerPos.y > m_fPointerMaxY) + vPointerPos.y = m_fPointerMaxY; - bStickInput = true; - } - else - { - m_iConsectiveInputTicks = 0; -#ifdef USE_POINTER_ACCEL - m_fPointerVelX = 0.0f; - m_fPointerVelY = 0.0f; - m_fPointerAccelX = 0.0f; - m_fPointerAccelY = 0.0f; -#endif - } + bStickInput = true; + } else { + m_iConsectiveInputTicks = 0; +#ifdef USE_POINTER_ACCEL + m_fPointerVelX = 0.0f; + m_fPointerVelY = 0.0f; + m_fPointerAccelX = 0.0f; + m_fPointerAccelY = 0.0f; +#endif + } #ifdef __ORBIS__ - } + } #endif - // Determine which slot the pointer is currently over. - ESceneSection eSectionUnderPointer = eSectionNone; - int iNewSlotX = -1; - int iNewSlotY = -1; - int iNewSlotIndex = -1; - bool bPointerIsOverSlot = false; + // Determine which slot the pointer is currently over. + ESceneSection eSectionUnderPointer = eSectionNone; + int iNewSlotX = -1; + int iNewSlotY = -1; + int iNewSlotIndex = -1; + bool bPointerIsOverSlot = false; - // Centre position of item under pointer, use this to snap pointer to item. - D3DXVECTOR3 vSnapPos; + // Centre position of item under pointer, use this to snap pointer to item. + D3DXVECTOR3 vSnapPos; - for ( int iSection = m_eFirstSection; iSection < m_eMaxSection; ++iSection ) - { - // Do not check any further if we have already found the item under the pointer. - if(m_eCurrTapState == eTapStateJump) - { - eSectionUnderPointer = m_eCurrSection; - } - else if ( eSectionUnderPointer == eSectionNone ) - { - ESceneSection eSection = ( ESceneSection )( iSection ); + for (int iSection = m_eFirstSection; iSection < m_eMaxSection; ++iSection) { + // Do not check any further if we have already found the item under the + // pointer. + if (m_eCurrTapState == eTapStateJump) { + eSectionUnderPointer = m_eCurrSection; + } else if (eSectionUnderPointer == eSectionNone) { + ESceneSection eSection = (ESceneSection)(iSection); - // Get position of this section. - UIVec2D sectionPos; - GetPositionOfSection( eSection, &( sectionPos ) ); + // Get position of this section. + UIVec2D sectionPos; + GetPositionOfSection(eSection, &(sectionPos)); - if(!IsSectionSlotList(eSection)) - { - UIVec2D itemPos; - UIVec2D itemSize; - GetItemScreenData( eSection, 0, &( itemPos ), &( itemSize ) ); + if (!IsSectionSlotList(eSection)) { + UIVec2D itemPos; + UIVec2D itemSize; + GetItemScreenData(eSection, 0, &(itemPos), &(itemSize)); - UIVec2D itemMax = itemSize; - itemMax += itemPos; + UIVec2D itemMax = itemSize; + itemMax += itemPos; - if ( ( vPointerPos.x >= sectionPos.x ) && ( vPointerPos.x <= itemMax.x ) && - ( vPointerPos.y >= sectionPos.y ) && ( vPointerPos.y <= itemMax.y ) ) - { - // Pointer is over this control! - eSectionUnderPointer = eSection; + if ((vPointerPos.x >= sectionPos.x) && + (vPointerPos.x <= itemMax.x) && + (vPointerPos.y >= sectionPos.y) && + (vPointerPos.y <= itemMax.y)) { + // Pointer is over this control! + eSectionUnderPointer = eSection; - vSnapPos.x = itemPos.x + ( itemSize.x / 2.0f ); - vSnapPos.y = itemPos.y + ( itemSize.y / 2.0f ); + vSnapPos.x = itemPos.x + (itemSize.x / 2.0f); + vSnapPos.y = itemPos.y + (itemSize.y / 2.0f); - // Does this section already have focus. - if ( !doesSectionTreeHaveFocus( eSection ) ) - { - // Give focus to this section. - setSectionFocus(eSection, getPad()); - } + // Does this section already have focus. + if (!doesSectionTreeHaveFocus(eSection)) { + // Give focus to this section. + setSectionFocus(eSection, getPad()); + } - bPointerIsOverSlot = false; + bPointerIsOverSlot = false; - // Have we actually changed slot? If so, input cannot be a tap. - if ( ( eSectionUnderPointer != m_eCurrSection ) || ( iNewSlotX != m_iCurrSlotX ) || ( iNewSlotY != m_iCurrSlotY ) ) - { - m_eCurrTapState = eTapNone; - } + // Have we actually changed slot? If so, input cannot be a + // tap. + if ((eSectionUnderPointer != m_eCurrSection) || + (iNewSlotX != m_iCurrSlotX) || + (iNewSlotY != m_iCurrSlotY)) { + m_eCurrTapState = eTapNone; + } - // Store what is currently under the pointer. - m_eCurrSection = eSectionUnderPointer; - } - } - else - { + // Store what is currently under the pointer. + m_eCurrSection = eSectionUnderPointer; + } + } else { + // Get dimensions of this section. + int iNumRows; + int iNumColumns; + int iNumItems = + GetSectionDimensions(eSection, &(iNumColumns), &(iNumRows)); - // Get dimensions of this section. - int iNumRows; - int iNumColumns; - int iNumItems = GetSectionDimensions( eSection, &( iNumColumns ), &( iNumRows ) ); + // Check each item to see if pointer is over it. + for (int iItem = 0; iItem < iNumItems; ++iItem) { + UIVec2D itemPos; + UIVec2D itemSize; + GetItemScreenData(eSection, iItem, &(itemPos), &(itemSize)); - // Check each item to see if pointer is over it. - for ( int iItem = 0; iItem < iNumItems; ++iItem ) - { - UIVec2D itemPos; - UIVec2D itemSize; - GetItemScreenData( eSection, iItem, &( itemPos ), &( itemSize ) ); + itemPos += sectionPos; - itemPos += sectionPos; + UIVec2D itemMax = itemSize; + itemMax += itemPos; - UIVec2D itemMax = itemSize; - itemMax += itemPos; + if ((vPointerPos.x >= itemPos.x) && + (vPointerPos.x <= itemMax.x) && + (vPointerPos.y >= itemPos.y) && + (vPointerPos.y <= itemMax.y)) { + // Pointer is over this slot! + eSectionUnderPointer = eSection; + iNewSlotIndex = iItem; + iNewSlotX = iNewSlotIndex % iNumColumns; + iNewSlotY = iNewSlotIndex / iNumColumns; - if ( ( vPointerPos.x >= itemPos.x ) && ( vPointerPos.x <= itemMax.x ) && - ( vPointerPos.y >= itemPos.y ) && ( vPointerPos.y <= itemMax.y ) ) - { - // Pointer is over this slot! - eSectionUnderPointer = eSection; - iNewSlotIndex = iItem; - iNewSlotX = iNewSlotIndex % iNumColumns; - iNewSlotY = iNewSlotIndex / iNumColumns; + vSnapPos.x = itemPos.x + (itemSize.x / 2.0f); + vSnapPos.y = itemPos.y + (itemSize.y / 2.0f); - vSnapPos.x = itemPos.x + ( itemSize.x / 2.0f ); - vSnapPos.y = itemPos.y + ( itemSize.y / 2.0f ); + // Does this section already have focus. + if (!doesSectionTreeHaveFocus(eSection)) { + // Give focus to this section. + setSectionFocus(eSection, getPad()); + } - // Does this section already have focus. - if ( !doesSectionTreeHaveFocus( eSection ) ) - { - // Give focus to this section. - setSectionFocus(eSection, getPad()); - } + // Set the highlight marker. + setSectionSelectedSlot(eSection, iNewSlotX, iNewSlotY); - // Set the highlight marker. - setSectionSelectedSlot(eSection, iNewSlotX, iNewSlotY ); - - bPointerIsOverSlot = true; + bPointerIsOverSlot = true; #ifdef TAP_DETECTION - // Have we actually changed slot? If so, input cannot be a tap. - if ( ( eSectionUnderPointer != m_eCurrSection ) || ( iNewSlotX != m_iCurrSlotX ) || ( iNewSlotY != m_iCurrSlotY ) ) - { - m_eCurrTapState = eTapNone; - } + // Have we actually changed slot? If so, input cannot be + // a tap. + if ((eSectionUnderPointer != m_eCurrSection) || + (iNewSlotX != m_iCurrSlotX) || + (iNewSlotY != m_iCurrSlotY)) { + m_eCurrTapState = eTapNone; + } - // Store what is currently under the pointer. - m_eCurrSection = eSectionUnderPointer; - m_iCurrSlotX = iNewSlotX; - m_iCurrSlotY = iNewSlotY; -#endif // TAP_DETECTION - // No need to check any further slots, the pointer can only ever be over one. - break; - } - } - } - } - } + // Store what is currently under the pointer. + m_eCurrSection = eSectionUnderPointer; + m_iCurrSlotX = iNewSlotX; + m_iCurrSlotY = iNewSlotY; +#endif // TAP_DETECTION + // No need to check any further slots, the pointer can only ever be over + // one. + break; + } + } + } + } + } - // If we are not over any slot, set focus elsewhere. - if ( eSectionUnderPointer == eSectionNone ) - { - setFocusToPointer( getPad() ); + // If we are not over any slot, set focus elsewhere. + if (eSectionUnderPointer == eSectionNone) { + setFocusToPointer(getPad()); #ifdef TAP_DETECTION - // Input cannot be a tap. - m_eCurrTapState = eTapNone; + // Input cannot be a tap. + m_eCurrTapState = eTapNone; - // Store what is currently under the pointer. - m_eCurrSection = eSectionNone; - m_iCurrSlotX = -1; - m_iCurrSlotY = -1; -#endif // TAP_DETECTION - } - else - { - if ( !bStickInput ) - { - // Did we get a tap input? - int iDesiredSlotX = -1; - int iDesiredSlotY = -1; + // Store what is currently under the pointer. + m_eCurrSection = eSectionNone; + m_iCurrSlotX = -1; + m_iCurrSlotY = -1; +#endif // TAP_DETECTION + } else { + if (!bStickInput) { + // Did we get a tap input? + int iDesiredSlotX = -1; + int iDesiredSlotY = -1; - switch( m_eCurrTapState ) - { - case eTapStateUp: - iDesiredSlotX = m_iCurrSlotX; - iDesiredSlotY = m_iCurrSlotY - 1; - break; - case eTapStateDown: - iDesiredSlotX = m_iCurrSlotX; - iDesiredSlotY = m_iCurrSlotY + 1; - break; - case eTapStateLeft: - iDesiredSlotX = m_iCurrSlotX - 1; - iDesiredSlotY = m_iCurrSlotY; - break; - case eTapStateRight: - iDesiredSlotX = m_iCurrSlotX + 1; - iDesiredSlotY = m_iCurrSlotY; - break; - case eTapStateJump: - iDesiredSlotX = m_iCurrSlotX; - iDesiredSlotY = m_iCurrSlotY; - break; - default: - break; - } + switch (m_eCurrTapState) { + case eTapStateUp: + iDesiredSlotX = m_iCurrSlotX; + iDesiredSlotY = m_iCurrSlotY - 1; + break; + case eTapStateDown: + iDesiredSlotX = m_iCurrSlotX; + iDesiredSlotY = m_iCurrSlotY + 1; + break; + case eTapStateLeft: + iDesiredSlotX = m_iCurrSlotX - 1; + iDesiredSlotY = m_iCurrSlotY; + break; + case eTapStateRight: + iDesiredSlotX = m_iCurrSlotX + 1; + iDesiredSlotY = m_iCurrSlotY; + break; + case eTapStateJump: + iDesiredSlotX = m_iCurrSlotX; + iDesiredSlotY = m_iCurrSlotY; + break; + default: + break; + } - int iNumRows; - int iNumColumns; - int iNumItems = GetSectionDimensions( eSectionUnderPointer, &( iNumColumns ), &( iNumRows ) ); + int iNumRows; + int iNumColumns; + int iNumItems = GetSectionDimensions(eSectionUnderPointer, + &(iNumColumns), &(iNumRows)); + if ((m_eCurrTapState != eTapNone && + m_eCurrTapState != eTapStateNoInput) && + (!IsSectionSlotList(eSectionUnderPointer) || + ((iDesiredSlotX < 0) || (iDesiredSlotX >= iNumColumns) || + (iDesiredSlotY < 0) || (iDesiredSlotY >= iNumRows)))) { + eSectionUnderPointer = GetSectionAndSlotInDirection( + eSectionUnderPointer, m_eCurrTapState, &iDesiredSlotX, + &iDesiredSlotY); - if ( (m_eCurrTapState != eTapNone && m_eCurrTapState != eTapStateNoInput) && - ( !IsSectionSlotList(eSectionUnderPointer) || - ( ( iDesiredSlotX < 0 ) || ( iDesiredSlotX >= iNumColumns ) || ( iDesiredSlotY < 0 ) || ( iDesiredSlotY >= iNumRows ) ) - )) - { + if (!IsSectionSlotList(eSectionUnderPointer)) + bPointerIsOverSlot = false; - eSectionUnderPointer = GetSectionAndSlotInDirection( eSectionUnderPointer, m_eCurrTapState, &iDesiredSlotX, &iDesiredSlotY ); + // Get the details for the new section + iNumItems = GetSectionDimensions(eSectionUnderPointer, + &(iNumColumns), &(iNumRows)); + } - if(!IsSectionSlotList(eSectionUnderPointer)) bPointerIsOverSlot = false; + if (!IsSectionSlotList(eSectionUnderPointer) || + ((iDesiredSlotX >= 0) && (iDesiredSlotX < iNumColumns) && + (iDesiredSlotY >= 0) && (iDesiredSlotY < iNumRows))) { + // Desired slot after tap input is valid, so make the jump to + // this slot. + UIVec2D sectionPos; + GetPositionOfSection(eSectionUnderPointer, &(sectionPos)); - // Get the details for the new section - iNumItems = GetSectionDimensions( eSectionUnderPointer, &( iNumColumns ), &( iNumRows ) ); - } + iNewSlotIndex = (iDesiredSlotY * iNumColumns) + iDesiredSlotX; - if ( !IsSectionSlotList(eSectionUnderPointer) || ( ( iDesiredSlotX >= 0 ) && ( iDesiredSlotX < iNumColumns ) && ( iDesiredSlotY >= 0 ) && ( iDesiredSlotY < iNumRows ) ) ) - { - // Desired slot after tap input is valid, so make the jump to this slot. - UIVec2D sectionPos; - GetPositionOfSection( eSectionUnderPointer, &( sectionPos ) ); + UIVec2D itemPos; + UIVec2D itemSize; + GetItemScreenData(eSectionUnderPointer, iNewSlotIndex, + &(itemPos), &(itemSize)); - iNewSlotIndex = ( iDesiredSlotY * iNumColumns ) + iDesiredSlotX; + if (IsSectionSlotList(eSectionUnderPointer)) + itemPos += sectionPos; - UIVec2D itemPos; - UIVec2D itemSize; - GetItemScreenData( eSectionUnderPointer, iNewSlotIndex, &( itemPos ), &( itemSize ) ); + vSnapPos.x = itemPos.x + (itemSize.x / 2.0f); + vSnapPos.y = itemPos.y + (itemSize.y / 2.0f); - if(IsSectionSlotList(eSectionUnderPointer)) itemPos += sectionPos; + m_eCurrSection = eSectionUnderPointer; + m_iCurrSlotX = iDesiredSlotX; + m_iCurrSlotY = iDesiredSlotY; + } - vSnapPos.x = itemPos.x + ( itemSize.x / 2.0f); - vSnapPos.y = itemPos.y + ( itemSize.y / 2.0f); + m_eCurrTapState = eTapStateNoInput; - m_eCurrSection = eSectionUnderPointer; - m_iCurrSlotX = iDesiredSlotX; - m_iCurrSlotY = iDesiredSlotY; - } + // If there is no stick input, and we are over a slot, then snap + // pointer to slot centre. 4J - TomK - only if this particular + // component allows so! + if (CanHaveFocus(eSectionUnderPointer)) { + vPointerPos.x = vSnapPos.x; + vPointerPos.y = vSnapPos.y; + } + } + } - m_eCurrTapState = eTapStateNoInput; + // Clamp to pointer extents. + if (vPointerPos.x < m_fPointerMinX) + vPointerPos.x = m_fPointerMinX; + else if (vPointerPos.x > m_fPointerMaxX) + vPointerPos.x = m_fPointerMaxX; + if (vPointerPos.y < m_fPointerMinY) + vPointerPos.y = m_fPointerMinY; + else if (vPointerPos.y > m_fPointerMaxY) + vPointerPos.y = m_fPointerMaxY; - // If there is no stick input, and we are over a slot, then snap pointer to slot centre. - // 4J - TomK - only if this particular component allows so! - if(CanHaveFocus(eSectionUnderPointer)) - { - vPointerPos.x = vSnapPos.x; - vPointerPos.y = vSnapPos.y; - } - } - } + // Check if the pointer is outside of the panel. + bool bPointerIsOutsidePanel = false; + if ((vPointerPos.x < m_fPanelMinX) || (vPointerPos.x > m_fPanelMaxX) || + (vPointerPos.y < m_fPanelMinY) || (vPointerPos.y > m_fPanelMaxY)) { + bPointerIsOutsidePanel = true; + } - // Clamp to pointer extents. - if ( vPointerPos.x < m_fPointerMinX ) vPointerPos.x = m_fPointerMinX; - else if ( vPointerPos.x > m_fPointerMaxX ) vPointerPos.x = m_fPointerMaxX; - if ( vPointerPos.y < m_fPointerMinY ) vPointerPos.y = m_fPointerMinY; - else if ( vPointerPos.y > m_fPointerMaxY ) vPointerPos.y = m_fPointerMaxY; + // Determine appropriate context sensitive tool tips, based on what is + // carried on the pointer and what is under the pointer. - // Check if the pointer is outside of the panel. - bool bPointerIsOutsidePanel = false; - if ( ( vPointerPos.x < m_fPanelMinX ) || ( vPointerPos.x > m_fPanelMaxX ) || ( vPointerPos.y < m_fPanelMinY ) || ( vPointerPos.y > m_fPanelMaxY ) ) - { - bPointerIsOutsidePanel = true; - } + // What are we carrying on pointer. + std::shared_ptr player = + Minecraft::GetInstance()->localplayers[getPad()]; + std::shared_ptr carriedItem = nullptr; + if (player != NULL) carriedItem = player->inventory->getCarried(); - // Determine appropriate context sensitive tool tips, based on what is carried on the pointer and what is under the pointer. + std::shared_ptr slotItem = nullptr; + Slot* slot = NULL; + int slotIndex = 0; + if (bPointerIsOverSlot) { + slotIndex = iNewSlotIndex + getSectionStartOffset(eSectionUnderPointer); + slot = m_menu->getSlot(slotIndex); + } + bool bIsItemCarried = carriedItem != NULL; + int iCarriedCount = 0; + bool bCarriedIsSameAsSlot = false; // Indicates if same item is carried on + // pointer as is in slot under pointer. + if (bIsItemCarried) { + iCarriedCount = carriedItem->count; + } - // What are we carrying on pointer. - std::shared_ptr player = Minecraft::GetInstance()->localplayers[getPad()]; - std::shared_ptr carriedItem = nullptr; - if(player != NULL) carriedItem = player->inventory->getCarried(); + // What is in the slot that we are over. + bool bSlotHasItem = false; + bool bMayPlace = false; + bool bCanPlaceOne = false; + bool bCanPlaceAll = false; + bool bCanCombine = false; + bool bCanDye = false; + int iSlotCount = 0; + int iSlotStackSizeRemaining = + 0; // How many more items can be stacked on this slot. + if (bPointerIsOverSlot) { + slotItem = slot->getItem(); + bSlotHasItem = slotItem != NULL; + if (bSlotHasItem) { + iSlotCount = slotItem->GetCount(); - std::shared_ptr slotItem = nullptr; - Slot *slot = NULL; - int slotIndex = 0; - if(bPointerIsOverSlot) - { - slotIndex = iNewSlotIndex + getSectionStartOffset( eSectionUnderPointer ); - slot = m_menu->getSlot(slotIndex); - } - bool bIsItemCarried = carriedItem != NULL; - int iCarriedCount = 0; - bool bCarriedIsSameAsSlot = false; // Indicates if same item is carried on pointer as is in slot under pointer. - if ( bIsItemCarried ) - { - iCarriedCount = carriedItem->count; - } + if (bIsItemCarried) { + bCarriedIsSameAsSlot = IsSameItemAs(carriedItem, slotItem); + bCanCombine = m_menu->mayCombine(slot, carriedItem); + bCanDye = bCanCombine && + dynamic_cast(slot->getItem()->getItem()); - // What is in the slot that we are over. - bool bSlotHasItem = false; - bool bMayPlace = false; - bool bCanPlaceOne = false; - bool bCanPlaceAll = false; - bool bCanCombine = false; - bool bCanDye = false; - int iSlotCount = 0; - int iSlotStackSizeRemaining = 0; // How many more items can be stacked on this slot. - if ( bPointerIsOverSlot ) - { - slotItem = slot->getItem(); - bSlotHasItem = slotItem != NULL; - if ( bSlotHasItem ) - { - iSlotCount = slotItem->GetCount(); + if (bCarriedIsSameAsSlot) { + iSlotStackSizeRemaining = + GetEmptyStackSpace(m_menu->getSlot(slotIndex)); + } + } + } - if ( bIsItemCarried ) - { - bCarriedIsSameAsSlot = IsSameItemAs(carriedItem, slotItem); - bCanCombine = m_menu->mayCombine(slot,carriedItem); - bCanDye = bCanCombine && dynamic_cast(slot->getItem()->getItem()); + if (bIsItemCarried) { + bMayPlace = slot->mayPlace(carriedItem); - if ( bCarriedIsSameAsSlot ) - { - iSlotStackSizeRemaining = GetEmptyStackSpace( m_menu->getSlot(slotIndex) ); - } - } - } + if (bSlotHasItem) + iSlotStackSizeRemaining = GetEmptyStackSpace(slot); + else + iSlotStackSizeRemaining = slot->getMaxStackSize(); - if( bIsItemCarried) - { - bMayPlace = slot->mayPlace(carriedItem); + if (bMayPlace && iSlotStackSizeRemaining > 0) bCanPlaceOne = true; + if (bMayPlace && iSlotStackSizeRemaining > 1 && + carriedItem->count > 1) + bCanPlaceAll = true; + } + } - if ( bSlotHasItem ) iSlotStackSizeRemaining = GetEmptyStackSpace( slot ); - else iSlotStackSizeRemaining = slot->getMaxStackSize(); + if (bPointerIsOverSlot && bSlotHasItem) { + std::vector unformattedStrings; + std::wstring desc = GetItemDescription(slot, unformattedStrings); + SetPointerText(desc, unformattedStrings, + slot != m_lastPointerLabelSlot); + m_lastPointerLabelSlot = slot; + } else { + std::vector unformattedStrings; + SetPointerText(L"", unformattedStrings, false); + m_lastPointerLabelSlot = NULL; + } - if(bMayPlace && iSlotStackSizeRemaining > 0) bCanPlaceOne = true; - if(bMayPlace && iSlotStackSizeRemaining > 1 && carriedItem->count > 1) bCanPlaceAll = true; - } - } + EToolTipItem buttonA, buttonX, buttonY, buttonRT; + buttonA = buttonX = buttonY = buttonRT = eToolTipNone; + if (bPointerIsOverSlot) { + SetPointerOutsideMenu(false); + if (bIsItemCarried) { + if (bSlotHasItem) { + // Item in hand and item in slot ... is item in slot the same as + // in out hand? If so, can we stack on to it? + if (bCarriedIsSameAsSlot) { + // Can we stack more into this slot? + if (iSlotStackSizeRemaining == 0) { + // Cannot stack any more. + buttonRT = eToolTipWhatIsThis; + } else if (iSlotStackSizeRemaining == 1) { + // Can only put 1 more on the stack. + buttonA = eToolTipPlaceGeneric; + buttonRT = eToolTipWhatIsThis; + } else // can put 1 or all. + { + if (bCanPlaceAll) { + // Multiple items in hand. + buttonA = eToolTipPlaceAll; + buttonX = eToolTipPlaceOne; + } else if (bCanPlaceOne) { + if (iCarriedCount > 1) + buttonA = eToolTipPlaceOne; + else + buttonA = eToolTipPlaceGeneric; + } + buttonRT = eToolTipWhatIsThis; + } + } else // items are different, click here will swap them. + { + if (bMayPlace) buttonA = eToolTipSwap; + buttonRT = eToolTipWhatIsThis; + } + if (bCanDye) { + buttonX = eToolTipDye; + } else if (bCanCombine) { + buttonX = eToolTipRepair; + } + } else // slot empty. + { + // Item in hand, slot is empty. + if (iCarriedCount == 1) { + // Only one item in hand. + buttonA = eToolTipPlaceGeneric; + } else { + if (bCanPlaceAll) { + // Multiple items in hand. + buttonA = eToolTipPlaceAll; + buttonX = eToolTipPlaceOne; + } else if (bCanPlaceOne) { + buttonA = eToolTipPlaceOne; + } + } + } + } else // no object in hand + { + if (bSlotHasItem) { + if (iSlotCount == 1) { + buttonA = eToolTipPickUpGeneric; + buttonRT = eToolTipWhatIsThis; + } else { + // Multiple items in slot. + buttonA = eToolTipPickUpAll; + buttonX = eToolTipPickUpHalf; + buttonRT = eToolTipWhatIsThis; + } + } else { + // Nothing in slot and nothing in hand. + } + } - if( bPointerIsOverSlot && bSlotHasItem ) - { - std::vector unformattedStrings; - std::wstring desc = GetItemDescription( slot, unformattedStrings ); - SetPointerText(desc, unformattedStrings, slot != m_lastPointerLabelSlot); - m_lastPointerLabelSlot = slot; - } - else - { - std::vector unformattedStrings; - SetPointerText(L"", unformattedStrings, false); - m_lastPointerLabelSlot = NULL; - } + if (bSlotHasItem) { + // Item in slot - EToolTipItem buttonA, buttonX, buttonY, buttonRT; - buttonA = buttonX = buttonY = buttonRT = eToolTipNone; - if ( bPointerIsOverSlot ) - { - SetPointerOutsideMenu( false ); - if ( bIsItemCarried ) - { - if ( bSlotHasItem ) - { - // Item in hand and item in slot ... is item in slot the same as in out hand? If so, can we stack on to it? - if ( bCarriedIsSameAsSlot ) - { - // Can we stack more into this slot? - if ( iSlotStackSizeRemaining == 0 ) - { - // Cannot stack any more. - buttonRT = eToolTipWhatIsThis; - } - else if ( iSlotStackSizeRemaining == 1 ) - { - // Can only put 1 more on the stack. - buttonA = eToolTipPlaceGeneric; - buttonRT = eToolTipWhatIsThis; - } - else // can put 1 or all. - { - if(bCanPlaceAll) - { - // Multiple items in hand. - buttonA = eToolTipPlaceAll; - buttonX = eToolTipPlaceOne; - } - else if(bCanPlaceOne) - { - if(iCarriedCount > 1) buttonA = eToolTipPlaceOne; - else buttonA = eToolTipPlaceGeneric; - } - buttonRT = eToolTipWhatIsThis; - } - } - else // items are different, click here will swap them. - { + // 4J-PB - show tooltips for quick use of armour - if(bMayPlace) buttonA = eToolTipSwap; - buttonRT = eToolTipWhatIsThis; - } - if(bCanDye) - { - buttonX = eToolTipDye; - } - else if(bCanCombine) - { - buttonX = eToolTipRepair; - } - } - else // slot empty. - { - // Item in hand, slot is empty. - if ( iCarriedCount == 1 ) - { - // Only one item in hand. - buttonA = eToolTipPlaceGeneric; - } - else - { - if(bCanPlaceAll) - { - // Multiple items in hand. - buttonA = eToolTipPlaceAll; - buttonX = eToolTipPlaceOne; - } - else if(bCanPlaceOne) - { - buttonA = eToolTipPlaceOne; - } - } - } - } - else // no object in hand - { - if ( bSlotHasItem ) - { - if ( iSlotCount == 1 ) - { - buttonA = eToolTipPickUpGeneric; - buttonRT = eToolTipWhatIsThis; - } - else - { - // Multiple items in slot. - buttonA = eToolTipPickUpAll; - buttonX = eToolTipPickUpHalf; - buttonRT = eToolTipWhatIsThis; - } - } - else - { - // Nothing in slot and nothing in hand. - } - } + if ((eSectionUnderPointer == eSectionInventoryUsing) || + (eSectionUnderPointer == eSectionInventoryInventory)) { + std::shared_ptr item = + getSlotItem(eSectionUnderPointer, iNewSlotIndex); + ArmorRecipes::_eArmorType eArmourType = + ArmorRecipes::GetArmorType(item->id); - if ( bSlotHasItem ) - { - // Item in slot + if (eArmourType == ArmorRecipes::eArmorType_None) { + buttonY = eToolTipQuickMove; + } else { + // check that the slot required is empty + switch (eArmourType) { + case ArmorRecipes::eArmorType_Helmet: + if (isSlotEmpty(eSectionInventoryArmor, 0)) { + buttonY = eToolTipEquip; + } else { + buttonY = eToolTipQuickMove; + } + break; + case ArmorRecipes::eArmorType_Chestplate: + if (isSlotEmpty(eSectionInventoryArmor, 1)) { + buttonY = eToolTipEquip; + } else { + buttonY = eToolTipQuickMove; + } + break; + case ArmorRecipes::eArmorType_Leggings: + if (isSlotEmpty(eSectionInventoryArmor, 2)) { + buttonY = eToolTipEquip; + } else { + buttonY = eToolTipQuickMove; + } + break; + case ArmorRecipes::eArmorType_Boots: + if (isSlotEmpty(eSectionInventoryArmor, 3)) { + buttonY = eToolTipEquip; + } else { + buttonY = eToolTipQuickMove; + } + break; + default: + buttonY = eToolTipQuickMove; + break; + } + } + } + // 4J-PB - show tooltips for quick use of fuel or ingredient + else if ((eSectionUnderPointer == eSectionFurnaceUsing) || + (eSectionUnderPointer == eSectionFurnaceInventory)) { + // Get the info on this item. + std::shared_ptr item = + getSlotItem(eSectionUnderPointer, iNewSlotIndex); + bool bValidFuel = FurnaceTileEntity::isFuel(item); + bool bValidIngredient = + FurnaceRecipes::getInstance()->getResult( + item->getItem()->id) != NULL; - // 4J-PB - show tooltips for quick use of armour + if (bValidIngredient) { + // is there already something in the ingredient slot? + if (!isSlotEmpty(eSectionFurnaceIngredient, 0)) { + // is it the same as this item + std::shared_ptr IngredientItem = + getSlotItem(eSectionFurnaceIngredient, 0); + if (IngredientItem->id == item->id) { + buttonY = eToolTipQuickMoveIngredient; + } else { + if (FurnaceRecipes::getInstance()->getResult( + item->id) == NULL) { + buttonY = eToolTipQuickMove; + } else { + buttonY = eToolTipQuickMoveIngredient; + } + } + } else { + // ingredient slot empty + buttonY = eToolTipQuickMoveIngredient; + } + } else if (bValidFuel) { + // Is there already something in the fuel slot? + if (!isSlotEmpty(eSectionFurnaceFuel, 0)) { + // is it the same as this item + std::shared_ptr fuelItem = + getSlotItem(eSectionFurnaceFuel, 0); + if (fuelItem->id == item->id) { + buttonY = eToolTipQuickMoveFuel; + } else if (bValidIngredient) { + // check if the ingredient slot is empty, or the + // same as this + if (!isSlotEmpty(eSectionFurnaceIngredient, 0)) { + // is it the same as this item + std::shared_ptr IngredientItem = + getSlotItem(eSectionFurnaceIngredient, 0); + if (IngredientItem->id == item->id) { + buttonY = eToolTipQuickMoveIngredient; + } else { + if (FurnaceRecipes::getInstance() + ->getResult(item->id) == NULL) { + buttonY = eToolTipQuickMove; + } else { + buttonY = eToolTipQuickMoveIngredient; + } + } + } else { + // ingredient slot empty + buttonY = eToolTipQuickMoveIngredient; + } + } else { + buttonY = eToolTipQuickMove; + } + } else { + buttonY = eToolTipQuickMoveFuel; + } + } else { + buttonY = eToolTipQuickMove; + } + } + // 4J-PB - show tooltips for quick use of ingredients in brewing + else if ((eSectionUnderPointer == eSectionBrewingUsing) || + (eSectionUnderPointer == eSectionBrewingInventory)) { + // Get the info on this item. + std::shared_ptr item = + getSlotItem(eSectionUnderPointer, iNewSlotIndex); + int iId = item->id; - if((eSectionUnderPointer==eSectionInventoryUsing)||(eSectionUnderPointer==eSectionInventoryInventory)) - { - std::shared_ptr item = getSlotItem(eSectionUnderPointer, iNewSlotIndex); - ArmorRecipes::_eArmorType eArmourType=ArmorRecipes::GetArmorType(item->id); + // valid ingredient? + bool bValidIngredient = false; + // bool bValidIngredientBottom=false; - if(eArmourType==ArmorRecipes::eArmorType_None) - { - buttonY = eToolTipQuickMove; - } - else - { - // check that the slot required is empty - switch(eArmourType) - { - case ArmorRecipes::eArmorType_Helmet: - if(isSlotEmpty(eSectionInventoryArmor,0)) - { - buttonY = eToolTipEquip; - } - else - { - buttonY = eToolTipQuickMove; - } - break; - case ArmorRecipes::eArmorType_Chestplate: - if(isSlotEmpty(eSectionInventoryArmor,1)) - { - buttonY = eToolTipEquip; - } - else - { - buttonY = eToolTipQuickMove; - } - break; - case ArmorRecipes::eArmorType_Leggings: - if(isSlotEmpty(eSectionInventoryArmor,2)) - { - buttonY = eToolTipEquip; - } - else - { - buttonY = eToolTipQuickMove; - } - break; - case ArmorRecipes::eArmorType_Boots: - if(isSlotEmpty(eSectionInventoryArmor,3)) - { - buttonY = eToolTipEquip; - } - else - { - buttonY = eToolTipQuickMove; - } - break; - default: - buttonY = eToolTipQuickMove; - break; - } + if (Item::items[iId]->hasPotionBrewingFormula() || + (iId == Item::netherStalkSeeds_Id)) { + bValidIngredient = true; + } - } - } - // 4J-PB - show tooltips for quick use of fuel or ingredient - else if((eSectionUnderPointer==eSectionFurnaceUsing)||(eSectionUnderPointer==eSectionFurnaceInventory)) - { - // Get the info on this item. - std::shared_ptr item = getSlotItem(eSectionUnderPointer, iNewSlotIndex); - bool bValidFuel = FurnaceTileEntity::isFuel(item); - bool bValidIngredient = FurnaceRecipes::getInstance()->getResult(item->getItem()->id) != NULL; + if (bValidIngredient) { + // is there already something in the ingredient slot? + if (!isSlotEmpty(eSectionBrewingIngredient, 0)) { + // is it the same as this item + std::shared_ptr IngredientItem = + getSlotItem(eSectionBrewingIngredient, 0); + if (IngredientItem->id == item->id) { + buttonY = eToolTipQuickMoveIngredient; + } else { + buttonY = eToolTipQuickMove; + } + } else { + // ingredient slot empty + buttonY = eToolTipQuickMoveIngredient; + } + } else { + // valid potion? Glass bottle with water in it is a 'potion' + // too. + if (iId == Item::potion_Id) { + // space available? + if (isSlotEmpty(eSectionBrewingBottle1, 0) || + isSlotEmpty(eSectionBrewingBottle2, 0) || + isSlotEmpty(eSectionBrewingBottle3, 0)) { + buttonY = eToolTipQuickMoveIngredient; + } else { + buttonY = eToolTipNone; + } + } else { + buttonY = eToolTipQuickMove; + } + } + } else if ((eSectionUnderPointer == eSectionEnchantUsing) || + (eSectionUnderPointer == eSectionEnchantInventory)) { + // Get the info on this item. + std::shared_ptr item = + getSlotItem(eSectionUnderPointer, iNewSlotIndex); + int iId = item->id; - if(bValidIngredient) - { - // is there already something in the ingredient slot? - if(!isSlotEmpty(eSectionFurnaceIngredient,0)) - { - // is it the same as this item - std::shared_ptr IngredientItem = getSlotItem(eSectionFurnaceIngredient,0); - if(IngredientItem->id == item->id) - { - buttonY = eToolTipQuickMoveIngredient; - } - else - { - if(FurnaceRecipes::getInstance()->getResult(item->id)==NULL) - { - buttonY = eToolTipQuickMove; - } - else - { - buttonY = eToolTipQuickMoveIngredient; - } - } - } - else - { - // ingredient slot empty - buttonY = eToolTipQuickMoveIngredient; - } - } - else if(bValidFuel) - { - // Is there already something in the fuel slot? - if(!isSlotEmpty(eSectionFurnaceFuel,0)) - { - // is it the same as this item - std::shared_ptr fuelItem = getSlotItem(eSectionFurnaceFuel,0); - if(fuelItem->id == item->id) - { - buttonY = eToolTipQuickMoveFuel; - } - else if(bValidIngredient) - { - // check if the ingredient slot is empty, or the same as this - if(!isSlotEmpty(eSectionFurnaceIngredient,0)) - { - // is it the same as this item - std::shared_ptr IngredientItem = getSlotItem(eSectionFurnaceIngredient,0); - if(IngredientItem->id == item->id) - { - buttonY = eToolTipQuickMoveIngredient; - } - else - { - if(FurnaceRecipes::getInstance()->getResult(item->id)==NULL) - { - buttonY = eToolTipQuickMove; - } - else - { - buttonY = eToolTipQuickMoveIngredient; - } - } - } - else - { - // ingredient slot empty - buttonY = eToolTipQuickMoveIngredient; - } - } - else - { - buttonY = eToolTipQuickMove; - } - } - else - { - buttonY = eToolTipQuickMoveFuel; - } - } - else - { - buttonY = eToolTipQuickMove; - } - } - // 4J-PB - show tooltips for quick use of ingredients in brewing - else if((eSectionUnderPointer==eSectionBrewingUsing)||(eSectionUnderPointer==eSectionBrewingInventory)) - { - // Get the info on this item. - std::shared_ptr item = getSlotItem(eSectionUnderPointer, iNewSlotIndex); - int iId=item->id; + // valid enchantable tool? + if (Item::items[iId]->isEnchantable(item)) { + // is there already something in the ingredient slot? + if (isSlotEmpty(eSectionEnchantSlot, 0)) { + // tool slot empty + switch (iId) { + case Item::bow_Id: + case Item::sword_wood_Id: + case Item::sword_stone_Id: + case Item::sword_iron_Id: + case Item::sword_diamond_Id: + buttonY = eToolTipQuickMoveWeapon; + break; - // valid ingredient? - bool bValidIngredient=false; - //bool bValidIngredientBottom=false; + case Item::helmet_cloth_Id: + case Item::chestplate_cloth_Id: + case Item::leggings_cloth_Id: + case Item::boots_cloth_Id: - if(Item::items[iId]->hasPotionBrewingFormula() || (iId == Item::netherStalkSeeds_Id)) - { - bValidIngredient=true; - } + case Item::helmet_chain_Id: + case Item::chestplate_chain_Id: + case Item::leggings_chain_Id: + case Item::boots_chain_Id: - if(bValidIngredient) - { - // is there already something in the ingredient slot? - if(!isSlotEmpty(eSectionBrewingIngredient,0)) - { - // is it the same as this item - std::shared_ptr IngredientItem = getSlotItem(eSectionBrewingIngredient,0); - if(IngredientItem->id == item->id) - { - buttonY = eToolTipQuickMoveIngredient; - } - else - { - buttonY=eToolTipQuickMove; - } - } - else - { - // ingredient slot empty - buttonY = eToolTipQuickMoveIngredient; - } - } - else - { - // valid potion? Glass bottle with water in it is a 'potion' too. - if(iId==Item::potion_Id) - { - // space available? - if(isSlotEmpty(eSectionBrewingBottle1,0) || - isSlotEmpty(eSectionBrewingBottle2,0) || - isSlotEmpty(eSectionBrewingBottle3,0)) - { - buttonY = eToolTipQuickMoveIngredient; - } - else - { - buttonY=eToolTipNone; - } - } - else - { - buttonY=eToolTipQuickMove; - } - } - } - else if((eSectionUnderPointer==eSectionEnchantUsing)||(eSectionUnderPointer==eSectionEnchantInventory)) - { - // Get the info on this item. - std::shared_ptr item = getSlotItem(eSectionUnderPointer, iNewSlotIndex); - int iId=item->id; + case Item::helmet_iron_Id: + case Item::chestplate_iron_Id: + case Item::leggings_iron_Id: + case Item::boots_iron_Id: - // valid enchantable tool? - if(Item::items[iId]->isEnchantable(item)) - { - // is there already something in the ingredient slot? - if(isSlotEmpty(eSectionEnchantSlot,0)) - { - // tool slot empty - switch(iId) - { - case Item::bow_Id: - case Item::sword_wood_Id: - case Item::sword_stone_Id: - case Item::sword_iron_Id: - case Item::sword_diamond_Id: - buttonY=eToolTipQuickMoveWeapon; - break; + case Item::helmet_diamond_Id: + case Item::chestplate_diamond_Id: + case Item::leggings_diamond_Id: + case Item::boots_diamond_Id: - case Item::helmet_cloth_Id: - case Item::chestplate_cloth_Id: - case Item::leggings_cloth_Id: - case Item::boots_cloth_Id: + case Item::helmet_gold_Id: + case Item::chestplate_gold_Id: + case Item::leggings_gold_Id: + case Item::boots_gold_Id: + buttonY = eToolTipQuickMoveArmor; - case Item::helmet_chain_Id: - case Item::chestplate_chain_Id: - case Item::leggings_chain_Id: - case Item::boots_chain_Id: + break; + case Item::book_Id: + buttonY = eToolTipQuickMove; + break; + default: + buttonY = eToolTipQuickMoveTool; + break; + } + } else { + buttonY = eToolTipQuickMove; + } + } else { + buttonY = eToolTipQuickMove; + } + } else { + buttonY = eToolTipQuickMove; + } + } + } - case Item::helmet_iron_Id: - case Item::chestplate_iron_Id: - case Item::leggings_iron_Id: - case Item::boots_iron_Id: + if (bPointerIsOutsidePanel) { + SetPointerOutsideMenu(true); + // Outside window, we dropping items. + if (bIsItemCarried) { + // int iCount = m_pointerControl->GetObjectCount( + // m_pointerControl->m_hObj ); + if (iCarriedCount > 1) { + buttonA = eToolTipDropAll; + buttonX = eToolTipDropOne; + } else { + buttonA = eToolTipDropGeneric; + } + } + } else // pointer is just over dead space ... can't really do anything. + { + SetPointerOutsideMenu(false); + } - case Item::helmet_diamond_Id: - case Item::chestplate_diamond_Id: - case Item::leggings_diamond_Id: - case Item::boots_diamond_Id: + std::shared_ptr item = nullptr; + if (bPointerIsOverSlot && bSlotHasItem) + item = getSlotItem(eSectionUnderPointer, iNewSlotIndex); + overrideTooltips(eSectionUnderPointer, item, bIsItemCarried, bSlotHasItem, + bCarriedIsSameAsSlot, iSlotStackSizeRemaining, buttonA, + buttonX, buttonY, buttonRT); - case Item::helmet_gold_Id: - case Item::chestplate_gold_Id: - case Item::leggings_gold_Id: - case Item::boots_gold_Id: - buttonY=eToolTipQuickMoveArmor; + SetToolTip(eToolTipButtonA, buttonA); + SetToolTip(eToolTipButtonX, buttonX); + SetToolTip(eToolTipButtonY, buttonY); + SetToolTip(eToolTipButtonRT, buttonRT); - break; - case Item::book_Id: - buttonY = eToolTipQuickMove; - break; - default: - buttonY=eToolTipQuickMoveTool; - break; - } - } - else - { - buttonY = eToolTipQuickMove; - } - } - else - { - buttonY=eToolTipQuickMove; - } - } - else - { - buttonY = eToolTipQuickMove; - } - } - } + // Offset back to image top left. + vPointerPos.x -= m_fPointerImageOffsetX; + vPointerPos.y -= m_fPointerImageOffsetY; - if ( bPointerIsOutsidePanel ) - { - SetPointerOutsideMenu( true ); - // Outside window, we dropping items. - if ( bIsItemCarried ) - { - //int iCount = m_pointerControl->GetObjectCount( m_pointerControl->m_hObj ); - if ( iCarriedCount > 1 ) - { - buttonA = eToolTipDropAll; - buttonX = eToolTipDropOne; - } - else - { - buttonA = eToolTipDropGeneric; - } - } - } - else // pointer is just over dead space ... can't really do anything. - { - SetPointerOutsideMenu( false ); - } + // Update pointer position. + // 4J-PB - do not allow sub pixel positions or we get broken lines in box + // edges - std::shared_ptr item = nullptr; - if(bPointerIsOverSlot && bSlotHasItem) item = getSlotItem(eSectionUnderPointer, iNewSlotIndex); - overrideTooltips(eSectionUnderPointer, item, bIsItemCarried, bSlotHasItem, bCarriedIsSameAsSlot, iSlotStackSizeRemaining, buttonA, buttonX, buttonY, buttonRT); + // problem here when sensitivity is low - we'll be moving a sub pixel size, + // so it'll clamp, and we'll never move. In that case, move 1 pixel + if (fInputDirX != 0.0f) { + if (fInputDirX == 1.0f) { + vPointerPos.x += 0.999999f; + } else { + vPointerPos.x -= 0.999999f; + } + } - SetToolTip( eToolTipButtonA, buttonA ); - SetToolTip( eToolTipButtonX, buttonX ); - SetToolTip( eToolTipButtonY, buttonY ); - SetToolTip( eToolTipButtonRT, buttonRT ); + if (fInputDirY != 0.0f) { + if (fInputDirY == 1.0f) { + vPointerPos.y += 0.999999f; + } else { + vPointerPos.y -= 0.999999f; + } + } + vPointerPos.x = floor(vPointerPos.x); + vPointerPos.x += ((int)vPointerPos.x % 2); + vPointerPos.y = floor(vPointerPos.y); + vPointerPos.y += ((int)vPointerPos.y % 2); + m_pointerPos = vPointerPos; - // Offset back to image top left. - vPointerPos.x -= m_fPointerImageOffsetX; - vPointerPos.y -= m_fPointerImageOffsetY; - - // Update pointer position. - // 4J-PB - do not allow sub pixel positions or we get broken lines in box edges - - // problem here when sensitivity is low - we'll be moving a sub pixel size, so it'll clamp, and we'll never move. In that case, move 1 pixel - if(fInputDirX!=0.0f) - { - if(fInputDirX==1.0f) - { - vPointerPos.x+=0.999999f; - } - else - { - vPointerPos.x-=0.999999f; - } - } - - if(fInputDirY!=0.0f) - { - if(fInputDirY==1.0f) - { - vPointerPos.y+=0.999999f; - } - else - { - vPointerPos.y-=0.999999f; - } - } - - vPointerPos.x = floor(vPointerPos.x); - vPointerPos.x += ( (int)vPointerPos.x%2); - vPointerPos.y = floor(vPointerPos.y); - vPointerPos.y += ( (int)vPointerPos.y%2); - m_pointerPos = vPointerPos; - - adjustPointerForSafeZone(); + adjustPointerForSafeZone(); } -bool IUIScene_AbstractContainerMenu::handleKeyDown(int iPad, int iAction, bool bRepeat) -{ - bool bHandled = false; +bool IUIScene_AbstractContainerMenu::handleKeyDown(int iPad, int iAction, + bool bRepeat) { + bool bHandled = false; - Minecraft *pMinecraft = Minecraft::GetInstance(); - if( pMinecraft->localgameModes[getPad()] != NULL ) - { - Tutorial *tutorial = pMinecraft->localgameModes[getPad()]->getTutorial(); - if(tutorial != NULL) - { - tutorial->handleUIInput(iAction); - if(ui.IsTutorialVisible(getPad()) && !tutorial->isInputAllowed(iAction)) - { - return S_OK; - } - } - } + Minecraft* pMinecraft = Minecraft::GetInstance(); + if (pMinecraft->localgameModes[getPad()] != NULL) { + Tutorial* tutorial = + pMinecraft->localgameModes[getPad()]->getTutorial(); + if (tutorial != NULL) { + tutorial->handleUIInput(iAction); + if (ui.IsTutorialVisible(getPad()) && + !tutorial->isInputAllowed(iAction)) { + return S_OK; + } + } + } #ifdef _XBOX - ui.AnimateKeyPress(iPad, iAction); + ui.AnimateKeyPress(iPad, iAction); #else - ui.AnimateKeyPress(iPad, iAction, bRepeat, true, false); + ui.AnimateKeyPress(iPad, iAction, bRepeat, true, false); #endif - int buttonNum=0; // 0 = LeftMouse, 1 = RightMouse - bool quickKeyHeld = false; // Represents shift key on PC + int buttonNum = 0; // 0 = LeftMouse, 1 = RightMouse + bool quickKeyHeld = false; // Represents shift key on PC - bool validKeyPress = false; - //BOOL itemEditorKeyPress = FALSE; + bool validKeyPress = false; + // BOOL itemEditorKeyPress = FALSE; - // Ignore input from other players - //if(pMinecraft->player->GetXboxPad()!=pInputData->UserIndex) return S_OK; + // Ignore input from other players + // if(pMinecraft->player->GetXboxPad()!=pInputData->UserIndex) return S_OK; - switch(iAction) - { + switch (iAction) { #ifdef _DEBUG_MENUS_ENABLED #if TO_BE_IMPLEMENTED - case VK_PAD_RTHUMB_PRESS: - itemEditorKeyPress = TRUE; - break; + case VK_PAD_RTHUMB_PRESS: + itemEditorKeyPress = TRUE; + break; #endif #endif - case ACTION_MENU_A: + case ACTION_MENU_A: #ifdef __ORBIS__ - case ACTION_MENU_TOUCHPAD_PRESS: + case ACTION_MENU_TOUCHPAD_PRESS: #endif - if(!bRepeat) - { - validKeyPress = true; + if (!bRepeat) { + validKeyPress = true; - // Standard left click - buttonNum = 0; - quickKeyHeld = false; - ui.PlayUISFX(eSFX_Press); - } - break; - case ACTION_MENU_X: - if(!bRepeat) - { - validKeyPress = true; + // Standard left click + buttonNum = 0; + quickKeyHeld = false; + ui.PlayUISFX(eSFX_Press); + } + break; + case ACTION_MENU_X: + if (!bRepeat) { + validKeyPress = true; - // Standard right click - buttonNum = 1; - quickKeyHeld = false; - ui.PlayUISFX(eSFX_Press); - } - break; - case ACTION_MENU_Y: - if(!bRepeat) - { - //bool bIsItemCarried = !m_pointerControl->isEmpty( m_pointerControl->m_hObj ); + // Standard right click + buttonNum = 1; + quickKeyHeld = false; + ui.PlayUISFX(eSFX_Press); + } + break; + case ACTION_MENU_Y: + if (!bRepeat) { + // bool bIsItemCarried = !m_pointerControl->isEmpty( + // m_pointerControl->m_hObj ); - // 4J Stu - TU8: Remove this fix, and fix the tooltip display instead as customers liked the feature + // 4J Stu - TU8: Remove this fix, and fix the tooltip display + // instead as customers liked the feature - // Fix for #58583 - TU6: Content: UI: The Quick Move button prompt disappears even though it still works - // No quick move tooltip is shown if something is carried, so disable the action as well - //if(!bIsItemCarried) - { - validKeyPress = true; + // Fix for #58583 - TU6: Content: UI: The Quick Move button + // prompt disappears even though it still works No quick move + // tooltip is shown if something is carried, so disable the + // action as well + // if(!bIsItemCarried) + { + validKeyPress = true; - // Shift and left click - buttonNum = 0; - quickKeyHeld = true; - ui.PlayUISFX(eSFX_Press); - } - } - break; - // 4J Stu - Also enable start to exit the scene. This key is also not constrained by the tutorials. - case ACTION_MENU_PAUSEMENU: - case ACTION_MENU_B: - { + // Shift and left click + buttonNum = 0; + quickKeyHeld = true; + ui.PlayUISFX(eSFX_Press); + } + } + break; + // 4J Stu - Also enable start to exit the scene. This key is also + // not constrained by the tutorials. + case ACTION_MENU_PAUSEMENU: + case ACTION_MENU_B: { + ui.SetTooltips(iPad, -1); - ui.SetTooltips(iPad, -1); + // 4J Stu - Fix for #11302 - TCR 001: Network Connectivity: Host + // crashed after being killed by the client while accessing a chest + // during burst packet loss. We need to make sure that we call + // closeContainer() anytime this menu is closed, even if it is + // forced to close by some other reason (like the player dying) + // Therefore I have moved this call to the OnDestroy() method to + // make sure that it always happens. + // Minecraft::GetInstance()->localplayers[pInputData->UserIndex]->closeContainer(); - // 4J Stu - Fix for #11302 - TCR 001: Network Connectivity: Host crashed after being killed by the client while accessing a chest during burst packet loss. - // We need to make sure that we call closeContainer() anytime this menu is closed, even if it is forced to close by some other reason (like the player dying) - // Therefore I have moved this call to the OnDestroy() method to make sure that it always happens. - //Minecraft::GetInstance()->localplayers[pInputData->UserIndex]->closeContainer(); + // Return to the game. We should really callback to the app here as + // well to let it know that we have closed the ui incase we need to + // do things when that happens - // Return to the game. We should really callback to the app here as well - // to let it know that we have closed the ui incase we need to do things when that happens + if (m_bNavigateBack) { + ui.NavigateBack(iPad); + } else { + ui.CloseUIScenes(iPad); + } - if(m_bNavigateBack) - { - ui.NavigateBack(iPad); - } - else - { - ui.CloseUIScenes(iPad); - } - - bHandled = true; - return S_OK; - } - break; - case ACTION_MENU_LEFT: - { - //ui.PlayUISFX(eSFX_Focus); - m_eCurrTapState = eTapStateLeft; - } - break; - case ACTION_MENU_RIGHT: - { - //ui.PlayUISFX(eSFX_Focus); - m_eCurrTapState = eTapStateRight; - } - break; - case ACTION_MENU_UP: - { - //ui.PlayUISFX(eSFX_Focus); - m_eCurrTapState = eTapStateUp; - } - break; - case ACTION_MENU_DOWN: - { - //ui.PlayUISFX(eSFX_Focus); - m_eCurrTapState = eTapStateDown; - } - break; - case ACTION_MENU_PAGEUP: - { - // 4J Stu - Do nothing except stop this being passed anywhere else - bHandled = true; - } - break; + bHandled = true; + return S_OK; + } break; + case ACTION_MENU_LEFT: { + // ui.PlayUISFX(eSFX_Focus); + m_eCurrTapState = eTapStateLeft; + } break; + case ACTION_MENU_RIGHT: { + // ui.PlayUISFX(eSFX_Focus); + m_eCurrTapState = eTapStateRight; + } break; + case ACTION_MENU_UP: { + // ui.PlayUISFX(eSFX_Focus); + m_eCurrTapState = eTapStateUp; + } break; + case ACTION_MENU_DOWN: { + // ui.PlayUISFX(eSFX_Focus); + m_eCurrTapState = eTapStateDown; + } break; + case ACTION_MENU_PAGEUP: { + // 4J Stu - Do nothing except stop this being passed anywhere else + bHandled = true; + } break; #ifdef __PSVITA__ - //CD - Vita uses select for What's this - key 40 - case MINECRAFT_ACTION_GAME_INFO: + // CD - Vita uses select for What's this - key 40 + case MINECRAFT_ACTION_GAME_INFO: #else - case ACTION_MENU_PAGEDOWN: + case ACTION_MENU_PAGEDOWN: #endif - { - if( IsSectionSlotList( m_eCurrSection ) ) - { - int currentIndex = getCurrentIndex( m_eCurrSection ) - getSectionStartOffset(m_eCurrSection); + { + if (IsSectionSlotList(m_eCurrSection)) { + int currentIndex = getCurrentIndex(m_eCurrSection) - + getSectionStartOffset(m_eCurrSection); - bool bSlotHasItem = !isSlotEmpty(m_eCurrSection, currentIndex); - if ( bSlotHasItem ) - { - std::shared_ptr item = getSlotItem(m_eCurrSection, currentIndex); - if( Minecraft::GetInstance()->localgameModes[iPad] != NULL ) - { - Tutorial::PopupMessageDetails *message = new Tutorial::PopupMessageDetails; - message->m_messageId = item->getUseDescriptionId(); + bool bSlotHasItem = !isSlotEmpty(m_eCurrSection, currentIndex); + if (bSlotHasItem) { + std::shared_ptr item = + getSlotItem(m_eCurrSection, currentIndex); + if (Minecraft::GetInstance()->localgameModes[iPad] != + NULL) { + Tutorial::PopupMessageDetails* message = + new Tutorial::PopupMessageDetails; + message->m_messageId = item->getUseDescriptionId(); - if(Item::items[item->id] != NULL) message->m_titleString = Item::items[item->id]->getHoverName(item); - message->m_titleId = item->getDescriptionId(); + if (Item::items[item->id] != NULL) + message->m_titleString = + Item::items[item->id]->getHoverName(item); + message->m_titleId = item->getDescriptionId(); - message->m_icon = item->id; - message->m_iAuxVal = item->getAuxValue(); - message->m_forceDisplay = true; + message->m_icon = item->id; + message->m_iAuxVal = item->getAuxValue(); + message->m_forceDisplay = true; - TutorialMode *gameMode = (TutorialMode *)Minecraft::GetInstance()->localgameModes[iPad]; - gameMode->getTutorial()->setMessage(NULL, message); - ui.PlayUISFX(eSFX_Press); - } - } - } - bHandled = true; - } - break; - }; + TutorialMode* gameMode = + (TutorialMode*)Minecraft::GetInstance() + ->localgameModes[iPad]; + gameMode->getTutorial()->setMessage(NULL, message); + ui.PlayUISFX(eSFX_Press); + } + } + } + bHandled = true; + } break; + }; - if(validKeyPress) - { - if(handleValidKeyPress(iPad,buttonNum,quickKeyHeld)) - { - // Used to allow overriding certain keypresses, so do nothing here - } - else - { - if( IsSectionSlotList( m_eCurrSection ) ) - { - handleSlotListClicked(m_eCurrSection,buttonNum,quickKeyHeld); - } - else - { - // TODO Clicked something else, like for example the craft result. Do something here + if (validKeyPress) { + if (handleValidKeyPress(iPad, buttonNum, quickKeyHeld)) { + // Used to allow overriding certain keypresses, so do nothing here + } else { + if (IsSectionSlotList(m_eCurrSection)) { + handleSlotListClicked(m_eCurrSection, buttonNum, quickKeyHeld); + } else { + // TODO Clicked something else, like for example the craft + // result. Do something here - // 4J WESTY : For pointer system we can legally drop items outside of the window panel here, or may press button while - // pointer is over empty panel space. - if ( m_bPointerOutsideMenu ) - { - handleOutsideClicked(iPad, buttonNum, quickKeyHeld); - } - else // - { - // over empty space or something else??? - handleOtherClicked(iPad,m_eCurrSection,buttonNum,quickKeyHeld?true:false); - //assert( FALSE ); - } - } - } - bHandled = true; - } + // 4J WESTY : For pointer system we can legally drop items + // outside of the window panel here, or may press button while + // pointer is over empty panel space. + if (m_bPointerOutsideMenu) { + handleOutsideClicked(iPad, buttonNum, quickKeyHeld); + } else // + { + // over empty space or something else??? + handleOtherClicked(iPad, m_eCurrSection, buttonNum, + quickKeyHeld ? true : false); + // assert( FALSE ); + } + } + } + bHandled = true; + } #ifdef _DEBUG_MENUS_ENABLED #if TO_BE_IMPLEMENTED - else if(itemEditorKeyPress == TRUE) - { - HXUIOBJ hFocusObject = GetFocus(pInputData->UserIndex); - HXUIOBJ hFocusObjectParent; - XuiElementGetParent( hFocusObject, &hFocusObjectParent ); + else if (itemEditorKeyPress == TRUE) { + HXUIOBJ hFocusObject = GetFocus(pInputData->UserIndex); + HXUIOBJ hFocusObjectParent; + XuiElementGetParent(hFocusObject, &hFocusObjectParent); - HXUICLASS hClassCXuiCtrlSlotList; + HXUICLASS hClassCXuiCtrlSlotList; - // TODO Define values for these - hClassCXuiCtrlSlotList = XuiFindClass( L"CXuiCtrlSlotList" ); + // TODO Define values for these + hClassCXuiCtrlSlotList = XuiFindClass(L"CXuiCtrlSlotList"); - // If the press comes from a SlotList, cast it up then send a clicked call to it's menu - if( XuiIsInstanceOf( hFocusObjectParent, hClassCXuiCtrlSlotList ) ) - { - CXuiCtrlSlotList* slotList; - void *pObj; - XuiObjectFromHandle( hFocusObjectParent, &pObj ); - slotList = (CXuiCtrlSlotList *)pObj; + // If the press comes from a SlotList, cast it up then send a clicked + // call to it's menu + if (XuiIsInstanceOf(hFocusObjectParent, hClassCXuiCtrlSlotList)) { + CXuiCtrlSlotList* slotList; + void* pObj; + XuiObjectFromHandle(hFocusObjectParent, &pObj); + slotList = (CXuiCtrlSlotList*)pObj; - int currentIndex = slotList->GetCurSel(); + int currentIndex = slotList->GetCurSel(); - CXuiCtrlSlotItemListItem* pCXuiCtrlSlotItem; - slotList->GetCXuiCtrlSlotItem( currentIndex, &( pCXuiCtrlSlotItem ) ); + CXuiCtrlSlotItemListItem* pCXuiCtrlSlotItem; + slotList->GetCXuiCtrlSlotItem(currentIndex, &(pCXuiCtrlSlotItem)); - //Minecraft *pMinecraft = Minecraft::GetInstance(); + // Minecraft *pMinecraft = Minecraft::GetInstance(); - CScene_DebugItemEditor::ItemEditorInput *initData = new CScene_DebugItemEditor::ItemEditorInput(); - initData->iPad = m_iPad; - initData->slot = pCXuiCtrlSlotItem->getSlot( pCXuiCtrlSlotItem->m_hObj ); - initData->menu = m_menu; + CScene_DebugItemEditor::ItemEditorInput* initData = + new CScene_DebugItemEditor::ItemEditorInput(); + initData->iPad = m_iPad; + initData->slot = + pCXuiCtrlSlotItem->getSlot(pCXuiCtrlSlotItem->m_hObj); + initData->menu = m_menu; - // Add timer to poll controller stick input at 60Hz - HRESULT timerResult = KillTimer( POINTER_INPUT_TIMER_ID ); - assert( timerResult == S_OK ); + // Add timer to poll controller stick input at 60Hz + HRESULT timerResult = KillTimer(POINTER_INPUT_TIMER_ID); + assert(timerResult == S_OK); - app.NavigateToScene(m_iPad,eUIScene_DebugItemEditor,(void *)initData,false,TRUE); - } - } + app.NavigateToScene(m_iPad, eUIScene_DebugItemEditor, + (void*)initData, false, TRUE); + } + } #endif #endif - else - { - handleAdditionalKeyPress(iAction); - } + else { + handleAdditionalKeyPress(iAction); + } - UpdateTooltips(); + UpdateTooltips(); - return bHandled; + return bHandled; } -bool IUIScene_AbstractContainerMenu::handleValidKeyPress(int iUserIndex, int buttonNum, bool quickKeyHeld) -{ - return false; +bool IUIScene_AbstractContainerMenu::handleValidKeyPress(int iUserIndex, + int buttonNum, + bool quickKeyHeld) { + return false; } -void IUIScene_AbstractContainerMenu::handleOutsideClicked(int iPad, int buttonNum, bool quickKeyHeld) -{ - // Drop items. +void IUIScene_AbstractContainerMenu::handleOutsideClicked(int iPad, + int buttonNum, + bool quickKeyHeld) { + // Drop items. - //pMinecraft->localgameModes[m_iPad]->handleInventoryMouseClick(menu->containerId, AbstractContainerMenu::CLICKED_OUTSIDE, buttonNum, quickKeyHeld?true:false, pMinecraft->localplayers[m_iPad] ); - slotClicked(AbstractContainerMenu::CLICKED_OUTSIDE, buttonNum, quickKeyHeld?true:false); + // pMinecraft->localgameModes[m_iPad]->handleInventoryMouseClick(menu->containerId, + // AbstractContainerMenu::CLICKED_OUTSIDE, buttonNum, + // quickKeyHeld?true:false, pMinecraft->localplayers[m_iPad] ); + slotClicked(AbstractContainerMenu::CLICKED_OUTSIDE, buttonNum, + quickKeyHeld ? true : false); } -void IUIScene_AbstractContainerMenu::handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey) -{ - // Do nothing +void IUIScene_AbstractContainerMenu::handleOtherClicked(int iPad, + ESceneSection eSection, + int buttonNum, + bool quickKey) { + // Do nothing } -void IUIScene_AbstractContainerMenu::handleAdditionalKeyPress(int iAction) -{ - // Do nothing +void IUIScene_AbstractContainerMenu::handleAdditionalKeyPress(int iAction) { + // Do nothing } -void IUIScene_AbstractContainerMenu::handleSlotListClicked(ESceneSection eSection, int buttonNum, bool quickKeyHeld) -{ - int currentIndex = getCurrentIndex(eSection); +void IUIScene_AbstractContainerMenu::handleSlotListClicked( + ESceneSection eSection, int buttonNum, bool quickKeyHeld) { + int currentIndex = getCurrentIndex(eSection); - //pMinecraft->localgameModes[m_iPad]->handleInventoryMouseClick(menu->containerId, currentIndex, buttonNum, quickKeyHeld?true:false, pMinecraft->localplayers[m_iPad] ); - slotClicked(currentIndex, buttonNum, quickKeyHeld?true:false); + // pMinecraft->localgameModes[m_iPad]->handleInventoryMouseClick(menu->containerId, + // currentIndex, buttonNum, quickKeyHeld?true:false, + // pMinecraft->localplayers[m_iPad] ); + slotClicked(currentIndex, buttonNum, quickKeyHeld ? true : false); - handleSectionClick(eSection); + handleSectionClick(eSection); } -void IUIScene_AbstractContainerMenu::slotClicked(int slotId, int buttonNum, bool quickKey) -{ - // 4J Stu - Removed this line as unused - //if (slot != NULL) slotId = slot->index; +void IUIScene_AbstractContainerMenu::slotClicked(int slotId, int buttonNum, + bool quickKey) { + // 4J Stu - Removed this line as unused + // if (slot != NULL) slotId = slot->index; - Minecraft *pMinecraft = Minecraft::GetInstance(); - pMinecraft->localgameModes[getPad()]->handleInventoryMouseClick(m_menu->containerId, slotId, buttonNum, quickKey, pMinecraft->localplayers[getPad()] ); + Minecraft* pMinecraft = Minecraft::GetInstance(); + pMinecraft->localgameModes[getPad()]->handleInventoryMouseClick( + m_menu->containerId, slotId, buttonNum, quickKey, + pMinecraft->localplayers[getPad()]); } -int IUIScene_AbstractContainerMenu::getCurrentIndex(ESceneSection eSection) -{ - int rows, columns; - GetSectionDimensions( eSection, &columns, &rows ); - int currentIndex = (m_iCurrSlotY * columns) + m_iCurrSlotX; +int IUIScene_AbstractContainerMenu::getCurrentIndex(ESceneSection eSection) { + int rows, columns; + GetSectionDimensions(eSection, &columns, &rows); + int currentIndex = (m_iCurrSlotY * columns) + m_iCurrSlotX; - return currentIndex + getSectionStartOffset(eSection); + return currentIndex + getSectionStartOffset(eSection); } -bool IUIScene_AbstractContainerMenu::IsSameItemAs(std::shared_ptr itemA, std::shared_ptr itemB) -{ - if(itemA == NULL || itemB == NULL) return false; +bool IUIScene_AbstractContainerMenu::IsSameItemAs( + std::shared_ptr itemA, std::shared_ptr itemB) { + if (itemA == NULL || itemB == NULL) return false; - bool bStackedByData = itemA->isStackedByData(); - return ( ( itemA->id == itemB->id ) && ( (bStackedByData && itemA->getAuxValue() == itemB->getAuxValue()) || !bStackedByData ) ); + bool bStackedByData = itemA->isStackedByData(); + return ((itemA->id == itemB->id) && + ((bStackedByData && itemA->getAuxValue() == itemB->getAuxValue()) || + !bStackedByData)); } -int IUIScene_AbstractContainerMenu::GetEmptyStackSpace(Slot *slot) -{ - int iResult = 0; +int IUIScene_AbstractContainerMenu::GetEmptyStackSpace(Slot* slot) { + int iResult = 0; - if(slot != NULL && slot->hasItem()) - { - std::shared_ptr item = slot->getItem(); - if ( item->isStackable() ) - { - int iCount = item->GetCount(); - int iMaxStackSize = std::min(item->getMaxStackSize(), slot->getMaxStackSize() ); + if (slot != NULL && slot->hasItem()) { + std::shared_ptr item = slot->getItem(); + if (item->isStackable()) { + int iCount = item->GetCount(); + int iMaxStackSize = + std::min(item->getMaxStackSize(), slot->getMaxStackSize()); - iResult = iMaxStackSize - iCount; + iResult = iMaxStackSize - iCount; - if(iResult < 0 ) iResult = 0; - } - } + if (iResult < 0) iResult = 0; + } + } - return iResult; + return iResult; } -std::wstring IUIScene_AbstractContainerMenu::GetItemDescription(Slot *slot, std::vector &unformattedStrings) -{ - if(slot == NULL) return L""; +std::wstring IUIScene_AbstractContainerMenu::GetItemDescription( + Slot* slot, std::vector& unformattedStrings) { + if (slot == NULL) return L""; - std::wstring desc = L""; - std::vector *strings = slot->getItem()->getHoverText(nullptr, false, unformattedStrings); - bool firstLine = true; - for(AUTO_VAR(it, strings->begin()); it != strings->end(); ++it) - { - std::wstring thisString = *it; - if(!firstLine) - { - desc.append( L"
" ); - } - else - { - firstLine = false; - wchar_t formatted[256]; - eMinecraftColour rarityColour = slot->getItem()->getRarity()->color; - int colour = app.GetHTMLColour(rarityColour); + std::wstring desc = L""; + std::vector* strings = + slot->getItem()->getHoverText(nullptr, false, unformattedStrings); + bool firstLine = true; + for (AUTO_VAR(it, strings->begin()); it != strings->end(); ++it) { + std::wstring thisString = *it; + if (!firstLine) { + desc.append(L"
"); + } else { + firstLine = false; + wchar_t formatted[256]; + eMinecraftColour rarityColour = slot->getItem()->getRarity()->color; + int colour = app.GetHTMLColour(rarityColour); - if(slot->getItem()->hasCustomHoverName()) - { - colour = app.GetHTMLColour(eTextColor_RenamedItemTitle); - } + if (slot->getItem()->hasCustomHoverName()) { + colour = app.GetHTMLColour(eTextColor_RenamedItemTitle); + } - swprintf(formatted, 256, L"%ls",colour,thisString.c_str()); - thisString = formatted; - } - desc.append( thisString ); - } - strings->clear(); - delete strings; - return desc; + swprintf(formatted, 256, L"%ls", + colour, thisString.c_str()); + thisString = formatted; + } + desc.append(thisString); + } + strings->clear(); + delete strings; + return desc; } diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.h b/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.h index 43e8dbe9a..53e6779be 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.h +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_AbstractContainerMenu.h @@ -1,223 +1,260 @@ #pragma once -// Uncomment to enable tap input detection to jump 1 slot. Doesn't work particularly well yet, and I feel the system does not need it. -// Would probably be required if we decide to slow down the pointer movement. -// 4J Stu - There was a request to be able to navigate the scenes with the dpad, so I have used much of the TAP_DETECTION -// code as it worked well for that situation. This #define should still stop the same things happening when using the -// stick though when not defined +// Uncomment to enable tap input detection to jump 1 slot. Doesn't work +// particularly well yet, and I feel the system does not need it. Would probably +// be required if we decide to slow down the pointer movement. 4J Stu - There +// was a request to be able to navigate the scenes with the dpad, so I have used +// much of the TAP_DETECTION code as it worked well for that situation. This +// #define should still stop the same things happening when using the stick +// though when not defined #define TAP_DETECTION // Uncomment to enable acceleration on pointer input. -//#define USE_POINTER_ACCEL +// #define USE_POINTER_ACCEL -#define POINTER_INPUT_TIMER_ID (0) // Arbitrary timer ID. -#define POINTER_SPEED_FACTOR (13.0f) // Speed of pointer. -//#define POINTER_PANEL_OVER_REACH (42.0f) // Amount beyond edge of panel which pointer can go over to drop items. - comes from the pointer size in the scene +#define POINTER_INPUT_TIMER_ID (0) // Arbitrary timer ID. +#define POINTER_SPEED_FACTOR (13.0f) // Speed of pointer. +// #define POINTER_PANEL_OVER_REACH (42.0f) // Amount beyond edge of +// panel which pointer can go over to drop items. - comes from the pointer size +// in the scene -#define MAX_INPUT_TICKS_FOR_SCALING (7) -#define MAX_INPUT_TICKS_FOR_TAPPING (15) +#define MAX_INPUT_TICKS_FOR_SCALING (7) +#define MAX_INPUT_TICKS_FOR_TAPPING (15) class AbstractContainerMenu; class Slot; -class IUIScene_AbstractContainerMenu -{ +class IUIScene_AbstractContainerMenu { protected: - // Sections of this scene containing items selectable by the pointer. - // 4J Stu - Always make the Using section the first one - enum ESceneSection - { - eSectionNone = -1, - eSectionContainerUsing = 0, - eSectionContainerInventory, - eSectionContainerChest, - eSectionContainerMax, - - eSectionFurnaceUsing, - eSectionFurnaceInventory, - eSectionFurnaceIngredient, - eSectionFurnaceFuel, - eSectionFurnaceResult, - eSectionFurnaceMax, - - eSectionInventoryUsing, - eSectionInventoryInventory, - eSectionInventoryArmor, - eSectionInventoryMax, - - eSectionTrapUsing, - eSectionTrapInventory, - eSectionTrapTrap, - eSectionTrapMax, + // Sections of this scene containing items selectable by the pointer. + // 4J Stu - Always make the Using section the first one + enum ESceneSection { + eSectionNone = -1, + eSectionContainerUsing = 0, + eSectionContainerInventory, + eSectionContainerChest, + eSectionContainerMax, - eSectionInventoryCreativeUsing, - eSectionInventoryCreativeSelector, + eSectionFurnaceUsing, + eSectionFurnaceInventory, + eSectionFurnaceIngredient, + eSectionFurnaceFuel, + eSectionFurnaceResult, + eSectionFurnaceMax, + + eSectionInventoryUsing, + eSectionInventoryInventory, + eSectionInventoryArmor, + eSectionInventoryMax, + + eSectionTrapUsing, + eSectionTrapInventory, + eSectionTrapTrap, + eSectionTrapMax, + + eSectionInventoryCreativeUsing, + eSectionInventoryCreativeSelector, #ifndef _XBOX - eSectionInventoryCreativeTab_0, - eSectionInventoryCreativeTab_1, - eSectionInventoryCreativeTab_2, - eSectionInventoryCreativeTab_3, - eSectionInventoryCreativeTab_4, - eSectionInventoryCreativeTab_5, - eSectionInventoryCreativeTab_6, - eSectionInventoryCreativeTab_7, - eSectionInventoryCreativeSlider, + eSectionInventoryCreativeTab_0, + eSectionInventoryCreativeTab_1, + eSectionInventoryCreativeTab_2, + eSectionInventoryCreativeTab_3, + eSectionInventoryCreativeTab_4, + eSectionInventoryCreativeTab_5, + eSectionInventoryCreativeTab_6, + eSectionInventoryCreativeTab_7, + eSectionInventoryCreativeSlider, #endif - eSectionInventoryCreativeMax, - - eSectionEnchantUsing, - eSectionEnchantInventory, - eSectionEnchantSlot, - eSectionEnchantButton1, - eSectionEnchantButton2, - eSectionEnchantButton3, - eSectionEnchantMax, + eSectionInventoryCreativeMax, - eSectionBrewingUsing, - eSectionBrewingInventory, - eSectionBrewingBottle1, - eSectionBrewingBottle2, - eSectionBrewingBottle3, - eSectionBrewingIngredient, - eSectionBrewingMax, + eSectionEnchantUsing, + eSectionEnchantInventory, + eSectionEnchantSlot, + eSectionEnchantButton1, + eSectionEnchantButton2, + eSectionEnchantButton3, + eSectionEnchantMax, - eSectionAnvilUsing, - eSectionAnvilInventory, - eSectionAnvilItem1, - eSectionAnvilItem2, - eSectionAnvilResult, - eSectionAnvilName, - eSectionAnvilMax, - }; + eSectionBrewingUsing, + eSectionBrewingInventory, + eSectionBrewingBottle1, + eSectionBrewingBottle2, + eSectionBrewingBottle3, + eSectionBrewingIngredient, + eSectionBrewingMax, - AbstractContainerMenu* m_menu; - bool m_autoDeleteMenu; + eSectionAnvilUsing, + eSectionAnvilInventory, + eSectionAnvilItem1, + eSectionAnvilItem2, + eSectionAnvilResult, + eSectionAnvilName, + eSectionAnvilMax, + }; - eTutorial_State m_previousTutorialState; + AbstractContainerMenu* m_menu; + bool m_autoDeleteMenu; - UIVec2D m_pointerPos; + eTutorial_State m_previousTutorialState; - // Offset from pointer image top left to centre (we use the centre as the actual pointer). - float m_fPointerImageOffsetX; - float m_fPointerImageOffsetY; + UIVec2D m_pointerPos; - // Min and max extents for the pointer. - float m_fPointerMinX; - float m_fPointerMaxX; - float m_fPointerMinY; - float m_fPointerMaxY; + // Offset from pointer image top left to centre (we use the centre as the + // actual pointer). + float m_fPointerImageOffsetX; + float m_fPointerImageOffsetY; - // Min and max extents of the panel. - float m_fPanelMinX; - float m_fPanelMaxX; - float m_fPanelMinY; - float m_fPanelMaxY; + // Min and max extents for the pointer. + float m_fPointerMinX; + float m_fPointerMaxX; + float m_fPointerMinY; + float m_fPointerMaxY; - int m_iConsectiveInputTicks; + // Min and max extents of the panel. + float m_fPanelMinX; + float m_fPanelMaxX; + float m_fPanelMinY; + float m_fPanelMaxY; - // Used for detecting quick "taps" in a direction, should jump cursor to next slot. - enum ETapState - { - eTapStateNoInput = 0, - eTapStateUp, - eTapStateDown, - eTapStateLeft, - eTapStateRight, - eTapStateJump, - eTapNone - }; + int m_iConsectiveInputTicks; - ETapState m_eCurrTapState; - ESceneSection m_eCurrSection; - int m_iCurrSlotX; - int m_iCurrSlotY; + // Used for detecting quick "taps" in a direction, should jump cursor to + // next slot. + enum ETapState { + eTapStateNoInput = 0, + eTapStateUp, + eTapStateDown, + eTapStateLeft, + eTapStateRight, + eTapStateJump, + eTapNone + }; + + ETapState m_eCurrTapState; + ESceneSection m_eCurrSection; + int m_iCurrSlotX; + int m_iCurrSlotY; #ifdef __ORBIS__ - bool m_bFirstTouchStored[XUSER_MAX_COUNT]; // monitor the first position of a touch, so we can use relative distances of movement - UIVec2D m_oldvPointerPos; - UIVec2D m_oldvTouchPos; - // store the multipliers to map the UI window to the touchpad window - float m_fTouchPadMulX; - float m_fTouchPadMulY; - float m_fTouchPadDeadZoneX; // usese the multipliers - float m_fTouchPadDeadZoneY; - + bool + m_bFirstTouchStored[XUSER_MAX_COUNT]; // monitor the first position of + // a touch, so we can use + // relative distances of movement + UIVec2D m_oldvPointerPos; + UIVec2D m_oldvTouchPos; + // store the multipliers to map the UI window to the touchpad window + float m_fTouchPadMulX; + float m_fTouchPadMulY; + float m_fTouchPadDeadZoneX; // usese the multipliers + float m_fTouchPadDeadZoneY; #endif - // ENum indexes of the first section for this scene, and 1+the last section - ESceneSection m_eFirstSection, m_eMaxSection; + // ENum indexes of the first section for this scene, and 1+the last section + ESceneSection m_eFirstSection, m_eMaxSection; - // 4J - WESTY - Added for pointer prototype. - // Current tooltip settings. - EToolTipItem m_aeToolTipSettings[ eToolTipNumButtons ]; - - // 4J - WESTY - Added for pointer prototype. - // Indicates if pointer is outside UI window (used to drop items). - bool m_bPointerOutsideMenu; - Slot *m_lastPointerLabelSlot; + // 4J - WESTY - Added for pointer prototype. + // Current tooltip settings. + EToolTipItem m_aeToolTipSettings[eToolTipNumButtons]; - bool m_bSplitscreen; - bool m_bNavigateBack; // should we exit the xuiscenes or just navigate back on exit? - - virtual bool IsSectionSlotList( ESceneSection eSection ) { return eSection != eSectionNone; } - virtual bool CanHaveFocus( ESceneSection eSection ) { return true; } - int GetSectionDimensions( ESceneSection eSection, int* piNumColumns, int* piNumRows ); - virtual int getSectionColumns(ESceneSection eSection) = 0; - virtual int getSectionRows(ESceneSection eSection) = 0; - virtual ESceneSection GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY ) = 0; - virtual void GetPositionOfSection( ESceneSection eSection, UIVec2D* pPosition ) = 0; - virtual void GetItemScreenData( ESceneSection eSection, int iItemIndex, UIVec2D* pPosition, UIVec2D* pSize ) = 0; - void updateSlotPosition( ESceneSection eSection, ESceneSection newSection, ETapState eTapDirection, int *piTargetX, int *piTargetY, int xOffset ); + // 4J - WESTY - Added for pointer prototype. + // Indicates if pointer is outside UI window (used to drop items). + bool m_bPointerOutsideMenu; + Slot* m_lastPointerLabelSlot; - #ifdef TAP_DETECTION - ETapState GetTapInputType( float fInputX, float fInputY ); - #endif + bool m_bSplitscreen; + bool m_bNavigateBack; // should we exit the xuiscenes or just navigate back + // on exit? - // Current tooltip settings. - void SetToolTip( EToolTipButton eButton, EToolTipItem eItem ); - void UpdateTooltips(); + virtual bool IsSectionSlotList(ESceneSection eSection) { + return eSection != eSectionNone; + } + virtual bool CanHaveFocus(ESceneSection eSection) { return true; } + int GetSectionDimensions(ESceneSection eSection, int* piNumColumns, + int* piNumRows); + virtual int getSectionColumns(ESceneSection eSection) = 0; + virtual int getSectionRows(ESceneSection eSection) = 0; + virtual ESceneSection GetSectionAndSlotInDirection(ESceneSection eSection, + ETapState eTapDirection, + int* piTargetX, + int* piTargetY) = 0; + virtual void GetPositionOfSection(ESceneSection eSection, + UIVec2D* pPosition) = 0; + virtual void GetItemScreenData(ESceneSection eSection, int iItemIndex, + UIVec2D* pPosition, UIVec2D* pSize) = 0; + void updateSlotPosition(ESceneSection eSection, ESceneSection newSection, + ETapState eTapDirection, int* piTargetX, + int* piTargetY, int xOffset); - // 4J - WESTY - Added for pointer prototype. - void SetPointerOutsideMenu( bool bOutside ) { m_bPointerOutsideMenu = bOutside; } - - void Initialize(int m_iPad, AbstractContainerMenu* menu, bool autoDeleteMenu, int startIndex,ESceneSection firstSection,ESceneSection maxSection, bool bNavigateBack=false); - virtual void PlatformInitialize(int iPad, int startIndex) = 0; - virtual void InitDataAssociations(int iPad, AbstractContainerMenu *menu, int startIndex = 0) = 0; +#ifdef TAP_DETECTION + ETapState GetTapInputType(float fInputX, float fInputY); +#endif - void onMouseTick(); - bool handleKeyDown(int iPad, int iAction, bool bRepeat); - virtual bool handleValidKeyPress(int iUserIndex, int buttonNum, bool quickKeyHeld); - virtual void handleOutsideClicked(int iPad, int buttonNum, bool quickKeyHeld); - virtual void handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey); - virtual void handleAdditionalKeyPress(int iAction); - virtual void handleSlotListClicked(ESceneSection eSection, int buttonNum, bool quickKeyHeld); - virtual void handleSectionClick(ESceneSection eSection) = 0; - void slotClicked(int slotId, int buttonNum, bool quickKey); - int getCurrentIndex(ESceneSection eSection); - virtual int getSectionStartOffset(ESceneSection eSection) = 0; - virtual bool doesSectionTreeHaveFocus(ESceneSection eSection) = 0; - virtual void setSectionFocus(ESceneSection eSection, int iPad) = 0; - virtual void setSectionSelectedSlot(ESceneSection eSection, int x, int y) = 0; - virtual void setFocusToPointer(int iPad) = 0; - virtual void SetPointerText(const std::wstring &description, std::vector &unformattedStrings, bool newSlot) = 0; - virtual std::shared_ptr getSlotItem(ESceneSection eSection, int iSlot) = 0; - virtual bool isSlotEmpty(ESceneSection eSection, int iSlot) = 0; - virtual void adjustPointerForSafeZone() = 0; + // Current tooltip settings. + void SetToolTip(EToolTipButton eButton, EToolTipItem eItem); + void UpdateTooltips(); - virtual bool overrideTooltips(ESceneSection sectionUnderPointer, std::shared_ptr itemUnderPointer, bool bIsItemCarried, bool bSlotHasItem, bool bCarriedIsSameAsSlot, int iSlotStackSizeRemaining, - EToolTipItem &buttonA, EToolTipItem &buttonX, EToolTipItem &buttonY, EToolTipItem &buttonRT) { return false; } + // 4J - WESTY - Added for pointer prototype. + void SetPointerOutsideMenu(bool bOutside) { + m_bPointerOutsideMenu = bOutside; + } + + void Initialize(int m_iPad, AbstractContainerMenu* menu, + bool autoDeleteMenu, int startIndex, + ESceneSection firstSection, ESceneSection maxSection, + bool bNavigateBack = false); + virtual void PlatformInitialize(int iPad, int startIndex) = 0; + virtual void InitDataAssociations(int iPad, AbstractContainerMenu* menu, + int startIndex = 0) = 0; + + void onMouseTick(); + bool handleKeyDown(int iPad, int iAction, bool bRepeat); + virtual bool handleValidKeyPress(int iUserIndex, int buttonNum, + bool quickKeyHeld); + virtual void handleOutsideClicked(int iPad, int buttonNum, + bool quickKeyHeld); + virtual void handleOtherClicked(int iPad, ESceneSection eSection, + int buttonNum, bool quickKey); + virtual void handleAdditionalKeyPress(int iAction); + virtual void handleSlotListClicked(ESceneSection eSection, int buttonNum, + bool quickKeyHeld); + virtual void handleSectionClick(ESceneSection eSection) = 0; + void slotClicked(int slotId, int buttonNum, bool quickKey); + int getCurrentIndex(ESceneSection eSection); + virtual int getSectionStartOffset(ESceneSection eSection) = 0; + virtual bool doesSectionTreeHaveFocus(ESceneSection eSection) = 0; + virtual void setSectionFocus(ESceneSection eSection, int iPad) = 0; + virtual void setSectionSelectedSlot(ESceneSection eSection, int x, + int y) = 0; + virtual void setFocusToPointer(int iPad) = 0; + virtual void SetPointerText(const std::wstring& description, + std::vector& unformattedStrings, + bool newSlot) = 0; + virtual std::shared_ptr getSlotItem(ESceneSection eSection, + int iSlot) = 0; + virtual bool isSlotEmpty(ESceneSection eSection, int iSlot) = 0; + virtual void adjustPointerForSafeZone() = 0; + + virtual bool overrideTooltips( + ESceneSection sectionUnderPointer, + std::shared_ptr itemUnderPointer, bool bIsItemCarried, + bool bSlotHasItem, bool bCarriedIsSameAsSlot, + int iSlotStackSizeRemaining, EToolTipItem& buttonA, + EToolTipItem& buttonX, EToolTipItem& buttonY, EToolTipItem& buttonRT) { + return false; + } private: - bool IsSameItemAs(std::shared_ptr itemA, std::shared_ptr itemB); - int GetEmptyStackSpace(Slot *slot); - std::wstring GetItemDescription(Slot *slot, std::vector &unformattedStrings); + bool IsSameItemAs(std::shared_ptr itemA, + std::shared_ptr itemB); + int GetEmptyStackSpace(Slot* slot); + std::wstring GetItemDescription( + Slot* slot, std::vector& unformattedStrings); protected: - - IUIScene_AbstractContainerMenu(); - virtual ~IUIScene_AbstractContainerMenu(); + IUIScene_AbstractContainerMenu(); + virtual ~IUIScene_AbstractContainerMenu(); public: - virtual int getPad() = 0; + virtual int getPad() = 0; }; diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.cpp index 05cfbb98f..265c06d6c 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.cpp @@ -7,270 +7,225 @@ #include "../../Minecraft.Client/Player/MultiPlayerLocalPlayer.h" #include "../../Minecraft.Client/Network/ClientConnection.h" -IUIScene_AnvilMenu::IUIScene_AnvilMenu() -{ - m_inventory = nullptr; - m_repairMenu = NULL; - m_itemName = L""; +IUIScene_AnvilMenu::IUIScene_AnvilMenu() { + m_inventory = nullptr; + m_repairMenu = NULL; + m_itemName = L""; } -IUIScene_AbstractContainerMenu::ESceneSection IUIScene_AnvilMenu::GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY ) -{ - ESceneSection newSection = eSection; - int xOffset = 0; +IUIScene_AbstractContainerMenu::ESceneSection +IUIScene_AnvilMenu::GetSectionAndSlotInDirection(ESceneSection eSection, + ETapState eTapDirection, + int* piTargetX, + int* piTargetY) { + ESceneSection newSection = eSection; + int xOffset = 0; - // Find the new section if there is one - switch( eSection ) - { - case eSectionAnvilItem1: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionAnvilName; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionAnvilInventory; - xOffset = ANVIL_SCENE_ITEM1_SLOT_DOWN_OFFSET; - } - else if(eTapDirection == eTapStateLeft) - { - newSection = eSectionAnvilResult; - } - else if(eTapDirection == eTapStateRight) - { - newSection = eSectionAnvilItem2; - } - break; - case eSectionAnvilItem2: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionAnvilName; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionAnvilInventory; - xOffset = ANVIL_SCENE_ITEM2_SLOT_DOWN_OFFSET; - } - else if(eTapDirection == eTapStateLeft) - { - newSection = eSectionAnvilItem1; - } - else if(eTapDirection == eTapStateRight) - { - newSection = eSectionAnvilResult; - } - break; - case eSectionAnvilResult: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionAnvilName; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionAnvilInventory; - xOffset = ANVIL_SCENE_RESULT_SLOT_DOWN_OFFSET; - } - else if(eTapDirection == eTapStateLeft) - { - newSection = eSectionAnvilItem2; - } - else if(eTapDirection == eTapStateRight) - { - newSection = eSectionAnvilItem1; - } - break; - case eSectionAnvilName: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionAnvilUsing; - xOffset = ANVIL_SCENE_ITEM2_SLOT_UP_OFFSET; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionAnvilItem2; - } - break; - case eSectionAnvilInventory: - if(eTapDirection == eTapStateDown) - { - newSection = eSectionAnvilUsing; - } - else if(eTapDirection == eTapStateUp) - { - if( *piTargetX <= ANVIL_SCENE_ITEM1_SLOT_UP_OFFSET) - { - newSection = eSectionAnvilItem1; - } - else if( *piTargetX <= ANVIL_SCENE_ITEM2_SLOT_UP_OFFSET) - { - newSection = eSectionAnvilItem2; - } - else if( *piTargetX >= ANVIL_SCENE_RESULT_SLOT_UP_OFFSET) - { - newSection = eSectionAnvilResult; - } - } - break; - case eSectionAnvilUsing: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionAnvilInventory; - } - else if(eTapDirection == eTapStateDown) - { - if( *piTargetX <= ANVIL_SCENE_ITEM1_SLOT_UP_OFFSET) - { - newSection = eSectionAnvilItem1; - } - else if( *piTargetX <= ANVIL_SCENE_ITEM2_SLOT_UP_OFFSET) - { - newSection = eSectionAnvilName; - } - else if( *piTargetX >= ANVIL_SCENE_RESULT_SLOT_UP_OFFSET) - { - newSection = eSectionAnvilName; - } - } - break; - default: - assert( false ); - break; - } + // Find the new section if there is one + switch (eSection) { + case eSectionAnvilItem1: + if (eTapDirection == eTapStateUp) { + newSection = eSectionAnvilName; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionAnvilInventory; + xOffset = ANVIL_SCENE_ITEM1_SLOT_DOWN_OFFSET; + } else if (eTapDirection == eTapStateLeft) { + newSection = eSectionAnvilResult; + } else if (eTapDirection == eTapStateRight) { + newSection = eSectionAnvilItem2; + } + break; + case eSectionAnvilItem2: + if (eTapDirection == eTapStateUp) { + newSection = eSectionAnvilName; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionAnvilInventory; + xOffset = ANVIL_SCENE_ITEM2_SLOT_DOWN_OFFSET; + } else if (eTapDirection == eTapStateLeft) { + newSection = eSectionAnvilItem1; + } else if (eTapDirection == eTapStateRight) { + newSection = eSectionAnvilResult; + } + break; + case eSectionAnvilResult: + if (eTapDirection == eTapStateUp) { + newSection = eSectionAnvilName; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionAnvilInventory; + xOffset = ANVIL_SCENE_RESULT_SLOT_DOWN_OFFSET; + } else if (eTapDirection == eTapStateLeft) { + newSection = eSectionAnvilItem2; + } else if (eTapDirection == eTapStateRight) { + newSection = eSectionAnvilItem1; + } + break; + case eSectionAnvilName: + if (eTapDirection == eTapStateUp) { + newSection = eSectionAnvilUsing; + xOffset = ANVIL_SCENE_ITEM2_SLOT_UP_OFFSET; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionAnvilItem2; + } + break; + case eSectionAnvilInventory: + if (eTapDirection == eTapStateDown) { + newSection = eSectionAnvilUsing; + } else if (eTapDirection == eTapStateUp) { + if (*piTargetX <= ANVIL_SCENE_ITEM1_SLOT_UP_OFFSET) { + newSection = eSectionAnvilItem1; + } else if (*piTargetX <= ANVIL_SCENE_ITEM2_SLOT_UP_OFFSET) { + newSection = eSectionAnvilItem2; + } else if (*piTargetX >= ANVIL_SCENE_RESULT_SLOT_UP_OFFSET) { + newSection = eSectionAnvilResult; + } + } + break; + case eSectionAnvilUsing: + if (eTapDirection == eTapStateUp) { + newSection = eSectionAnvilInventory; + } else if (eTapDirection == eTapStateDown) { + if (*piTargetX <= ANVIL_SCENE_ITEM1_SLOT_UP_OFFSET) { + newSection = eSectionAnvilItem1; + } else if (*piTargetX <= ANVIL_SCENE_ITEM2_SLOT_UP_OFFSET) { + newSection = eSectionAnvilName; + } else if (*piTargetX >= ANVIL_SCENE_RESULT_SLOT_UP_OFFSET) { + newSection = eSectionAnvilName; + } + } + break; + default: + assert(false); + break; + } - updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, piTargetY, xOffset); + updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, + piTargetY, xOffset); - return newSection; + return newSection; } -int IUIScene_AnvilMenu::getSectionStartOffset(ESceneSection eSection) -{ - int offset = 0; - switch( eSection ) - { - case eSectionAnvilItem1: - offset = MerchantMenu::PAYMENT1_SLOT; - break; - case eSectionAnvilItem2: - offset = MerchantMenu::PAYMENT2_SLOT; - break; - case eSectionAnvilResult: - offset = MerchantMenu::RESULT_SLOT; - break; - case eSectionAnvilInventory: - offset = MerchantMenu::INV_SLOT_START; - break; - case eSectionAnvilUsing: - offset = MerchantMenu::USE_ROW_SLOT_START; - break; - default: - assert( false ); - break; - } - return offset; +int IUIScene_AnvilMenu::getSectionStartOffset(ESceneSection eSection) { + int offset = 0; + switch (eSection) { + case eSectionAnvilItem1: + offset = MerchantMenu::PAYMENT1_SLOT; + break; + case eSectionAnvilItem2: + offset = MerchantMenu::PAYMENT2_SLOT; + break; + case eSectionAnvilResult: + offset = MerchantMenu::RESULT_SLOT; + break; + case eSectionAnvilInventory: + offset = MerchantMenu::INV_SLOT_START; + break; + case eSectionAnvilUsing: + offset = MerchantMenu::USE_ROW_SLOT_START; + break; + default: + assert(false); + break; + } + return offset; } -void IUIScene_AnvilMenu::handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey) -{ - switch(eSection) - { - case eSectionAnvilName: - handleEditNamePressed(); - break; - default: - break; - }; +void IUIScene_AnvilMenu::handleOtherClicked(int iPad, ESceneSection eSection, + int buttonNum, bool quickKey) { + switch (eSection) { + case eSectionAnvilName: + handleEditNamePressed(); + break; + default: + break; + }; } -bool IUIScene_AnvilMenu::IsSectionSlotList( ESceneSection eSection ) -{ - switch( eSection ) - { - case eSectionAnvilUsing: - case eSectionAnvilInventory: - case eSectionAnvilItem1: - case eSectionAnvilItem2: - case eSectionAnvilResult: - return true; - default: - break; - } - return false; +bool IUIScene_AnvilMenu::IsSectionSlotList(ESceneSection eSection) { + switch (eSection) { + case eSectionAnvilUsing: + case eSectionAnvilInventory: + case eSectionAnvilItem1: + case eSectionAnvilItem2: + case eSectionAnvilResult: + return true; + default: + break; + } + return false; } -void IUIScene_AnvilMenu::handleTick() -{ - Minecraft *pMinecraft = Minecraft::GetInstance(); - bool canAfford = true; - std::wstring m_costString = L""; +void IUIScene_AnvilMenu::handleTick() { + Minecraft* pMinecraft = Minecraft::GetInstance(); + bool canAfford = true; + std::wstring m_costString = L""; - if(m_repairMenu->cost > 0) - { - if(m_repairMenu->cost >= 40 && !pMinecraft->localplayers[getPad()]->abilities.instabuild) - { - m_costString = app.GetString(IDS_REPAIR_EXPENSIVE); - canAfford = false; - } - else if(!m_repairMenu->getSlot(RepairMenu::RESULT_SLOT)->hasItem()) - { - // Do nothing - } - else - { - const wchar_t *costString = app.GetString(IDS_REPAIR_COST); - wchar_t temp[256]; - swprintf(temp, 256, costString, m_repairMenu->cost); - m_costString = temp; - if(!m_repairMenu->getSlot(RepairMenu::RESULT_SLOT)->mayPickup(std::dynamic_pointer_cast(m_inventory->player->shared_from_this()))) - { - canAfford = false; - } - } - } - setCostLabel(m_costString, canAfford); + if (m_repairMenu->cost > 0) { + if (m_repairMenu->cost >= 40 && + !pMinecraft->localplayers[getPad()]->abilities.instabuild) { + m_costString = app.GetString(IDS_REPAIR_EXPENSIVE); + canAfford = false; + } else if (!m_repairMenu->getSlot(RepairMenu::RESULT_SLOT)->hasItem()) { + // Do nothing + } else { + const wchar_t* costString = app.GetString(IDS_REPAIR_COST); + wchar_t temp[256]; + swprintf(temp, 256, costString, m_repairMenu->cost); + m_costString = temp; + if (!m_repairMenu->getSlot(RepairMenu::RESULT_SLOT) + ->mayPickup(std::dynamic_pointer_cast( + m_inventory->player->shared_from_this()))) { + canAfford = false; + } + } + } + setCostLabel(m_costString, canAfford); - bool crossVisible = (m_repairMenu->getSlot(RepairMenu::INPUT_SLOT)->hasItem() || m_repairMenu->getSlot(RepairMenu::ADDITIONAL_SLOT)->hasItem()) && !m_repairMenu->getSlot(RepairMenu::RESULT_SLOT)->hasItem(); - showCross(crossVisible); + bool crossVisible = + (m_repairMenu->getSlot(RepairMenu::INPUT_SLOT)->hasItem() || + m_repairMenu->getSlot(RepairMenu::ADDITIONAL_SLOT)->hasItem()) && + !m_repairMenu->getSlot(RepairMenu::RESULT_SLOT)->hasItem(); + showCross(crossVisible); } -void IUIScene_AnvilMenu::updateItemName() -{ - Slot *slot = m_repairMenu->getSlot(RepairMenu::INPUT_SLOT); - if (slot != NULL && slot->hasItem()) - { - if (!slot->getItem()->hasCustomHoverName() && m_itemName.compare(slot->getItem()->getHoverName())==0) - { - m_itemName = L""; - } - } +void IUIScene_AnvilMenu::updateItemName() { + Slot* slot = m_repairMenu->getSlot(RepairMenu::INPUT_SLOT); + if (slot != NULL && slot->hasItem()) { + if (!slot->getItem()->hasCustomHoverName() && + m_itemName.compare(slot->getItem()->getHoverName()) == 0) { + m_itemName = L""; + } + } - m_repairMenu->setItemName(m_itemName); + m_repairMenu->setItemName(m_itemName); - // Convert to byteArray - ByteArrayOutputStream baos; - DataOutputStream dos(&baos); - dos.writeUTF(m_itemName); - Minecraft::GetInstance()->localplayers[getPad()]->connection->send(std::shared_ptr(new CustomPayloadPacket(CustomPayloadPacket::SET_ITEM_NAME_PACKET, baos.toByteArray()))); + // Convert to byteArray + ByteArrayOutputStream baos; + DataOutputStream dos(&baos); + dos.writeUTF(m_itemName); + Minecraft::GetInstance()->localplayers[getPad()]->connection->send( + std::shared_ptr(new CustomPayloadPacket( + CustomPayloadPacket::SET_ITEM_NAME_PACKET, baos.toByteArray()))); } -void IUIScene_AnvilMenu::refreshContainer(AbstractContainerMenu *container, std::vector > *items) -{ - slotChanged(container, RepairMenu::INPUT_SLOT, container->getSlot(0)->getItem()); +void IUIScene_AnvilMenu::refreshContainer( + AbstractContainerMenu* container, + std::vector >* items) { + slotChanged(container, RepairMenu::INPUT_SLOT, + container->getSlot(0)->getItem()); } -void IUIScene_AnvilMenu::slotChanged(AbstractContainerMenu *container, int slotIndex, std::shared_ptr item) -{ - if (slotIndex == RepairMenu::INPUT_SLOT) - { - m_itemName = item == NULL ? L"" : item->getHoverName(); - setEditNameValue(m_itemName); - setEditNameEditable(item != NULL); - if (item != NULL) - { - updateItemName(); - } - } +void IUIScene_AnvilMenu::slotChanged(AbstractContainerMenu* container, + int slotIndex, + std::shared_ptr item) { + if (slotIndex == RepairMenu::INPUT_SLOT) { + m_itemName = item == NULL ? L"" : item->getHoverName(); + setEditNameValue(m_itemName); + setEditNameEditable(item != NULL); + if (item != NULL) { + updateItemName(); + } + } } -void IUIScene_AnvilMenu::setContainerData(AbstractContainerMenu *container, int id, int value) -{ -} +void IUIScene_AnvilMenu::setContainerData(AbstractContainerMenu* container, + int id, int value) {} diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.h b/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.h index 32416fcdd..d1789a860 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.h +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_AnvilMenu.h @@ -13,33 +13,40 @@ class Inventory; class RepairMenu; -class IUIScene_AnvilMenu : public virtual IUIScene_AbstractContainerMenu, public net_minecraft_world_inventory::ContainerListener -{ +class IUIScene_AnvilMenu + : public virtual IUIScene_AbstractContainerMenu, + public net_minecraft_world_inventory::ContainerListener { protected: - std::shared_ptr m_inventory; - RepairMenu *m_repairMenu; - std::wstring m_itemName; + std::shared_ptr m_inventory; + RepairMenu* m_repairMenu; + std::wstring m_itemName; protected: - IUIScene_AnvilMenu(); + IUIScene_AnvilMenu(); - virtual ESceneSection GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY ); - int getSectionStartOffset(ESceneSection eSection); - virtual void handleOtherClicked(int iPad, ESceneSection eSection, int buttonNum, bool quickKey); - bool IsSectionSlotList( ESceneSection eSection ); + virtual ESceneSection GetSectionAndSlotInDirection(ESceneSection eSection, + ETapState eTapDirection, + int* piTargetX, + int* piTargetY); + int getSectionStartOffset(ESceneSection eSection); + virtual void handleOtherClicked(int iPad, ESceneSection eSection, + int buttonNum, bool quickKey); + bool IsSectionSlotList(ESceneSection eSection); - void handleTick(); + void handleTick(); - // Anvil only - virtual void handleEditNamePressed() = 0; - virtual void setEditNameValue(const std::wstring &name) = 0; - virtual void setEditNameEditable(bool enabled) = 0; - virtual void setCostLabel(const std::wstring &label, bool canAfford) = 0; - virtual void showCross(bool show) = 0; - void updateItemName(); + // Anvil only + virtual void handleEditNamePressed() = 0; + virtual void setEditNameValue(const std::wstring& name) = 0; + virtual void setEditNameEditable(bool enabled) = 0; + virtual void setCostLabel(const std::wstring& label, bool canAfford) = 0; + virtual void showCross(bool show) = 0; + void updateItemName(); - // ContainerListenr - void refreshContainer(AbstractContainerMenu *container, std::vector > *items); - void slotChanged(AbstractContainerMenu *container, int slotIndex, std::shared_ptr item); - void setContainerData(AbstractContainerMenu *container, int id, int value); + // ContainerListenr + void refreshContainer(AbstractContainerMenu* container, + std::vector >* items); + void slotChanged(AbstractContainerMenu* container, int slotIndex, + std::shared_ptr item); + void setContainerData(AbstractContainerMenu* container, int id, int value); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.cpp index 99bd28400..3cccef704 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.cpp @@ -3,149 +3,115 @@ #include "IUIScene_BrewingMenu.h" #include "../../Minecraft.World/Headers/net.minecraft.world.inventory.h" -IUIScene_AbstractContainerMenu::ESceneSection IUIScene_BrewingMenu::GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY ) -{ - ESceneSection newSection = eSection; - int xOffset = 0; +IUIScene_AbstractContainerMenu::ESceneSection +IUIScene_BrewingMenu::GetSectionAndSlotInDirection(ESceneSection eSection, + ETapState eTapDirection, + int* piTargetX, + int* piTargetY) { + ESceneSection newSection = eSection; + int xOffset = 0; - // Find the new section if there is one - switch( eSection ) - { - case eSectionBrewingBottle1: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionBrewingIngredient; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionBrewingInventory; - xOffset = BREWING_SCENE_BOTTLE1_SLOT_DOWN_OFFSET; - } - else if(eTapDirection == eTapStateLeft) - { - newSection = eSectionBrewingBottle3; - } - else if(eTapDirection == eTapStateRight) - { - newSection = eSectionBrewingBottle2; - } - break; - case eSectionBrewingBottle2: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionBrewingIngredient; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionBrewingInventory; - xOffset = BREWING_SCENE_BOTTLE2_SLOT_DOWN_OFFSET; - } - else if(eTapDirection == eTapStateLeft) - { - newSection = eSectionBrewingBottle1; - } - else if(eTapDirection == eTapStateRight) - { - newSection = eSectionBrewingBottle3; - } - break; - case eSectionBrewingBottle3: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionBrewingIngredient; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionBrewingInventory; - xOffset = BREWING_SCENE_BOTTLE3_SLOT_DOWN_OFFSET; - } - else if(eTapDirection == eTapStateLeft) - { - newSection = eSectionBrewingBottle2; - } - else if(eTapDirection == eTapStateRight) - { - newSection = eSectionBrewingBottle1; - } - break; - case eSectionBrewingIngredient: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionBrewingUsing; - xOffset = BREWING_SCENE_INGREDIENT_SLOT_DOWN_OFFSET; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionBrewingBottle2; - } - break; - case eSectionBrewingInventory: - if(eTapDirection == eTapStateDown) - { - newSection = eSectionBrewingUsing; - } - else if(eTapDirection == eTapStateUp) - { - if( *piTargetX <= BREWING_SCENE_BOTTLE1_SLOT_UP_OFFSET) - { - newSection = eSectionBrewingBottle1; - } - else if( *piTargetX <= BREWING_SCENE_BOTTLE2_SLOT_UP_OFFSET) - { - newSection = eSectionBrewingBottle2; - } - else if( *piTargetX >= BREWING_SCENE_BOTTLE3_SLOT_UP_OFFSET) - { - newSection = eSectionBrewingBottle3; - } - } - break; - case eSectionBrewingUsing: - if(eTapDirection == eTapStateUp) - { - newSection = eSectionBrewingInventory; - } - else if(eTapDirection == eTapStateDown) - { - newSection = eSectionBrewingIngredient; - } - break; - default: - assert( false ); - break; - } + // Find the new section if there is one + switch (eSection) { + case eSectionBrewingBottle1: + if (eTapDirection == eTapStateUp) { + newSection = eSectionBrewingIngredient; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionBrewingInventory; + xOffset = BREWING_SCENE_BOTTLE1_SLOT_DOWN_OFFSET; + } else if (eTapDirection == eTapStateLeft) { + newSection = eSectionBrewingBottle3; + } else if (eTapDirection == eTapStateRight) { + newSection = eSectionBrewingBottle2; + } + break; + case eSectionBrewingBottle2: + if (eTapDirection == eTapStateUp) { + newSection = eSectionBrewingIngredient; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionBrewingInventory; + xOffset = BREWING_SCENE_BOTTLE2_SLOT_DOWN_OFFSET; + } else if (eTapDirection == eTapStateLeft) { + newSection = eSectionBrewingBottle1; + } else if (eTapDirection == eTapStateRight) { + newSection = eSectionBrewingBottle3; + } + break; + case eSectionBrewingBottle3: + if (eTapDirection == eTapStateUp) { + newSection = eSectionBrewingIngredient; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionBrewingInventory; + xOffset = BREWING_SCENE_BOTTLE3_SLOT_DOWN_OFFSET; + } else if (eTapDirection == eTapStateLeft) { + newSection = eSectionBrewingBottle2; + } else if (eTapDirection == eTapStateRight) { + newSection = eSectionBrewingBottle1; + } + break; + case eSectionBrewingIngredient: + if (eTapDirection == eTapStateUp) { + newSection = eSectionBrewingUsing; + xOffset = BREWING_SCENE_INGREDIENT_SLOT_DOWN_OFFSET; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionBrewingBottle2; + } + break; + case eSectionBrewingInventory: + if (eTapDirection == eTapStateDown) { + newSection = eSectionBrewingUsing; + } else if (eTapDirection == eTapStateUp) { + if (*piTargetX <= BREWING_SCENE_BOTTLE1_SLOT_UP_OFFSET) { + newSection = eSectionBrewingBottle1; + } else if (*piTargetX <= BREWING_SCENE_BOTTLE2_SLOT_UP_OFFSET) { + newSection = eSectionBrewingBottle2; + } else if (*piTargetX >= BREWING_SCENE_BOTTLE3_SLOT_UP_OFFSET) { + newSection = eSectionBrewingBottle3; + } + } + break; + case eSectionBrewingUsing: + if (eTapDirection == eTapStateUp) { + newSection = eSectionBrewingInventory; + } else if (eTapDirection == eTapStateDown) { + newSection = eSectionBrewingIngredient; + } + break; + default: + assert(false); + break; + } - updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, piTargetY, xOffset); + updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, + piTargetY, xOffset); - return newSection; + return newSection; } -int IUIScene_BrewingMenu::getSectionStartOffset(ESceneSection eSection) -{ - int offset = 0; - switch( eSection ) - { - case eSectionBrewingBottle1: - offset = BrewingStandMenu::BOTTLE_SLOT_START; - break; - case eSectionBrewingBottle2: - offset = BrewingStandMenu::BOTTLE_SLOT_START + 1; - break; - case eSectionBrewingBottle3: - offset = BrewingStandMenu::BOTTLE_SLOT_START + 2; - break; - case eSectionBrewingIngredient: - offset = BrewingStandMenu::INGREDIENT_SLOT; - break; - case eSectionBrewingInventory: - offset = BrewingStandMenu::INV_SLOT_START; - break; - case eSectionBrewingUsing: - offset = BrewingStandMenu::INV_SLOT_START + 27; - break; - default: - assert( false ); - break; - } - return offset; +int IUIScene_BrewingMenu::getSectionStartOffset(ESceneSection eSection) { + int offset = 0; + switch (eSection) { + case eSectionBrewingBottle1: + offset = BrewingStandMenu::BOTTLE_SLOT_START; + break; + case eSectionBrewingBottle2: + offset = BrewingStandMenu::BOTTLE_SLOT_START + 1; + break; + case eSectionBrewingBottle3: + offset = BrewingStandMenu::BOTTLE_SLOT_START + 2; + break; + case eSectionBrewingIngredient: + offset = BrewingStandMenu::INGREDIENT_SLOT; + break; + case eSectionBrewingInventory: + offset = BrewingStandMenu::INV_SLOT_START; + break; + case eSectionBrewingUsing: + offset = BrewingStandMenu::INV_SLOT_START + 27; + break; + default: + assert(false); + break; + } + return offset; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.h b/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.h index 2d5150bb4..806910712 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.h +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_BrewingMenu.h @@ -11,9 +11,11 @@ #define BREWING_SCENE_BOTTLE3_SLOT_UP_OFFSET 5 #define BREWING_SCENE_BOTTLE3_SLOT_DOWN_OFFSET 5 -class IUIScene_BrewingMenu : public virtual IUIScene_AbstractContainerMenu -{ +class IUIScene_BrewingMenu : public virtual IUIScene_AbstractContainerMenu { protected: - virtual ESceneSection GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY ); - int getSectionStartOffset(ESceneSection eSection); + virtual ESceneSection GetSectionAndSlotInDirection(ESceneSection eSection, + ETapState eTapDirection, + int* piTargetX, + int* piTargetY); + int getSectionStartOffset(ESceneSection eSection); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.cpp index 92bf32b93..b4201cf59 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.cpp @@ -2,70 +2,62 @@ #include "IUIScene_ContainerMenu.h" #include "../../Minecraft.World/Headers/net.minecraft.world.inventory.h" -IUIScene_AbstractContainerMenu::ESceneSection IUIScene_ContainerMenu::GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY ) -{ - ESceneSection newSection = eSection; +IUIScene_AbstractContainerMenu::ESceneSection +IUIScene_ContainerMenu::GetSectionAndSlotInDirection(ESceneSection eSection, + ETapState eTapDirection, + int* piTargetX, + int* piTargetY) { + ESceneSection newSection = eSection; - // Find the new section if there is one - switch( eSection ) - { - case eSectionContainerChest: - if(eTapDirection == eTapStateDown) - { - newSection = eSectionContainerInventory; - } - else if(eTapDirection == eTapStateUp) - { - newSection = eSectionContainerUsing; - } - break; - case eSectionContainerInventory: - if(eTapDirection == eTapStateDown) - { - newSection = eSectionContainerUsing; - } - else if(eTapDirection == eTapStateUp) - { - newSection = eSectionContainerChest; - } - break; - case eSectionContainerUsing: - if(eTapDirection == eTapStateDown) - { - newSection = eSectionContainerChest; - } - else if(eTapDirection == eTapStateUp) - { - newSection = eSectionContainerInventory; - } - break; - default: - assert( false ); - break; - } + // Find the new section if there is one + switch (eSection) { + case eSectionContainerChest: + if (eTapDirection == eTapStateDown) { + newSection = eSectionContainerInventory; + } else if (eTapDirection == eTapStateUp) { + newSection = eSectionContainerUsing; + } + break; + case eSectionContainerInventory: + if (eTapDirection == eTapStateDown) { + newSection = eSectionContainerUsing; + } else if (eTapDirection == eTapStateUp) { + newSection = eSectionContainerChest; + } + break; + case eSectionContainerUsing: + if (eTapDirection == eTapStateDown) { + newSection = eSectionContainerChest; + } else if (eTapDirection == eTapStateUp) { + newSection = eSectionContainerInventory; + } + break; + default: + assert(false); + break; + } - updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, piTargetY, 0); + updateSlotPosition(eSection, newSection, eTapDirection, piTargetX, + piTargetY, 0); - return newSection; + return newSection; } -int IUIScene_ContainerMenu::getSectionStartOffset(ESceneSection eSection) -{ - int offset = 0; - switch( eSection ) - { - case eSectionContainerChest: - offset = 0; - break; - case eSectionContainerInventory: - offset = m_menu->getSize() - (27+9); - break; - case eSectionContainerUsing: - offset = m_menu->getSize() - 9; - break; - default: - assert( false ); - break; - } - return offset; +int IUIScene_ContainerMenu::getSectionStartOffset(ESceneSection eSection) { + int offset = 0; + switch (eSection) { + case eSectionContainerChest: + offset = 0; + break; + case eSectionContainerInventory: + offset = m_menu->getSize() - (27 + 9); + break; + case eSectionContainerUsing: + offset = m_menu->getSize() - 9; + break; + default: + assert(false); + break; + } + return offset; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.h b/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.h index e0408b390..bb9f2e8a7 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.h +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_ContainerMenu.h @@ -2,9 +2,11 @@ #include "IUIScene_AbstractContainerMenu.h" -class IUIScene_ContainerMenu : public virtual IUIScene_AbstractContainerMenu -{ +class IUIScene_ContainerMenu : public virtual IUIScene_AbstractContainerMenu { protected: - virtual ESceneSection GetSectionAndSlotInDirection( ESceneSection eSection, ETapState eTapDirection, int *piTargetX, int *piTargetY ); - int getSectionStartOffset(ESceneSection eSection); + virtual ESceneSection GetSectionAndSlotInDirection(ESceneSection eSection, + ETapState eTapDirection, + int* piTargetX, + int* piTargetY); + int getSectionStartOffset(ESceneSection eSection); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_CraftingMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_CraftingMenu.cpp index 60d62372c..6570b22d3 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_CraftingMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_CraftingMenu.cpp @@ -6,61 +6,43 @@ #include "../../Minecraft.Client/Player/LocalPlayer.h" #include "IUIScene_CraftingMenu.h" -Recipy::_eGroupType IUIScene_CraftingMenu::m_GroupTypeMapping4GridA[IUIScene_CraftingMenu::m_iMaxGroup2x2]= -{ - Recipy::eGroupType_Structure, - Recipy::eGroupType_Tool, - Recipy::eGroupType_Food, - Recipy::eGroupType_Mechanism, - Recipy::eGroupType_Transport, - Recipy::eGroupType_Decoration, +Recipy::_eGroupType IUIScene_CraftingMenu::m_GroupTypeMapping4GridA + [IUIScene_CraftingMenu::m_iMaxGroup2x2] = { + Recipy::eGroupType_Structure, Recipy::eGroupType_Tool, + Recipy::eGroupType_Food, Recipy::eGroupType_Mechanism, + Recipy::eGroupType_Transport, Recipy::eGroupType_Decoration, }; -Recipy::_eGroupType IUIScene_CraftingMenu::m_GroupTypeMapping9GridA[IUIScene_CraftingMenu::m_iMaxGroup3x3]= -{ - Recipy::eGroupType_Structure, - Recipy::eGroupType_Tool, - Recipy::eGroupType_Food, - Recipy::eGroupType_Armour, - Recipy::eGroupType_Mechanism, - Recipy::eGroupType_Transport, - Recipy::eGroupType_Decoration, +Recipy::_eGroupType IUIScene_CraftingMenu::m_GroupTypeMapping9GridA + [IUIScene_CraftingMenu::m_iMaxGroup3x3] = { + Recipy::eGroupType_Structure, Recipy::eGroupType_Tool, + Recipy::eGroupType_Food, Recipy::eGroupType_Armour, + Recipy::eGroupType_Mechanism, Recipy::eGroupType_Transport, + Recipy::eGroupType_Decoration, }; - -const wchar_t *IUIScene_CraftingMenu::m_GroupIconNameA[m_iMaxGroup3x3]= -{ - L"Structures",//Recipy::eGroupType_Structure, - L"Tools",//Recipy::eGroupType_Tool, - L"Food",//Recipy::eGroupType_Food, - L"Armour",//Recipy::eGroupType_Armour, - L"Mechanisms",//Recipy::eGroupType_Mechanism, - L"Transport",//Recipy::eGroupType_Transport, - L"Decoration",//Recipy::eGroupType_Decoration, +const wchar_t* IUIScene_CraftingMenu::m_GroupIconNameA[m_iMaxGroup3x3] = { + L"Structures", // Recipy::eGroupType_Structure, + L"Tools", // Recipy::eGroupType_Tool, + L"Food", // Recipy::eGroupType_Food, + L"Armour", // Recipy::eGroupType_Armour, + L"Mechanisms", // Recipy::eGroupType_Mechanism, + L"Transport", // Recipy::eGroupType_Transport, + L"Decoration", // Recipy::eGroupType_Decoration, }; -IUIScene_CraftingMenu::_eGroupTab IUIScene_CraftingMenu::m_GroupTabBkgMapping2x2A[m_iMaxGroup2x2]= -{ - eGroupTab_Left, - eGroupTab_Middle, - eGroupTab_Middle, - eGroupTab_Middle, - eGroupTab_Middle, - eGroupTab_Right, +IUIScene_CraftingMenu::_eGroupTab + IUIScene_CraftingMenu::m_GroupTabBkgMapping2x2A[m_iMaxGroup2x2] = { + eGroupTab_Left, eGroupTab_Middle, eGroupTab_Middle, + eGroupTab_Middle, eGroupTab_Middle, eGroupTab_Right, }; -IUIScene_CraftingMenu::_eGroupTab IUIScene_CraftingMenu::m_GroupTabBkgMapping3x3A[m_iMaxGroup3x3]= -{ - eGroupTab_Left, - eGroupTab_Middle, - eGroupTab_Middle, - eGroupTab_Middle, - eGroupTab_Middle, - eGroupTab_Middle, - eGroupTab_Right, +IUIScene_CraftingMenu::_eGroupTab + IUIScene_CraftingMenu::m_GroupTabBkgMapping3x3A[m_iMaxGroup3x3] = { + eGroupTab_Left, eGroupTab_Middle, eGroupTab_Middle, eGroupTab_Middle, + eGroupTab_Middle, eGroupTab_Middle, eGroupTab_Right, }; - // mapping array to map the base objects to their description string // This should map the enums // enum @@ -91,499 +73,523 @@ IUIScene_CraftingMenu::_eGroupTab IUIScene_CraftingMenu::m_GroupTabBkgMapping3x3 // eBaseItemType_bow, // eBaseItemType_pockettool, // eBaseItemType_utensil, -// +// // } // eBaseItemType; -IUIScene_CraftingMenu::IUIScene_CraftingMenu() -{ - m_iCurrentSlotHIndex=0; - m_iCurrentSlotVIndex=1; +IUIScene_CraftingMenu::IUIScene_CraftingMenu() { + m_iCurrentSlotHIndex = 0; + m_iCurrentSlotVIndex = 1; - for(int i=0;ilocalgameModes[getPad()] != NULL ) - { - Tutorial *tutorial = pMinecraft->localgameModes[getPad()]->getTutorial(); - if(tutorial != NULL) - { - tutorial->handleUIInput(iAction); - if(ui.IsTutorialVisible(getPad()) && !tutorial->isInputAllowed(iAction)) - { - return S_OK; - } - } - } + if (pMinecraft->localgameModes[getPad()] != NULL) { + Tutorial* tutorial = + pMinecraft->localgameModes[getPad()]->getTutorial(); + if (tutorial != NULL) { + tutorial->handleUIInput(iAction); + if (ui.IsTutorialVisible(getPad()) && + !tutorial->isInputAllowed(iAction)) { + return S_OK; + } + } + } + switch (iAction) { + case ACTION_MENU_X: - switch(iAction) - { - case ACTION_MENU_X: + // change the display + m_iDisplayDescription++; + if (m_iDisplayDescription == DISPLAY_MAX) + m_iDisplayDescription = DISPLAY_INVENTORY; + ui.PlayUISFX(eSFX_Focus); + UpdateMultiPanel(); + UpdateTooltips(); + break; + case ACTION_MENU_PAUSEMENU: + case ACTION_MENU_B: + ui.ShowTooltip(iPad, eToolTipButtonX, false); + ui.ShowTooltip(iPad, eToolTipButtonB, false); + ui.ShowTooltip(iPad, eToolTipButtonA, false); + ui.ShowTooltip(iPad, eToolTipButtonRB, false); + // kill the crafting xui + // ui.PlayUISFX(eSFX_Back); + ui.CloseUIScenes(iPad); - // change the display - m_iDisplayDescription++; - if(m_iDisplayDescription==DISPLAY_MAX) m_iDisplayDescription=DISPLAY_INVENTORY; - ui.PlayUISFX(eSFX_Focus); - UpdateMultiPanel(); - UpdateTooltips(); - break; - case ACTION_MENU_PAUSEMENU: - case ACTION_MENU_B: - ui.ShowTooltip( iPad, eToolTipButtonX, false ); - ui.ShowTooltip( iPad, eToolTipButtonB, false ); - ui.ShowTooltip( iPad, eToolTipButtonA, false ); - ui.ShowTooltip( iPad, eToolTipButtonRB, false ); - // kill the crafting xui - //ui.PlayUISFX(eSFX_Back); - ui.CloseUIScenes(iPad); - - bHandled = true; - break; - case ACTION_MENU_A: + bHandled = true; + break; + case ACTION_MENU_A: #ifdef __ORBIS__ - case ACTION_MENU_TOUCHPAD_PRESS: + case ACTION_MENU_TOUCHPAD_PRESS: #endif - // Do some crafting! - if(m_pPlayer && m_pPlayer->inventory) - { - //RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); - Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); - // Force a make if the debug is on - if(app.DebugSettingsOn() && app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L<inventory) { + // RecipyList *recipes = ((Recipes + // *)Recipes::getInstance())->getRecipies(); + Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = + Recipes::getInstance()->getRecipeIngredientsArray(); + // Force a make if the debug is on + if (app.DebugSettingsOn() && + app.GetGameSettingsDebugMask( + ProfileManager.GetPrimaryPad()) & + (1L << eDebugSetting_CraftAnything)) { + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount != 0) { + int iSlot = iVSlotIndexA[m_iCurrentSlotVIndex]; - int iRecipe= CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; - std::shared_ptr pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); - //int iIcon=pTempItemInst->getItem()->getIcon(pTempItemInst->getAuxValue()); + int iRecipe = + CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; + std::shared_ptr pTempItemInst = + pRecipeIngredientsRequired[iRecipe] + .pRecipy->assemble(nullptr); + // int + // iIcon=pTempItemInst->getItem()->getIcon(pTempItemInst->getAuxValue()); - if( pMinecraft->localgameModes[iPad] != NULL) - { - Tutorial *tutorial = pMinecraft->localgameModes[iPad]->getTutorial(); - if(tutorial != NULL) - { - tutorial->onCrafted(pTempItemInst); - } - } + if (pMinecraft->localgameModes[iPad] != NULL) { + Tutorial* tutorial = + pMinecraft->localgameModes[iPad]->getTutorial(); + if (tutorial != NULL) { + tutorial->onCrafted(pTempItemInst); + } + } - pMinecraft->localgameModes[iPad]->handleCraftItem(iRecipe,m_pPlayer); + pMinecraft->localgameModes[iPad]->handleCraftItem( + iRecipe, m_pPlayer); - if(m_pPlayer->inventory->add(pTempItemInst)==false) - { - // no room in inventory, so throw it down - m_pPlayer->drop(pTempItemInst); - } - // play a sound - //pMinecraft->soundEngine->playUI( L"random.pop", 1.0f, 1.0f); - ui.PlayUISFX(eSFX_Craft); - } - } - else if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0) - { - int iSlot; - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) - { - iSlot=iVSlotIndexA[m_iCurrentSlotVIndex]; - } - else - { - iSlot=0; - } - int iRecipe= CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; - std::shared_ptr pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); - //int iIcon=pTempItemInst->getItem()->getIcon(pTempItemInst->getAuxValue()); + if (m_pPlayer->inventory->add(pTempItemInst) == false) { + // no room in inventory, so throw it down + m_pPlayer->drop(pTempItemInst); + } + // play a sound + // pMinecraft->soundEngine->playUI( + // L"random.pop", 1.0f, 1.0f); + ui.PlayUISFX(eSFX_Craft); + } + } else if (CanBeMadeA[m_iCurrentSlotHIndex].iCount != 0) { + int iSlot; + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 1) { + iSlot = iVSlotIndexA[m_iCurrentSlotVIndex]; + } else { + iSlot = 0; + } + int iRecipe = + CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; + std::shared_ptr pTempItemInst = + pRecipeIngredientsRequired[iRecipe].pRecipy->assemble( + nullptr); + // int + // iIcon=pTempItemInst->getItem()->getIcon(pTempItemInst->getAuxValue()); - if( pMinecraft->localgameModes[iPad] != NULL ) - { - Tutorial *tutorial = pMinecraft->localgameModes[iPad]->getTutorial(); - if(tutorial != NULL) - { - tutorial->createItemSelected(pTempItemInst, pRecipeIngredientsRequired[iRecipe].bCanMake[iPad]); - } - } + if (pMinecraft->localgameModes[iPad] != NULL) { + Tutorial* tutorial = + pMinecraft->localgameModes[iPad]->getTutorial(); + if (tutorial != NULL) { + tutorial->createItemSelected( + pTempItemInst, + pRecipeIngredientsRequired[iRecipe] + .bCanMake[iPad]); + } + } - if(pRecipeIngredientsRequired[iRecipe].bCanMake[iPad]) - { - pTempItemInst->onCraftedBy(m_pPlayer->level, std::dynamic_pointer_cast( m_pPlayer->shared_from_this() ), pTempItemInst->count ); - // TODO 4J Stu - handleCraftItem should do a lot more than what it does, loads of the "can we craft" code should also probably be - // shifted to the GameMode - pMinecraft->localgameModes[iPad]->handleCraftItem(iRecipe,m_pPlayer); + if (pRecipeIngredientsRequired[iRecipe].bCanMake[iPad]) { + pTempItemInst->onCraftedBy( + m_pPlayer->level, + std::dynamic_pointer_cast( + m_pPlayer->shared_from_this()), + pTempItemInst->count); + // TODO 4J Stu - handleCraftItem should do a lot more + // than what it does, loads of the "can we craft" code + // should also probably be shifted to the GameMode + pMinecraft->localgameModes[iPad]->handleCraftItem( + iRecipe, m_pPlayer); - // play a sound - //pMinecraft->soundEngine->playUI( L"random.pop", 1.0f, 1.0f); - ui.PlayUISFX(eSFX_Craft); + // play a sound + // pMinecraft->soundEngine->playUI( + // L"random.pop", 1.0f, 1.0f); + ui.PlayUISFX(eSFX_Craft); - // and remove those resources from your inventory - for(int i=0;i ingItemInst = nullptr; - // do we need to remove a specific aux value? - if(pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]!=Recipes::ANY_AUX_VALUE) - { - ingItemInst = m_pPlayer->inventory->getResourceItem( pRecipeIngredientsRequired[iRecipe].iIngIDA[i],pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i] ); - m_pPlayer->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i],pRecipeIngredientsRequired[iRecipe].iIngAuxValA[i]); - } - else - { - ingItemInst = m_pPlayer->inventory->getResourceItem( pRecipeIngredientsRequired[iRecipe].iIngIDA[i] ); - m_pPlayer->inventory->removeResource(pRecipeIngredientsRequired[iRecipe].iIngIDA[i]); - } + // and remove those resources from your inventory + for (int i = 0; + i < pRecipeIngredientsRequired[iRecipe].iIngC; + i++) { + for (int j = 0; + j < pRecipeIngredientsRequired[iRecipe] + .iIngValA[i]; + j++) { + std::shared_ptr ingItemInst = + nullptr; + // do we need to remove a specific aux value? + if (pRecipeIngredientsRequired[iRecipe] + .iIngAuxValA[i] != + Recipes::ANY_AUX_VALUE) { + ingItemInst = + m_pPlayer->inventory->getResourceItem( + pRecipeIngredientsRequired[iRecipe] + .iIngIDA[i], + pRecipeIngredientsRequired[iRecipe] + .iIngAuxValA[i]); + m_pPlayer->inventory->removeResource( + pRecipeIngredientsRequired[iRecipe] + .iIngIDA[i], + pRecipeIngredientsRequired[iRecipe] + .iIngAuxValA[i]); + } else { + ingItemInst = + m_pPlayer->inventory->getResourceItem( + pRecipeIngredientsRequired[iRecipe] + .iIngIDA[i]); + m_pPlayer->inventory->removeResource( + pRecipeIngredientsRequired[iRecipe] + .iIngIDA[i]); + } - // 4J Stu - Fix for #13097 - Bug: Milk Buckets are removed when crafting Cake - if (ingItemInst != NULL) - { - if (ingItemInst->getItem()->hasCraftingRemainingItem()) - { - // replace item with remaining result - m_pPlayer->inventory->add( std::shared_ptr( new ItemInstance(ingItemInst->getItem()->getCraftingRemainingItem()) ) ); - } + // 4J Stu - Fix for #13097 - Bug: Milk Buckets + // are removed when crafting Cake + if (ingItemInst != NULL) { + if (ingItemInst->getItem() + ->hasCraftingRemainingItem()) { + // replace item with remaining result + m_pPlayer->inventory->add( + std::shared_ptr< + ItemInstance>(new ItemInstance( + ingItemInst->getItem() + ->getCraftingRemainingItem()))); + } + } + } + } - } - } - } + // 4J Stu - Fix for #13119 - We should add the item + // after we remove the ingredients + if (m_pPlayer->inventory->add(pTempItemInst) == false) { + // no room in inventory, so throw it down + m_pPlayer->drop(pTempItemInst); + } - // 4J Stu - Fix for #13119 - We should add the item after we remove the ingredients - if(m_pPlayer->inventory->add(pTempItemInst)==false ) - { - // no room in inventory, so throw it down - m_pPlayer->drop(pTempItemInst); - } + // 4J Gordon: Achievements + switch (pTempItemInst->id) { + case Tile::workBench_Id: + m_pPlayer->awardStat( + GenericStats::buildWorkbench(), + GenericStats::param_buildWorkbench()); + break; + case Item::pickAxe_wood_Id: + m_pPlayer->awardStat( + GenericStats::buildPickaxe(), + GenericStats::param_buildPickaxe()); + break; + case Tile::furnace_Id: + m_pPlayer->awardStat( + GenericStats::buildFurnace(), + GenericStats::param_buildFurnace()); + break; + case Item::hoe_wood_Id: + m_pPlayer->awardStat( + GenericStats::buildHoe(), + GenericStats::param_buildHoe()); + break; + case Item::bread_Id: + m_pPlayer->awardStat( + GenericStats::makeBread(), + GenericStats::param_makeBread()); + break; + case Item::cake_Id: + m_pPlayer->awardStat( + GenericStats::bakeCake(), + GenericStats::param_bakeCake()); + break; + case Item::pickAxe_stone_Id: + m_pPlayer->awardStat( + GenericStats::buildBetterPickaxe(), + GenericStats::param_buildBetterPickaxe()); + break; + case Item::sword_wood_Id: + m_pPlayer->awardStat( + GenericStats::buildSword(), + GenericStats::param_buildSword()); + break; + case Tile::dispenser_Id: + m_pPlayer->awardStat( + GenericStats::dispenseWithThis(), + GenericStats::param_dispenseWithThis()); + break; + case Tile::enchantTable_Id: + m_pPlayer->awardStat( + GenericStats::enchantments(), + GenericStats::param_enchantments()); + break; + case Tile::bookshelf_Id: + m_pPlayer->awardStat( + GenericStats::bookcase(), + GenericStats::param_bookcase()); + break; + } - //4J Gordon: Achievements - switch(pTempItemInst->id ) - { - case Tile::workBench_Id: m_pPlayer->awardStat(GenericStats::buildWorkbench(), GenericStats::param_buildWorkbench()); break; - case Item::pickAxe_wood_Id: m_pPlayer->awardStat(GenericStats::buildPickaxe(), GenericStats::param_buildPickaxe()); break; - case Tile::furnace_Id: m_pPlayer->awardStat(GenericStats::buildFurnace(), GenericStats::param_buildFurnace()); break; - case Item::hoe_wood_Id: m_pPlayer->awardStat(GenericStats::buildHoe(), GenericStats::param_buildHoe()); break; - case Item::bread_Id: m_pPlayer->awardStat(GenericStats::makeBread(), GenericStats::param_makeBread()); break; - case Item::cake_Id: m_pPlayer->awardStat(GenericStats::bakeCake(), GenericStats::param_bakeCake()); break; - case Item::pickAxe_stone_Id: m_pPlayer->awardStat(GenericStats::buildBetterPickaxe(), GenericStats::param_buildBetterPickaxe()); break; - case Item::sword_wood_Id: m_pPlayer->awardStat(GenericStats::buildSword(), GenericStats::param_buildSword()); break; - case Tile::dispenser_Id: m_pPlayer->awardStat(GenericStats::dispenseWithThis(), GenericStats::param_dispenseWithThis()); break; - case Tile::enchantTable_Id: m_pPlayer->awardStat(GenericStats::enchantments(), GenericStats::param_enchantments()); break; - case Tile::bookshelf_Id: m_pPlayer->awardStat(GenericStats::bookcase(), GenericStats::param_bookcase()); break; - } + // We've used some ingredients from our inventory, so + // update the recipes we can make + CheckRecipesAvailable(); + // don't reset the vertical slots - we want to stay + // where we are + UpdateVerticalSlots(); + UpdateHighlight(); + } else { + // pMinecraft->soundEngine->playUI( + // L"btn.back", 1.0f, 1.0f); + ui.PlayUISFX(eSFX_CraftFail); + } + } + } + break; - // We've used some ingredients from our inventory, so update the recipes we can make - CheckRecipesAvailable(); - // don't reset the vertical slots - we want to stay where we are - UpdateVerticalSlots(); - UpdateHighlight(); - } - else - { - //pMinecraft->soundEngine->playUI( L"btn.back", 1.0f, 1.0f); - ui.PlayUISFX(eSFX_CraftFail); - } - } - } - break; + case ACTION_MENU_LEFT_SCROLL: + // turn off the old group tab + showTabHighlight(m_iGroupIndex, false); - case ACTION_MENU_LEFT_SCROLL: - // turn off the old group tab - showTabHighlight(m_iGroupIndex,false); + if (m_iGroupIndex == 0) { + if (m_iContainerType == RECIPE_TYPE_3x3) { + m_iGroupIndex = m_iMaxGroup3x3 - 1; + } else { + m_iGroupIndex = m_iMaxGroup2x2 - 1; + } + } else { + m_iGroupIndex--; + } + // turn on the new group + showTabHighlight(m_iGroupIndex, true); - if(m_iGroupIndex==0) - { - if(m_iContainerType==RECIPE_TYPE_3x3) - { - m_iGroupIndex=m_iMaxGroup3x3-1; - } - else - { - m_iGroupIndex=m_iMaxGroup2x2-1; - } - } - else - { - m_iGroupIndex--; - } - // turn on the new group - showTabHighlight(m_iGroupIndex,true); + m_iCurrentSlotHIndex = 0; + m_iCurrentSlotVIndex = 1; - m_iCurrentSlotHIndex=0; - m_iCurrentSlotVIndex=1; + CheckRecipesAvailable(); + // reset the vertical slots + iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1; + iVSlotIndexA[1] = 0; + iVSlotIndexA[2] = 1; + ui.PlayUISFX(eSFX_Focus); + UpdateVerticalSlots(); + UpdateHighlight(); + setGroupText(GetGroupNameText(m_pGroupA[m_iGroupIndex])); - CheckRecipesAvailable(); - // reset the vertical slots - iVSlotIndexA[0]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1; - iVSlotIndexA[1]=0; - iVSlotIndexA[2]=1; - ui.PlayUISFX(eSFX_Focus); - UpdateVerticalSlots(); - UpdateHighlight(); - setGroupText(GetGroupNameText(m_pGroupA[m_iGroupIndex])); + break; + case ACTION_MENU_RIGHT_SCROLL: + // turn off the old group tab + showTabHighlight(m_iGroupIndex, false); - break; - case ACTION_MENU_RIGHT_SCROLL: - // turn off the old group tab - showTabHighlight(m_iGroupIndex,false); + m_iGroupIndex++; + if (m_iContainerType == RECIPE_TYPE_3x3) { + if (m_iGroupIndex == m_iMaxGroup3x3) m_iGroupIndex = 0; + } else { + if (m_iGroupIndex == m_iMaxGroup2x2) m_iGroupIndex = 0; + } + // turn on the new group + showTabHighlight(m_iGroupIndex, true); - m_iGroupIndex++; - if(m_iContainerType==RECIPE_TYPE_3x3) - { - if(m_iGroupIndex==m_iMaxGroup3x3) m_iGroupIndex=0; - } - else - { - if(m_iGroupIndex==m_iMaxGroup2x2) m_iGroupIndex=0; - } - // turn on the new group - showTabHighlight(m_iGroupIndex,true); + m_iCurrentSlotHIndex = 0; + m_iCurrentSlotVIndex = 1; + CheckRecipesAvailable(); + // reset the vertical slots + iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1; + iVSlotIndexA[1] = 0; + iVSlotIndexA[2] = 1; + ui.PlayUISFX(eSFX_Focus); + UpdateVerticalSlots(); + UpdateHighlight(); + setGroupText(GetGroupNameText(m_pGroupA[m_iGroupIndex])); + break; + } - m_iCurrentSlotHIndex=0; - m_iCurrentSlotVIndex=1; - CheckRecipesAvailable(); - // reset the vertical slots - iVSlotIndexA[0]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1; - iVSlotIndexA[1]=0; - iVSlotIndexA[2]=1; - ui.PlayUISFX(eSFX_Focus); - UpdateVerticalSlots(); - UpdateHighlight(); - setGroupText(GetGroupNameText(m_pGroupA[m_iGroupIndex])); - break; - } - - // 4J-Tomk - check if we've only got one vertical scroll slot (480, splits & Vita) - bool bNoScrollSlots = false; - if(m_bSplitscreen ||(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())) - { - bNoScrollSlots = true; - } + // 4J-Tomk - check if we've only got one vertical scroll slot (480, splits & + // Vita) + bool bNoScrollSlots = false; + if (m_bSplitscreen || + (!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())) { + bNoScrollSlots = true; + } #ifdef __PSVITA__ - bNoScrollSlots = true; + bNoScrollSlots = true; #endif - // 4J Stu - We did used to swap the thumsticks based on Southpaw in this scene, but ONLY in this scene - switch(iAction) - { - case ACTION_MENU_OTHER_STICK_UP: - scrollDescriptionUp(); - break; - case ACTION_MENU_OTHER_STICK_DOWN: - scrollDescriptionDown(); - break; - case ACTION_MENU_RIGHT: - { - int iOldHSlot=m_iCurrentSlotHIndex; + // 4J Stu - We did used to swap the thumsticks based on Southpaw in this + // scene, but ONLY in this scene + switch (iAction) { + case ACTION_MENU_OTHER_STICK_UP: + scrollDescriptionUp(); + break; + case ACTION_MENU_OTHER_STICK_DOWN: + scrollDescriptionDown(); + break; + case ACTION_MENU_RIGHT: { + int iOldHSlot = m_iCurrentSlotHIndex; - m_iCurrentSlotHIndex++; - if(m_iCurrentSlotHIndex>=m_iCraftablesMaxHSlotC) m_iCurrentSlotHIndex=0; - m_iCurrentSlotVIndex=1; - // clear the indices - iVSlotIndexA[0]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1; - iVSlotIndexA[1]=0; - iVSlotIndexA[2]=1; + m_iCurrentSlotHIndex++; + if (m_iCurrentSlotHIndex >= m_iCraftablesMaxHSlotC) + m_iCurrentSlotHIndex = 0; + m_iCurrentSlotVIndex = 1; + // clear the indices + iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1; + iVSlotIndexA[1] = 0; + iVSlotIndexA[2] = 1; - UpdateVerticalSlots(); - UpdateHighlight(); - // re-enable the old hslot - if(CanBeMadeA[iOldHSlot].iCount>0) - { - setShowCraftHSlot(iOldHSlot,true); - } - ui.PlayUISFX(eSFX_Focus); - bHandled = true; - } - break; - case ACTION_MENU_LEFT: - { - if(m_iCraftablesMaxHSlotC!=0) - { - int iOldHSlot=m_iCurrentSlotHIndex; - if(m_iCurrentSlotHIndex==0) m_iCurrentSlotHIndex=m_iCraftablesMaxHSlotC-1; - else m_iCurrentSlotHIndex--; - m_iCurrentSlotVIndex=1; - // clear the indices - iVSlotIndexA[0]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1; - iVSlotIndexA[1]=0; - iVSlotIndexA[2]=1; + UpdateVerticalSlots(); + UpdateHighlight(); + // re-enable the old hslot + if (CanBeMadeA[iOldHSlot].iCount > 0) { + setShowCraftHSlot(iOldHSlot, true); + } + ui.PlayUISFX(eSFX_Focus); + bHandled = true; + } break; + case ACTION_MENU_LEFT: { + if (m_iCraftablesMaxHSlotC != 0) { + int iOldHSlot = m_iCurrentSlotHIndex; + if (m_iCurrentSlotHIndex == 0) + m_iCurrentSlotHIndex = m_iCraftablesMaxHSlotC - 1; + else + m_iCurrentSlotHIndex--; + m_iCurrentSlotVIndex = 1; + // clear the indices + iVSlotIndexA[0] = CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1; + iVSlotIndexA[1] = 0; + iVSlotIndexA[2] = 1; - UpdateVerticalSlots(); - UpdateHighlight(); - // re-enable the old hslot - if(CanBeMadeA[iOldHSlot].iCount>0) - { - setShowCraftHSlot(iOldHSlot,true); - } - ui.PlayUISFX(eSFX_Focus); - } - bHandled = true; - } - break; - case ACTION_MENU_UP: - { - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) - { - if(bNoScrollSlots) - { - if(iVSlotIndexA[1]==0) - { - iVSlotIndexA[1]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1; - } - else - { - iVSlotIndexA[1]--; - } - ui.PlayUISFX(eSFX_Focus); - } - else - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>2) - { - { - if(m_iCurrentSlotVIndex!=0) - { - // just move the highlight - m_iCurrentSlotVIndex--; - ui.PlayUISFX(eSFX_Focus); - } - else - { - //move the slots - iVSlotIndexA[2]=iVSlotIndexA[1]; - iVSlotIndexA[1]=iVSlotIndexA[0]; - // on 0 and went up, so cycle the values - if(iVSlotIndexA[0]==0) - { - iVSlotIndexA[0]=CanBeMadeA[m_iCurrentSlotHIndex].iCount-1; - } - else - { - iVSlotIndexA[0]--; - } - ui.PlayUISFX(eSFX_Focus); - } - } - } - else - { - if(m_iCurrentSlotVIndex!=1) - { - // just move the highlight - m_iCurrentSlotVIndex--; - ui.PlayUISFX(eSFX_Focus); - } - } - UpdateVerticalSlots(); - UpdateHighlight(); - } + UpdateVerticalSlots(); + UpdateHighlight(); + // re-enable the old hslot + if (CanBeMadeA[iOldHSlot].iCount > 0) { + setShowCraftHSlot(iOldHSlot, true); + } + ui.PlayUISFX(eSFX_Focus); + } + bHandled = true; + } break; + case ACTION_MENU_UP: { + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 1) { + if (bNoScrollSlots) { + if (iVSlotIndexA[1] == 0) { + iVSlotIndexA[1] = + CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1; + } else { + iVSlotIndexA[1]--; + } + ui.PlayUISFX(eSFX_Focus); + } else if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 2) { + { + if (m_iCurrentSlotVIndex != 0) { + // just move the highlight + m_iCurrentSlotVIndex--; + ui.PlayUISFX(eSFX_Focus); + } else { + // move the slots + iVSlotIndexA[2] = iVSlotIndexA[1]; + iVSlotIndexA[1] = iVSlotIndexA[0]; + // on 0 and went up, so cycle the values + if (iVSlotIndexA[0] == 0) { + iVSlotIndexA[0] = + CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1; + } else { + iVSlotIndexA[0]--; + } + ui.PlayUISFX(eSFX_Focus); + } + } + } else { + if (m_iCurrentSlotVIndex != 1) { + // just move the highlight + m_iCurrentSlotVIndex--; + ui.PlayUISFX(eSFX_Focus); + } + } + UpdateVerticalSlots(); + UpdateHighlight(); + } - } - break; - case ACTION_MENU_DOWN: - { - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) - { - if(bNoScrollSlots) - { - if(iVSlotIndexA[1]==(CanBeMadeA[m_iCurrentSlotHIndex].iCount-1)) - { - iVSlotIndexA[1]=0; - } - else - { - iVSlotIndexA[1]++; - } - ui.PlayUISFX(eSFX_Focus); + } break; + case ACTION_MENU_DOWN: { + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 1) { + if (bNoScrollSlots) { + if (iVSlotIndexA[1] == + (CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1)) { + iVSlotIndexA[1] = 0; + } else { + iVSlotIndexA[1]++; + } + ui.PlayUISFX(eSFX_Focus); - } - else - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>2) - { - if(m_iCurrentSlotVIndex!=2) - { - m_iCurrentSlotVIndex++; - ui.PlayUISFX(eSFX_Focus); - } - else - { - iVSlotIndexA[0]=iVSlotIndexA[1]; - iVSlotIndexA[1]=iVSlotIndexA[2]; - if(iVSlotIndexA[m_iCurrentSlotVIndex]==(CanBeMadeA[m_iCurrentSlotHIndex].iCount-1)) - { - iVSlotIndexA[2]=0; - } - else - { - iVSlotIndexA[2]++; - } - ui.PlayUISFX(eSFX_Focus); - } - } - else - { - if(m_iCurrentSlotVIndex!=(CanBeMadeA[m_iCurrentSlotHIndex].iCount)) - { - m_iCurrentSlotVIndex++; - ui.PlayUISFX(eSFX_Focus); - } - } - UpdateVerticalSlots(); - UpdateHighlight(); - } - } - break; - } + } else if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 2) { + if (m_iCurrentSlotVIndex != 2) { + m_iCurrentSlotVIndex++; + ui.PlayUISFX(eSFX_Focus); + } else { + iVSlotIndexA[0] = iVSlotIndexA[1]; + iVSlotIndexA[1] = iVSlotIndexA[2]; + if (iVSlotIndexA[m_iCurrentSlotVIndex] == + (CanBeMadeA[m_iCurrentSlotHIndex].iCount - 1)) { + iVSlotIndexA[2] = 0; + } else { + iVSlotIndexA[2]++; + } + ui.PlayUISFX(eSFX_Focus); + } + } else { + if (m_iCurrentSlotVIndex != + (CanBeMadeA[m_iCurrentSlotHIndex].iCount)) { + m_iCurrentSlotVIndex++; + ui.PlayUISFX(eSFX_Focus); + } + } + UpdateVerticalSlots(); + UpdateHighlight(); + } + } break; + } - return bHandled; + return bHandled; } ////////////////////////////////////////////////////////////////////////// @@ -591,293 +597,319 @@ bool IUIScene_CraftingMenu::handleKeyDown(int iPad, int iAction, bool bRepeat) // CheckRecipesAvailable // ////////////////////////////////////////////////////////////////////////// -void IUIScene_CraftingMenu::CheckRecipesAvailable() -{ - int iHSlotBrushControl=0; +void IUIScene_CraftingMenu::CheckRecipesAvailable() { + int iHSlotBrushControl = 0; - // clear the current list - memset(CanBeMadeA,0,sizeof(CANBEMADE)*m_iCraftablesMaxHSlotC); + // clear the current list + memset(CanBeMadeA, 0, sizeof(CANBEMADE) * m_iCraftablesMaxHSlotC); - hideAllHSlots(); + hideAllHSlots(); - if(m_pPlayer && m_pPlayer->inventory) - { - // dump out the inventory - /* for (unsigned int k = 0; k < m_pPlayer->inventory->items.length; k++) - { - if (m_pPlayer->inventory->items[k] != NULL) - { - std::wstring itemstring=m_pPlayer->inventory->items[k]->toString(); + if (m_pPlayer && m_pPlayer->inventory) { + // dump out the inventory + /* for (unsigned int k = 0; k < + m_pPlayer->inventory->items.length; k++) + { + if (m_pPlayer->inventory->items[k] != NULL) + { + std::wstring itemstring=m_pPlayer->inventory->items[k]->toString(); - //printf("--- Player has "); - OutputDebugStringW(itemstring.c_str()); - //printf(" with Aux val = %d, base type = %d, Material = %d\n",m_pPlayer->inventory->items[k]->getAuxValue(),m_pPlayer->inventory->items[k]->getItem()->getBaseItemType(),m_pPlayer->inventory->items[k]->getItem()->getMaterial()); - } - } - */ - RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); - Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); - int iRecipeC=(int)recipes->size(); - AUTO_VAR(itRecipe, recipes->begin()); + //printf("--- Player has "); + OutputDebugStringW(itemstring.c_str()); + //printf(" with Aux val = %d, base type = %d, Material = + %d\n",m_pPlayer->inventory->items[k]->getAuxValue(),m_pPlayer->inventory->items[k]->getItem()->getBaseItemType(),m_pPlayer->inventory->items[k]->getItem()->getMaterial()); + } + } + */ + RecipyList* recipes = ((Recipes*)Recipes::getInstance())->getRecipies(); + Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = + Recipes::getInstance()->getRecipeIngredientsArray(); + int iRecipeC = (int)recipes->size(); + AUTO_VAR(itRecipe, recipes->begin()); - // dump out the recipe products + // dump out the recipe products - // for (int i = 0; i < iRecipeC; i++) - // { - // std::shared_ptr pTempItemInst=pRecipeIngredientsRequired[i].pRecipy->assemble(NULL); - // if (pTempItemInst != NULL) - // { - // std::wstring itemstring=pTempItemInst->toString(); - // - // printf("Recipe [%d] = ",i); - // OutputDebugStringW(itemstring.c_str()); - // if(pTempItemInst->id!=0) - // { - // if(pTempItemInst->id<256) - // { - // Tile *pTile=Tile::tiles[pTempItemInst->id]; - // printf("[TILE] ID\t%d\tAux val\t%d\tBase type\t%d\tMaterial\t%d\t Count=%d\n",pTempItemInst->id, pTempItemInst->getAuxValue(),pTile->getBaseItemType(),pTile->getMaterial(),pTempItemInst->GetCount()); - // } - // else - // { - // printf("ID\t%d\tAux val\t%d\tBase type\t%d\tMaterial\t%d Count=%d\n",pTempItemInst->id, pTempItemInst->getAuxValue(),pTempItemInst->getItem()->getBaseItemType(),pTempItemInst->getItem()->getMaterial(),pTempItemInst->GetCount()); - // } - // - // } - // } - // } + // for (int i = 0; i < iRecipeC; i++) + // { + // std::shared_ptr + // pTempItemInst=pRecipeIngredientsRequired[i].pRecipy->assemble(NULL); + // if (pTempItemInst != NULL) + // { + // std::wstring + // itemstring=pTempItemInst->toString(); + // + // printf("Recipe [%d] = ",i); + // OutputDebugStringW(itemstring.c_str()); + // if(pTempItemInst->id!=0) + // { + // if(pTempItemInst->id<256) + // { + // Tile + // *pTile=Tile::tiles[pTempItemInst->id]; printf("[TILE] ID\t%d\tAux + // val\t%d\tBase type\t%d\tMaterial\t%d\t Count=%d\n",pTempItemInst->id, + // pTempItemInst->getAuxValue(),pTile->getBaseItemType(),pTile->getMaterial(),pTempItemInst->GetCount()); + // } + // else + // { + // printf("ID\t%d\tAux + // val\t%d\tBase type\t%d\tMaterial\t%d Count=%d\n",pTempItemInst->id, + // pTempItemInst->getAuxValue(),pTempItemInst->getItem()->getBaseItemType(),pTempItemInst->getItem()->getMaterial(),pTempItemInst->GetCount()); + // } + // + // } + // } + // } - for(int i=0;igetGroup() != m_pGroupA[m_iGroupIndex]) { + itRecipe++; + pRecipeIngredientsRequired[i].bCanMake[getPad()] = false; + continue; + } + // if we are in the inventory menu, then we have 2x2 crafting + // available only + if ((m_iContainerType == RECIPE_TYPE_2x2) && + (pRecipeIngredientsRequired[i].iType == RECIPE_TYPE_3x3)) { + // need a crafting table for this recipe + itRecipe++; + pRecipeIngredientsRequired[i].bCanMake[getPad()] = false; + continue; + } + // clear the mask showing which ingredients are missing + pRecipeIngredientsRequired[i] + .usBitmaskMissingGridIngredients[getPad()] = 0; - // If this recipe isn't in the current grouptype, skip it - if(r->getGroup()!=m_pGroupA[m_iGroupIndex]) - { - itRecipe++; - pRecipeIngredientsRequired[i].bCanMake[getPad()]=false; - continue; - } - // if we are in the inventory menu, then we have 2x2 crafting available only - if((m_iContainerType==RECIPE_TYPE_2x2) && (pRecipeIngredientsRequired[i].iType==RECIPE_TYPE_3x3)) - { - // need a crafting table for this recipe - itRecipe++; - pRecipeIngredientsRequired[i].bCanMake[getPad()]=false; - continue; - } - // clear the mask showing which ingredients are missing - pRecipeIngredientsRequired[i].usBitmaskMissingGridIngredients[getPad()]=0; + // bool bCanMakeRecipe=true; + bool* bFoundA = new bool[pRecipeIngredientsRequired[i].iIngC]; + for (int j = 0; j < pRecipeIngredientsRequired[i].iIngC; j++) { + bFoundA[j] = false; + int iTotalCount = 0; - //bool bCanMakeRecipe=true; - bool *bFoundA= new bool [pRecipeIngredientsRequired[i].iIngC]; - for(int j=0;jinventory->items.length; + k++) { + if (m_pPlayer->inventory->items[k] != NULL) { + // do they have the ingredient, and the aux value + // matches, and enough off it? + if ((m_pPlayer->inventory->items[k]->id == + pRecipeIngredientsRequired[i].iIngIDA[j]) && + // check if the ingredient required doesn't care + // about the aux value, or if it does, does the + // inventory item aux match it + ((pRecipeIngredientsRequired[i].iIngAuxValA[j] == + Recipes::ANY_AUX_VALUE) || + (pRecipeIngredientsRequired[i].iIngAuxValA[j] == + m_pPlayer->inventory->items[k]->getAuxValue()))) { + // do they have enough? We need to check the whole + // inventory, since they may have enough in + // different slots (milk isn't milkx3, but + // milk,milk,milk) + if (m_pPlayer->inventory->items[k]->GetCount() >= + pRecipeIngredientsRequired[i].iIngValA[j]) { + // they have enough with one slot + bFoundA[j] = true; + } else { + // look at the combined value from the whole + // inventory - // Does the player have this ingredient? - for (unsigned int k = 0; k < m_pPlayer->inventory->items.length; k++) - { - if (m_pPlayer->inventory->items[k] != NULL) - { - // do they have the ingredient, and the aux value matches, and enough off it? - if((m_pPlayer->inventory->items[k]->id == pRecipeIngredientsRequired[i].iIngIDA[j]) && - // check if the ingredient required doesn't care about the aux value, or if it does, does the inventory item aux match it - ((pRecipeIngredientsRequired[i].iIngAuxValA[j]==Recipes::ANY_AUX_VALUE) || (pRecipeIngredientsRequired[i].iIngAuxValA[j]==m_pPlayer->inventory->items[k]->getAuxValue())) - ) - { - // do they have enough? We need to check the whole inventory, since they may have enough in different slots (milk isn't milkx3, but milk,milk,milk) - if(m_pPlayer->inventory->items[k]->GetCount()>=pRecipeIngredientsRequired[i].iIngValA[j]) - { - // they have enough with one slot - bFoundA[j]=true; - } - else - { - // look at the combined value from the whole inventory + for (unsigned int l = 0; + l < m_pPlayer->inventory->items.length; + l++) { + if (m_pPlayer->inventory->items[l] != + NULL) { + if ((m_pPlayer->inventory->items[l] + ->id == + pRecipeIngredientsRequired[i] + .iIngIDA[j]) && + ((pRecipeIngredientsRequired[i] + .iIngAuxValA[j] == + Recipes::ANY_AUX_VALUE) || + (pRecipeIngredientsRequired[i] + .iIngAuxValA[j] == + m_pPlayer->inventory->items[l] + ->getAuxValue()))) { + iTotalCount += + m_pPlayer->inventory->items[l] + ->GetCount(); + } + } + } - for(unsigned int l=0;linventory->items.length;l++) - { - if (m_pPlayer->inventory->items[l] != NULL) - { - if( - (m_pPlayer->inventory->items[l]->id == pRecipeIngredientsRequired[i].iIngIDA[j]) && - ( (pRecipeIngredientsRequired[i].iIngAuxValA[j]==Recipes::ANY_AUX_VALUE) || (pRecipeIngredientsRequired[i].iIngAuxValA[j]==m_pPlayer->inventory->items[l]->getAuxValue() )) - ) - { - iTotalCount+=m_pPlayer->inventory->items[l]->GetCount(); - } - } - } + if (iTotalCount >= + pRecipeIngredientsRequired[i].iIngValA[j]) { + bFoundA[j] = true; + } + } - if(iTotalCount>=pRecipeIngredientsRequired[i].iIngValA[j]) - { - bFoundA[j]=true; - } - } + // 4J Stu - TU-1 hotfix + // Fix for #13143 - Players are able to craft items + // they do not have enough ingredients for if they + // store the ingredients in multiple, smaller stacks + break; + } + } + } + // if bFoundA[j] is false, then we didn't have enough of the + // ingredient required by the recipe, so mark the grid items + // we're short of + if (bFoundA[j] == false) { + int iMissing = + pRecipeIngredientsRequired[i].iIngValA[j] - iTotalCount; + int iGridIndex = 0; + while (iMissing != 0) { + // need to check if there is an aux val and match that + if (((pRecipeIngredientsRequired[i] + .uiGridA[iGridIndex] & + 0x00FFFFFF) == + pRecipeIngredientsRequired[i].iIngIDA[j]) && + ((pRecipeIngredientsRequired[i].iIngAuxValA[j] == + Recipes::ANY_AUX_VALUE) || + (pRecipeIngredientsRequired[i].iIngAuxValA[j] == + ((pRecipeIngredientsRequired[i] + .uiGridA[iGridIndex] & + 0xFF000000) >> + 24)))) { + // this grid entry is the ingredient we don't have + // enough of + pRecipeIngredientsRequired[i] + .usBitmaskMissingGridIngredients[getPad()] |= + 1 << iGridIndex; + iMissing--; + } + iGridIndex++; + } + } + } - // 4J Stu - TU-1 hotfix - // Fix for #13143 - Players are able to craft items they do not have enough ingredients for if they store the ingredients in multiple, smaller stacks - break; - } - } - } - // if bFoundA[j] is false, then we didn't have enough of the ingredient required by the recipe, so mark the grid items we're short of - if(bFoundA[j]==false) - { - int iMissing = pRecipeIngredientsRequired[i].iIngValA[j]-iTotalCount; - int iGridIndex=0; - while(iMissing!=0) - { - // need to check if there is an aux val and match that - if(((pRecipeIngredientsRequired[i].uiGridA[iGridIndex]&0x00FFFFFF)==pRecipeIngredientsRequired[i].iIngIDA[j]) && - ((pRecipeIngredientsRequired[i].iIngAuxValA[j]==Recipes::ANY_AUX_VALUE) ||(pRecipeIngredientsRequired[i].iIngAuxValA[j]== ((pRecipeIngredientsRequired[i].uiGridA[iGridIndex]&0xFF000000)>>24))) ) - { - // this grid entry is the ingredient we don't have enough of - pRecipeIngredientsRequired[i].usBitmaskMissingGridIngredients[getPad()]|=1< pTempItemInst = + pRecipeIngredientsRequired[i].pRecipy->assemble(nullptr); + // int + // iIcon=pTempItemInst->getItem()->getIcon(pTempItemInst->getAuxValue()); + int iID = pTempItemInst->getItem()->id; + int iBaseType; - // Add the recipe to the CanBeMade list of lists - if(iHSlotBrushControl<=m_iCraftablesMaxHSlotC) - { - bool bFound=false; - std::shared_ptr pTempItemInst=pRecipeIngredientsRequired[i].pRecipy->assemble(nullptr); - //int iIcon=pTempItemInst->getItem()->getIcon(pTempItemInst->getAuxValue()); - int iID=pTempItemInst->getItem()->id; - int iBaseType; + if (iID < 256) // is it a tile? + { + iBaseType = Tile::tiles[iID]->getBaseItemType(); + } else { + iBaseType = pTempItemInst->getItem()->getBaseItemType(); + } - if(iID<256) // is it a tile? - { - iBaseType=Tile::tiles[iID]->getBaseItemType(); - } - else - { - iBaseType=pTempItemInst->getItem()->getBaseItemType(); - } + // ignore for the misc base type - these have not been placed in + // a base type group + if (iBaseType != Item::eBaseItemType_undefined) { + for (int k = 0; k < iHSlotBrushControl; k++) { + // if the item base type is the same as one already in, + // then add it to that list + if (CanBeMadeA[k].iItemBaseType == iBaseType) { + // base item type already in our list + bFound = true; + if (CanBeMadeA[k].iCount < m_iMaxVSlotC) { + CanBeMadeA[k].iRecipeA[CanBeMadeA[k].iCount++] = + i; + } else { + app.DebugPrintf("Need more V slots\n"); + } + break; + } + } + } - // ignore for the misc base type - these have not been placed in a base type group - if(iBaseType!=Item::eBaseItemType_undefined) - { - for(int k=0;kgetDescriptionId())); + OutputDebugStringW( + app.GetString(pTempItemInst->getDescriptionId())); #endif - app.DebugPrintf("\n"); + app.DebugPrintf("\n"); + } + } + } else { + app.DebugPrintf("Need more HSlots\n"); + } - } - } - } - else - { - app.DebugPrintf("Need more HSlots\n"); - } + delete[] bFoundA; + itRecipe++; + } + } - delete [] bFoundA; - itRecipe++; - } - } + // run through the canbemade list and update the icons displayed + int iIndex = 0; + // RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); + Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = + Recipes::getInstance()->getRecipeIngredientsArray(); - // run through the canbemade list and update the icons displayed - int iIndex=0; - //RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); - Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); + while ((iIndex < m_iCraftablesMaxHSlotC) && + CanBeMadeA[iIndex].iCount != 0) { + std::shared_ptr pTempItemInst = + pRecipeIngredientsRequired[CanBeMadeA[iIndex].iRecipeA[0]] + .pRecipy->assemble(nullptr); + assert(pTempItemInst->id != 0); + unsigned int uiAlpha; - while((iIndex pTempItemInst=pRecipeIngredientsRequired[CanBeMadeA[iIndex].iRecipeA[0]].pRecipy->assemble(nullptr); - assert(pTempItemInst->id!=0); - unsigned int uiAlpha; + if (app.DebugSettingsOn() && + app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad()) & + (1L << eDebugSetting_CraftAnything)) { + uiAlpha = 31; + } else { + if (pRecipeIngredientsRequired[CanBeMadeA[iIndex].iRecipeA[0]] + .bCanMake[getPad()]) { + uiAlpha = 31; + } else { + uiAlpha = 16; + } + } - if(app.DebugSettingsOn() && app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L<id == Item::clock_Id || + pTempItemInst->id == Item::compass_Id) { + pTempItemInst->setAuxValue(255); + } + setCraftHSlotItem(getPad(), iIndex, pTempItemInst, uiAlpha); - // 4J Stu - For clocks and compasses we set the aux value to a special one that signals we should use a default texture - // rather than the dynamic one for the player - if( pTempItemInst->id == Item::clock_Id || pTempItemInst->id == Item::compass_Id ) - { - pTempItemInst->setAuxValue( 255 ); - } - setCraftHSlotItem(getPad(),iIndex,pTempItemInst,uiAlpha); + iIndex++; + } - iIndex++; - } - - // 4J-PB - Removed - UpdateTooltips will do this - // Update tooltips - /*if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0) - { - ui.ShowTooltip( getPad(), eToolTipButtonA, true ); - // 4J-PB - not implemented ! - //ui.EnableTooltip( getPad(), eToolTipButtonA, true ); - } - else - { - ui.ShowTooltip( getPad(), eToolTipButtonA, false ); - }*/ + // 4J-PB - Removed - UpdateTooltips will do this + // Update tooltips + /*if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0) + { + ui.ShowTooltip( getPad(), eToolTipButtonA, true ); + // 4J-PB - not implemented ! + //ui.EnableTooltip( getPad(), eToolTipButtonA, true ); + } + else + { + ui.ShowTooltip( getPad(), eToolTipButtonA, false ); + }*/ } ////////////////////////////////////////////////////////////////////////// @@ -885,73 +917,64 @@ void IUIScene_CraftingMenu::CheckRecipesAvailable() // UpdateHighlight // ////////////////////////////////////////////////////////////////////////// -void IUIScene_CraftingMenu::UpdateHighlight() -{ - updateHighlightAndScrollPositions(); +void IUIScene_CraftingMenu::UpdateHighlight() { + updateHighlightAndScrollPositions(); - bool bCanBeMade=CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0; - if(bCanBeMade) - { - //RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); - Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); - int iSlot; - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) - { - iSlot=iVSlotIndexA[m_iCurrentSlotVIndex]; - } - else - { - iSlot=0; - } - std::shared_ptr pTempItemInstAdditional=pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].pRecipy->assemble(nullptr); + bool bCanBeMade = CanBeMadeA[m_iCurrentSlotHIndex].iCount != 0; + if (bCanBeMade) { + // RecipyList *recipes = ((Recipes + // *)Recipes::getInstance())->getRecipies(); + Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = + Recipes::getInstance()->getRecipeIngredientsArray(); + int iSlot; + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 1) { + iSlot = iVSlotIndexA[m_iCurrentSlotVIndex]; + } else { + iSlot = 0; + } + std::shared_ptr pTempItemInstAdditional = + pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex] + .iRecipeA[iSlot]] + .pRecipy->assemble(nullptr); - // special case for the torch coal/charcoal - int id=pTempItemInstAdditional->getDescriptionId(); - const wchar_t *itemstring; + // special case for the torch coal/charcoal + int id = pTempItemInstAdditional->getDescriptionId(); + const wchar_t* itemstring; - switch(id) - { - case IDS_TILE_TORCH: - { - if(pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].iIngAuxValA[0]==1) - { - itemstring=app.GetString( IDS_TILE_TORCHCHARCOAL ); - } - else - { - itemstring=app.GetString( IDS_TILE_TORCHCOAL ); - } - } - break; - case IDS_ITEM_FIREBALL: - { - if(pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]].iIngAuxValA[2]==1) - { - itemstring=app.GetString( IDS_ITEM_FIREBALLCHARCOAL ); - } - else - { - itemstring=app.GetString( IDS_ITEM_FIREBALLCOAL ); - } - } - break; - default: - itemstring=app.GetString(id ); - break; - } + switch (id) { + case IDS_TILE_TORCH: { + if (pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex] + .iRecipeA[iSlot]] + .iIngAuxValA[0] == 1) { + itemstring = app.GetString(IDS_TILE_TORCHCHARCOAL); + } else { + itemstring = app.GetString(IDS_TILE_TORCHCOAL); + } + } break; + case IDS_ITEM_FIREBALL: { + if (pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex] + .iRecipeA[iSlot]] + .iIngAuxValA[2] == 1) { + itemstring = app.GetString(IDS_ITEM_FIREBALLCHARCOAL); + } else { + itemstring = app.GetString(IDS_ITEM_FIREBALLCOAL); + } + } break; + default: + itemstring = app.GetString(id); + break; + } - setItemText(itemstring); - } - else - { - setItemText(L""); - } - UpdateDescriptionText(bCanBeMade); - DisplayIngredients(); + setItemText(itemstring); + } else { + setItemText(L""); + } + UpdateDescriptionText(bCanBeMade); + DisplayIngredients(); - UpdateMultiPanel(); + UpdateMultiPanel(); - UpdateTooltips(); + UpdateTooltips(); } ////////////////////////////////////////////////////////////////////////// @@ -959,71 +982,73 @@ void IUIScene_CraftingMenu::UpdateHighlight() // UpdateVerticalSlots // ////////////////////////////////////////////////////////////////////////// -void IUIScene_CraftingMenu::UpdateVerticalSlots() -{ - //RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); - Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); +void IUIScene_CraftingMenu::UpdateVerticalSlots() { + // RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); + Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = + Recipes::getInstance()->getRecipeIngredientsArray(); - // update the vertical items for the current horizontal slot - hideAllVSlots(); + // update the vertical items for the current horizontal slot + hideAllVSlots(); - // could have either 1 or 2 vertical slots, above and below the horizontal slot - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) - { - // turn off the horizontal one since we could be cycling through others - setShowCraftHSlot(m_iCurrentSlotHIndex,false); - int iSlots=(CanBeMadeA[m_iCurrentSlotHIndex].iCount>2)?3:2; + // could have either 1 or 2 vertical slots, above and below the horizontal + // slot + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 1) { + // turn off the horizontal one since we could be cycling through others + setShowCraftHSlot(m_iCurrentSlotHIndex, false); + int iSlots = (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 2) ? 3 : 2; - // 4J-Tomk - check if we've only got one vertical scroll slot (480, splits & Vita) - bool bNoScrollSlots = false; - if(m_bSplitscreen ||(!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())) - { - bNoScrollSlots = true; - } + // 4J-Tomk - check if we've only got one vertical scroll slot (480, + // splits & Vita) + bool bNoScrollSlots = false; + if (m_bSplitscreen || + (!RenderManager.IsHiDef() && !RenderManager.IsWidescreen())) { + bNoScrollSlots = true; + } #ifdef __PSVITA__ - bNoScrollSlots = true; + bNoScrollSlots = true; #endif - for(int i=0;i pTempItemInstAdditional=pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iVSlotIndexA[i]]].pRecipy->assemble(nullptr); + for (int i = 0; i < iSlots; i++) { + // 4J this check determines if the crafting scene has only one + // vertical scroll slot + if (bNoScrollSlots) { + if (i != 1) continue; + } + std::shared_ptr pTempItemInstAdditional = + pRecipeIngredientsRequired[CanBeMadeA[m_iCurrentSlotHIndex] + .iRecipeA[iVSlotIndexA[i]]] + .pRecipy->assemble(nullptr); - assert(pTempItemInstAdditional->id!=0); - unsigned int uiAlpha; + assert(pTempItemInstAdditional->id != 0); + unsigned int uiAlpha; - if(app.DebugSettingsOn() && app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L<id == Item::clock_Id || pTempItemInstAdditional->id == Item::compass_Id ) - { - pTempItemInstAdditional->setAuxValue( 255 ); - } + // 4J Stu - For clocks and compasses we set the aux value to a + // special one that signals we should use a default texture rather + // than the dynamic one for the player + if (pTempItemInstAdditional->id == Item::clock_Id || + pTempItemInstAdditional->id == Item::compass_Id) { + pTempItemInstAdditional->setAuxValue(255); + } - setCraftVSlotItem(getPad(),i,pTempItemInstAdditional,uiAlpha); + setCraftVSlotItem(getPad(), i, pTempItemInstAdditional, uiAlpha); - updateVSlotPositions(iSlots, i); - } - } + updateVSlotPositions(iSlots, i); + } + } } ////////////////////////////////////////////////////////////////////////// @@ -1031,261 +1056,249 @@ void IUIScene_CraftingMenu::UpdateVerticalSlots() // DisplayIngredients // ////////////////////////////////////////////////////////////////////////// -void IUIScene_CraftingMenu::DisplayIngredients() -{ - //RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); - Recipy::INGREDIENTS_REQUIRED *pRecipeIngredientsRequired=Recipes::getInstance()->getRecipeIngredientsArray(); +void IUIScene_CraftingMenu::DisplayIngredients() { + // RecipyList *recipes = ((Recipes *)Recipes::getInstance())->getRecipies(); + Recipy::INGREDIENTS_REQUIRED* pRecipeIngredientsRequired = + Recipes::getInstance()->getRecipeIngredientsArray(); - // hide the previous ingredients - hideAllIngredientsSlots(); + // hide the previous ingredients + hideAllIngredientsSlots(); - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount!=0) - { - int iSlot,iRecipy; - if(CanBeMadeA[m_iCurrentSlotHIndex].iCount>1) - { - iSlot=iVSlotIndexA[m_iCurrentSlotVIndex]; - iRecipy=CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; - } - else - { - iSlot=0; - iRecipy=CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[0]; - } + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount != 0) { + int iSlot, iRecipy; + if (CanBeMadeA[m_iCurrentSlotHIndex].iCount > 1) { + iSlot = iVSlotIndexA[m_iCurrentSlotVIndex]; + iRecipy = CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; + } else { + iSlot = 0; + iRecipy = CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[0]; + } - // show the 2x2 or 3x3 to make the current item - int iBoxWidth=(m_iContainerType==RECIPE_TYPE_2x2)?2:3; - int iRecipe=CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; - bool bCanMakeRecipe = pRecipeIngredientsRequired[iRecipe].bCanMake[getPad()]; - std::shared_ptr pTempItemInst=pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); + // show the 2x2 or 3x3 to make the current item + int iBoxWidth = (m_iContainerType == RECIPE_TYPE_2x2) ? 2 : 3; + int iRecipe = CanBeMadeA[m_iCurrentSlotHIndex].iRecipeA[iSlot]; + bool bCanMakeRecipe = + pRecipeIngredientsRequired[iRecipe].bCanMake[getPad()]; + std::shared_ptr pTempItemInst = + pRecipeIngredientsRequired[iRecipe].pRecipy->assemble(nullptr); - m_iIngredientsC=pRecipeIngredientsRequired[iRecipe].iIngC; + m_iIngredientsC = pRecipeIngredientsRequired[iRecipe].iIngC; - // update the ingredients required - these will all be hidden until cycled by the user - for(int i=0;i