Crossfire Server, Trunk
AttackMessagePanel.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include <QTableWidget>
14 #include "AttackMessagePanel.h"
15 #include "AttackMessagesWrapper.h"
16 #include "global.h"
17 #include "attack.h"
18 #include "sproto.h"
19 
20 AttackMessagePanel::AttackMessagePanel(QWidget* parent) : AssetSWrapperPanel(parent), myAttackType(0) {
21  myMessages = addWidget(nullptr, new QTableWidget(0, 4, this), false, nullptr, nullptr);
22  myMessages->setHorizontalHeaderLabels({tr("Max damage"), tr("First part"), tr("Second part"), tr("For victim")});
23  myMessages->setEditTriggers(QAbstractItemView::NoEditTriggers);
24  myMessages->setSelectionBehavior(QAbstractItemView::SelectRows);
25  myMessages->verticalHeader()->setVisible(false);
26  connect(myMessages, &QTableWidget::currentCellChanged, this, &AttackMessagePanel::currentCellChanged);
27  myForHitter = addLabel(nullptr, nullptr);
28  myForHitter->setTextInteractionFlags(Qt::TextSelectableByMouse);
29  myForVictim = addLabel(nullptr, nullptr);
30  myForVictim->setTextInteractionFlags(Qt::TextSelectableByMouse);
31 }
32 
33 static QTableWidgetItem *createItem(const QString &text) {
34  auto item = new QTableWidgetItem(text);
35  item->setData(Qt::ToolTipRole, text);
36  return item;
37 }
38 
40  myMessages->setRowCount(0);
42 
43  for (int message = 0; message < MAXATTACKMESS && attack_mess[myAttackType][message].level != -1; message++) {
44  myMessages->setRowCount(message + 1);
45  myMessages->setItem(message, 0, createItem(QString::number(attack_mess[myAttackType][message].level)));
49  }
50 }
51 
52 void AttackMessagePanel::currentCellChanged(int currentRow, int, int, int) {
53  myForHitter->clear();
54  myForVictim->clear();
55  if (currentRow < 0 || currentRow >= NROFATTACKMESS || attack_mess[myAttackType][currentRow].level == -1) {
56  return;
57  }
58 
59  char buf1[MAX_BUF], buf2[MAX_BUF];
60  get_attack_message_for_attack_type(attack_mess[myAttackType][currentRow].level - 1, myAttackType, "victim", buf1, buf2);
61  myForHitter->setText(QString("You %1").arg(buf1));
62  myForVictim->setText(QString("Hitter%1 you").arg(buf2));
63 }
AttackMessagesWrapper.h
NROFATTACKMESS
#define NROFATTACKMESS
Definition: attack.h:18
global.h
AttackMessagePanel::updateItem
virtual void updateItem() override
Definition: AttackMessagePanel.cpp:39
AttackMessagePanel::myMessages
QTableWidget * myMessages
Definition: AttackMessagePanel.h:38
AttackMessagePanel::currentCellChanged
void currentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn)
Definition: AttackMessagePanel.cpp:52
AssetSWrapperPanel< SingleAttackWrapper >::myItem
SingleAttackWrapper * myItem
Definition: AssetWrapperPanel.h:126
MAXATTACKMESS
#define MAXATTACKMESS
Definition: attack.h:19
AssetWrapperPanel::addLabel
QLabel * addLabel(const QString &label, const char *property, bool wrapText=false)
Definition: AssetWrapperPanel.cpp:68
attack.h
AttackMessagePanel::myForVictim
QLabel * myForVictim
Definition: AttackMessagePanel.h:40
AttackMessagePanel::AttackMessagePanel
AttackMessagePanel(QWidget *parent)
Definition: AttackMessagePanel.cpp:20
createItem
static QTableWidgetItem * createItem(const QString &text)
Definition: AttackMessagePanel.cpp:33
SingleAttackWrapper::attackType
uint8_t attackType() const
Definition: AttackMessagesWrapper.h:25
sproto.h
get_attack_message_for_attack_type
void get_attack_message_for_attack_type(int dam, uint8_t atm_type, const char *victim_name, char *buf1, char *buf2)
Definition: attack.cpp:538
guild_entry.text
text
Definition: guild_entry.py:41
MAX_BUF
#define MAX_BUF
Definition: define.h:35
AssetSWrapperPanel
Definition: AssetWrapperPanel.h:113
AttackMessagePanel::myForHitter
QLabel * myForHitter
Definition: AttackMessagePanel.h:39
attack_mess
attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]
Definition: init.cpp:78
diamondslots.message
string message
Definition: diamondslots.py:57
item
Definition: item.py:1
AttackMessagePanel::myAttackType
uint8_t myAttackType
Definition: AttackMessagePanel.h:37
AttackMessagePanel.h
AssetWrapperPanel::addWidget
T * addWidget(const QString &label, T *widget, bool sideBySide, const char *property, const char *widgetProperty)
Definition: AssetWrapperPanel.h:64
attackmess_t::level
int level
Definition: attack.h:119
say.item
dictionary item
Definition: say.py:149
connect
Definition: connect.py:1
level
Definition: level.py:1