DialogXML: Support <key> in <text> with optional ref=
This commit is contained in:
@@ -79,10 +79,14 @@
|
|||||||
<text size='large' top='60' left='209' width='223' height='16'>Target: HP: SP: Status:</text>
|
<text size='large' top='60' left='209' width='223' height='16'>Target: HP: SP: Status:</text>
|
||||||
<text top='0' left='202' width='290' height='57'>
|
<text top='0' left='202' width='290' height='57'>
|
||||||
Keyboard:
|
Keyboard:
|
||||||
Type '1'-'6' to pick caster,
|
<key ref='caster1'/><key ref='caster2'/><key ref='caster3'/>
|
||||||
Shift-'1' - '6' to select target,
|
<key ref='caster4'/><key ref='caster5'/><key ref='caster6'/>
|
||||||
'space' for Other Spells,
|
to pick caster,<br/>
|
||||||
key by spell to cast spell.
|
<key ref='target1'/><key ref='target2'/><key ref='target3'/>
|
||||||
|
<key ref='target4'/><key ref='target5'/><key ref='target6'/>
|
||||||
|
to select target,<br/>
|
||||||
|
<key ref='other'/> for Other Spells,<br/>
|
||||||
|
key by spell to cast spell.<br/>
|
||||||
Alt-click spell name for description.
|
Alt-click spell name for description.
|
||||||
</text>
|
</text>
|
||||||
<button name='help' type='help' def-key='help' top='6' left='596'/>
|
<button name='help' type='help' def-key='help' top='6' left='596'/>
|
||||||
|
|||||||
@@ -149,11 +149,16 @@
|
|||||||
</xs:simpleContent>
|
</xs:simpleContent>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
<xs:complexType mixed="true" name="message">
|
<xs:complexType mixed="true" name="message">
|
||||||
<xs:sequence>
|
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||||
<xs:element name="br" minOccurs="0" maxOccurs="unbounded">
|
<xs:element name="br">
|
||||||
<xs:complexType/>
|
<xs:complexType/>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
<xs:element name="key">
|
||||||
|
<xs:complexType>
|
||||||
|
<xs:attribute name='ref' type='xs:token'/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
</xs:choice>
|
||||||
<xs:attribute name="name" type="xs:token"/>
|
<xs:attribute name="name" type="xs:token"/>
|
||||||
<xs:attributeGroup ref="frame"/>
|
<xs:attributeGroup ref="frame"/>
|
||||||
<xs:attributeGroup ref="font"/>
|
<xs:attributeGroup ref="font"/>
|
||||||
@@ -312,5 +317,9 @@
|
|||||||
<xs:selector xpath="*"/>
|
<xs:selector xpath="*"/>
|
||||||
<xs:field xpath="@anchor"/>
|
<xs:field xpath="@anchor"/>
|
||||||
</xs:keyref>
|
</xs:keyref>
|
||||||
|
<xs:keyref name="keyRef" refer="uniqueID">
|
||||||
|
<xs:selector xpath="key"/>
|
||||||
|
<xs:field xpath="@ref"/>
|
||||||
|
</xs:keyref>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:schema>
|
</xs:schema>
|
||||||
|
|||||||
@@ -64,6 +64,13 @@ bool cTextMsg::parseContent(ticpp::Node& content, int n, std::string tagName, st
|
|||||||
// TODO: De-magic the | character
|
// TODO: De-magic the | character
|
||||||
text += '|'; // because vertical bar is replaced by a newline when drawing strings
|
text += '|'; // because vertical bar is replaced by a newline when drawing strings
|
||||||
return true;
|
return true;
|
||||||
|
} else if(content.Value() == "key") {
|
||||||
|
auto elem = dynamic_cast<ticpp::Element&>(content);
|
||||||
|
if(elem.HasAttribute("ref"))
|
||||||
|
keyRefs.push_back(elem.GetAttribute("ref"));
|
||||||
|
else keyRefs.push_back(boost::none);
|
||||||
|
text += '\a';
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return cControl::parseContent(content, n, tagName, fname, text);
|
return cControl::parseContent(content, n, tagName, fname, text);
|
||||||
}
|
}
|
||||||
@@ -120,15 +127,23 @@ void cTextMsg::draw(){
|
|||||||
draw_color.g = 256 - draw_color.g;
|
draw_color.g = 256 - draw_color.g;
|
||||||
draw_color.b = 256 - draw_color.b;
|
draw_color.b = 256 - draw_color.b;
|
||||||
}
|
}
|
||||||
|
std::string msg = lbl;
|
||||||
|
for(const auto& key : keyRefs) {
|
||||||
|
size_t pos = msg.find_first_of('\a');
|
||||||
|
if(pos == std::string::npos) break;
|
||||||
|
if(key && !parent->hasControl(*key)) continue;
|
||||||
|
cControl& ctrl = key ? parent->getControl(*key) : *this;
|
||||||
|
msg.replace(pos, 1, ctrl.getAttachedKeyDescription());
|
||||||
|
}
|
||||||
style.colour = draw_color;
|
style.colour = draw_color;
|
||||||
if(to_rect.bottom - to_rect.top < 20) { // essentially, it's a single line
|
if(to_rect.bottom - to_rect.top < 20) { // essentially, it's a single line
|
||||||
style.lineHeight = 12;
|
style.lineHeight = 12;
|
||||||
to_rect.left += 3;
|
to_rect.left += 3;
|
||||||
win_draw_string(*inWindow,to_rect,lbl,eTextMode::LEFT_BOTTOM,style);
|
win_draw_string(*inWindow,to_rect,msg,eTextMode::LEFT_BOTTOM,style);
|
||||||
}else {
|
}else {
|
||||||
style.lineHeight = textSize + 2;
|
style.lineHeight = textSize + 2;
|
||||||
to_rect.inset(4,4);
|
to_rect.inset(4,4);
|
||||||
win_draw_string(*inWindow,to_rect,lbl,eTextMode::WRAP,style);
|
win_draw_string(*inWindow,to_rect,msg,eTextMode::WRAP,style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include "control.hpp"
|
#include "control.hpp"
|
||||||
#include "render_text.hpp"
|
#include "render_text.hpp"
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ private:
|
|||||||
short textSize;
|
short textSize;
|
||||||
eFont textFont;
|
eFont textFont;
|
||||||
sf::Color color;
|
sf::Color color;
|
||||||
|
std::vector<boost::optional<std::string>> keyRefs;
|
||||||
std::string fromList;
|
std::string fromList;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user