forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreator_main_window.cpp
128 lines (105 loc) · 4.12 KB
/
creator_main_window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "creator_main_window.h"
#include "spell_window.h"
#include "item_group_window.h"
#include "enum_conversions.h"
#include "translations.h"
#include "worldfactory.h"
#include "mod_manager.h"
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qmainwindow.h>
#include <QtWidgets/qpushbutton.h>
#include <QtCore/QSettings>
namespace io
{
// *INDENT-OFF*
template<>
std::string enum_to_string<creator::jsobj_type>( creator::jsobj_type data )
{
switch( data ) {
case creator::jsobj_type::SPELL: return "Spell";
case creator::jsobj_type::item_group: return "Item group";
case creator::jsobj_type::LAST: break;
}
debugmsg( "Invalid valid_target" );
abort();
}
// *INDENT-ON*
} // namespace io
int creator::main_window::execute( QApplication &app )
{
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 );
int row = 0;
int col = 0;
int max_row = 0;
int max_col = 0;
//Does nothing on it's own but once settings.setvalue() is called it will create
//an ini file in C:\Users\User\AppData\Roaming\CleverRaven or equivalent directory
QSettings settings( QSettings::IniFormat, QSettings::UserScope,
"CleverRaven", "Cataclysm - DDA" );
// =========================================================================================
// first column of boxes
row = 0;
QMainWindow title_menu;
spell_window spell_editor( &title_menu );
item_group_window item_group_editor( &title_menu );
QLabel mods_label;
mods_label.setParent( &title_menu );
mods_label.setText( QString( "Select mods (restart required):" ) );
mods_label.resize( default_text_box_size * 2 );
mods_label.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
mods_label.show();
row++;
//We always load 'dda' so we exclude it from the mods list
QStringList all_mods;
for( const mod_id &e : world_generator->get_mod_manager().all_mods() ) {
if( !e->obsolete && e->ident.str() != "dda" ) {
all_mods.append( e->ident.c_str() );
}
}
dual_list_box mods_box;
mods_box.initialize( all_mods );
mods_box.resize( QSize( default_text_box_width * 8, default_text_box_height * 10 ) );
mods_box.setParent( &title_menu );
mods_box.move( QPoint( col * default_text_box_width, row * default_text_box_height ) );
mods_box.show();
//The user's mod selection gets saved to a file
QObject::connect( &mods_box, &dual_list_box::pressed, [&]() {
settings.setValue( "mods/include", mods_box.get_included() );
} );
//A previous selection of mods is loaded from disk and applied to the modlist widget
if( settings.contains( "mods/include" ) ) {
QStringList modlist = settings.value( "mods/include" ).value<QStringList>();
mods_box.set_included( modlist );
}
row += 11;
QPushButton spell_button( _( "Spell Creator" ), &title_menu );
spell_button.move( QPoint( col * default_text_box_width, row * default_text_box_height ) );
QObject::connect( &spell_button, &QPushButton::released,
[&]() {
title_menu.hide();
spell_editor.show();
} );
// =========================================================================================
// second column of boxes
col++;
QPushButton item_group_button( _( "Item group Creator" ), &title_menu );
item_group_button.move( QPoint( col * default_text_box_width, row++ * default_text_box_height ) );
item_group_button.resize( 150, 30 );
QObject::connect( &item_group_button, &QPushButton::released,
[&]() {
title_menu.hide();
item_group_editor.show();
} );
title_menu.show();
spell_button.show();
item_group_button.show();
row += 3;
col += 6;
max_row = std::max( max_row, row );
max_col = std::max( max_col, col );
title_menu.resize( QSize( ( max_col + 1 ) * default_text_box_width,
( max_row )*default_text_box_height ) );
return app.exec();
}