Skip to content

Commit

Permalink
Added the activity flag to InteractiveSurface; Some UI improvements;
Browse files Browse the repository at this point in the history
  • Loading branch information
redv committed Aug 25, 2013
1 parent d809397 commit 96ccf66
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/Basescape/BasescapeState.cpp
Expand Up @@ -134,7 +134,7 @@ BasescapeState::BasescapeState(Game *game, Base *base, Globe *globe) : State(gam

_txtFunds->setColor(Palette::blockOffset(13)+10);

_btnNewBase->setColor(Palette::blockOffset(13)+5);
_btnNewBase->setColor(Palette::blockOffset(13)+5, Palette::blockOffset(0)+3);
_btnNewBase->setText(_game->getLanguage()->getString("STR_BUILD_NEW_BASE_UC"));
_btnNewBase->onMouseClick((ActionHandler)&BasescapeState::btnNewBaseClick);

Expand Down Expand Up @@ -249,7 +249,7 @@ void BasescapeState::init()
s += Text::formatFunding(_game->getSavedGame()->getFunds());
_txtFunds->setText(s);

_btnNewBase->setVisible(_game->getSavedGame()->getBases()->size() < 8);
_btnNewBase->setActive(_game->getSavedGame()->getBases()->size() < 8);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions src/Basescape/SoldierInfoState.cpp
Expand Up @@ -181,15 +181,15 @@ SoldierInfoState::SoldierInfoState(Game *game, Base *base, size_t soldier) : Sta
_btnNext->setText(L">>");
_btnNext->onMouseClick((ActionHandler)&SoldierInfoState::btnNextClick);

_btnArmor->setColor(Palette::blockOffset(15)+6);
_btnArmor->setColor(Palette::blockOffset(15)+6, Palette::blockOffset(0)+3);
_btnArmor->setText(_game->getLanguage()->getString("STR_ARMOR"));
_btnArmor->onMouseClick((ActionHandler)&SoldierInfoState::btnArmorClick);

_edtSoldier->setColor(Palette::blockOffset(13)+10);
_edtSoldier->setBig();
_edtSoldier->onKeyboardPress((ActionHandler)&SoldierInfoState::edtSoldierKeyPress);

_btnSack->setColor(Palette::blockOffset(15)+6);
_btnSack->setColor(Palette::blockOffset(15)+6, Palette::blockOffset(0)+3);
_btnSack->setText(_game->getLanguage()->getString("STR_SACK"));
_btnSack->onMouseClick((ActionHandler)&SoldierInfoState::btnSackClick);

Expand Down Expand Up @@ -426,6 +426,10 @@ void SoldierInfoState::init()

_txtArmor->setText(_game->getLanguage()->getString(s->getArmor()->getType()));

bool isSoldierOnBase = !(s->getCraft() && s->getCraft()->getStatus() == "STR_OUT");
_btnArmor->setActive(isSoldierOnBase);
_btnSack->setActive(isSoldierOnBase);

std::wstringstream ss9;
ss9 << _game->getLanguage()->getString("STR_RANK_") << L'\x01' << _game->getLanguage()->getString(s->getRankString());
_txtRank->setText(ss9.str());
Expand Down Expand Up @@ -555,10 +559,7 @@ void SoldierInfoState::btnArmorClick(Action *)
{
_edtSoldier->deFocus();
_base->getSoldiers()->at(_soldier)->setName(_edtSoldier->getText());
if (!_base->getSoldiers()->at(_soldier)->getCraft() || (_base->getSoldiers()->at(_soldier)->getCraft() && _base->getSoldiers()->at(_soldier)->getCraft()->getStatus() != "STR_OUT"))
{
_game->pushState(new SoldierArmorState(_game, _base, _soldier));
}
_game->pushState(new SoldierArmorState(_game, _base, _soldier));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/InteractiveSurface.cpp
Expand Up @@ -30,7 +30,7 @@ namespace OpenXcom
* @param x X position in pixels.
* @param y Y position in pixels.
*/
InteractiveSurface::InteractiveSurface(int width, int height, int x, int y) : Surface(width, height, x, y), _buttonsPressed(0), _in(0), _over(0), _out(0), _isHovered(false), _isFocused(true), _listButton(false)
InteractiveSurface::InteractiveSurface(int width, int height, int x, int y) : Surface(width, height, x, y), _buttonsPressed(0), _in(0), _over(0), _out(0), _isHovered(false), _isFocused(true), _listButton(false), _active(true)
{
}

Expand Down Expand Up @@ -90,7 +90,7 @@ void InteractiveSurface::setVisible(bool visible)
*/
void InteractiveSurface::handle(Action *action, State *state)
{
if (!_visible || _hidden)
if (!_visible || _hidden || !_active)
return;

action->setSender(this);
Expand Down
6 changes: 5 additions & 1 deletion src/Engine/InteractiveSurface.h
Expand Up @@ -45,7 +45,7 @@ class InteractiveSurface : public Surface
std::map<Uint8, ActionHandler> _click, _press, _release;
ActionHandler _in, _over, _out;
std::map<SDLKey, ActionHandler> _keyPress, _keyRelease;
bool _isHovered, _isFocused, _listButton;
bool _isHovered, _isFocused, _listButton, _active;

/// Is any mouse button pressed?
bool isButtonPressed(Uint8 button = 0);
Expand Down Expand Up @@ -100,6 +100,10 @@ class InteractiveSurface : public Surface
virtual void keyboardRelease(Action *action, State *state);
/// Check this surface to see if it's a textlist button.
void setListButton();
/// Sets the activity flag of the interactive surface.
void setActive(bool active) {_active = active;}
/// Gets the activity flag of the interactive surface.
bool isActive() const {return _active;}
};

}
Expand Down
13 changes: 3 additions & 10 deletions src/Geoscape/BaseNameState.cpp
Expand Up @@ -66,14 +66,14 @@ BaseNameState::BaseNameState(Game *game, Base *base, Globe *globe, bool first) :
_window->setColor(Palette::blockOffset(8)+5);
_window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));

