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.
11 kB · 431 lines
C++
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432#include "stdafx.h"#include "UIGroup.h"
UIGroup::UIGroup(EUIGroup group, int iPad){ m_group = group; m_iPad = iPad; m_bMenuDisplayed = false; m_bPauseMenuDisplayed = false; m_bContainerMenuDisplayed = false; m_bIgnoreAutosaveMenuDisplayed = false; m_bIgnorePlayerJoinMenuDisplayed = false;
m_updateFocusStateCountdown = 0;
m_viewportType = C4JRender::VIEWPORT_TYPE_FULLSCREEN;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i] = new UILayer(this);#ifdef __PSVITA__ m_layers[i]->m_iLayer=(EUILayer)i;#endif }
m_tooltips = (UIComponent_Tooltips *)m_layers[(int)eUILayer_Tooltips]->addComponent(0, eUIComponent_Tooltips);
m_tutorialPopup = NULL; m_hud = NULL; m_pressStartToPlay = NULL; if(m_group != eUIGroup_Fullscreen) { m_tutorialPopup = (UIComponent_TutorialPopup *)m_layers[(int)eUILayer_Popup]->addComponent(m_iPad, eUIComponent_TutorialPopup);
m_hud = (UIScene_HUD *)m_layers[(int)eUILayer_HUD]->addComponent(m_iPad, eUIScene_HUD);
//m_layers[(int)eUILayer_Chat]->addComponent(m_iPad, eUIComponent_Chat); } else { m_pressStartToPlay = (UIComponent_PressStartToPlay *)m_layers[(int)eUILayer_Tooltips]->addComponent(0, eUIComponent_PressStartToPlay); }
// 4J Stu - Pre-allocate this for cached rendering in scenes. It's horribly slow to do dynamically, but we should only need one // per group as we will only be displaying one of these types of scenes at a time m_commandBufferList = MemoryTracker::genLists(1);}
void UIGroup::DestroyAll(){ for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->DestroyAll(); }}
void UIGroup::ReloadAll(){ // We only need to reload things when they are likely to be rendered int highestRenderable = 0; for(; highestRenderable < eUILayer_COUNT; ++highestRenderable) { if(m_layers[highestRenderable]->hidesLowerScenes()) break; } if(highestRenderable < eUILayer_Fullscreen) highestRenderable = eUILayer_Fullscreen; for(; highestRenderable >= 0; --highestRenderable) { if(highestRenderable < eUILayer_COUNT) m_layers[highestRenderable]->ReloadAll(highestRenderable != (int)eUILayer_Fullscreen); }}
void UIGroup::tick(){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->tick();
// TODO: May wish to ignore ticking other layers here based on current layer }
// Handle deferred update focus if (m_updateFocusStateCountdown > 0) { m_updateFocusStateCountdown--; if (m_updateFocusStateCountdown == 0)_UpdateFocusState();}}
void UIGroup::render(){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return; S32 width = 0; S32 height = 0; ui.getRenderDimensions(m_viewportType, width, height); int highestRenderable = 0; for(; highestRenderable < eUILayer_COUNT; ++highestRenderable) { if(m_layers[highestRenderable]->hidesLowerScenes()) break; } for(; highestRenderable >= 0; --highestRenderable) { if(highestRenderable < eUILayer_COUNT) m_layers[highestRenderable]->render(width, height,m_viewportType); }}
bool UIGroup::hidesLowerScenes(){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return false; bool hidesScenes = false; for(int i = eUILayer_COUNT - 1; i >= 0; --i) { hidesScenes = m_layers[i]->hidesLowerScenes(); if(hidesScenes) break; } return hidesScenes;}
void UIGroup::getRenderDimensions(S32 &width, S32 &height){ ui.getRenderDimensions(m_viewportType, width, height);}
// NAVIGATIONbool UIGroup::NavigateToScene(int iPad, EUIScene scene, void *initData, EUILayer layer){ bool succeeded = m_layers[(int)layer]->NavigateToScene(iPad, scene, initData); updateStackStates(); return succeeded;}
bool UIGroup::NavigateBack(int iPad, EUIScene eScene, EUILayer eLayer){ // Keep navigating back on every layer until we hit the target scene bool foundTarget = false; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { if(eLayer < eUILayer_COUNT && eLayer != i) continue; foundTarget = m_layers[i]->NavigateBack(iPad, eScene); if(foundTarget) break; } updateStackStates(); return foundTarget;}
void UIGroup::closeAllScenes(){ Minecraft *pMinecraft = Minecraft::GetInstance(); if( m_iPad >= 0 ) { if(pMinecraft != NULL && pMinecraft->localgameModes[m_iPad] != NULL ) { TutorialMode *gameMode = (TutorialMode *)pMinecraft->localgameModes[m_iPad];
// This just allows it to be shown gameMode->getTutorial()->showTutorialPopup(true); } }
for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { // Ignore the error layer if(i != (int)eUILayer_Error) m_layers[i]->closeAllScenes(); } updateStackStates();}
UIScene *UIGroup::GetTopScene(EUILayer layer){ return m_layers[(int)layer]->GetTopScene();}
bool UIGroup::GetMenuDisplayed(){ return m_bMenuDisplayed;}
bool UIGroup::IsSceneInStack(EUIScene scene){ bool found = false; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { found = m_layers[i]->IsSceneInStack(scene); if(found) break; } return found;}
bool UIGroup::HasFocus(int iPad){ bool hasFocus = false; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { if( m_layers[i]->m_hasFocus) { if(m_layers[i]->HasFocus(iPad)) { hasFocus = true; } break; } } return hasFocus;}
#ifdef __PSVITA__UIScene *UIGroup::getCurrentScene(){ UIScene *pScene; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { pScene=m_layers[i]->getCurrentScene();
if(pScene!=NULL) return pScene; }
return NULL;}#endif
// INPUTvoid UIGroup::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->handleInput(iPad, key, repeat, pressed, released, handled); if(handled) break; }}
// FOCUS
// Check that a layer may recieve focus, specifically that there is no infocus layer abovebool UIGroup::RequestFocus(UILayer* layerPtr){ // Find the layer unsigned int layerIndex = GetLayerIndex(layerPtr);
// Top layer is always allowed focus if (layerIndex == 0) return true;
// Check layers above to see if any of them have focus for (int i = layerIndex-1; i >= 0; i--) { if (m_layers[i]->m_hasFocus) return false; }
return true;}
void UIGroup::showComponent(int iPad, EUIScene scene, EUILayer layer, bool show){ m_layers[layer]->showComponent(iPad, scene, show);}
UIScene *UIGroup::addComponent(int iPad, EUIScene scene, EUILayer layer){ return m_layers[layer]->addComponent(iPad, scene);}
void UIGroup::removeComponent(EUIScene scene, EUILayer layer){ m_layers[layer]->removeComponent(scene);}
void UIGroup::SetViewportType(C4JRender::eViewportType type){ if(m_viewportType != type) { m_viewportType = type; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->ReloadAll(true); } }}
C4JRender::eViewportType UIGroup::GetViewportType(){ return m_viewportType;}
void UIGroup::HandleDLCMountingComplete(){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { app.DebugPrintf("UIGroup::HandleDLCMountingComplete - m_layers[%d]\n",i); m_layers[i]->HandleDLCMountingComplete(); }}
void UIGroup::HandleDLCInstalled(){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->HandleDLCInstalled(); }}
#ifdef _XBOX_ONEvoid UIGroup::HandleDLCLicenseChange(){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->HandleDLCLicenseChange(); }}#endif
void UIGroup::HandleMessage(EUIMessage message, void *data){ // Ignore this group if the player isn't signed in if(m_iPad >= 0 && !ProfileManager.IsSignedIn(m_iPad)) return; for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->HandleMessage(message, data); }}
bool UIGroup::IsFullscreenGroup(){ return m_group == eUIGroup_Fullscreen;}
void UIGroup::handleUnlockFullVersion(){ for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_layers[i]->handleUnlockFullVersion(); }}
void UIGroup::updateStackStates(){ m_bMenuDisplayed = false; m_bPauseMenuDisplayed = false; m_bContainerMenuDisplayed = false; m_bIgnoreAutosaveMenuDisplayed = false; m_bIgnorePlayerJoinMenuDisplayed = false;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { m_bMenuDisplayed = m_bMenuDisplayed || m_layers[i]->m_bMenuDisplayed; m_bPauseMenuDisplayed = m_bPauseMenuDisplayed || m_layers[i]->m_bPauseMenuDisplayed; m_bContainerMenuDisplayed = m_bContainerMenuDisplayed || m_layers[i]->m_bContainerMenuDisplayed; m_bIgnoreAutosaveMenuDisplayed = m_bIgnoreAutosaveMenuDisplayed || m_layers[i]->m_bIgnoreAutosaveMenuDisplayed; m_bIgnorePlayerJoinMenuDisplayed = m_bIgnorePlayerJoinMenuDisplayed || m_layers[i]->m_bIgnorePlayerJoinMenuDisplayed; }}
// Defer update focus till for 10 UI ticksvoid UIGroup::UpdateFocusState(){ m_updateFocusStateCountdown = 10;}
// Pass focus to uppermost layer that accepts focusvoid UIGroup::_UpdateFocusState(){ bool groupFocusSet = false;
for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { groupFocusSet = m_layers[i]->updateFocusState(true); if (groupFocusSet) break; }}
// Get the index of the layerunsigned int UIGroup::GetLayerIndex(UILayer* layerPtr){ for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { if (m_layers[i] == layerPtr) return i; }
// can't get here... return 0;} void UIGroup::PrintTotalMemoryUsage(__int64 &totalStatic, __int64 &totalDynamic){ __int64 groupStatic = 0; __int64 groupDynamic = 0; app.DebugPrintf(app.USER_SR, "-- BEGIN GROUP %d\n",m_group); for(unsigned int i = 0; i < eUILayer_COUNT; ++i) { app.DebugPrintf(app.USER_SR, " \\- BEGIN LAYER %d\n",i); m_layers[i]->PrintTotalMemoryUsage(groupStatic, groupDynamic); app.DebugPrintf(app.USER_SR, " \\- END LAYER %d\n",i); } app.DebugPrintf(app.USER_SR, "-- Group static: %d, Group dynamic: %d\n", groupStatic, groupDynamic); totalStatic += groupStatic; totalDynamic += groupDynamic; app.DebugPrintf(app.USER_SR, "-- END GROUP %d\n",m_group);}
int UIGroup::getCommandBufferList(){ return m_commandBufferList;}
// Returns the first scene of given type if it exists, NULL otherwise UIScene *UIGroup::FindScene(EUIScene sceneType){ UIScene *pScene = NULL;
for (int i = 0; i < eUILayer_COUNT; i++) { pScene = m_layers[i]->FindScene(sceneType);#ifdef __PS3__ if (pScene != NULL) return pScene;#else if (pScene != nullptr) return pScene;#endif }
return pScene;}