Something went wrong. Try again.
the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
Something went wrong. Try again.
8.8 kB · 295 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295#include "stdafx.h"#include "UI.h"#include "..\..\..\Minecraft.World\net.minecraft.world.inventory.h"#include "..\..\..\Minecraft.World\net.minecraft.world.item.h"#include "..\..\..\Minecraft.World\net.minecraft.world.item.trading.h"#include "..\..\..\Minecraft.World\net.minecraft.world.level.tile.entity.h"#include "MultiPlayerLocalPlayer.h"#include "..\..\Minecraft.h"#include "UIScene_TradingMenu.h"
UIScene_TradingMenu::UIScene_TradingMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene(iPad, parentLayer){ // Setup all the Iggy references we need for this scene initialiseMovie(); m_showingLeftArrow = true; m_showingRightArrow = true;
// 4J-PB - "Villager" appears for a short time on opening the trading menu //m_labelTrading.init( app.GetString(IDS_VILLAGER) ); m_labelTrading.init( L"" ); m_labelInventory.init( app.GetString(IDS_INVENTORY) ); m_labelRequired.init( app.GetString(IDS_REQUIRED_ITEMS_FOR_TRADE) );
m_labelRequest1.init(L""); m_labelRequest2.init(L"");
TradingScreenInput *initData = (TradingScreenInput *)_initData; m_merchant = initData->trader;
Minecraft *pMinecraft = Minecraft::GetInstance(); if( pMinecraft->localgameModes[iPad] != NULL ) { TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[iPad]; m_previousTutorialState = gameMode->getTutorial()->getCurrentState(); gameMode->getTutorial()->changeTutorialState(e_Tutorial_State_Trading_Menu, this); }
m_menu = new MerchantMenu( initData->inventory, initData->trader, initData->level ); Minecraft::GetInstance()->localplayers[iPad]->containerMenu = m_menu;
m_slotListRequest1.addSlots(BUY_A,1); m_slotListRequest2.addSlots(BUY_B,1);
m_slotListTrades.addSlots(TRADES_START,DISPLAY_TRADES_COUNT);
m_slotListInventory.addSlots(MerchantMenu::INV_SLOT_START, 27); m_slotListHotbar.addSlots(MerchantMenu::USE_ROW_SLOT_START, 9);
if(initData) delete initData;
// in this scene, we override the press sound with our own for crafting success or fail ui.OverrideSFX(m_iPad,ACTION_MENU_A,true); ui.OverrideSFX(m_iPad,ACTION_MENU_OK,true);#ifdef __ORBIS__ ui.OverrideSFX(m_iPad,ACTION_MENU_TOUCHPAD_PRESS,true);#endif ui.OverrideSFX(m_iPad,ACTION_MENU_LEFT_SCROLL,true); ui.OverrideSFX(m_iPad,ACTION_MENU_RIGHT_SCROLL,true); ui.OverrideSFX(m_iPad,ACTION_MENU_LEFT,true); ui.OverrideSFX(m_iPad,ACTION_MENU_RIGHT,true); ui.OverrideSFX(m_iPad,ACTION_MENU_UP,true); ui.OverrideSFX(m_iPad,ACTION_MENU_DOWN,true);
app.SetRichPresenceContext(iPad, CONTEXT_GAME_STATE_TRADING);}
wstring UIScene_TradingMenu::getMoviePath(){ if(app.GetLocalPlayerCount() > 1) { return L"TradingMenuSplit"; } else { return L"TradingMenu"; }}
void UIScene_TradingMenu::updateTooltips(){ ui.SetTooltips(m_iPad, IDS_TOOLTIPS_TRADE, IDS_TOOLTIPS_BACK);}
void UIScene_TradingMenu::handleDestroy(){ app.DebugPrintf("UIScene_TradingMenu::handleDestroy\n"); Minecraft *pMinecraft = Minecraft::GetInstance(); if( pMinecraft->localgameModes[m_iPad] != NULL ) { TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad]; if(gameMode != NULL) gameMode->getTutorial()->changeTutorialState(m_previousTutorialState); }
// 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) if(pMinecraft->localplayers[m_iPad] != NULL) pMinecraft->localplayers[m_iPad]->closeContainer();
ui.OverrideSFX(m_iPad,ACTION_MENU_A,false); ui.OverrideSFX(m_iPad,ACTION_MENU_OK,false);#ifdef __ORBIS__ ui.OverrideSFX(m_iPad,ACTION_MENU_TOUCHPAD_PRESS,false);#endif ui.OverrideSFX(m_iPad,ACTION_MENU_LEFT_SCROLL,false); ui.OverrideSFX(m_iPad,ACTION_MENU_RIGHT_SCROLL,false); ui.OverrideSFX(m_iPad,ACTION_MENU_LEFT,false); ui.OverrideSFX(m_iPad,ACTION_MENU_RIGHT,false); ui.OverrideSFX(m_iPad,ACTION_MENU_UP,false); ui.OverrideSFX(m_iPad,ACTION_MENU_DOWN,false);}
void UIScene_TradingMenu::handleReload(){ m_slotListRequest1.addSlots(BUY_A,1); m_slotListRequest2.addSlots(BUY_B,1);
m_slotListTrades.addSlots(TRADES_START,DISPLAY_TRADES_COUNT);
m_slotListInventory.addSlots(MerchantMenu::INV_SLOT_START, 27); m_slotListHotbar.addSlots(MerchantMenu::USE_ROW_SLOT_START, 9);
updateDisplay(); IggyDataValue result; IggyDataValue value[1];
value[0].type = IGGY_DATATYPE_number; value[0].number = m_selectedSlot; IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetActiveSlot , 1 , value );}
void UIScene_TradingMenu::tick(){ UIScene::tick(); handleTick();}
void UIScene_TradingMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled){ //app.DebugPrintf("UIScene_InventoryMenu handling input for pad %d, key %d, down- %s, pressed- %s, released- %s\n", iPad, key, down?"TRUE":"FALSE", pressed?"TRUE":"FALSE", released?"TRUE":"FALSE"); ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released);
switch(key) { default: if(pressed) { handled = handleKeyDown(m_iPad, key, repeat); } break; };}
void UIScene_TradingMenu::customDraw(IggyCustomDrawCallbackRegion *region){ Minecraft *pMinecraft = Minecraft::GetInstance(); if(pMinecraft->localplayers[m_iPad] == NULL || pMinecraft->localgameModes[m_iPad] == NULL) return;
shared_ptr<ItemInstance> item = nullptr; int slotId = -1; swscanf((wchar_t*)region->name,L"slot_%d",&slotId);
if(slotId < MerchantMenu::USE_ROW_SLOT_END) { Slot *slot = m_menu->getSlot(slotId); item = slot->getItem(); } else if(slotId >= TRADES_START) { int tradeId = (slotId - TRADES_START) + m_offersStartIndex; if(tradeId < m_activeOffers.size()) { item = m_activeOffers.at(tradeId).first->getSellItem(); } } else { int tradeId = m_selectedSlot + m_offersStartIndex; if( tradeId < m_activeOffers.size() ) { switch(slotId) { case BUY_A: item = m_activeOffers.at(tradeId).first->getBuyAItem(); break; case BUY_B: item = m_activeOffers.at(tradeId).first->getBuyBItem(); break; }; } } if(item != NULL) customDrawSlotControl(region,m_iPad,item,1.0f,item->isFoil(),true);}
void UIScene_TradingMenu::showScrollRightArrow(bool show){ if(m_showingRightArrow != show) { IggyDataValue result; IggyDataValue value[1];
value[0].type = IGGY_DATATYPE_boolean; value[0].boolval = show; IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowScrollRightArrow , 1 , value );
m_showingRightArrow = show; }}
void UIScene_TradingMenu::showScrollLeftArrow(bool show){ if(m_showingLeftArrow != show) { IggyDataValue result; IggyDataValue value[1];
value[0].type = IGGY_DATATYPE_boolean; value[0].boolval = show; IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcShowScrollLeftArrow , 1 , value );
m_showingLeftArrow = show; }}
void UIScene_TradingMenu::moveSelector(bool right){ IggyDataValue result; IggyDataValue value[1];
value[0].type = IGGY_DATATYPE_boolean; value[0].boolval = right; IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcMoveSelector , 1 , value );}
void UIScene_TradingMenu::setTitle(const wstring &name){ m_labelTrading.setLabel(name);}
void UIScene_TradingMenu::setRequest1Name(const wstring &name){ m_labelRequest1.setLabel(name);}
void UIScene_TradingMenu::setRequest2Name(const wstring &name){ m_labelRequest2.setLabel(name);}
void UIScene_TradingMenu::setRequest1RedBox(bool show){ m_slotListRequest1.showSlotRedBox(0,show);}
void UIScene_TradingMenu::setRequest2RedBox(bool show){ m_slotListRequest2.showSlotRedBox(0,show);}
void UIScene_TradingMenu::setTradeRedBox(int index, bool show){ m_slotListTrades.showSlotRedBox(index,show);}
void UIScene_TradingMenu::setOfferDescription(vector<HtmlString> *description){ wstring descriptionStr = HtmlString::Compose(description);
IggyDataValue result; IggyDataValue value[1];
IggyStringUTF16 stringVal; stringVal.string = (IggyUTF16*)descriptionStr.c_str(); stringVal.length = descriptionStr.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal;
IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetOfferDescription , 1 , value );}
void UIScene_TradingMenu::HandleMessage(EUIMessage message, void *data){ switch(message) { case eUIMessage_InventoryUpdated: handleInventoryUpdated(data); break; };}
void UIScene_TradingMenu::handleInventoryUpdated(LPVOID data){ HandleInventoryUpdated();}