_btnOk->setColor(Palette::blockOffset(8)+5);
_btnOk->setColor(Palette::blockOffset(8)+5, Palette::blockOffset(10));
_btnOk->setText(_game->getLanguage()->getString("STR_OK"));
_btnOk->onMouseClick((ActionHandler)&BaseNameState::btnOkClick);
//_btnOk->onKeyboardPress((ActionHandler)&BaseNameState::btnOkClick, (SDLKey)Options::getInt("keyOk"));
_btnOk->onKeyboardPress((ActionHandler)&BaseNameState::btnOkClick, (SDLKey)Options::getInt("keyCancel"));

//something must be in the name before it is acceptable
_btnOk->setVisible(false);
_btnOk->setActive(false);

_txtTitle->setColor(Palette::blockOffset(8)+5);
_txtTitle->setAlign(ALIGN_CENTER);
Expand Down Expand Up @@ -128,14 +128,7 @@ void BaseNameState::edtNameKeyPress(Action *action)
}
else
{
if(_edtName->getText().size() > 0)
{
_btnOk->setVisible(true);
}
else
{
_btnOk->setVisible(false);
}
_btnOk->setActive(_edtName->getText().size() > 0);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Geoscape/GeoscapeOptionsState.cpp
Expand Up @@ -64,11 +64,11 @@ GeoscapeOptionsState::GeoscapeOptionsState(Game *game) : State(game)
_window->setColor(Palette::blockOffset(15)-1);
_window->setBackground(_game->getResourcePack()->getSurface("BACK01.SCR"));

_btnLoad->setColor(Palette::blockOffset(15)-1);
_btnLoad->setColor(Palette::blockOffset(15)-1, Palette::blockOffset(10));
_btnLoad->setText(_game->getLanguage()->getString("STR_LOAD_GAME"));
_btnLoad->onMouseClick((ActionHandler)&GeoscapeOptionsState::btnLoadClick);

_btnSave->setColor(Palette::blockOffset(15)-1);
_btnSave->setColor(Palette::blockOffset(15)-1, Palette::blockOffset(10));
_btnSave->setText(_game->getLanguage()->getString("STR_SAVE_GAME"));
_btnSave->onMouseClick((ActionHandler)&GeoscapeOptionsState::btnSaveClick);

Expand All @@ -88,8 +88,8 @@ GeoscapeOptionsState::GeoscapeOptionsState(Game *game) : State(game)

if (Options::getInt("autosave") >= 2)
{
_btnSave->setVisible(false);
_btnLoad->setVisible(false);
_btnSave->setActive(false);
_btnLoad->setActive(false);
}
}

