Refactor messagelogwidget (#3875)
This commit is contained in:
parent
2de863f645
commit
1eea8e9a37
5 changed files with 77 additions and 80 deletions
|
@ -122,6 +122,7 @@ SET(cockatrice_SOURCES
|
|||
src/carddbparser/cockatricexml3.cpp
|
||||
src/carddbparser/cockatricexml4.cpp
|
||||
src/filter_string.cpp
|
||||
src/phase.cpp
|
||||
src/customlineedit.cpp
|
||||
src/translatecountername.cpp
|
||||
${VERSION_STRING_CPP}
|
||||
|
|
|
@ -5,49 +5,50 @@
|
|||
#include "pb/context_move_card.pb.h"
|
||||
#include "pb/context_mulligan.pb.h"
|
||||
#include "pb/serverinfo_user.pb.h"
|
||||
#include "phase.h"
|
||||
#include "player.h"
|
||||
#include "soundengine.h"
|
||||
#include "translatecountername.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
const QString MessageLogWidget::tableConstant() const
|
||||
const QString &MessageLogWidget::tableConstant() const
|
||||
{
|
||||
static const QString constant("table");
|
||||
return constant;
|
||||
}
|
||||
|
||||
const QString MessageLogWidget::graveyardConstant() const
|
||||
const QString &MessageLogWidget::graveyardConstant() const
|
||||
{
|
||||
static const QString constant("grave");
|
||||
return constant;
|
||||
}
|
||||
|
||||
const QString MessageLogWidget::exileConstant() const
|
||||
const QString &MessageLogWidget::exileConstant() const
|
||||
{
|
||||
static const QString constant("rfg");
|
||||
return constant;
|
||||
}
|
||||
|
||||
const QString MessageLogWidget::handConstant() const
|
||||
const QString &MessageLogWidget::handConstant() const
|
||||
{
|
||||
static const QString constant("hand");
|
||||
return constant;
|
||||
}
|
||||
|
||||
const QString MessageLogWidget::deckConstant() const
|
||||
const QString &MessageLogWidget::deckConstant() const
|
||||
{
|
||||
static const QString constant("deck");
|
||||
return constant;
|
||||
}
|
||||
|
||||
const QString MessageLogWidget::sideboardConstant() const
|
||||
const QString &MessageLogWidget::sideboardConstant() const
|
||||
{
|
||||
static const QString constant("sb");
|
||||
return constant;
|
||||
}
|
||||
|
||||
const QString MessageLogWidget::stackConstant() const
|
||||
const QString &MessageLogWidget::stackConstant() const
|
||||
{
|
||||
static const QString constant("stack");
|
||||
return constant;
|
||||
|
@ -561,73 +562,14 @@ void MessageLogWidget::logSay(Player *player, QString message)
|
|||
QString::fromStdString(player->getUserInfo()->privlevel()), true);
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetActivePhase(int phase)
|
||||
void MessageLogWidget::logSetActivePhase(int phaseNumber)
|
||||
{
|
||||
QString phaseName;
|
||||
QString color;
|
||||
switch (phase) { // TODO: define phases
|
||||
case 0:
|
||||
phaseName = tr("Untap");
|
||||
soundEngine->playSound("untap_step");
|
||||
color = "green";
|
||||
break;
|
||||
case 1:
|
||||
phaseName = tr("Upkeep");
|
||||
soundEngine->playSound("upkeep_step");
|
||||
color = "green";
|
||||
break;
|
||||
case 2:
|
||||
phaseName = tr("Draw");
|
||||
soundEngine->playSound("draw_step");
|
||||
color = "green";
|
||||
break;
|
||||
case 3:
|
||||
phaseName = tr("First Main");
|
||||
soundEngine->playSound("main_1");
|
||||
color = "blue";
|
||||
break;
|
||||
case 4:
|
||||
phaseName = tr("Beginning of Combat");
|
||||
soundEngine->playSound("start_combat");
|
||||
color = "red";
|
||||
break;
|
||||
case 5:
|
||||
phaseName = tr("Declare Attackers");
|
||||
soundEngine->playSound("attack_step");
|
||||
color = "red";
|
||||
break;
|
||||
case 6:
|
||||
phaseName = tr("Declare Blockers");
|
||||
soundEngine->playSound("block_step");
|
||||
color = "red";
|
||||
break;
|
||||
case 7:
|
||||
phaseName = tr("Combat Damage");
|
||||
soundEngine->playSound("damage_step");
|
||||
color = "red";
|
||||
break;
|
||||
case 8:
|
||||
phaseName = tr("End of Combat");
|
||||
soundEngine->playSound("end_combat");
|
||||
color = "red";
|
||||
break;
|
||||
case 9:
|
||||
phaseName = tr("Second Main");
|
||||
soundEngine->playSound("main_2");
|
||||
color = "blue";
|
||||
break;
|
||||
case 10:
|
||||
phaseName = tr("End/Cleanup");
|
||||
soundEngine->playSound("end_step");
|
||||
color = "green";
|
||||
break;
|
||||
default:
|
||||
phaseName = tr("Unknown Phase");
|
||||
color = "black";
|
||||
break;
|
||||
}
|
||||
appendHtml("<font color=\"" + color + "\"><b>" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") +
|
||||
QString("%1").arg(phaseName) + "</b></font>");
|
||||
Phase phase = Phases::getPhase(phaseNumber);
|
||||
|
||||
soundEngine->playSound(phase.soundFileName);
|
||||
|
||||
appendHtml("<font color=\"" + phase.color + "\"><b>" + QDateTime::currentDateTime().toString("[hh:mm:ss] ") +
|
||||
phase.name + "</b></font>");
|
||||
}
|
||||
|
||||
void MessageLogWidget::logSetActivePlayer(Player *player)
|
||||
|
|
|
@ -26,13 +26,13 @@ private:
|
|||
MessageContext currentContext;
|
||||
QString messagePrefix, messageSuffix;
|
||||
|
||||
const QString tableConstant() const;
|
||||
const QString graveyardConstant() const;
|
||||
const QString exileConstant() const;
|
||||
const QString handConstant() const;
|
||||
const QString deckConstant() const;
|
||||
const QString sideboardConstant() const;
|
||||
const QString stackConstant() const;
|
||||
const QString &tableConstant() const;
|
||||
const QString &graveyardConstant() const;
|
||||
const QString &exileConstant() const;
|
||||
const QString &handConstant() const;
|
||||
const QString &deckConstant() const;
|
||||
const QString &sideboardConstant() const;
|
||||
const QString &stackConstant() const;
|
||||
|
||||
QString sanitizeHtml(QString dirty) const;
|
||||
QString cardLink(QString cardName) const;
|
||||
|
|
29
cockatrice/src/phase.cpp
Normal file
29
cockatrice/src/phase.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "phase.h"
|
||||
|
||||
Phase::Phase(const char *_name, QString _color, QString _soundFileName) : color(_color), soundFileName(_soundFileName)
|
||||
{
|
||||
name = tr(_name);
|
||||
}
|
||||
|
||||
Phase Phases::getPhase(int phase)
|
||||
{
|
||||
if (0 <= phase && phase < Phases::phaseTypesCount) {
|
||||
return phases[phase];
|
||||
} else {
|
||||
return unknownPhase;
|
||||
}
|
||||
}
|
||||
|
||||
const Phase Phases::unknownPhase(QT_TRANSLATE_NOOP("Phase", "Unknown Phase"), "black", "unknown_phase");
|
||||
const Phase Phases::phases[Phases::phaseTypesCount] = {
|
||||
{QT_TRANSLATE_NOOP("Phase", "Untap"), "green", "untap_step"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "Upkeep"), "green", "upkeep_step"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "Draw"), "green", "draw_step"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "First Main"), "blue", "main_1"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "Beginning of Combat"), "red", "start_combat"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "Declare Attackers"), "red", "attack_step"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "Declare Blockers"), "red", "block_step"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "Combat Damage"), "red", "damage_step"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "End of Combat"), "red", "end_combat"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "Second Main"), "blue", "main_2"},
|
||||
{QT_TRANSLATE_NOOP("Phase", "End/Cleanup"), "green", "end_step"}};
|
25
cockatrice/src/phase.h
Normal file
25
cockatrice/src/phase.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef PHASE_H
|
||||
#define PHASE_H
|
||||
|
||||
#include <QString>
|
||||
#include <QtCore>
|
||||
|
||||
class Phase
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(Phase)
|
||||
|
||||
public:
|
||||
QString name, color, soundFileName;
|
||||
Phase(const char *_name, QString _color, QString _soundFileName);
|
||||
};
|
||||
|
||||
struct Phases
|
||||
{
|
||||
const static int phaseTypesCount = 11;
|
||||
const static Phase unknownPhase;
|
||||
const static Phase phases[phaseTypesCount];
|
||||
|
||||
static Phase getPhase(int);
|
||||
};
|
||||
|
||||
#endif // PHASE_H
|
Loading…
Reference in a new issue