Qt4: Handle saving/loading message history
This commit is contained in:
@@ -18,6 +18,7 @@ extern "C" {
|
||||
#undef max
|
||||
|
||||
#include <QtGui/QtGui>
|
||||
#include <QStringList>
|
||||
#if QT_VERSION >= 0x050000
|
||||
#include <QtWidgets/QtWidgets>
|
||||
#include <QtMultimedia/QSound>
|
||||
@@ -119,6 +120,9 @@ NetHackQtBind::NetHackQtBind(int& argc, char** argv) :
|
||||
main = new NetHackQtMainWindow(keybuffer);
|
||||
connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));
|
||||
qt_settings=new NetHackQtSettings(main->width(),main->height());
|
||||
msgs_strings = new QStringList();
|
||||
msgs_initd = false;
|
||||
msgs_saved = false;
|
||||
}
|
||||
|
||||
void NetHackQtBind::qt_init_nhwindows(int* argc, char** argv)
|
||||
@@ -616,19 +620,37 @@ char * NetHackQtBind::qt_getmsghistory(BOOLEAN_P init)
|
||||
void NetHackQtBind::qt_putmsghistory(const char *msg, BOOLEAN_P is_restoring)
|
||||
{
|
||||
NetHackQtMessageWindow* window = main->GetMessageWindow();
|
||||
//raw_printf("msg='%s'", msg);
|
||||
if (window && msg)
|
||||
if (!window)
|
||||
return;
|
||||
|
||||
if (is_restoring && !msgs_initd) {
|
||||
/* we're restoring history from the previous session, but new
|
||||
messages have already been issued this session */
|
||||
int i = 0;
|
||||
const char *str;
|
||||
|
||||
while ((str = window->GetStr((i == 0)))) {
|
||||
msgs_strings->append(str);
|
||||
i++;
|
||||
}
|
||||
msgs_initd = true;
|
||||
msgs_saved = (i > 0);
|
||||
window->ClearMessages();
|
||||
}
|
||||
|
||||
if (msg) {
|
||||
//raw_printf("msg='%s'", msg);
|
||||
window->PutStr(ATR_NONE, QString::fromLatin1(msg));
|
||||
} else if (msgs_saved) {
|
||||
/* restore strings */
|
||||
int i;
|
||||
for (i = 0; i < msgs_strings->size(); i++)
|
||||
window->PutStr(ATR_NONE, msgs_strings->at((i)));
|
||||
delete msgs_strings;
|
||||
msgs_initd = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NetHackQtBind::qt_putmsghistory(const std::string& msg, BOOLEAN_P is_restoring)
|
||||
{
|
||||
NetHackQtMessageWindow* window = main->GetMessageWindow();
|
||||
if (window)
|
||||
window->PutStr(ATR_NONE, QString::fromLatin1(msg.c_str(), msg.size()));
|
||||
}
|
||||
|
||||
|
||||
bool NetHackQtBind::notify(QObject *receiver, QEvent *event)
|
||||
{
|
||||
// Ignore Alt-key navigation to menubar, it's annoying when you
|
||||
@@ -682,6 +704,9 @@ NetHackQtKeyBuffer NetHackQtBind::keybuffer;
|
||||
NetHackQtClickBuffer NetHackQtBind::clickbuffer;
|
||||
NetHackQtMainWindow* NetHackQtBind::main=0;
|
||||
QFrame* NetHackQtBind::splash=0;
|
||||
QStringList *NetHackQtBind::msgs_strings;
|
||||
boolean NetHackQtBind::msgs_saved = false;
|
||||
boolean NetHackQtBind::msgs_initd = false;
|
||||
|
||||
static void Qt_positionbar(char *) {}
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ public:
|
||||
|
||||
static char *qt_getmsghistory(BOOLEAN_P init);
|
||||
static void qt_putmsghistory(const char *msg, BOOLEAN_P is_restoring);
|
||||
static void qt_putmsghistory(const std::string& msg, BOOLEAN_P is_restoring);
|
||||
|
||||
static void qt_outrip(winid wid, int how, time_t when);
|
||||
static int qt_kbhit();
|
||||
@@ -89,6 +88,10 @@ public:
|
||||
|
||||
private:
|
||||
virtual bool notify(QObject *receiver, QEvent *event);
|
||||
|
||||
static QStringList *msgs_strings;
|
||||
static boolean msgs_saved;
|
||||
static boolean msgs_initd;
|
||||
};
|
||||
|
||||
} // namespace nethack_qt4
|
||||
|
||||
@@ -73,6 +73,12 @@ void NetHackQtMessageWindow::Clear()
|
||||
map->clearMessages();
|
||||
}
|
||||
|
||||
void NetHackQtMessageWindow::ClearMessages()
|
||||
{
|
||||
if (list)
|
||||
list->clear();
|
||||
}
|
||||
|
||||
void NetHackQtMessageWindow::Display(bool block)
|
||||
{
|
||||
if (changed) {
|
||||
@@ -86,7 +92,7 @@ const char * NetHackQtMessageWindow::GetStr(bool init)
|
||||
if (init)
|
||||
currgetmsg = 0;
|
||||
|
||||
QListWidgetItem *item = list->item(++currgetmsg);
|
||||
QListWidgetItem *item = list->item(currgetmsg++);
|
||||
if (item) {
|
||||
QString str = item->text();
|
||||
//raw_printf("getstr[%i]='%s'", currgetmsg, str.toLatin1().constData());
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
virtual void PutStr(int attr, const QString& text);
|
||||
|
||||
void Scroll(int dx, int dy);
|
||||
void ClearMessages();
|
||||
|
||||
void setMap(NetHackQtMapWindow2*);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user