Crossfire Server, Branch 1.12
R12190
|
00001 #include <Qt> 00002 #include <QtGui> 00003 00004 extern "C" { 00005 #include "global.h" 00006 #include "recipe.h" 00007 } 00008 00009 #include "CREFormulaePanel.h" 00010 #include "CREUtils.h" 00011 00012 CREFormulaePanel::CREFormulaePanel() 00013 { 00014 myRecipe = NULL; 00015 00016 QGridLayout* layout = new QGridLayout(this); 00017 00018 layout->addWidget(new QLabel(tr("Title:"), this), 1, 1); 00019 myTitle = new QLineEdit(this); 00020 layout->addWidget(myTitle, 1, 2); 00021 00022 layout->addWidget(new QLabel(tr("Skill:"), this), 2, 1); 00023 mySkill = new QComboBox(this); 00024 layout->addWidget(mySkill, 2, 2); 00025 00026 layout->addWidget(new QLabel(tr("Cauldron:"), this), 3, 1); 00027 myCauldron = new QComboBox(this); 00028 layout->addWidget(myCauldron, 3, 2); 00029 00030 layout->addWidget(new QLabel(tr("Yield:"), this), 4, 1); 00031 myYield = new QLineEdit(this); 00032 layout->addWidget(myYield, 4, 2); 00033 00034 layout->addWidget(new QLabel(tr("Chance:"), this), 5, 1); 00035 myChance = new QLineEdit(this); 00036 layout->addWidget(myChance, 5, 2); 00037 00038 layout->addWidget(new QLabel(tr("Experience:"), this), 6, 1); 00039 myExperience = new QLineEdit(this); 00040 layout->addWidget(myExperience, 6, 2); 00041 00042 layout->addWidget(new QLabel(tr("Difficulty:"), this), 7, 1); 00043 myDifficulty = new QLineEdit(this); 00044 layout->addWidget(myDifficulty, 7, 2); 00045 00046 mySkill->addItem(tr("(none)"), 0); 00047 myCauldron->addItem(tr("(none)"), 0); 00048 const archt* arch = first_archetype; 00049 for (; arch; arch = arch->next) 00050 { 00051 if (arch->clone.type == SKILL) 00052 mySkill->addItem(arch->clone.name); 00053 if (QUERY_FLAG(&arch->clone, FLAG_IS_CAULDRON)) 00054 myCauldron->addItem(arch->name); 00055 } 00056 00057 myArchetypes = new QTreeWidget(this); 00058 myArchetypes->setHeaderLabel(tr("Archetypes:")); 00059 myArchetypes->setRootIsDecorated(false); 00060 myArchetypes->setIconSize(QSize(32, 32)); 00061 layout->addWidget(myArchetypes, 8, 1, 1, 2); 00062 00063 layout->addWidget(new QLabel(tr("Ingredients:"), this), 9, 1, 1, 2); 00064 myIngredients = new QTextEdit(this); 00065 layout->addWidget(myIngredients, 10, 1, 1, 2); 00066 00067 QHBoxLayout* buttons = new QHBoxLayout; 00068 myValidate = new QPushButton(tr("&Validate")); 00069 buttons->addWidget(myValidate); 00070 myReset = new QPushButton(tr("&Reset")); 00071 buttons->addWidget(myReset); 00072 layout->addLayout(buttons, 11, 1, 1, 2); 00073 00074 connect(myReset, SIGNAL(clicked(bool)), this, SLOT(resetClicked(bool))); 00075 connect(myValidate, SIGNAL(clicked(bool)), this, SLOT(validateClicked(bool))); 00076 } 00077 00078 void CREFormulaePanel::setRecipe(const recipe* recipe) 00079 { 00080 Q_ASSERT(recipe); 00081 myRecipe = recipe; 00082 00083 myTitle->setText(recipe->title); 00084 myYield->setText(QString::number(recipe->yield)); 00085 myChance->setText(QString::number(recipe->chance)); 00086 myExperience->setText(QString::number(recipe->exp)); 00087 myDifficulty->setText(QString::number(recipe->diff)); 00088 00089 int index = mySkill->findText(recipe->skill); 00090 if (index == -1) 00091 index = 0; 00092 mySkill->setCurrentIndex(index); 00093 00094 index = myCauldron->findText(recipe->cauldron); 00095 if (index == -1) 00096 index = 0; 00097 myCauldron->setCurrentIndex(index); 00098 00099 myArchetypes->clear(); 00100 00101 const archt* arch; 00102 for (size_t a = 0; a < recipe->arch_names; a++) 00103 { 00104 arch = find_archetype(recipe->arch_name[a]); 00105 myArchetypes->addTopLevelItem(CREUtils::archetypeNode(arch, NULL)); 00106 } 00107 00108 QStringList list; 00109 for (const linked_char* ing = myRecipe->ingred; ing; ing = ing->next) 00110 { 00111 list.append(ing->name); 00112 } 00113 myIngredients->setPlainText(list.join("\n")); 00114 } 00115 00116 void CREFormulaePanel::resetClicked(bool) 00117 { 00118 setRecipe(myRecipe); 00119 } 00120 00121 void CREFormulaePanel::validateClicked(bool) 00122 { 00123 #if 0 00124 Q_ASSERT(myRecipe); 00125 00126 myRecipe->setTitle(myTitle->text()); 00127 myRecipe->setYield(myYield->text().toInt()); 00128 myRecipe->setChance(myChance->text().toInt()); 00129 myRecipe->setExperience(myExperience->text().toInt()); 00130 myRecipe->setDifficulty(myDifficulty->text().toInt()); 00131 if (mySkill->currentIndex() != 0) 00132 myRecipe->setSkill(mySkill->currentText()); 00133 else 00134 myRecipe->setSkill(""); 00135 if (myCauldron->currentIndex() != 0) 00136 myRecipe->setCauldron(myCauldron->currentText()); 00137 else 00138 myRecipe->setCauldron(""); 00139 00140 QStringList arches; 00141 const Archetype* arch; 00142 ManagedReference ref; 00143 for (int a = 0; a < myArchetypes->topLevelItemCount(); a++) 00144 { 00145 ref = myArchetypes->topLevelItem(a)->data(0, Qt::UserRole).toInt(); 00146 arch = DM_ARCHS->get(ref); 00147 arches.append(arch->name); 00148 DM_ARCHS->release(ref); 00149 } 00150 myRecipe->setArches(arches); 00151 00152 myRecipe->setIngredients(myIngredients->toPlainText().split('\n')); 00153 #endif 00154 }