the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 176 lines 3.6 kB view raw
1#include "stdafx.h" 2 3#include "..\..\..\Minecraft.World\StringHelpers.h" 4 5#include "UIString.h" 6 7bool UIString::setCurrentLanguage() 8{ 9 int nextLanguage, nextLocale; 10 nextLanguage = XGetLanguage(); 11 nextLocale = XGetLocale(); 12 13 if ( (nextLanguage != s_currentLanguage) || (nextLocale != s_currentLocale) ) 14 { 15 s_currentLanguage = nextLanguage; 16 s_currentLocale = nextLocale; 17 return true; 18 } 19 20 return false; 21} 22 23int UIString::getCurrentLanguage() 24{ 25 return s_currentLanguage; 26} 27 28UIString::UIStringCore::UIStringCore(StringBuilder wstrBuilder) 29{ 30 m_bIsConstant = false; 31 32 m_lastSetLanguage = m_lastSetLocale = -1; 33 m_lastUpdatedLanguage = m_lastUpdatedLocale = -1; 34 35 m_fStringBuilder = wstrBuilder; 36 37 m_wstrCache = L""; 38 update(true); 39} 40 41UIString::UIStringCore::UIStringCore(const wstring &str) 42{ 43 m_bIsConstant = true; 44 45 m_lastSetLanguage = m_lastSetLocale = -1; 46 m_lastUpdatedLanguage = m_lastUpdatedLocale = -1; 47 48 m_wstrCache = str; 49} 50 51wstring &UIString::UIStringCore::getString() 52{ 53 if (hasNewString()) update(true); 54 return m_wstrCache; 55} 56 57bool UIString::UIStringCore::hasNewString() 58{ 59 if (m_bIsConstant) return false; 60 return (m_lastSetLanguage != s_currentLanguage) || (m_lastSetLocale != s_currentLocale); 61} 62 63bool UIString::UIStringCore::update(bool force) 64{ 65 if ( !m_bIsConstant && (force || hasNewString()) ) 66 { 67 m_wstrCache = m_fStringBuilder(); 68 m_lastSetLanguage = s_currentLanguage; 69 m_lastSetLocale = s_currentLocale; 70 return true; 71 } 72 return false; 73} 74 75bool UIString::UIStringCore::needsUpdating() 76{ 77 if (m_bIsConstant) return false; 78 return (m_lastSetLanguage != s_currentLanguage) || (m_lastUpdatedLanguage != m_lastSetLanguage) 79 || (m_lastSetLocale != s_currentLocale) || (m_lastUpdatedLocale != m_lastSetLocale); 80} 81 82void UIString::UIStringCore::setUpdated() 83{ 84 m_lastUpdatedLanguage = m_lastSetLanguage; 85 m_lastUpdatedLocale = m_lastSetLocale; 86} 87 88int UIString::s_currentLanguage = -1; 89int UIString::s_currentLocale = -1; 90 91UIString::UIString() 92{ 93 m_core = shared_ptr<UIStringCore>(); 94} 95 96UIString::UIString(int ids) 97{ 98#ifdef __PS3__ 99 StringBuilder builder = StringBuilder( new IdsStringBuilder(ids) ); 100#else 101 StringBuilder builder = [ids](){ return app.GetString(ids); }; 102#endif 103 UIStringCore *core = new UIStringCore( builder ); 104 m_core = shared_ptr<UIStringCore>(core); 105} 106 107UIString::UIString(StringBuilder wstrBuilder) 108{ 109 UIStringCore *core = new UIStringCore(wstrBuilder); 110 m_core = shared_ptr<UIStringCore>(core); 111} 112 113UIString::UIString(const string &constant) 114{ 115 wstring wstr = convStringToWstring(constant); 116 UIStringCore *core = new UIStringCore( wstr ); 117 m_core = shared_ptr<UIStringCore>(core); 118} 119 120UIString::UIString(const wstring &constant) 121{ 122 UIStringCore *core = new UIStringCore(constant); 123 m_core = shared_ptr<UIStringCore>(core); 124} 125 126UIString::UIString(const wchar_t *constant) 127{ 128 wstring str = wstring(constant); 129 UIStringCore *core = new UIStringCore(str); 130 m_core = shared_ptr<UIStringCore>(core); 131} 132 133UIString::~UIString() 134{ 135#ifndef __PS3__ 136 m_core = nullptr; 137#endif 138} 139 140bool UIString::empty() 141{ 142 return m_core.get() == NULL; 143} 144 145bool UIString::compare(const UIString &uiString) 146{ 147 return m_core.get() != uiString.m_core.get(); 148} 149 150bool UIString::needsUpdating() 151{ 152 if (m_core != NULL) return m_core->needsUpdating(); 153 else return false; 154} 155 156void UIString::setUpdated() 157{ 158 if (m_core != NULL) m_core->setUpdated(); 159} 160 161wstring &UIString::getString() 162{ 163 static wstring blank(L""); 164 if (m_core != NULL) return m_core->getString(); 165 else return blank; 166} 167 168const wchar_t *UIString::c_str() 169{ 170 return getString().c_str(); 171} 172 173unsigned int UIString::length() 174{ 175 return getString().length(); 176}