the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 103 lines 2.0 kB view raw
1#pragma once 2 3#include <set> 4#include <functional> 5 6 7#ifndef __PS3__ 8 9typedef function<wstring(void)> StringBuilder; 10 11#else 12 13class StringBuilderCore 14{ 15public: 16 virtual wstring getString() = 0; 17}; 18 19struct StringBuilder 20{ 21 shared_ptr<StringBuilderCore> m_coreBuilder; 22 virtual wstring operator()() { return m_coreBuilder->getString(); } 23 StringBuilder() {} 24 StringBuilder(StringBuilderCore *core) { m_coreBuilder = shared_ptr<StringBuilderCore>(core); } 25}; 26 27class IdsStringBuilder : public StringBuilderCore 28{ 29 const int m_ids; 30public: 31 IdsStringBuilder(int ids) : m_ids(ids) {} 32 virtual wstring getString(void) { return app.GetString(m_ids); } 33}; 34#endif 35 36using namespace std; 37 38class UIString 39{ 40protected: 41 static int s_currentLanguage; 42 static int s_currentLocale; 43 44public: 45 static bool setCurrentLanguage(); 46 static int getCurrentLanguage(); 47 48protected: 49 class UIStringCore : public enable_shared_from_this<UIStringCore> 50 { 51 private: 52 int m_lastSetLanguage; 53 int m_lastSetLocale; 54 55 int m_lastUpdatedLanguage; 56 int m_lastUpdatedLocale; 57 58 wstring m_wstrCache; 59 60 bool m_bIsConstant; 61 62 StringBuilder m_fStringBuilder; 63 64 public: 65 UIStringCore(StringBuilder wstrBuilder); 66 UIStringCore(const wstring &str); 67 68 wstring &getString(); 69 70 bool hasNewString(); 71 bool update(bool force); 72 73 bool needsUpdating(); 74 void setUpdated(); 75 }; 76 77 shared_ptr<UIStringCore> m_core; 78 79public: 80 UIString(); 81 82 UIString(int ids); // Create a dynamic UI string from a string id value. 83 84 UIString(StringBuilder wstrBuilder); // Create a dynamic UI string with a custom update function. 85 86 // Create a UIString with a constant value. 87 UIString(const string &constant); 88 UIString(const wstring &constant); 89 UIString(const wchar_t *constant); 90 91 ~UIString(); 92 93 bool empty(); 94 bool compare(const UIString &uiString); 95 96 bool needsUpdating(); // Language has been change since the last time setUpdated was called. 97 void setUpdated(); // The new text has been used. 98 99 wstring &getString(); 100 101 const wchar_t *c_str(); 102 unsigned int length(); 103};