Skip to content

Commit

Permalink
more fields in fake_spell popup
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Oct 9, 2020
1 parent bee2e43 commit e93d67a
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 128 deletions.
17 changes: 14 additions & 3 deletions object_creator/fake_spell_listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,22 @@ creator::fake_spell_listbox::fake_spell_listbox( QWidget *parent )
add_spell_button.move( QPoint( default_text_box_width * col, default_text_box_height * row ) );
add_spell_button.show();
QObject::connect( &add_spell_button, &QPushButton::clicked,
[&]() {
[&]() {
const int index = windows.size();
windows.push_back( new fake_spell_window() );
windows.back()->hide();
QObject::connect( windows.back(), &fake_spell_window::modified, this, &fake_spell_listbox::modified );
windows.back()->index = index;
QObject::connect( windows.back(), &fake_spell_window::modified, this,
&fake_spell_listbox::modified );
fake_spell_list_box.addItem( QString( "NEW (edit)" ) );
QObject::connect( windows.back(), &fake_spell_window::modified,
[&]() {
const fake_spell_window *win = windows.back();
const fake_spell &sp = win->get_fake_spell();
if( !sp.id.is_empty() ) {
fake_spell_list_box.setItemText( win->index, sp.id.c_str() );
}
} );
} );

// =========================================================================================
Expand All @@ -48,7 +59,7 @@ creator::fake_spell_listbox::fake_spell_listbox( QWidget *parent )
fake_spell_list_box.move( QPoint( default_text_box_width * col, default_text_box_height * row ) );
fake_spell_list_box.show();
QObject::connect( &fake_spell_list_box, qOverload<int>( &QComboBox::currentIndexChanged ),
[&]() {
[&]() {
for( fake_spell_window *win : windows ) {
win->hide();
}
Expand Down
5 changes: 2 additions & 3 deletions object_creator/fake_spell_listbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace creator
{
class fake_spell_listbox : public QListWidget
{
Q_OBJECT
Q_OBJECT
public:
fake_spell_listbox( QWidget *parent = nullptr );

Expand All @@ -28,8 +28,7 @@ class fake_spell_listbox : public QListWidget
void set_spells( const std::vector<fake_spell> &spells );
std::vector<fake_spell> creator::fake_spell_listbox::get_spells() const;

void setText( const QString &str )
{
void setText( const QString &str ) {
id_label.setText( str );
}
signals:
Expand Down
82 changes: 80 additions & 2 deletions object_creator/fake_spell_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ creator::fake_spell_window::fake_spell_window( QWidget *parent, Qt::WindowFlags
const int default_text_box_height = 20;
const int default_text_box_width = 100;
const QSize default_text_box_size( default_text_box_width, default_text_box_height );
const QSize half_width_text_box( default_text_box_width / 2, default_text_box_height );

int row = 0;
int col = 0;
Expand All @@ -24,7 +25,30 @@ creator::fake_spell_window::fake_spell_window( QWidget *parent, Qt::WindowFlags
id_label.setDisabled( true );
id_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
id_label.show();


max_level_label.setParent( this );
max_level_label.setText( QString( "maximum level" ) );
max_level_label.resize( default_text_box_size );
max_level_label.setDisabled( true );
max_level_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
max_level_label.show();

min_level_label.setParent( this );
min_level_label.setText( QString( "minimum level" ) );
min_level_label.resize( default_text_box_size );
min_level_label.setDisabled( true );
min_level_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
min_level_label.show();

once_in_label.setParent( this );
once_in_label.setText( QString( "once in" ) );
once_in_label.resize( default_text_box_size );
once_in_label.setDisabled( true );
once_in_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
once_in_label.setToolTip( QString(
_( "The frequency this spell activates when part of an intermittent enchantment. RNG-based." ) ) );
once_in_label.show();

// =========================================================================================
// second column of boxes
max_row = std::max( row, max_row );
Expand All @@ -37,8 +61,62 @@ creator::fake_spell_window::fake_spell_window( QWidget *parent, Qt::WindowFlags
id_box.setToolTip( QString( _( "The id of the spell" ) ) );
id_box.show();
QObject::connect( &id_box, &QLineEdit::textChanged,
[&]() {
[&]() {
editable_spell.id = spell_id( id_box.text().toStdString() );
if( editable_spell.id.is_valid() ) {
max_level_box.setMaximum( editable_spell.id->max_level );
min_level_box.setMaximum( editable_spell.id->max_level );
}
} );
QObject::connect( &id_box, &QLineEdit::textChanged, this, &fake_spell_window::modified );

max_level_box.setParent( this );
max_level_box.resize( default_text_box_size );
max_level_box.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
max_level_box.setToolTip( QString(
_( "The max level this fake_spell can achieve. Set to -1 for max == max_level of spell." ) ) );
max_level_box.setMinimum( -1 );
max_level_box.show();

min_level_box.setParent( this );
min_level_box.resize( default_text_box_size );
min_level_box.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
min_level_box.setToolTip( QString(
_( "The min level of this fake_spell. Max level takes precedence." ) ) );
min_level_box.setMinimum( 0 );
min_level_box.show();

once_in_duration_box.setParent( this );
once_in_duration_box.resize( half_width_text_box );
once_in_duration_box.move( QPoint( col * default_text_box_width, row * default_text_box_height ) );
once_in_duration_box.setToolTip( QString(
_( "The min level of this fake_spell. Max level takes precedence." ) ) );
once_in_duration_box.setMinimum( 1 );
once_in_duration_box.show();
const auto update_spell_trigger_duration = [&]() {
time_duration unit = 1_turns;
for( const std::pair<std::string, time_duration> &unit_pair : time_duration::units ) {
if( unit_pair.first == once_in_units_box.currentText().toStdString() ) {
unit = unit_pair.second;
}
}
editable_spell.trigger_once_in = to_turns<int>( unit * once_in_duration_box.value() );
};
QObject::connect( &once_in_duration_box, qOverload<int>( &QSpinBox::valueChanged ),
update_spell_trigger_duration );

once_in_units_box.setParent( this );
once_in_units_box.resize( half_width_text_box );
once_in_units_box.move( QPoint( col * default_text_box_width + default_text_box_width / 2,
row++ * default_text_box_height ) );
once_in_units_box.setToolTip( QString( _( "The unit to be used for the once_in frequency." ) ) );
for( const std::pair<std::string, time_duration> &unit_pair : time_duration::units ) {
// intentionally limiting the available units to single letter abbreviations
if( unit_pair.first.length() == 1 ) {
once_in_units_box.addItem( QString( unit_pair.first.c_str() ) );
}
}
once_in_units_box.show();
QObject::connect( &once_in_units_box, qOverload<int>( &QComboBox::currentIndexChanged ),
update_spell_trigger_duration );
}
18 changes: 15 additions & 3 deletions object_creator/fake_spell_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

#include "magic.h"

#include <QtWidgets/qcombobox.h>
#include <QtWidgets/qlineedit.h>
#include <QtWidgets/qlistwidget.h>
#include <QtWidgets/qmainwindow.h>
#include <QtWidgets/qspinbox.h>

namespace creator
{
class fake_spell_window : public QMainWindow
{
Q_OBJECT
Q_OBJECT
public:
fake_spell_window( QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );

Expand All @@ -31,10 +33,12 @@ class fake_spell_window : public QMainWindow
editable_spell = sp;
}

void set_update_func( const std::function<void( void )> &func )
{
void set_update_func( const std::function<void( void )> &func ) {
update_func = func;
}

// the index of this window in the windows vector in fake_spell_listbox
int index = 0;
signals:
// emits a signal if any attached data is modified
void modified();
Expand All @@ -46,7 +50,15 @@ class fake_spell_window : public QMainWindow
QLineEdit error_window;

QLineEdit id_label;
QLineEdit max_level_label;
QLineEdit min_level_label;
QLineEdit once_in_label;

QLineEdit id_box;
QSpinBox max_level_box;
QSpinBox min_level_box;
QSpinBox once_in_duration_box;
QComboBox once_in_units_box;
};
}

Expand Down
122 changes: 67 additions & 55 deletions object_creator/moc_fake_spell_listbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ struct qt_meta_stringdata_creator__fake_spell_listbox_t {
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_creator__fake_spell_listbox_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_creator__fake_spell_listbox_t qt_meta_stringdata_creator__fake_spell_listbox = {
qptrdiff(offsetof(qt_meta_stringdata_creator__fake_spell_listbox_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_creator__fake_spell_listbox_t
qt_meta_stringdata_creator__fake_spell_listbox = {
{
QT_MOC_LITERAL(0, 0, 27), // "creator::fake_spell_listbox"
QT_MOC_LITERAL(1, 28, 8), // "modified"
QT_MOC_LITERAL(2, 37, 0) // ""
QT_MOC_LITERAL( 0, 0, 27 ), // "creator::fake_spell_listbox"
QT_MOC_LITERAL( 1, 28, 8 ), // "modified"
QT_MOC_LITERAL( 2, 37, 0 ) // ""

},
"creator::fake_spell_listbox\0modified\0"
Expand All @@ -44,83 +45,94 @@ QT_MOC_LITERAL(2, 37, 0) // ""

static const uint qt_meta_data_creator__fake_spell_listbox[] = {

// content:
8, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
1, // signalCount
// content:
8, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
1, // signalCount

// signals: name, argc, parameters, tag, flags
1, 0, 19, 2, 0x06 /* Public */,
// signals: name, argc, parameters, tag, flags
1, 0, 19, 2, 0x06 /* Public */,

// signals: parameters
// signals: parameters
QMetaType::Void,

0 // eod
0 // eod
};

void creator::fake_spell_listbox::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
void creator::fake_spell_listbox::qt_static_metacall( QObject *_o, QMetaObject::Call _c, int _id,
void **_a )
{
if (_c == QMetaObject::InvokeMetaMethod) {
auto *_t = static_cast<fake_spell_listbox *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->modified(); break;
default: ;
if( _c == QMetaObject::InvokeMetaMethod ) {
auto *_t = static_cast<fake_spell_listbox *>( _o );
Q_UNUSED( _t )
switch( _id ) {
case 0:
_t->modified();
break;
default:
;
}
} else if (_c == QMetaObject::IndexOfMethod) {
int *result = reinterpret_cast<int *>(_a[0]);
} else if( _c == QMetaObject::IndexOfMethod ) {
int *result = reinterpret_cast<int *>( _a[0] );
{
using _t = void (fake_spell_listbox::*)();
if (*reinterpret_cast<_t *>(_a[1]) == static_cast<_t>(&fake_spell_listbox::modified)) {
using _t = void ( fake_spell_listbox::* )();
if( *reinterpret_cast<_t *>( _a[1] ) == static_cast<_t>( &fake_spell_listbox::modified ) ) {
*result = 0;
return;
}
}
}
Q_UNUSED(_a);
Q_UNUSED( _a );
}

QT_INIT_METAOBJECT const QMetaObject creator::fake_spell_listbox::staticMetaObject = { {
QMetaObject::SuperData::link<QListWidget::staticMetaObject>(),
qt_meta_stringdata_creator__fake_spell_listbox.data,
qt_meta_data_creator__fake_spell_listbox,
qt_static_metacall,
nullptr,
nullptr
} };
QMetaObject::SuperData::link<QListWidget::staticMetaObject>(),
qt_meta_stringdata_creator__fake_spell_listbox.data,
qt_meta_data_creator__fake_spell_listbox,
qt_static_metacall,
nullptr,
nullptr
}
};


const QMetaObject *creator::fake_spell_listbox::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}

void *creator::fake_spell_listbox::qt_metacast(const char *_clname)
void *creator::fake_spell_listbox::qt_metacast( const char *_clname )
{
if (!_clname) return nullptr;
if (!strcmp(_clname, qt_meta_stringdata_creator__fake_spell_listbox.stringdata0))
return static_cast<void*>(this);
return QListWidget::qt_metacast(_clname);
if( !_clname ) {
return nullptr;
}
if( !strcmp( _clname, qt_meta_stringdata_creator__fake_spell_listbox.stringdata0 ) ) {
return static_cast<void *>( this );
}
return QListWidget::qt_metacast( _clname );
}

int creator::fake_spell_listbox::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
int creator::fake_spell_listbox::qt_metacall( QMetaObject::Call _c, int _id, void **_a )
{
_id = QListWidget::qt_metacall(_c, _id, _a);
if (_id < 0)
_id = QListWidget::qt_metacall( _c, _id, _a );
if( _id < 0 ) {
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
}
if( _c == QMetaObject::InvokeMetaMethod ) {
if( _id < 1 ) {
qt_static_metacall( this, _c, _id, _a );
}
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
} else if( _c == QMetaObject::RegisterMethodArgumentMetaType ) {
if( _id < 1 ) {
*reinterpret_cast<int *>( _a[0] ) = -1;
}
_id -= 1;
}
return _id;
Expand All @@ -129,7 +141,7 @@ int creator::fake_spell_listbox::qt_metacall(QMetaObject::Call _c, int _id, void
// SIGNAL 0
void creator::fake_spell_listbox::modified()
{
QMetaObject::activate(this, &staticMetaObject, 0, nullptr);
QMetaObject::activate( this, &staticMetaObject, 0, nullptr );
}
QT_WARNING_POP
QT_END_MOC_NAMESPACE
Loading

0 comments on commit e93d67a

Please sign in to comment.