Use the editable string picker for item type flags in the item editor.

This commit is contained in:
2025-02-23 11:59:16 -05:00
committed by Celtic Minstrel
parent 0ccdd38cb1
commit 1ad973c59e
8 changed files with 31 additions and 2 deletions

View File

@@ -73,7 +73,7 @@
<text top='268' left='8' width='148' height='14'>Bonus: (0-10)</text>
<text top='292' left='8' width='148' height='14'>Protection: (-10 - 20)</text>
<text top='316' left='8' width='148' height='14'>Charges: (0-100)</text>
<text top='220' left='220' width='137' height='13'>Type flag: (0-1000)</text>
<button name='edit-flag' type='tiny' text-size='10' top='220' left='220' width='137' height='13'>Type flag:</button>
<text top='244' left='220' width='141' height='13'>Value: (0-10000)</text>
<text top='268' left='220' width='141' height='13'>Weight: (0-250)</text>
<button name='edit-ic' type='tiny' text-size='10' top='292' left='220' width='141' height='13'>Special class:</button>

View File

@@ -313,6 +313,7 @@ names are used when showing the Pick Sound dialog in various places. The require
attribute specifies which sound it applies to.
* `<event>` - (max unbounded) Gives a name to a major event flag. These names are shown (and editable) when showing the Pick Event dialog in various places. The required `id` attribute specifies which event.
* `<item-class>` - (max unbounded) Gives a name to an item special class. These names are shown (and editable) when showing the Pick Item Class dialog in various places. The required `id` attribute specifies which class.
* `<item-typeflag>` - (max unbounded) Gives a name to an item type flag. These names are shown (and editable) when showing the Pick Item Type Flag dialog in the item editor. The required `id` attribute specifies which flag.
Terrain Types
-------------

View File

@@ -382,6 +382,15 @@
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="item-typeflag" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" use="required" type="xs:integer"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="scenario">

View File

@@ -959,6 +959,12 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
if(icnum > scenario.ic_names.size())
scenario.ic_names.resize(icnum);
edit->GetText(&scenario.ic_names[icnum - 1], false);
} else if(type == "item-typeflag") {
int itfnum = 0;
edit->GetAttribute("id", &itfnum);
if(itfnum > scenario.itf_names.size())
scenario.itf_names.resize(itfnum);
edit->GetText(&scenario.itf_names[itfnum - 1], false);
} else if(type == "graphics") {
static const std::set<ePicType> valid_pictypes = {
PIC_TER, PIC_TER_ANIM, PIC_TER_MAP,

View File

@@ -204,6 +204,7 @@ void swap(cScenario& lhs, cScenario& rhs) {
swap(lhs.towns, rhs.towns);
swap(lhs.evt_names, rhs.evt_names);
swap(lhs.ic_names, rhs.ic_names);
swap(lhs.itf_names, rhs.itf_names);
}
cScenario::cItemStorage::cItemStorage() : ter_type(-1), property(0) {

View File

@@ -102,6 +102,7 @@ public:
std::vector<std::string> snd_names;
std::vector<std::string> evt_names;
std::vector<std::string> ic_names;
std::vector<std::string> itf_names;
bool adjust_diff;
bool is_legacy;
fs::path scen_file; // transient

View File

@@ -1727,6 +1727,10 @@ static bool edit_item_type_event_filter(cDialog& me, std::string hit, cItem& ite
int value = me["class"].getTextAsNum();
value = choose_text_editable(scenario.ic_names, value, &me, "Select item class:");
me["class"].setTextToNum(value);
} else if(hit == "edit-flag") {
int value = me["flag"].getTextAsNum();
value = choose_text_editable(scenario.itf_names, value, &me, "Select item type flag:");
me["flag"].setTextToNum(value);
}
return true;
}
@@ -1780,7 +1784,7 @@ bool edit_item_type(short which) {
item_dlg["weight"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, 250, "Weight"));
item_dlg["class"].attachFocusHandler(std::bind(check_range, _1, _2, _3, 0, 100, "Special Class"));
item_dlg["variety"].attachFocusHandler(std::bind(change_item_variety, _1, _2, std::ref(item)));
item_dlg.attachClickHandlers(std::bind(edit_item_type_event_filter, _1, _2, std::ref(item), std::ref(which)), {"okay", "cancel", "abils", "choosepic", "choosetp", "choosemiss", "desc", "preview", "edit-ic"});
item_dlg.attachClickHandlers(std::bind(edit_item_type_event_filter, _1, _2, std::ref(item), std::ref(which)), {"okay", "cancel", "abils", "choosepic", "choosetp", "choosemiss", "desc", "preview", "edit-ic", "edit-flag"});
if(scenario.scen_items.size() == 1) {
item_dlg["prev"].hide();

View File

@@ -408,6 +408,13 @@ void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario) {
data.PushText(scenario.ic_names[i]);
data.CloseElement("item-class");
}
for(int i = 0; i < scenario.itf_names.size(); i++) {
if(scenario.itf_names[i].empty()) continue;
data.OpenElement("item-typeflag");
data.PushAttribute("id", i + 1);
data.PushText(scenario.itf_names[i]);
data.CloseElement("item-typeflag");
}
data.CloseElement("editor");
data.CloseElement("scenario");
}