Implement customizable background patterns to be displayed behind the game interface based on which town/sector the player is in and whether they are in combat mode, with cascading defaults.

- All the hard-coded background changes are no longer present and not even preserved.
This commit is contained in:
2015-01-26 18:39:35 -05:00
parent a3c998eaad
commit 91c52fca77
19 changed files with 239 additions and 49 deletions

View File

@@ -39,6 +39,7 @@ cButton::cButton(cDialog* parent) :
cControl(CTRL_BTN,*parent),
wrapLabel(false),
type(BTN_REG),
textClr(parent->getDefTextClr()),
fromList("none") {}
cButton::cButton(cDialog* parent,eControlType t) :
@@ -73,6 +74,7 @@ void cButton::draw(){
if(type == BTN_TINY) {
textMode = eTextMode::LEFT_TOP;
to_rect.left += 18;
style.colour = textClr;
} else if(type == BTN_PUSH) {
to_rect.top += 34;
}
@@ -100,13 +102,12 @@ short cButton::getFormat(eFormat prop) throw(xUnsupportedProp){
else throw xUnsupportedProp(prop);
}
void cButton::setColour(sf::Color) throw(xUnsupportedProp) {
// TODO: Colour is not supported
void cButton::setColour(sf::Color clr) throw(xUnsupportedProp) {
textClr = clr;
}
sf::Color cButton::getColour() throw(xUnsupportedProp) {
// TODO: Colour is not supported
return sf::Color();
return textClr;
}
// Indices within the buttons array.
@@ -187,8 +188,7 @@ cLed::cLed(cDialog* parent) :
cButton(parent,CTRL_LED),
state(led_off),
textFont(FONT_BOLD),
textSize(10),
color(parent->getDefTextClr()) {
textSize(10) {
type = BTN_LED;
}
@@ -254,7 +254,7 @@ void cLed::draw(){
to_rect.right = to_rect.left + 14;
to_rect.bottom = to_rect.top + 10;
rect_draw_some_item(buttons[btnGW[BTN_LED]],from_rect,*inWindow,to_rect);
style.colour = parent->getDefTextClr();
style.colour = textClr;
to_rect.right = frame.right;
to_rect.left = frame.left + 18; // Possibly could be 20
win_draw_string(*inWindow,to_rect,lbl,eTextMode::LEFT_TOP,style);

View File

@@ -87,6 +87,8 @@ private:
std::string fromList;
static rectangle btnRects[13][2];
protected:
/// The button's text colour; only used by LED and tiny buttons
sf::Color textClr;
/// The index in buttons of the texture for each button type.
static size_t btnGW[14];
/// The textures that hold the graphics for the buttons.
@@ -129,7 +131,6 @@ public:
private:
eLedState state;
eFont textFont;
sf::Color color;
short textSize;
static rectangle ledRects[3][2];
focus_callback_t onFocus;

View File

@@ -294,9 +294,15 @@ sf::Color cDialog::parseColor(string what){
sf::Color clr;
if(what[0] == '#'){
unsigned int r,g,b;
if(sscanf(what.c_str(),"#%2x%2x%2x",&r,&g,&b) < 3)
if(sscanf(what.c_str(),"#%2x%2x%2x",&r,&g,&b) < 3) {
if(sscanf(what.c_str(),"#%1x%1x%1x",&r,&g,&b) < 3)
throw -1;
else {
r *= 0x11;
g *= 0x11;
b *= 0x11;
}
}
clr.r = r, clr.g = g, clr.b = b;
}else if(what == "black")
clr.r = 0x00, clr.g = 0x00, clr.b = 0x00;
@@ -384,6 +390,16 @@ template<> pair<string,cButton*> cDialog::parse(Element& who /*button*/){
p.second->setBtnType(BTN_TRAIT);
else if(val == "push")
p.second->setBtnType(BTN_PUSH);
}else if(name == "color" || name == "colour"){
std::string val;
attr->GetValue(&val);
sf::Color clr;
try{
clr = parseColor(val);
}catch(int){
throw xBadVal("button",name,val,attr->Row(),attr->Column(),fname);
}
p.second->setColour(clr);
}else if(name == "def-key"){
attr->GetValue(&keyMain);
foundKey = true;
@@ -424,11 +440,7 @@ template<> pair<string,cButton*> cDialog::parse(Element& who /*button*/){
}
p.second->attachKey(theKey);
}
if(width > 0 || height > 0) {
// TODO: What if width is set but height isn't?
frame.right = frame.left + width;
frame.bottom = frame.top + height;
}else switch(p.second->getBtnType()){
switch(p.second->getBtnType()){
case BTN_SM:
frame.right = frame.left + 23;
frame.bottom = frame.top + 23;
@@ -459,6 +471,10 @@ template<> pair<string,cButton*> cDialog::parse(Element& who /*button*/){
frame.right = frame.left + 63;
frame.bottom = frame.top + 23;
}
if(width > 0)
frame.right = frame.left + width;
if(height > 0)
frame.bottom = frame.top + height;
p.second->setBounds(frame);
string content;
for(node = node.begin(&who); node != node.end(); node++){
@@ -575,7 +591,7 @@ template<> pair<string,cLed*> cDialog::parse(Element& who /*LED*/){
p.second->setFormat(TXT_FONT, FONT_BOLD);
else if(val == "maidenword")
p.second->setFormat(TXT_FONT, FONT_MAIDWORD);
else throw xBadVal("text",name,val,attr->Row(),attr->Column(),fname);
else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
}else if(name == "size"){
std::string val;
attr->GetValue(&val);
@@ -585,7 +601,7 @@ template<> pair<string,cLed*> cDialog::parse(Element& who /*LED*/){
p.second->setFormat(TXT_SIZE, 10);
else if(val == "title")
p.second->setFormat(TXT_SIZE, 18);
else throw xBadVal("text",name,val,attr->Row(),attr->Column(),fname);
else throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
}else if(name == "color" || name == "colour"){
std::string val;
attr->GetValue(&val);
@@ -593,7 +609,7 @@ template<> pair<string,cLed*> cDialog::parse(Element& who /*LED*/){
try{
clr = parseColor(val);
}catch(int){
throw xBadVal("text",name,val,attr->Row(),attr->Column(),fname);
throw xBadVal("led",name,val,attr->Row(),attr->Column(),fname);
}
p.second->setColour(clr);
}else if(name == "top"){