Subversion Repositories spk

Rev

Rev 104 | Rev 197 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 104 Rev 122
Line 2... Line 2...
2
 
2
 
3
#include <stdarg.h>
3
#include <stdarg.h>
4
 
4
 
5
CLanguages *CLanguages::_pInstance = NULL;
5
CLanguages *CLanguages::_pInstance = NULL;
6
 
6
 
-
 
7
 
-
 
8
void CLanguages::DEBUG_AddDefaultTexts()
-
 
9
{
-
 
10
	if (_lTexts)
-
 
11
	{
-
 
12
		_pDefaultLang = &(*_lTexts)[44];
-
 
13
 
-
 
14
		{
-
 
15
			LangPage &page = (*_pDefaultLang)[LS_STARTUP];
-
 
16
			page[LANGSTARTUP_ANOTHERINSTANCE_TITLE] = "Another Instance Detected";
-
 
17
			page[LANGSTARTUP_ANOTHERINSTANCE] = "Another instance of the plugin manager is already running";
-
 
18
			page[LANGSTARTUP_LOCKEDDIR_TITLE] = "Directory Locked";
-
 
19
			page[LANGSTARTUP_LOCKEDDIR] = "ERROR: The game directory:\n%s\n\nIs locked and unable to add/remove any plugins";
-
 
20
			page[LANGSTARTUP_PROTECTEDDIR] = "";
-
 
21
		}
-
 
22
 
-
 
23
		{
-
 
24
			LangPage &page = (*_pDefaultLang)[LS_DIRECTORY];
-
 
25
			page[LANGDIR_TITLE] = "Directory Control";
-
 
26
		}
-
 
27
	}
-
 
28
}
-
 
29
 
-
 
30
 
7
CLanguages::CLanguages() : m_iLanguage(-1)
31
CLanguages::CLanguages() : 
-
 
32
	_iLanguage(-1),
-
 
33
	_pDefaultLang(NULL),
-
 
34
	_pCurrentLang(NULL)
8
{
35
{
9
	_lLanguages = new std::vector<SLanguageTexts>();
36
	_lTexts = new LangTexts();
10
}
37
}
11
 
38
 
12
CLanguages::~CLanguages()
39
CLanguages::~CLanguages()
13
{
40
{
14
	delete _lLanguages;
41
	delete _lTexts;
-
 
42
	_pDefaultLang = NULL;
-
 
43
	_pCurrentLang = NULL;
15
}
44
}
16
 
45
 
17
CLanguages *CLanguages::Instance()
46
CLanguages *CLanguages::Instance()
18
{
47
{
19
	if ( !_pInstance ) {
48
	if ( !_pInstance ) {
20
		_pInstance = new CLanguages();
49
		_pInstance = new CLanguages();
-
 
50
		_pInstance->DEBUG_AddDefaultTexts();
21
	}
51
	}
22
 
52
 
23
	return _pInstance;
53
	return _pInstance;
24
}
54
}
25
 
55
 
26
void CLanguages::Release()
56
void CLanguages::Release()
27
{
57
{
28
	if ( _pInstance ) {
58
	if ( _pInstance ) {
29
		delete _pInstance;
59
		delete _pInstance;
30
		_pInstance = NULL;
60
		_pInstance = NULL;
31
	}
61
	}
-
 
62
}
-
 
63
 
-
 
64
void CLanguages::SetLanguage(int lang) 
-
 
65
{ 
-
 
66
	_iLanguage = lang; 
-
 
67
	_pCurrentLang = NULL;
-
 
68
	if (_lTexts)
-
 
69
	{
-
 
70
		auto itr = _lTexts->find(lang);
-
 
71
		if (itr != _lTexts->end())
-
 
72
			_pCurrentLang = &itr->second;
-
 
73
	}
32
}
74
}
33
 
75
 
34
 
76
 
35
Utils::String CLanguages::findText(int section, int id)
77
Utils::String CLanguages::findText(int section, int id)
36
{
78
{
-
 
79
	LangPages *text = _pCurrentLang;
-
 
80
	if (!text) text = _pDefaultLang;
37
	SLanguageTexts *text = _findLanguageText();
81
	if (!text) text = _findLanguageText();
-
 
82
 
-
 
83
	Utils::String out;
-
 
84
	if (_findText(text, section, id, &out))
38
	if ( text )
85
		return out;
-
 
86
 
-
 
87
	if (_pDefaultLang && text != _pDefaultLang)
39
	{
88
	{
40
		LANGMAP::iterator itr = text->texts.find(Utils::String::Number(section) + ":" + Utils::String::Number(id));
-
 
41
		if ( itr != text-&gt;texts.end() )
89
		if (_findText(_pDefaultLang, section, id, &amp;out))
42
			return itr->second;
90
			return out;
43
	}
91
	}
44
 
92
 
45
	return GetText(section, id);
93
	return _error(section, id);
46
}
94
}
47
 
95
 
48
SLanguageTexts *CLanguages::_findLanguageText(int id)
96
bool CLanguages::_findText(LangPages *texts, int section, int id, Utils::String *out) const
49
{
97
{
50
	if ( id == -1 ) id = m_iLanguage;
98
	if (texts)
51
 
99
	{
52
	if ( _lLanguages ) {
100
		auto itr = texts->find(section);
53
		for ( int i = 0; i < (int)_lLanguages->;size(); i++ )
101
		if (itr != texts->;end())
54
		{
102
		{
55
			if ( _lLanguages->at(i).iLang == id )
103
			LangPage *m = &itr->second;
-
 
104
			auto itr2 = m->find(id);
-
 
105
			if (itr2 != m->end())
-
 
106
			{
-
 
107
				if (out)
-
 
108
					(*out) = itr2->second;
56
				return &_lLanguages->at(i);
109
				return true;
-
 
110
			}
57
		}
111
		}
-
 
112
	}
-
 
113
 
-
 
114
	return false;
-
 
115
}
-
 
116
 
-
 
117
LangPages *CLanguages::_findLanguageText(int id) const
-
 
118
{
-
 
119
	if ( id == -1 ) id = _iLanguage;
-
 
120
 
-
 
121
	if ( _lTexts ) {
-
 
122
		auto itr = _lTexts->find(id);
-
 
123
		if (itr != _lTexts->end())
-
 
124
			return &itr->second;
58
	}
125
	}
59
 
126
 
60
	return NULL;
127
	return NULL;
-
 
128
}
-
 
129
 
-
 
130
Utils::String CLanguages::_error(int section, int id) const
-
 
131
{
-
 
132
	return "ReadText" + Utils::String::Number(section) + "-" + Utils::String::Number(id);
61
}
133
}