67 << QVariant(100) // get away time 41 |
67 << QVariant(100) // get away time 41 |
68 << QVariant(0) // world edge 42 |
68 << QVariant(0) // world edge 42 |
69 << QVariant() // scriptparam 43 |
69 << QVariant() // scriptparam 43 |
70 ; |
70 ; |
71 |
71 |
72 AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) : |
72 AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & directory) : |
73 QAbstractTableModel(parent), |
73 QAbstractTableModel(parent), |
74 fileConfig(fileName, QSettings::IniFormat) |
74 fileConfig(cfgdir->absolutePath() + "/schemes.ini", QSettings::IniFormat) |
75 { |
75 { |
76 predefSchemesNames = QStringList() |
76 predefSchemesNames = QStringList() |
77 << "Default" |
77 << "Default" |
78 << "Pro Mode" |
78 << "Pro Mode" |
79 << "Shoppa" |
79 << "Shoppa" |
567 << QVariant(100) // get away time 41 |
567 << QVariant(100) // get away time 41 |
568 << QVariant(0) // world edge 42 |
568 << QVariant(0) // world edge 42 |
569 << QVariant() // scriptparam 43 |
569 << QVariant() // scriptparam 43 |
570 ; |
570 ; |
571 |
571 |
572 QList<QVariant> construction; |
572 QList<QVariant> construction; |
573 construction |
573 construction |
574 << predefSchemesNames[10] // name 0 |
574 << predefSchemesNames[10] // name 0 |
575 << QVariant(false) // fortsmode 1 |
575 << QVariant(false) // fortsmode 1 |
576 << QVariant(false) // team divide 2 |
576 << QVariant(false) // team divide 2 |
577 << QVariant(false) // solid land 3 |
577 << QVariant(false) // solid land 3 |
615 << QVariant(100) // get away time 41 |
615 << QVariant(100) // get away time 41 |
616 << QVariant(0) // world edge 42 |
616 << QVariant(0) // world edge 42 |
617 << QVariant() // scriptparam 43 |
617 << QVariant() // scriptparam 43 |
618 ; |
618 ; |
619 |
619 |
620 QList<QVariant> hedgeeditor; |
620 QList<QVariant> hedgeeditor; |
621 hedgeeditor |
621 hedgeeditor |
622 << predefSchemesNames[11] // name 0 |
622 << predefSchemesNames[11] // name 0 |
623 << QVariant(false) // fortsmode 1 |
623 << QVariant(false) // fortsmode 1 |
624 << QVariant(false) // team divide 2 |
624 << QVariant(false) // team divide 2 |
625 << QVariant(false) // solid land 3 |
625 << QVariant(false) // solid land 3 |
662 << QVariant(100) // rope modfier 40 |
662 << QVariant(100) // rope modfier 40 |
663 << QVariant(100) // get away time 41 |
663 << QVariant(100) // get away time 41 |
664 << QVariant(0) // world edge 42 |
664 << QVariant(0) // world edge 42 |
665 << QVariant() // scriptparam 43 |
665 << QVariant() // scriptparam 43 |
666 ; |
666 ; |
667 |
667 |
668 |
668 |
669 |
669 |
670 schemes.append(defaultScheme); |
670 schemes.append(defaultScheme); |
671 schemes.append(proMode); |
671 schemes.append(proMode); |
672 schemes.append(shoppa); |
672 schemes.append(shoppa); |
673 schemes.append(cleanslate); |
673 schemes.append(cleanslate); |
674 schemes.append(minefield); |
674 schemes.append(minefield); |
679 schemes.append(kingmode); |
679 schemes.append(kingmode); |
680 schemes.append(construction); |
680 schemes.append(construction); |
681 schemes.append(hedgeeditor); |
681 schemes.append(hedgeeditor); |
682 |
682 |
683 |
683 |
684 int size = fileConfig.beginReadArray("schemes"); |
684 if (!QDir(directory).exists()) { |
685 for (int i = 0; i < size; ++i) |
685 QDir().mkdir(directory); |
686 { |
686 |
687 fileConfig.setArrayIndex(i); |
687 int size = fileConfig.beginReadArray("schemes"); |
688 |
688 for (int i = 0; i < size; ++i) |
689 if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString())) |
|
690 { |
689 { |
|
690 fileConfig.setArrayIndex(i); |
|
691 |
|
692 if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString())) |
|
693 { |
|
694 QList<QVariant> scheme; |
|
695 QSettings file(directory + "/" + fileConfig.value(spNames[0]).toString() + ".ini", QSettings::IniFormat); |
|
696 |
|
697 for (int k = 0; k < spNames.size(); ++k) { |
|
698 scheme << fileConfig.value(spNames[k], defaultScheme[k]); |
|
699 file.setValue(spNames[k], fileConfig.value(spNames[k], defaultScheme[k])); |
|
700 } |
|
701 file.sync(); |
|
702 |
|
703 schemes.append(scheme); |
|
704 } |
|
705 } |
|
706 fileConfig.endArray(); |
|
707 } else { |
|
708 QStringList scheme_dir = QDir(directory).entryList(); |
|
709 |
|
710 for(int i = 0; i < scheme_dir.size(); i++) |
|
711 { |
|
712 if (scheme_dir[i] == "." || scheme_dir[i] == "..") continue; |
691 QList<QVariant> scheme; |
713 QList<QVariant> scheme; |
|
714 QSettings file(directory + "/" + scheme_dir[i], QSettings::IniFormat); |
692 |
715 |
693 for (int k = 0; k < spNames.size(); ++k) |
716 for (int k = 0; k < spNames.size(); ++k) |
694 scheme << fileConfig.value(spNames[k], defaultScheme[k]); |
717 scheme << file.value(spNames[k], defaultScheme[k]); |
695 |
718 |
696 schemes.append(scheme); |
719 schemes.append(scheme); |
697 } |
720 } |
698 } |
721 } |
699 fileConfig.endArray(); |
|
700 } |
722 } |
701 |
723 |
702 QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
724 QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const |
703 { |
725 { |
704 Q_UNUSED(section); |
726 Q_UNUSED(section); |
807 || row >= schemes.size()) |
829 || row >= schemes.size()) |
808 return false; |
830 return false; |
809 |
831 |
810 beginRemoveRows(parent, row, row); |
832 beginRemoveRows(parent, row, row); |
811 |
833 |
|
834 QList<QVariant> scheme = schemes[row]; |
|
835 int j = spNames.indexOf("name"); |
|
836 QFile(cfgdir->absolutePath() + "/Game Settings/" + scheme[j].toString() + ".ini").remove(); |
812 schemes.removeAt(row); |
837 schemes.removeAt(row); |
813 |
838 |
814 endRemoveRows(); |
839 endRemoveRows(); |
815 |
840 |
816 return true; |
841 return true; |
828 return schemes[index.row()][index.column()]; |
853 return schemes[index.row()][index.column()]; |
829 } |
854 } |
830 |
855 |
831 void AmmoSchemeModel::Save() |
856 void AmmoSchemeModel::Save() |
832 { |
857 { |
833 fileConfig.beginWriteArray("schemes", schemes.size() - numberOfDefaultSchemes); |
|
834 |
|
835 for (int i = 0; i < schemes.size() - numberOfDefaultSchemes; ++i) |
858 for (int i = 0; i < schemes.size() - numberOfDefaultSchemes; ++i) |
836 { |
859 { |
837 fileConfig.setArrayIndex(i); |
|
838 |
|
839 QList<QVariant> scheme = schemes[i + numberOfDefaultSchemes]; |
860 QList<QVariant> scheme = schemes[i + numberOfDefaultSchemes]; |
|
861 int j = spNames.indexOf("name"); |
|
862 QSettings file(cfgdir->absolutePath() + "/Game Settings/" + scheme[j].toString() + ".ini", QSettings::IniFormat); |
840 |
863 |
841 for (int k = 0; k < scheme.size(); ++k) |
864 for (int k = 0; k < scheme.size(); ++k) |
842 fileConfig.setValue(spNames[k], scheme[k]); |
865 file.setValue(spNames[k], scheme[k]); |
|
866 |
|
867 file.sync(); |
843 } |
868 } |
844 fileConfig.endArray(); |
869 fileConfig.endArray(); |
845 } |
870 } |
846 |
871 |
847 |
872 |