Skip to content

Commit

Permalink
Changed the way world.Note is done in various ways
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Jul 18, 2010
1 parent 328e54d commit 602264a
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 37 deletions.
40 changes: 39 additions & 1 deletion ProcessPreviousLine.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -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 ())
Expand Down
2 changes: 1 addition & 1 deletion dialogs/ImportXMLdlg.cpp
Expand Up @@ -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 ();

}
Expand Down
4 changes: 2 additions & 2 deletions dialogs/plugins/PluginsDlg.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 ();
}
Expand Down
2 changes: 1 addition & 1 deletion dialogs/world_prefs/genpropertypage.cpp
Expand Up @@ -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 ();
}

Expand Down
49 changes: 48 additions & 1 deletion doc.cpp
Expand Up @@ -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<CPaneStyle>::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)
{
Expand Down Expand Up @@ -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;)
Expand Down Expand Up @@ -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 ();
}
Expand Down
3 changes: 3 additions & 0 deletions doc.h
Expand Up @@ -1275,6 +1275,8 @@ class CMUSHclientDoc : public CDocument
// for mapping colours to colours
map<COLORREF, COLORREF> m_ColourTranslationMap;

list<CPaneStyle> m_OutstandingLines;

#ifdef PANE
// for pane windows

Expand Down Expand Up @@ -1462,6 +1464,7 @@ class CMUSHclientDoc : public CDocument

BOOL OpenSession (void);
void SetUpOutputWindow (void);
void OutputOutstandingLines (void);

bool m_bInPlaySoundFilePlugin;
bool m_bInCancelSoundFilePlugin;
Expand Down
11 changes: 4 additions & 7 deletions scripting/lua_scripting.cpp
Expand Up @@ -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: ";
Expand Down Expand Up @@ -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?

Expand Down
11 changes: 7 additions & 4 deletions scripting/methods.cpp
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions scripting/scriptengine.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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?

Expand Down
7 changes: 2 additions & 5 deletions scripting/scripting.cpp
Expand Up @@ -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<string> v;
Expand All @@ -512,7 +509,7 @@ vector<string> 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)
Expand All @@ -525,7 +522,7 @@ vector<string> 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
Expand Down
3 changes: 3 additions & 0 deletions stdafx.h
Expand Up @@ -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"
10 changes: 3 additions & 7 deletions xml/xml_load_world.cpp
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 602264a

Please sign in to comment.