Example #1
0
	IMPL_LUA_FUNC(LuaCButtonUI, SetFocusedImage)
	{
		try
		{
			CButtonUI* self;
			self = static_cast<CButtonUI*>(LuaStatic::CheckUserData(l, 1));
			CDuiString pstrText;
			lua_op_t<CDuiString>::lua_to_value(l, 2, pstrText);
			self->SetFocusedImage(pstrText);
			return 0;
		}
		catch (...)
		{
			DuiException(_T("LuaCButtonUI::SetFocusedImage"));
			return 0;
		}
	}
Example #2
0
void CQuizWnd::InitWindow()
{
	assert(m_songInfo);
	CenterWindow();
	auto& quizInfo = m_songInfo->GetQuizInfo();

	// show title
	CTextUI* title = static_cast<CTextUI*>(m_PaintManager.FindControl(L"title"));
	if (!title) return;
	title->SetText(quizInfo.get_title().c_str());
	
	// show questoins button
	CHorizontalLayoutUI* questions_btn = static_cast<CHorizontalLayoutUI*>(m_PaintManager.FindControl(L"questions_btn"));
	if (!questions_btn) return;
	wchar_t ndx[3] = L"1";
	auto cnt = quizInfo.get_quiz_count();
	static const int FIXED_LENGTH = 64;
	SIZE sz = { 1,1 };
	for (auto i = 0; i < cnt; i++) {
		CButtonUI* btn = new CButtonUI();
		btn->SetName(((wstring)BTN_QUESTION_PREFIX + ndx).c_str());
		btn->SetFloat();
		btn->SetFixedXY(sz);
		btn->SetFixedHeight(FIXED_LENGTH);
		btn->SetFixedWidth(FIXED_LENGTH);
		btn->SetNormalImage(((wstring)NORMAL_PREFIX + ndx + POSTFIX_PNG).c_str());
		btn->SetFocusedImage(((wstring)NORMAL_PREFIX + ndx + POSTFIX_PNG).c_str());
		btn->SetHotImage(((wstring)HOT_PREFIX + ndx + POSTFIX_PNG).c_str());
		btn->SetPushedImage(((wstring)HOT_PREFIX + ndx + POSTFIX_PNG).c_str());
		questions_btn->Add(btn);
		ndx[0]++;
		sz.cx += FIXED_LENGTH + 1;
		if (ndx[0] == 58) {
			ndx[0] = L'1';
			ndx[1] = L'0';
		}
	}

	// show doen button
	if (cnt > 0) {
		CButtonUI* btn = new CButtonUI();
		btn->SetName(((wstring)BTN_QUESTION_PREFIX + DONE).c_str());
		btn->SetFloat();
		btn->SetFixedXY(sz);
		btn->SetFixedHeight(FIXED_LENGTH);
		btn->SetFixedWidth(FIXED_LENGTH);
		btn->SetNormalImage(((wstring)NORMAL_PREFIX + DONE + POSTFIX_PNG).c_str());
		btn->SetFocusedImage(((wstring)NORMAL_PREFIX + DONE + POSTFIX_PNG).c_str());
		btn->SetHotImage(((wstring)HOT_PREFIX + DONE + POSTFIX_PNG).c_str());
		btn->SetPushedImage(((wstring)HOT_PREFIX + DONE + POSTFIX_PNG).c_str());
		questions_btn->Add(btn);

	}

	// init question container
	CActiveXUI* question = static_cast<CActiveXUI*>(m_PaintManager.FindControl(_T("question")));
	if (!question) return;
	question->SetDelayCreate(false);              // 相当于界面设计器里的DelayCreate属性改为FALSE,在duilib自带的FlashDemo里可以看到此属性为TRUE             
	question->CreateControl(CLSID_WebBrowser);    // 相当于界面设计器里的Clsid属性里填入{8856F961-340A-11D0-A96B-00C04FD705A2},建议用CLSID_WebBrowser,如果想看相应的值,请见<ExDisp.h>
	question->GetControl(IID_IWebBrowser2, (void**)&m_question);
	assert(m_question);

	// show 1st question
	ShowQuiz(1);
}
Example #3
0
void CQuizWnd::show_result()
{
	wchar_t ndx[3] = L"1";
	auto& quizInfo = m_songInfo->GetQuizInfo();
	size_t cnt = quizInfo.get_quiz_count();
	size_t right_cnt = 0;
	std::wstring image_right = L"New\\勾.png";
	std::wstring image_wrong = L"New\\叉.png";
	for (size_t i = 0; i < cnt; i++) {
		auto quiz = quizInfo.get_quiz(i);
		if (quiz) {
			CButtonUI* btn = static_cast<CButtonUI*>(m_PaintManager.FindControl(((wstring)BTN_QUESTION_PREFIX + ndx).c_str())); assert(btn);
			if (quiz->get_answer() == quiz->get_user_answer()) {
				btn->SetNormalImage(image_right.c_str());
				btn->SetFocusedImage(image_right.c_str());
				btn->SetHotImage(image_right.c_str());
				btn->SetPushedImage(image_right.c_str());
				right_cnt++;
			} else {
				btn->SetNormalImage(image_wrong.c_str());
				btn->SetFocusedImage(image_wrong.c_str());
				btn->SetHotImage(image_wrong.c_str());
				btn->SetPushedImage(image_wrong.c_str());
			}
			ndx[0]++;
			if (ndx[0] == 58) {
				ndx[0] = L'1';
				ndx[1] = L'0';
			}
		}
	}

	// remove options
	CVerticalLayoutUI* options = static_cast<CVerticalLayoutUI*>(m_PaintManager.FindControl(L"options"));
	if (!options)return; options->RemoveAll();

	// show result
	std::wstring html_path = m_songInfo->get_tmp_path() + L"\\" + m_songInfo->get_id() + L"\\result.html";
	std::wofstream out(html_path); if (!out.is_open())return;
	std::wstringstream ss;
	ss << L"<HTML>"
		L"<head>"
		L"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
		L"<title>lyric</title>"
		L"</head>"
		L"<BODY SCROLL=NO align='center' bgcolor='#FFFFBF' topmargin='2' leftmargin='2'>"
		L"<h3 align='CENTER'>"
		L"<font size='5' color=#FF8600>You have " << right_cnt << L" out of " << cnt << L" right answers." << L"</font>"
		L"</h3>";

	if (right_cnt < cnt) {
			ss << L"<h4 align='CENTER'"
			L"<font size='3' color=#000000>You missed questions. Read the book again or try a diffrent book.</font>"
			L"</h4>"
			L"</BODY>"
			L"</HTML>";
	} else {
		ss << L"<h4 align='CENTER'"
			L"<font size='3' color=#000000>You passed this quiz. Congratulations!</font>"
			L"</h4>"
			L"</BODY>"
			L"</HTML>";
	}

	std::wstring w = ss.str();
	std::string u;
	utf8::utf16to8(w.begin(), w.end(), std::back_inserter(u));
	out << u.c_str();
	out.close();
	m_question->Navigate(const_cast<wchar_t*>(html_path.c_str()), nullptr, nullptr, nullptr, nullptr);

	// save total score
	CConfig::get_instance()->add_score(right_cnt * 10);

	// show score wnd
	CScoreWnd* wnd = new CScoreWnd(L"ScoreWnd.xml");
	wnd->Create(m_hWnd, L"ScoreWnd", UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
	wnd->ShowModal();
	delete wnd;
	PostMessage(WM_CLOSE);
}