示例#1
0
void UI::init (ServiceProvider& serviceProvider, EventHandler &eventHandler, IFrontend &frontend)
{
	System.track("step", "initui");
	const std::string& language = Config.getLanguage();
	if (!initLanguage(language))
		initLanguage("en_GB");
	Commands.registerCommand(CMD_UI_PRINTSTACK, bindFunction(UI, printStack));
	Commands.registerCommand(CMD_UI_PUSH, bindFunction(UI, pushCmd));
	Commands.registerCommand(CMD_UI_RESTART, bindFunction(UI, initRestart));
	Commands.registerCommand(CMD_UI_POP, bindFunction(UI, pop));
	Commands.registerCommand(CMD_UI_FOCUS_NEXT, bindFunction(UI, focusNext));
	Commands.registerCommand(CMD_UI_FOCUS_PREV, bindFunction(UI, focusPrev));
	Commands.registerCommand(CMD_UI_EXECUTE, bindFunction(UI, runFocusNode));
	_showCursor = Config.getConfigVar("showcursor", System.wantCursor() ? "true" : "false", true)->getBoolValue();
	_cursor = _showCursor;
	if (_cursor)
		info(LOG_CLIENT, "enable cursor");
	else
		info(LOG_CLIENT, "disable cursor");

	_serviceProvider = &serviceProvider;
	_eventHandler = &eventHandler;
	_frontend = &frontend;
	eventHandler.registerObserver(this);

	info(LOG_CLIENT, "init the texture cache with " + serviceProvider.getTextureDefinition().getTextureSize());
	_textureCache.init(_frontend, serviceProvider.getTextureDefinition());
	_spriteCache.init();

	FontDefinition& fontDef = Singleton<FontDefinition>::getInstance();
	FontDefMapConstIter i = fontDef.begin();
	for (; i != fontDef.end(); ++i) {
		_fonts[i->second->id] = BitmapFontPtr(new BitmapFont(i->second, _frontend));
	}

	Singleton<GameRegistry>::getInstance().getGame()->initUI(_frontend, serviceProvider);

	_mouseCursor = loadTexture("mouse");

	loadGesture(zoominGesture, SDL_arraysize(zoominGesture));
	loadGesture(zoomoutGesture, SDL_arraysize(zoomoutGesture));
}