Updated German translation
[dasher.git] / Src / DasherCore / DashIntfScreenMsgs.cpp
blob8a26d58973af583d450c0c3b9924c07c8c106374
1 #include "DashIntfScreenMsgs.h"
2 #include "ScreenGameModule.h"
4 using namespace Dasher;
6 CDashIntfScreenMsgs::CDashIntfScreenMsgs(CSettingsStore *pSettingsStore, CFileUtils* fileUtils)
7 : CDashIntfSettings(pSettingsStore, fileUtils) {
10 void CDashIntfScreenMsgs::Message(const string &strText, bool bInterrupt) {
11 //Just store the messages for Redraw...
12 CDasherScreen::Label *lab = GetView()->Screen()->MakeLabel(strText,GetLongParameter(LP_MESSAGE_FONTSIZE));
13 if (bInterrupt) {
14 m_dqModalMessages.push_back(pair<CDasherScreen::Label*,bool>(lab,false));
15 if (CInputFilter *fil=GetActiveInputMethod()) fil->pause();
17 else
18 m_dqAsyncMessages.push_back(pair<CDasherScreen::Label*,unsigned long>(lab, 0));
21 bool CDashIntfScreenMsgs::FinishRender(unsigned long ulTime) {
22 bool bMsgsChanged=false;
23 //Finally any messages - newest that will fit at bottom, proceeding upwards.
24 // Firstly clear any non-modal messages that have been onscreen for long enough
25 while (!m_dqAsyncMessages.empty() && m_dqAsyncMessages.front().second && ulTime-m_dqAsyncMessages.front().second>GetLongParameter(LP_MESSAGE_TIME)) {
26 delete m_dqAsyncMessages.front().first; //the Label
27 m_dqAsyncMessages.pop_front(); // => stop displaying it
28 bMsgsChanged=true;
30 CDasherScreen * const pScreen(GetView()->Screen());
31 if (!m_dqAsyncMessages.empty() || !m_dqModalMessages.empty()) {
32 screenint iY = pScreen->GetHeight();
33 const screenint iMinY((iY*3)/4), iSW(pScreen->GetWidth());
34 //still messages to display...first find out longest-ago N that will fit
35 for (deque<pair<CDasherScreen::Label*, unsigned long> >::iterator it = m_dqAsyncMessages.begin(); it!=m_dqAsyncMessages.end() && iY>iMinY; it++) {
36 if (it->second==0) {
37 //reached a not-yet-displayed asynchronous message
38 if (!m_dqModalMessages.empty()) break; //don't start displaying anything while there are modal msgs
39 it->second = ulTime; //display message for first time
40 bMsgsChanged=true;
42 iY-=pScreen->TextSize(it->first, GetLongParameter(LP_MESSAGE_FONTSIZE)).second;
44 if (!m_dqModalMessages.empty()) {
45 bool bDisp(m_dqModalMessages.front().second != 0); //displaying anything atm?
46 for (deque<pair<CDasherScreen::Label*,unsigned long> >::iterator it=m_dqModalMessages.begin(); it!=m_dqModalMessages.end() && iY>iMinY; it++) {
47 if (bDisp) {
48 if (it->second==0) break; //don't start displaying more until previous dismissed
49 } else {
50 DASHER_ASSERT(it->second==0);
51 it->second = ulTime;
52 bMsgsChanged = true;
54 iY-=pScreen->TextSize(it->first, GetLongParameter(LP_MESSAGE_FONTSIZE)).second;
57 //Now render messages proceeding downwards - non-modal first, then oldest first
58 bool bModal(false);
59 for (deque<pair<CDasherScreen::Label*, unsigned long> >::const_iterator it = m_dqAsyncMessages.begin(); it != m_dqAsyncMessages.end(); it++) {
60 if (it->second==0) continue;
61 pair<screenint,screenint> textDims = pScreen->TextSize(it->first, GetLongParameter(LP_MESSAGE_FONTSIZE));
62 //black (5) rectangle:
63 pScreen->DrawRectangle((iSW - textDims.first)/2, iY, (iSW+textDims.first)/2, iY+textDims.second, 5, -1, -1);
64 //white (0) text for non-modal, yellow (111) for modal
65 pScreen->DrawString(it->first, (iSW-textDims.first)/2, iY, GetLongParameter(LP_MESSAGE_FONTSIZE), bModal ? 111 : 0);
66 iY+=textDims.second;
68 bModal=true;
69 for (deque<pair<CDasherScreen::Label*, unsigned long> >::const_iterator it = m_dqModalMessages.begin(); it != m_dqModalMessages.end(); it++) {
70 if (it->second==0) continue;
71 pair<screenint,screenint> textDims = pScreen->TextSize(it->first, GetLongParameter(LP_MESSAGE_FONTSIZE));
72 //black (5) rectangle:
73 pScreen->DrawRectangle((iSW - textDims.first)/2, iY, (iSW+textDims.first)/2, iY+textDims.second, 5, -1, -1);
74 //white (0) text for non-modal, yellow (111) for modal
75 pScreen->DrawString(it->first, (iSW-textDims.first)/2, iY, GetLongParameter(LP_MESSAGE_FONTSIZE), bModal ? 111 : 0);
76 iY+=textDims.second;
79 return bMsgsChanged;
82 void CDashIntfScreenMsgs::ChangeScreen(CDasherScreen *pNewScreen) {
83 CDasherInterfaceBase::ChangeScreen(pNewScreen);
84 for (deque<pair<CDasherScreen::Label*,unsigned long> >::iterator it=m_dqAsyncMessages.begin(); ; it++) {
85 if (it==m_dqAsyncMessages.end()) it = m_dqModalMessages.begin();
86 if (it==m_dqModalMessages.end()) break;
87 const CDasherScreen::Label *pOldLabel(it->first);
88 it->first = pNewScreen->MakeLabel(pOldLabel->m_strText, pOldLabel->m_iWrapSize);
89 delete pOldLabel;
93 void CDashIntfScreenMsgs::onUnpause(unsigned long lTime) {
94 while (!m_dqModalMessages.empty()) {
95 if (m_dqModalMessages.front().second) {
96 //Message has been displayed; delete it
97 delete m_dqModalMessages.front().first; //the label
98 m_dqModalMessages.pop_front();
99 } else {
100 //there are more, not-yet displayed, modal messages!
101 //These should be after any that were displayed (which have now been erased),
102 // so do not unpause; next frame will render more messages instead.
103 GetActiveInputMethod()->pause();
104 return;
107 CDasherInterfaceBase::onUnpause(lTime);
110 CGameModule *CDashIntfScreenMsgs::CreateGameModule() {
111 return new CScreenGameModule(this, this, GetView(), m_pDasherModel);