Qt MenuOrTextWindow tweak
Funnel all potential "<action> called before we know if Menu or Text" warnings through a common routine. Aside from rephrasing a message which no one should ever see, there's no change in behavior.
This commit is contained in:
@@ -1284,11 +1284,21 @@ NetHackQtMenuOrTextWindow::NetHackQtMenuOrTextWindow(QWidget *parent_) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartMenu() turns a MenuOrTextWindow into a MenuWindow,
|
||||||
|
// PutStr() turns one into a TextWindow;
|
||||||
|
// calling any other MenuOrTextWindow routine before either of those
|
||||||
|
// elicits a warning. (Should probably quit via panic() instead.)
|
||||||
|
void NetHackQtMenuOrTextWindow::MenuOrText_too_soon_warning(const char *which)
|
||||||
|
{
|
||||||
|
impossible("'%s' called before we know whether window is Menu or Text.",
|
||||||
|
which);
|
||||||
|
}
|
||||||
|
|
||||||
QWidget* NetHackQtMenuOrTextWindow::Widget()
|
QWidget* NetHackQtMenuOrTextWindow::Widget()
|
||||||
{
|
{
|
||||||
QWidget *result = NULL;
|
QWidget *result = NULL;
|
||||||
if (!actual)
|
if (!actual)
|
||||||
impossible("Widget called before we know if Menu or Text");
|
MenuOrText_too_soon_warning("Widget");
|
||||||
else
|
else
|
||||||
result = actual->Widget();
|
result = actual->Widget();
|
||||||
return result;
|
return result;
|
||||||
@@ -1298,14 +1308,14 @@ QWidget* NetHackQtMenuOrTextWindow::Widget()
|
|||||||
void NetHackQtMenuOrTextWindow::Clear()
|
void NetHackQtMenuOrTextWindow::Clear()
|
||||||
{
|
{
|
||||||
if (!actual)
|
if (!actual)
|
||||||
impossible("Clear called before we know if Menu or Text");
|
MenuOrText_too_soon_warning("Clear");
|
||||||
else
|
else
|
||||||
actual->Clear();
|
actual->Clear();
|
||||||
}
|
}
|
||||||
void NetHackQtMenuOrTextWindow::Display(bool block)
|
void NetHackQtMenuOrTextWindow::Display(bool block)
|
||||||
{
|
{
|
||||||
if (!actual)
|
if (!actual)
|
||||||
impossible("Display called before we know if Menu or Text");
|
MenuOrText_too_soon_warning("Display");
|
||||||
else
|
else
|
||||||
actual->Display(block);
|
actual->Display(block);
|
||||||
}
|
}
|
||||||
@@ -1313,45 +1323,47 @@ bool NetHackQtMenuOrTextWindow::Destroy()
|
|||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (!actual)
|
if (!actual)
|
||||||
impossible("Destroy called before we know if Menu or Text");
|
MenuOrText_too_soon_warning("Destroy");
|
||||||
else
|
else
|
||||||
result = actual->Destroy();
|
result = actual->Destroy();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetHackQtMenuOrTextWindow::PutStr(int attr, const QString& text)
|
void NetHackQtMenuOrTextWindow::PutStr(int attr, const QString& text)
|
||||||
{
|
{
|
||||||
if (!actual) actual=new NetHackQtTextWindow(parent);
|
if (!actual)
|
||||||
actual->PutStr(attr,text);
|
actual = new NetHackQtTextWindow(parent);
|
||||||
|
actual->PutStr(attr, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Menu
|
// Menu
|
||||||
void NetHackQtMenuOrTextWindow::StartMenu(bool using_WIN_INVEN)
|
void NetHackQtMenuOrTextWindow::StartMenu(bool using_WIN_INVEN)
|
||||||
{
|
{
|
||||||
if (!actual) actual=new NetHackQtMenuWindow(parent);
|
if (!actual)
|
||||||
|
actual = new NetHackQtMenuWindow(parent);
|
||||||
actual->StartMenu(using_WIN_INVEN);
|
actual->StartMenu(using_WIN_INVEN);
|
||||||
}
|
}
|
||||||
void NetHackQtMenuOrTextWindow::AddMenu(int glyph, const ANY_P* identifier,
|
void NetHackQtMenuOrTextWindow::AddMenu(
|
||||||
char ch, char gch, int attr,
|
int glyph, const ANY_P* identifier,
|
||||||
const QString& str, unsigned itemflags)
|
char ch, char gch, int attr,
|
||||||
|
const QString& str, unsigned itemflags)
|
||||||
{
|
{
|
||||||
if (!actual)
|
if (!actual)
|
||||||
impossible("AddMenu called before we know if Menu or Text");
|
MenuOrText_too_soon_warning("AddMenu");
|
||||||
else
|
else
|
||||||
actual->AddMenu(glyph, identifier, ch, gch, attr, str, itemflags);
|
actual->AddMenu(glyph, identifier, ch, gch, attr, str, itemflags);
|
||||||
}
|
}
|
||||||
void NetHackQtMenuOrTextWindow::EndMenu(const QString& prompt)
|
void NetHackQtMenuOrTextWindow::EndMenu(const QString& prompt)
|
||||||
{
|
{
|
||||||
if (!actual)
|
if (!actual)
|
||||||
impossible("EndMenu called before we know if Menu or Text");
|
MenuOrText_too_soon_warning("EndMenu");
|
||||||
else
|
else
|
||||||
actual->EndMenu(prompt);
|
actual->EndMenu(prompt);
|
||||||
}
|
}
|
||||||
int NetHackQtMenuOrTextWindow::SelectMenu(int how, MENU_ITEM_P **menu_list)
|
int NetHackQtMenuOrTextWindow::SelectMenu(int how, MENU_ITEM_P **menu_list)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1; // cancelled
|
||||||
if (!actual)
|
if (!actual)
|
||||||
impossible("SelectMenu called before we know if Menu or Text");
|
MenuOrText_too_soon_warning("SelectMenu");
|
||||||
else
|
else
|
||||||
result = actual->SelectMenu(how, menu_list);
|
result = actual->SelectMenu(how, menu_list);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -179,6 +179,8 @@ private:
|
|||||||
NetHackQtWindow* actual;
|
NetHackQtWindow* actual;
|
||||||
QWidget *parent;
|
QWidget *parent;
|
||||||
|
|
||||||
|
static void MenuOrText_too_soon_warning(const char *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NetHackQtMenuOrTextWindow(QWidget *parent = NULL);
|
NetHackQtMenuOrTextWindow(QWidget *parent = NULL);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user