Crossfire Server, Trunk
CREHPBarMaker.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 "CREHPBarMaker.h"
14 #include "CREPixmap.h"
15 #include <QtWidgets>
16 #include <QtCore/qiodevice.h>
17 #include <QtCore/qfile.h>
18 
19 #include "global.h"
20 
22 {
23  QGridLayout* layout = new QGridLayout(this);
24  int line = 0;
25 
26  layout->addWidget(new QLabel(tr("Path where to create items:"), this), line, 0);
27  myDestination = new QLineEdit();
28  layout->addWidget(myDestination, line, 1);
29 
30  QPushButton* browse = new QPushButton(tr("Browse"), this);
31  layout->addWidget(browse, line++, 2);
32  connect(browse, SIGNAL(clicked(bool)), this, SLOT(browse(bool)));
33 
34  layout->addWidget(new QLabel(tr("Archetype name:"), this), line, 0);
35  myName = new QLineEdit();
36  layout->addWidget(myName, line++, 1, 1, 2);
37 
38  layout->addWidget(new QLabel(tr("Color:"), this), line, 0);
39  myColorSelect = new QPushButton();
40  layout->addWidget(myColorSelect, line++, 1, 1, 2);
41  connect(myColorSelect, SIGNAL(clicked(bool)), this, SLOT(selectColor(bool)));
42 
43  layout->addWidget(new QLabel(tr("Y position from top:"), this), line, 0);
44  myShift = new QSpinBox(this);
45  myShift->setRange(1, 31);
46  layout->addWidget(myShift, line++, 1, 1, 2);
47 
48  layout->addWidget(new QLabel(tr("Bar height:"), this), line, 0);
49  myHeight = new QSpinBox(this);
50  myHeight->setRange(1, 31);
51  myHeight->setValue(5);
52  layout->addWidget(myHeight, line++, 1, 1, 2);
53 
54  QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, Qt::Horizontal, this);
55  layout->addWidget(box, line++, 1, 1, 3);
56  connect(box, SIGNAL(rejected()), this, SLOT(reject()));
57  connect(box, SIGNAL(accepted()), this, SLOT(makeBar()));
58 
59  myColor = QColor::fromRgb(255, 0, 0, 180);
60  adjustColor();
61 
62  setWindowTitle(tr("HP bar face generator"));
63 }
64 
66 {
67 }
68 
70 {
71  if (myDestination->text().isEmpty())
72  {
73  QMessageBox::warning(this, tr("Oops"), tr("You must select a destination!"));
74  return;
75  }
76 
77  if (myName->text().isEmpty())
78  {
79  QMessageBox::warning(this, tr("Oops"), tr("You must enter a name!"));
80  return;
81  }
82 
83  QString base = myDestination->text() + QDir::separator() + myName->text();
84 
85  if (QFile::exists(base + ".arc"))
86  {
87  if (QMessageBox::question(this, tr("Confirm file overwrite"), tr("File %1 already exists. Overwrite it?").arg(base + ".arc"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
88  return;
89  }
90 
91  QFile arc(base + ".arc");
92  if (!arc.open(QFile::Truncate | QFile::WriteOnly))
93  {
94  QMessageBox::critical(this, tr("Error"), tr("Error while opening the archetype file %1!").arg(arc.fileName()));
95  return;
96  }
97 
98  int shift = myShift->value();
99  int height = myHeight->value();
100 
101  for (int value = 1; value <= 30; value++)
102  {
103  QString line = tr("Object %1_%2\nface %1_%2.111\nend\n").arg(myName->text()).arg(value);
104  arc.write(line.toLocal8Bit());
105 
106  QPixmap pic(32, 32);
107  pic.fill(QColor(0, 0, 0, 0));
108  QPainter device(&pic);
109  device.fillRect(1, shift, value, height, myColor);
110 
111  QString picName = base + "_" + QString::number(value) + ".base.111.png";
112 
113  if (!pic.save(picName, "PNG"))
114  {
115  QMessageBox::critical(this, tr("Error"), tr("Error while saving the picture %1!").arg(picName));
116  return;
117  }
118 
119  }
120 
121  arc.close();
122 
123  QMessageBox::information(this, tr("Bar created"), tr("The bar was correctly saved as %1").arg(arc.fileName()));
124 }
125 
127 {
128  QString dest = QFileDialog::getExistingDirectory(this, tr("Select destination directory"), "");
129  if (dest.isEmpty())
130  return;
131 
132  myDestination->setText(dest);
133 }
134 
136 {
137  const QString style("QPushButton { background-color : %1; }");
138  myColorSelect->setStyleSheet(style.arg(myColor.name()));
139 }
140 
142 {
143  QColor color = QColorDialog::getColor(myColor, this, tr("Select bar color"), QColorDialog::ShowAlphaChannel);
144  if (!color.isValid())
145  return;
146  myColor = color;
147  adjustColor();
148 }
global.h
CREHPBarMaker::makeBar
void makeBar()
Definition: CREHPBarMaker.cpp:69
layout
Definition: main.cpp:84
CREHPBarMaker::myColor
QColor myColor
Definition: CREHPBarMaker.h:43
CREHPBarMaker::adjustColor
void adjustColor()
Definition: CREHPBarMaker.cpp:135
smoking_pipe.color
color
Definition: smoking_pipe.py:5
CREHPBarMaker::browse
void browse(bool)
Definition: CREHPBarMaker.cpp:126
is_valid_types_gen.line
line
Definition: is_valid_types_gen.py:34
CREHPBarMaker::myColorSelect
QPushButton * myColorSelect
Definition: CREHPBarMaker.h:44
CREHPBarMaker::myShift
QSpinBox * myShift
Definition: CREHPBarMaker.h:42
CFInsulter.style
style
Definition: CFInsulter.py:69
CREHPBarMaker::myName
QLineEdit * myName
Definition: CREHPBarMaker.h:40
say.box
box
Definition: say.py:152
CREHPBarMaker::CREHPBarMaker
CREHPBarMaker()
Definition: CREHPBarMaker.cpp:21
CREHPBarMaker::selectColor
void selectColor(bool)
Definition: CREHPBarMaker.cpp:141
CREHPBarMaker::myDestination
QLineEdit * myDestination
Definition: CREHPBarMaker.h:39
autojail.value
value
Definition: autojail.py:6
CREHPBarMaker::~CREHPBarMaker
virtual ~CREHPBarMaker()
Definition: CREHPBarMaker.cpp:65
convert.dest
dest
Definition: convert.py:25
CREHPBarMaker.h
CREHPBarMaker::myHeight
QSpinBox * myHeight
Definition: CREHPBarMaker.h:41
connect
Definition: connect.py:1
CREPixmap.h