Skip to content

Commit

Permalink
Make crosslink blur optional, and clean up some
Browse files Browse the repository at this point in the history
redundant code.
  • Loading branch information
rohit-n committed Dec 18, 2015
1 parent 3d8a0be commit 8032853
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 48 deletions.
1 change: 1 addition & 0 deletions config.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
crosslink_blur = 1
entered_light_flash = 0
fullscreen = 0
input_popups = 1
Expand Down
1 change: 1 addition & 0 deletions config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bool ConfigManager::isKeyValid(const char* key)
if (!strcmp(key, "music_volume")) return true;
if (!strcmp(key, "tutorial_popups")) return true;
if (!strcmp(key, "input_popups")) return true;
if (!strcmp(key, "crosslink_blur")) return true;

return false;
}
Expand Down
16 changes: 14 additions & 2 deletions draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ bool Renderer::init(int x, int y)
screenshotIndex = 1;
wireframe = false;
_enteredLightFlash = false;
_crosslinkBlur = false;

linkProgress = 0.0f;

Expand Down Expand Up @@ -1379,10 +1380,20 @@ void Renderer::drawTileLayer(Scene* scene, int z)

void Renderer::drawBackground(Scene* scene, GLuint tex, int x, int z, float offset)
{
glUseProgramObject(pgmButton);
GLuint pgm;
if (scene->inCrosslinkMode() && !_crosslinkBlur)
{
pgm = pgmCrosslinkProp;
}
else
{
pgm = pgmButton;
}
glUseProgramObject(pgm);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUniform1i(glGetUniformLocation(pgmButton, "use_blur"), scene->inCrosslinkMode() ? 1 : 0);
unsigned int should_blur = scene->inCrosslinkMode() && _crosslinkBlur ? 1 : 0;
glUniform1i(glGetUniformLocation(pgmButton, "use_blur"), should_blur);
float xOffset = scene->getCamera().x * offset;

float verts[] = { 0.0f, 0.0f,
Expand Down Expand Up @@ -1731,6 +1742,7 @@ void Renderer::setScreenshotIndex(unsigned int value)
void Renderer::handleSettingsChange()
{
_enteredLightFlash = (Locator::getConfigManager()->getBool("entered_light_flash"));
_crosslinkBlur = (Locator::getConfigManager()->getBool("crosslink_blur"));
_bindingStrings[UESwitch] = "Flip Switch: " + Locator::getBindingsManager()->getFirstKeyBound(Bind_MoveUp);
_bindingStrings[UETerminal] = "Hack: " + Locator::getBindingsManager()->getFirstKeyBound(Bind_MoveUp);
_bindingStrings[UEElevator] = "Move Up: " + Locator::getBindingsManager()->getFirstKeyBound(Bind_MoveUp) + "\nMove Down: " +
Expand Down
1 change: 1 addition & 0 deletions draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class Renderer
GLuint notex;

bool _enteredLightFlash;
bool _crosslinkBlur;

//for animating crosslink lines
float linkProgress;
Expand Down
97 changes: 52 additions & 45 deletions optionsstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ OptionsState::OptionsState(StateManager* sm) : MenuState(sm)

_soundVolumeLabel = new TextLabel(0, 0, "Sound Volume", 1, 1, 1);
_musicVolumeLabel = new TextLabel(0, 0, "Music Volume", 1, 1, 1);
_crosslinkBlurLabel = new TextLabel(0, 0, "Crosslink Blur", 1, 1, 1);
_crossLinkBlurState = new ImageButton(0, 0, 32, 32, cbs, cbs);

_labels.push_back(_titleLabel);
_labels.push_back(_resolutionLabel);
Expand All @@ -92,6 +94,7 @@ OptionsState::OptionsState(StateManager* sm) : MenuState(sm)
_labels.push_back(_saveMessage);
_labels.push_back(_soundVolumeLabel);
_labels.push_back(_musicVolumeLabel);
_labels.push_back(_crosslinkBlurLabel);

_gameplayPage.push_back(_exitButton);
_gameplayPage.push_back(_saveChangesButton);
Expand All @@ -101,6 +104,7 @@ OptionsState::OptionsState(StateManager* sm) : MenuState(sm)
_gameplayPage.push_back(_lightEnteredAlphaState);
_gameplayPage.push_back(_tutorialPopupsState);
_gameplayPage.push_back(_inputPopupsState);
_gameplayPage.push_back(_crossLinkBlurState);
_gameplayPage.push_back(_toBindingsPage);

//Bindings page
Expand Down Expand Up @@ -209,25 +213,28 @@ void OptionsState::resetPositions(int w, int h)
_resolutionText->setPositionWithOffset(w * 0.4f, y, 408, 260);
_resDown->setPositionWithOffset(w * 0.4f, y, 440, 272);

_saveChangesButton->setPosition(w * 0.45f, h * 0.75f);
_exitButton->setPosition(x, h * 0.8f);
_saveChangesButton->setPosition(w * 0.75f, h * 0.8f);
_exitButton->setPosition(w * 0.75f, h * 0.85f);

x = w * 0.4f;
y = h * 0.6f;

for (i = 0; i < NUM_VOLUME_BARS; i++)
{
_soundVolumeProgress[i]->setPositionWithOffset(x, y, 16 * i, 0);
_musicVolumeProgress[i]->setPositionWithOffset(x, y, 16 * i, 36);
_soundVolumeProgress[i]->setPositionWithOffset(x, y, 16 * i, 72);
_musicVolumeProgress[i]->setPositionWithOffset(x, y, 16 * i, 108);
}

_soundVolumeDecr->setPositionWithOffset(x, y, (16 * i) + 32, 0);
_soundVolumeIncr->setPositionWithOffset(x, y, (16 * i) + 64, 0);
_musicVolumeDecr->setPositionWithOffset(x, y, (16 * i) + 32, 36);
_musicVolumeIncr->setPositionWithOffset(x, y, (16 * i) + 64, 36);
_soundVolumeDecr->setPositionWithOffset(x, y, (16 * i) + 32, 72);
_soundVolumeIncr->setPositionWithOffset(x, y, (16 * i) + 64, 72);
_musicVolumeDecr->setPositionWithOffset(x, y, (16 * i) + 32, 108);
_musicVolumeIncr->setPositionWithOffset(x, y, (16 * i) + 64, 108);

_soundVolumeLabel->setPositionWithOffset(w * 0.25f, h * 0.6f, 0, 24);
_musicVolumeLabel->setPositionWithOffset(w * 0.25f, h * 0.6f, 0, 60);
_soundVolumeLabel->setPositionWithOffset(w * 0.25f, h * 0.6f, 0, 88);
_musicVolumeLabel->setPositionWithOffset(w * 0.25f, h * 0.6f, 0, 128);

_crosslinkBlurLabel->setPosition(w * 0.25f, y + 32);
_crossLinkBlurState->setPositionWithOffset(w * 0.4f, y, 440, 12);

//bindings page
_toGameplayPage->setPosition(w * 0.2f, h * 0.1f);
Expand All @@ -252,56 +259,29 @@ void OptionsState::update(unsigned int dT)

void OptionsState::handleButton(Button* button)
{
unsigned int cb = Locator::getSpriteManager()->getIndex("./data/sprites/interface.sprites", "checkbox");
unsigned int cbs = Locator::getSpriteManager()->getIndex("./data/sprites/interface.sprites", "checkbox_selected");

if (button == _exitButton)
{
_manager->switchToState(MAINMENU_SCREEN);
}
else if (button == _fullscreenState)
{
if (_fullscreenState->getSpriteIndex() == cb)
{
_fullscreenState->changeSprites(cbs, cbs);
}
else
{
_fullscreenState->changeSprites(cb, cb);
}
toggleCheckbox(_fullscreenState);
}
else if (button == _crossLinkBlurState)
{
toggleCheckbox(_crossLinkBlurState);
}
else if (button == _lightEnteredAlphaState)
{
if (_lightEnteredAlphaState->getSpriteIndex() == cb)
{
_lightEnteredAlphaState->changeSprites(cbs, cbs);
}
else
{
_lightEnteredAlphaState->changeSprites(cb, cb);
}
toggleCheckbox(_lightEnteredAlphaState);
}
else if (button == _tutorialPopupsState)
{
if (_tutorialPopupsState->getSpriteIndex() == cb)
{
_tutorialPopupsState->changeSprites(cbs, cbs);
}
else
{
_tutorialPopupsState->changeSprites(cb, cb);
}
toggleCheckbox(_tutorialPopupsState);
}
else if (button == _inputPopupsState)
{
if (_inputPopupsState->getSpriteIndex() == cb)
{
_inputPopupsState->changeSprites(cbs, cbs);
}
else
{
_inputPopupsState->changeSprites(cb, cb);
}
toggleCheckbox(_inputPopupsState);
}
else if (button == _resUp)
{
Expand Down Expand Up @@ -403,6 +383,15 @@ void OptionsState::setLabels()
_fullscreenState->changeSprites(cb, cb);
}

if (Locator::getConfigManager()->getBool("crosslink_blur"))
{
_crossLinkBlurState->changeSprites(cbs, cbs);
}
else
{
_crossLinkBlurState->changeSprites(cb, cb);
}

if (Locator::getConfigManager()->getBool("entered_light_flash"))
{
_lightEnteredAlphaState->changeSprites(cbs, cbs);
Expand Down Expand Up @@ -478,6 +467,7 @@ void OptionsState::saveSettings()
Locator::getConfigManager()->setValue("music_volume", std::string(musvolstr));
Locator::getAudio()->setSoundVolume((float)_currSoundVolume / 10);
Locator::getAudio()->setMusicVolume((float)_currMusicVolume / 10);
Locator::getConfigManager()->setValue("crosslink_blur", _crossLinkBlurState->getSpriteIndex() == cbs ? "1" : "0");
}

void OptionsState::addMode(std::string mode)
Expand All @@ -500,6 +490,7 @@ void OptionsState::changeToGameplayPage()
_musicVolumeLabel->setVisible(true);
_tutorialPopupsText->setVisible(true);
_inputPopupsText->setVisible(true);
_crosslinkBlurLabel->setVisible(true);
//bindings
_moveLeftLabel->setVisible(false);
_moveRightLabel->setVisible(false);
Expand All @@ -521,6 +512,7 @@ void OptionsState::changeToBindingsPage()
_musicVolumeLabel->setVisible(false);
_tutorialPopupsText->setVisible(false);
_inputPopupsText->setVisible(false);
_crosslinkBlurLabel->setVisible(false);
//bindings
_moveLeftLabel->setVisible(true);
_moveRightLabel->setVisible(true);
Expand Down Expand Up @@ -645,4 +637,19 @@ void OptionsState::handleDecrIncrVisibility(Button* decr, Button* incr, int valu
_buttons.push_back(incr);
}
}
}

void OptionsState::toggleCheckbox(ImageButton* ib)
{
unsigned int cb = Locator::getSpriteManager()->getIndex("./data/sprites/interface.sprites", "checkbox");
unsigned int cbs = Locator::getSpriteManager()->getIndex("./data/sprites/interface.sprites", "checkbox_selected");

if (ib->getSpriteIndex() == cb)
{
ib->changeSprites(cbs, cbs);
}
else
{
ib->changeSprites(cb, cb);
}
}
5 changes: 4 additions & 1 deletion optionsstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class OptionsState : public MenuState
void rebindKey(SDL_Keycode key);
void updateBindingButtons();
void updateProgressBars();
void handleDecrIncrVisibility(Button* decr, Button* incr, int value, int size);
bool _settingsChanged;
private:
void handleDecrIncrVisibility(Button* decr, Button* incr, int value, int size);
void toggleCheckbox(ImageButton* ib);
TextLabel* _titleLabel;
TextButton* _exitButton;
TextButton* _saveChangesButton;
Expand All @@ -73,6 +74,8 @@ class OptionsState : public MenuState
TextLabel* _resolutionLabel;
TextLabel* _soundVolumeLabel;
TextLabel* _musicVolumeLabel;
TextLabel* _crosslinkBlurLabel;
ImageButton* _crossLinkBlurState;
ImageButton* _resUp;
ImageButton* _resDown;
TextLabel* _fullscreenLabel;
Expand Down

0 comments on commit 8032853

Please sign in to comment.