Registry Mirror
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 52 additions & 21 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set(mmapper_SRCS
main.cpp
adventure/AdventureLogModel.cpp
adventure/AdventureLogModel.h
adventure/adventuresession.cpp
adventure/adventuresession.h
adventure/adventuretracker.cpp
Expand All @@ -10,8 +12,6 @@ set(mmapper_SRCS
adventure/lineparsers.h
adventure/xpstatuswidget.cpp
adventure/xpstatuswidget.h
display/AudioHintWidget.cpp
display/AudioHintWidget.h
media/AudioManager.cpp
media/AudioManager.h
media/DescriptionWidget.cpp
Expand All @@ -22,26 +22,32 @@ set(mmapper_SRCS
media/MusicManager.h
media/SfxManager.cpp
media/SfxManager.h
media/StackBlur.cpp
media/StackBlur.h
client/ClientTelnet.cpp
client/ClientTelnet.h
client/ClientWidget.cpp
client/ClientWidget.h
client/PaletteManager.cpp
client/PaletteManager.h
client/displaywidget.cpp
client/displaywidget.h
client/inputwidget.cpp
client/inputwidget.h
client/stackedinputwidget.cpp
client/stackedinputwidget.h
client/InputHistory.cpp
client/InputHistory.h
client/Hotkey.cpp
client/Hotkey.h
client/HotkeyManager.cpp
client/HotkeyManager.h
client/displaywidget.cpp
client/displaywidget.h
client/PaletteManager.cpp
client/PaletteManager.h
client/PasswordDialog.cpp
client/PasswordDialog.h
client/PreviewWidget.cpp
client/PreviewWidget.h
client/inputwidget.cpp
client/inputwidget.h
client/stackedinputwidget.cpp
client/stackedinputwidget.h
clock/ClockStrings.cpp
clock/ClockStrings.h
clock/mumeclock.cpp
clock/mumeclock.h
clock/mumeclockwidget.cpp
Expand Down Expand Up @@ -77,6 +83,9 @@ set(mmapper_SRCS
display/MapCanvasData.h
display/MapCanvasRoomDrawer.cpp
display/MapCanvasRoomDrawer.h
display/MapCanvasWindow.cpp
display/MapCanvasWindow.h
display/MapCanvasWindow_gl.cpp
display/FrameManager.cpp
display/FrameManager.h
display/ProjectionUtils.cpp
Expand All @@ -91,10 +100,14 @@ set(mmapper_SRCS
display/mapcanvas.cpp
display/mapcanvas.h
display/mapcanvas_gl.cpp
display/MapScroller.cpp
display/MapScroller.h
display/mapwindow.cpp
display/mapwindow.h
display/prespammedpath.cpp
display/prespammedpath.h
global/AnsiHtml.cpp
global/AnsiHtml.h
global/AnsiOstream.cpp
global/AnsiOstream.h
global/AnsiTextUtils.cpp
Expand Down Expand Up @@ -237,42 +250,48 @@ set(mmapper_SRCS
group/ColorGenerator.h
group/GroupManagerApi.cpp
group/GroupManagerApi.h
group/enums.cpp
group/enums.h
group/GroupModel.cpp
group/GroupModel.h
group/groupwidget.cpp
group/groupwidget.h
group/enums.cpp
group/enums.h
group/mmapper2character.cpp
group/mmapper2character.h
group/mmapper2group.cpp
group/mmapper2group.h
logger/autologger.cpp
logger/autologger.h
mainwindow/aboutdialog.cpp
mainwindow/aboutdialog.h
mainwindow/AsyncTypes.h
mainwindow/AudioVolumeSlider.cpp
mainwindow/AudioVolumeSlider.h
mainwindow/CompactLayout.h
mainwindow/MapZoomSlider.cpp
mainwindow/MapZoomSlider.h
mainwindow/TasksPanel.cpp
mainwindow/TasksPanel.h
mainwindow/ThemeManager.cpp
mainwindow/ThemeManager.h
mainwindow/UpdateChecker.cpp
mainwindow/UpdateChecker.h
mainwindow/UpdateDialog.cpp
mainwindow/UpdateDialog.h
mainwindow/aboutdialog.cpp
mainwindow/aboutdialog.h
mainwindow/findroomsdlg.cpp
mainwindow/findroomsdlg.h
mainwindow/infomarkseditdlg.cpp
mainwindow/infomarkseditdlg.h
mainwindow/roomeditattrdlg.cpp
mainwindow/roomeditattrdlg.h
mainwindow/mainwindow-async.cpp
mainwindow/mainwindow-async.h
mainwindow/mainwindow-compact.cpp
mainwindow/mainwindow-saveslots.cpp
mainwindow/mainwindow.cpp
mainwindow/mainwindow.h
mainwindow/metatypes.cpp
mainwindow/metatypes.h
mainwindow/roomeditattrdlg.cpp
mainwindow/roomeditattrdlg.h
mainwindow/utils.cpp
mainwindow/utils.h
map/AbstractChangeVisitor.cpp
Expand Down Expand Up @@ -385,6 +404,8 @@ set(mmapper_SRCS
mapfrontend/mapfrontend.h
mapstorage/MapDestination.cpp
mapstorage/MapDestination.h
mapstorage/MapLoadHelper.cpp
mapstorage/MapLoadHelper.h
mapstorage/MapSource.cpp
mapstorage/MapSource.h
mapstorage/MmpMapStorage.cpp
Expand All @@ -409,6 +430,10 @@ set(mmapper_SRCS
mpi/remoteedit.h
mpi/remoteeditsession.cpp
mpi/remoteeditsession.h
mpi/RemoteEditDocumentOps.cpp
mpi/RemoteEditDocumentOps.h
mpi/RemoteEditHighlighter.cpp
mpi/RemoteEditHighlighter.h
mpi/remoteeditwidget.cpp
mpi/remoteeditwidget.h
mpi/gotowidget.cpp
Expand Down Expand Up @@ -516,6 +541,8 @@ set(mmapper_SRCS
preferences/AdvancedGraphics.h
preferences/audiopage.cpp
preferences/audiopage.h
preferences/AnsiColorTables.cpp
preferences/AnsiColorTables.h
preferences/AnsiColorDialog.cpp
preferences/AnsiColorDialog.h
preferences/ansicombo.cpp
Expand All @@ -524,22 +551,22 @@ set(mmapper_SRCS
preferences/autologpage.h
preferences/clientpage.cpp
preferences/clientpage.h
preferences/configdialog.cpp
preferences/configdialog.h
preferences/generalpage.cpp
preferences/generalpage.h
preferences/graphicspage.cpp
preferences/graphicspage.h
preferences/grouppage.cpp
preferences/grouppage.h
preferences/mumeprotocolpage.cpp
preferences/mumeprotocolpage.h
preferences/ManagePasswordDialog.cpp
preferences/ManagePasswordDialog.h
preferences/mumeprotocolpage.cpp
preferences/mumeprotocolpage.h
preferences/parserpage.cpp
preferences/parserpage.h
preferences/pathmachinepage.cpp
preferences/pathmachinepage.h
preferences/configdialog.cpp
preferences/configdialog.h
proxy/AbstractSocket.h
proxy/AbstractTelnet.cpp
proxy/AbstractTelnet.h
Expand All @@ -565,6 +592,8 @@ set(mmapper_SRCS
proxy/connectionlistener.h
proxy/mumesocket.cpp
proxy/mumesocket.h
proxy/ProxyHost.cpp
proxy/ProxyHost.h
proxy/proxy.cpp
proxy/proxy.h
proxy/telnetfilter.cpp
Expand All @@ -575,6 +604,8 @@ set(mmapper_SRCS
roompanel/RoomMob.h
roompanel/RoomMobs.cpp
roompanel/RoomMobs.h
roompanel/RoomModel.cpp
roompanel/RoomModel.h
roompanel/RoomWidget.cpp
roompanel/RoomWidget.h
syntax/Accept.cpp
Expand Down Expand Up @@ -602,9 +633,9 @@ set(mmapper_SRCS
timers/CTimers.cpp
timers/CTimers.h
timers/TimerDelegate.cpp
timers/TimerDelegate.h
timers/TimerModel.cpp
timers/TimerModel.h
timers/TimerDelegate.h
timers/TimerWidget.cpp
timers/TimerWidget.h
viewers/AnsiViewWindow.cpp
Expand Down
157 changes: 157 additions & 0 deletions src/adventure/AdventureLogModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2026 The MMapper Authors

#include "AdventureLogModel.h"

#include "../global/Consts.h"
#include "adventuresession.h"

AdventureLogModel::AdventureLogModel(AdventureTracker &tracker, QObject *const parent)
: QAbstractListModel(parent)
{
addDefaultContent();

connect(&tracker,
&AdventureTracker::sig_accomplishedTask,
this,
&AdventureLogModel::slot_onAccomplishedTask);

connect(&tracker,
&AdventureTracker::sig_achievedSomething,
this,
&AdventureLogModel::slot_onAchievedSomething);

connect(&tracker, &AdventureTracker::sig_diedInGame, this, &AdventureLogModel::slot_onDied);

connect(&tracker,
&AdventureTracker::sig_gainedLevel,
this,
&AdventureLogModel::slot_onGainedLevel);

connect(&tracker, &AdventureTracker::sig_killedMob, this, &AdventureLogModel::slot_onKilledMob);

connect(&tracker,
&AdventureTracker::sig_receivedHint,
this,
&AdventureLogModel::slot_onReceivedHint);
}

int AdventureLogModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return static_cast<int>(m_lines.size());
}

QVariant AdventureLogModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() < 0
|| static_cast<qsizetype>(index.row()) >= m_lines.size()) {
return QVariant();
}

if (role == Qt::DisplayRole) {
return m_lines.at(index.row());
}

return QVariant();
}

QHash<int, QByteArray> AdventureLogModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[Qt::DisplayRole] = "display";
return roles;
}

void AdventureLogModel::clear()
{
if (!m_lines.isEmpty()) {
beginRemoveRows(QModelIndex(), 0, static_cast<int>(m_lines.size()) - 1);
m_lines.clear();
endRemoveRows();
}
addDefaultContent();
}

void AdventureLogModel::addDefaultContent()
{
addAdventureUpdate(DEFAULT_MSG);
}

void AdventureLogModel::addAdventureUpdate(const QString &msg)
{
QString line = msg;
while (line.endsWith(char_consts::C_NEWLINE)) {
line.chop(1);
}

const int row = static_cast<int>(m_lines.size());
beginInsertRows(QModelIndex(), row, row);
m_lines.append(line);
endInsertRows();

// If more than MAX_LINES, preserve by deleting from the start
const int over = static_cast<int>(m_lines.size()) - MAX_LINES;
if (over > 0) {
beginRemoveRows(QModelIndex(), 0, over - 1);
m_lines.erase(m_lines.begin(), m_lines.begin() + over);
endRemoveRows();
}
}

void AdventureLogModel::slot_onAccomplishedTask(double xpGained)
{
// Only record accomplishedTask if it actually has associated xp to avoid
// spam, since sometimes it co-triggers with achievement and can be redundant.
if (xpGained > 0.0) {
auto msg = QString(ACCOMPLISH_MSG).arg(AdventureSession::formatPoints(xpGained));
addAdventureUpdate(msg);
}
}

void AdventureLogModel::slot_onAchievedSomething(const QString &achievement, double xpGained)
{
QString msg;

if (xpGained > 0.0) {
msg = QString(ACHIEVE_MSG_XP).arg(achievement, AdventureSession::formatPoints(xpGained));
} else {
msg = QString(ACHIEVE_MSG).arg(achievement);
}

addAdventureUpdate(msg);
}

void AdventureLogModel::slot_onDied(double xpLost)
{
// Ignore Died messages that don't have an accompanying XP loss (to avoid whois spam, etc.)
if (xpLost < 0.0) {
auto msg = QString(DIED_MSG).arg(AdventureSession::formatPoints(xpLost));
addAdventureUpdate(msg);
}
}

void AdventureLogModel::slot_onGainedLevel()
{
addAdventureUpdate(QString(GAINED_LEVEL_MSG));
}

void AdventureLogModel::slot_onKilledMob(const QString &mobName, double xpGained)
{
// When player gets XP from multiple kills on the same heartbeat, as
// frequently happens with quake xp, then the first mob gets all the XP
// attributed and the others are zero. No way to solve this given
// current MUME "protocol".
auto xpf = (xpGained > 0.0) ? AdventureSession::formatPoints(xpGained) : "?";
auto msg = QString(KILL_TROPHY_MSG).arg(mobName, xpf);

addAdventureUpdate(msg);
}

void AdventureLogModel::slot_onReceivedHint(const QString &hint)
{
auto msg = QString(HINT_MSG).arg(hint);

addAdventureUpdate(msg);
}
Loading
Loading