Expand Down
44 changes: 27 additions & 17 deletions src/Interface/TextButton.cpp
Expand Up @@ -35,7 +35,7 @@ Sound *TextButton::soundPress = 0;
* @param x X position in pixels.
* @param y Y position in pixels.
*/
TextButton::TextButton(int width, int height, int x, int y) : InteractiveSurface(width, height, x, y), _color(0), _group(0), _contrast(false)
TextButton::TextButton(int width, int height, int x, int y) : InteractiveSurface(width, height, x, y), _color(0), _inactiveColor(0), _group(0), _contrast(false)
{
_text = new Text(width, height, 0, 0);
_text->setSmall();
Expand All @@ -55,11 +55,13 @@ TextButton::~TextButton()
/**
* Changes the color for the button and text.
* @param color Color value.
* @param inactiveColor Color value for inactive button.
*/
void TextButton::setColor(Uint8 color)
void TextButton::setColor(Uint8 color, Uint8 inactiveColor)
{
_color = color;
_text->setColor(_color);
_inactiveColor = inactiveColor;
_text->setColor(_active? color : inactiveColor);
_redraw = true;
}

Expand Down Expand Up @@ -87,13 +89,13 @@ void TextButton::setFonts(Font *big, Font *small)

/**
* Enables/disables high contrast color. Mostly used for
* Battlescape UI.
* Battlescape UI. Inactive buttons have a low contrast.
* @param contrast High contrast setting.
*/
void TextButton::setHighContrast(bool contrast)
{
_contrast = contrast;
_text->setHighContrast(contrast);
_text->setHighContrast(contrast && _active);
_redraw = true;
}

Expand Down Expand Up @@ -148,13 +150,9 @@ void TextButton::draw()
Surface::draw();
SDL_Rect square;

int mul = 1;
if (_contrast)
{
mul = 2;
}

int color = _color + 1 * mul;
int mul = (_contrast && _active)? 2 : 1;
int baseColor = _active? _color : _inactiveColor;
int color = baseColor + 1 * mul;

square.x = 0;
square.y = 0;
Expand All @@ -176,18 +174,18 @@ void TextButton::draw()
switch (i)
{
case 0:
color = _color + 5 * mul;
color = baseColor + 5 * mul;
setPixel(square.w, 0, color);
break;
case 1:
color = _color + 2 * mul;
color = baseColor + 2 * mul;
break;
case 2:
color = _color + 4 * mul;
color = baseColor + 4 * mul;
setPixel(square.w+1, 1, color);
break;
case 3:
color = _color + 3 * mul;
color = baseColor + 3 * mul;
break;
}
}
Expand All @@ -200,7 +198,7 @@ void TextButton::draw()

if (press)
{
this->invert(_color + 3 * mul);
this->invert(baseColor + 3 * mul);
}
_text->setInvert(press);

Expand Down Expand Up @@ -244,4 +242,16 @@ void TextButton::mouseRelease(Action *action, State *state)
//_redraw = true;
}

/**
* Enables/disables activity. Inactive buttons have a low contrast.
* @param active Sets activity flag.
*/
void TextButton::setActive(bool active)
{
InteractiveSurface::setActive(active);
_text->setHighContrast(_contrast && _active);
_text->setColor(_active? _color : _inactiveColor);
_redraw = true;
}

}
6 changes: 4 additions & 2 deletions src/Interface/TextButton.h
Expand Up @@ -38,7 +38,7 @@ class Sound;
class TextButton : public InteractiveSurface
{
private:
Uint8 _color;
Uint8 _color, _inactiveColor;
Text *_text;
TextButton **_group;
bool _contrast;
Expand All @@ -49,7 +49,7 @@ class TextButton : public InteractiveSurface
/// Cleans up the text button.
~TextButton();
/// Sets the text button's color.
void setColor(Uint8 color);
void setColor(Uint8 color, Uint8 inactiveColor = 0);
/// Gets the text button's color.
Uint8 getColor() const;
/// Sets the text button's various fonts.
Expand All @@ -70,6 +70,8 @@ class TextButton : public InteractiveSurface
void mousePress(Action *action, State *state);
/// Special handling for mouse releases.
void mouseRelease(Action *action, State *state);
/// Sets the activity flag.
void setActive(bool active);
};

}
Expand Down

0 comments on commit 96ccf66

Please sign in to comment.