From 602264a48a458c02e4a522c2446666d86311a649 Mon Sep 17 00:00:00 2001 From: Nick Gammon Date: Sun, 18 Jul 2010 13:16:07 +1000 Subject: [PATCH] Changed the way world.Note is done in various ways --- ProcessPreviousLine.cpp | 40 +++++++++++++++++++- dialogs/ImportXMLdlg.cpp | 2 +- dialogs/plugins/PluginsDlg.cpp | 4 +- dialogs/world_prefs/genpropertypage.cpp | 2 +- doc.cpp | 49 ++++++++++++++++++++++++- doc.h | 3 ++ scripting/lua_scripting.cpp | 11 ++---- scripting/methods.cpp | 11 ++++-- scripting/scriptengine.cpp | 13 +++---- scripting/scripting.cpp | 7 +--- stdafx.h | 3 ++ xml/xml_load_world.cpp | 10 ++--- 12 files changed, 118 insertions(+), 37 deletions(-) diff --git a/ProcessPreviousLine.cpp b/ProcessPreviousLine.cpp index 4426961e..caa8d491 100644 --- a/ProcessPreviousLine.cpp +++ b/ProcessPreviousLine.cpp @@ -697,7 +697,42 @@ assemble the full text of the original line. if (m_LineList.GetCount () % JUMP_SIZE == 1) m_pLinePositions [m_LineList.GetCount () / JUMP_SIZE] = NULL; - delete m_LineList.GetTail (); // delete contents of tail iten -- version 3.85 + // version 4.54 - keep notes, even if omitted from output ;) + + // we have to push_front because we are going through the lines backwards + // this means the newline goes first. Also we process the styles in reverse order. + + CLine* pLine = m_LineList.GetTail (); + + if (pLine->flags & COMMENT) + { + CString strLine = CString (pLine->text, pLine->len); + int iCol = 0; + + // throw in the newline if required + if (pLine->hard_return) + m_OutstandingLines.push_front (CPaneStyle (ENDLINE, 0, 0, 0)); + + for (POSITION stylepos = pLine->styleList.GetTailPosition(); stylepos; ) + { + CStyle * pStyle = pLine->styleList.GetPrev (stylepos); + + COLORREF cText, + cBack; + + // find actual RGB colour of style + GetStyleRGB (pStyle, cText, cBack); + + m_OutstandingLines.push_front (CPaneStyle ((const char *) + strLine.Mid (iCol, pStyle->iLength), + cText, cBack, pStyle->iFlags & 7)); + iCol += pStyle->iLength; // new column + } // end of each style + + + } // end of coming across a note line + + delete pLine; // delete contents of tail iten -- version 3.85 m_LineList.RemoveTail (); // get rid of the line m_total_lines--; // don't count as received @@ -737,6 +772,9 @@ assemble the full text of the original line. else Screendraw (0, !bNoLog, strCurrentLine); + // put note lines back + OutputOutstandingLines (); + // display any stuff sent to output window if (!strExtraOutput.IsEmpty ()) diff --git a/dialogs/ImportXMLdlg.cpp b/dialogs/ImportXMLdlg.cpp index 5f53b235..04b6ebdb 100644 --- a/dialogs/ImportXMLdlg.cpp +++ b/dialogs/ImportXMLdlg.cpp @@ -240,7 +240,7 @@ void CImportXMLdlg::ImportArchive (CArchive & ar) catch (CArchiveException* e) { ::TMessageBox ("There was a problem parsing the XML. " - "See the error window for more details"); + "See the output window for more details"); e->Delete (); } diff --git a/dialogs/plugins/PluginsDlg.cpp b/dialogs/plugins/PluginsDlg.cpp index 464e19fe..17129e24 100644 --- a/dialogs/plugins/PluginsDlg.cpp +++ b/dialogs/plugins/PluginsDlg.cpp @@ -362,7 +362,7 @@ void CPluginsDlg::OnAddPlugin() catch (CException* e) { ::UMessageBox (TFormat ("There was a problem loading the plugin %s. " - "See the error window for more details", + "See the output window for more details", (LPCTSTR) strPath), MB_ICONEXCLAMATION); e->Delete (); EditPlugin (strPath); // let them see the problem @@ -506,7 +506,7 @@ for (int nItem = -1; catch (CArchiveException* e) { ::UMessageBox (TFormat ("There was a problem loading the plugin %s. " - "See the error window for more details", + "See the output window for more details", (LPCTSTR) strName), MB_ICONEXCLAMATION); e->Delete (); } diff --git a/dialogs/world_prefs/genpropertypage.cpp b/dialogs/world_prefs/genpropertypage.cpp index 5857101f..0f69852f 100644 --- a/dialogs/world_prefs/genpropertypage.cpp +++ b/dialogs/world_prefs/genpropertypage.cpp @@ -957,7 +957,7 @@ CString strContents; catch (CArchiveException* e) { ::TMessageBox ("There was a problem parsing the XML on the clipboard. " - "See the error window for more details"); + "See the output window for more details"); e->Delete (); } diff --git a/doc.cpp b/doc.cpp index a26b3cd2..01965b75 100644 --- a/doc.cpp +++ b/doc.cpp @@ -674,6 +674,49 @@ static void zlib_free (void * opaque, void * address) */ +void CMUSHclientDoc::OutputOutstandingLines (void) + { + + // minimal work ... + if (m_OutstandingLines.empty ()) + return; + + // save old colours + bool bOldNotesInRGB = m_bNotesInRGB; + COLORREF iOldNoteColourFore = m_iNoteColourFore; + COLORREF iOldNoteColourBack = m_iNoteColourBack; + unsigned short iOldNoteStyle = m_iNoteStyle; + + m_bNotesInRGB = true; + + // output saved lines + + list::iterator it; + + for (it = m_OutstandingLines.begin (); it != m_OutstandingLines.end (); it++) + { + m_iNoteColourFore = it->m_cText; + m_iNoteColourBack = it->m_cBack; + m_iNoteStyle = it->m_iStyle; + Tell (it->m_sText.c_str ()); + } + + m_OutstandingLines.clear (); + + // put the colours back + if (bOldNotesInRGB) + { + m_iNoteColourFore = iOldNoteColourFore; + m_iNoteColourBack = iOldNoteColourBack; + } + else + m_bNotesInRGB = false; + + m_iNoteStyle = iOldNoteStyle; + + + } // end of CMUSHclientDoc::OutputOutstandingLines + void CMUSHclientDoc::SetUpOutputWindow (void) { @@ -748,6 +791,10 @@ void CMUSHclientDoc::SetUpOutputWindow (void) "deepskyblue", "black", TRUE); Note (""); + + // output stuff that appeared before we set up the output buffer + OutputOutstandingLines (); + // set output window(s) to "pause" if wanted for(POSITION pos=GetFirstViewPosition();pos!=NULL;) @@ -825,7 +872,7 @@ void CMUSHclientDoc::SetUpOutputWindow (void) catch (CArchiveException* e) { UMessageBox (TFormat ("There was a problem loading the plugin %s. " - "See the error window for more details", + "See the output window for more details", (LPCTSTR) strPath), MB_ICONEXCLAMATION); e->Delete (); } diff --git a/doc.h b/doc.h index 0b4eea71..5d5712d3 100644 --- a/doc.h +++ b/doc.h @@ -1275,6 +1275,8 @@ class CMUSHclientDoc : public CDocument // for mapping colours to colours map m_ColourTranslationMap; + list m_OutstandingLines; + #ifdef PANE // for pane windows @@ -1462,6 +1464,7 @@ class CMUSHclientDoc : public CDocument BOOL OpenSession (void); void SetUpOutputWindow (void); + void OutputOutstandingLines (void); bool m_bInPlaySoundFilePlugin; bool m_bInCancelSoundFilePlugin; diff --git a/scripting/lua_scripting.cpp b/scripting/lua_scripting.cpp index 052851fe..ea7441dd 100644 --- a/scripting/lua_scripting.cpp +++ b/scripting/lua_scripting.cpp @@ -309,9 +309,6 @@ void LuaError (lua_State *L, { CScriptErrorDlg dlg; - const char * sForeColour = "darkorange"; - const char * sBackColour = "black"; - if (!strlen (strProcedure) == 0) { dlg.m_strCalledBy = "Function/Sub: "; @@ -364,10 +361,10 @@ void LuaError (lua_State *L, } else { - pDoc->ColourNote (sForeColour, sBackColour, strEvent); - pDoc->ColourNote (sForeColour, sBackColour, dlg.m_strRaisedBy); - pDoc->ColourNote (sForeColour, sBackColour, dlg.m_strCalledBy); - pDoc->ColourNote (sForeColour, sBackColour, dlg.m_strDescription); + pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, strEvent); + pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, dlg.m_strRaisedBy); + pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, dlg.m_strCalledBy); + pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, dlg.m_strDescription); // show bad lines? diff --git a/scripting/methods.cpp b/scripting/methods.cpp index 262eddfe..defd5379 100644 --- a/scripting/methods.cpp +++ b/scripting/methods.cpp @@ -237,14 +237,17 @@ void CMUSHclientDoc::Note(LPCTSTR Message) void CMUSHclientDoc::Tell(LPCTSTR Message) { - // return if attempt to do tell (or note) before output buffer exists - if (m_pCurrentLine == NULL) - return; - // don't muck around if empty message if (Message [0] == 0) return; + // if output buffer doesn't exist yet, remember note for later + if (m_pCurrentLine == NULL) + { + m_OutstandingLines.push_back (CPaneStyle (Message, m_iNoteColourFore, m_iNoteColourBack, m_iNoteStyle)); + return; + } + // If current line is not a note line, force a line change (by displaying // an empty string), so that the style change is on the note line and not // the back of the previous line. This has various implications, including diff --git a/scripting/scriptengine.cpp b/scripting/scriptengine.cpp index 46ffc31d..cf576ab4 100644 --- a/scripting/scriptengine.cpp +++ b/scripting/scriptengine.cpp @@ -163,9 +163,6 @@ STDMETHODIMP CActiveScriptSite::OnScriptError(IActiveScriptError *pscripterror) EXCEPINFO ei; ZeroMemory(&ei, sizeof(ei)); - const char * sForeColour = "darkorange"; - const char * sBackColour = "black"; - TRACE ("CActiveScriptSite: OnScriptError\n"); pscripterror->GetSourcePosition(&dwCookie, &nLine, &nChar); @@ -236,11 +233,11 @@ STDMETHODIMP CActiveScriptSite::OnScriptError(IActiveScriptError *pscripterror) } else { - m_pDoc->ColourNote (sForeColour, sBackColour, Translate ("Script error")); - m_pDoc->ColourNote (sForeColour, sBackColour, dlg.m_strRaisedBy); - m_pDoc->ColourNote (sForeColour, sBackColour, dlg.m_strEvent); - m_pDoc->ColourNote (sForeColour, sBackColour, dlg.m_strCalledBy); - m_pDoc->ColourNote (sForeColour, sBackColour, dlg.m_strDescription); + m_pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, Translate ("Script error")); + m_pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, dlg.m_strRaisedBy); + m_pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, dlg.m_strEvent); + m_pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, dlg.m_strCalledBy); + m_pDoc->ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, dlg.m_strDescription); // show bad lines? diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp index f41099c9..6efc0407 100644 --- a/scripting/scripting.cpp +++ b/scripting/scripting.cpp @@ -495,9 +495,6 @@ bool CMUSHclientDoc::ExecuteScript (DISPID & dispid, // dispatch ID, will be ze void CMUSHclientDoc::ShowErrorLines (const int iLine) // show script file around the error point { -const char * sForeColour = "darkorange"; -const char * sBackColour = "black"; -const char * sContextForeColour = "burlywood"; string sScript; vector v; @@ -512,7 +509,7 @@ vector v; // provided wanted line is in the table if (!sScript.empty () && v.size () >= iLine) { - ColourNote (sForeColour, sBackColour, Translate ("Error context in script:")); + ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, Translate ("Error context in script:")); int iStart = iLine - 4; // start 4 lines back if (iStart < 1) @@ -525,7 +522,7 @@ vector v; // show that range, marking error line with an asterisk for (int i = iStart; i <= iEnd; i++) - ColourNote (sContextForeColour, sBackColour, + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, SCRIPTERRORBACKCOLOUR, CFormat ("%4i%s: %s", i, // line number i == iLine ? "*" : " ", // mark current line diff --git a/stdafx.h b/stdafx.h index 36991401..f9d5e5d1 100644 --- a/stdafx.h +++ b/stdafx.h @@ -916,3 +916,6 @@ long LoadPngMemory (unsigned char * Buffer, const size_t Length, HBITMAP & hbmp, void ChangeToFileBrowsingDirectory (); void ChangeToStartupDirectory (); +#define SCRIPTERRORFORECOLOUR "darkorange" +#define SCRIPTERRORBACKCOLOUR "black" +#define SCRIPTERRORCONTEXTFORECOLOUR "burlywood" diff --git a/xml/xml_load_world.cpp b/xml/xml_load_world.cpp index 655c7e5b..3de4a05c 100644 --- a/xml/xml_load_world.cpp +++ b/xml/xml_load_world.cpp @@ -570,6 +570,8 @@ void CMUSHclientDoc::LoadError (const char * sType, const char * sMessage, UINT CString strTitle = "XML import warnings - "; strTitle += strFileName; + ColourNote (SCRIPTERRORFORECOLOUR, SCRIPTERRORBACKCOLOUR, strTitle); + // line defaults to last attribute line if (iLine == 0) iLine = iLineLastItemFound; @@ -580,13 +582,7 @@ void CMUSHclientDoc::LoadError (const char * sType, const char * sMessage, UINT sType, // type of thing (eg, trigger) ENDLINE); - AppendToTheNotepad (strTitle, - str, // start new line - false, // append - eNotepadWorldLoadError); - - // make sure they see it - ActivateNotepad (strTitle); + ColourNote (SCRIPTERRORCONTEXTFORECOLOUR, SCRIPTERRORBACKCOLOUR, str); iErrorCount++; } // end of CMUSHclientDoc::LoadError