Skip to content

Commit

Permalink
Fixes for reticle preview and allowReticleChange
Browse files Browse the repository at this point in the history
  • Loading branch information
bboudaoud-nv committed Dec 13, 2022
1 parent 4fd687b commit fa4f7c8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
21 changes: 19 additions & 2 deletions source/FPSciApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ void FPSciApp::updateSession(const String& id, const bool forceSceneReload) {

void FPSciApp::updateTrial(const shared_ptr<TrialConfig> config, const bool forceSceneReload, const bool respawn) {
trialConfig = config; // Naive way to store trial config pointer for now
updateUserMenu = true;
updateConfigParameters(config, forceSceneReload, respawn);
}

Expand Down Expand Up @@ -1404,12 +1405,28 @@ void FPSciApp::onUserInput(UserInput* ui) {
}
}

if (m_lastReticleLoaded != currentUser()->reticle.index || m_userSettingsWindow->visible()) {
// Update reticle from user settings change (if needed)
if (reticleConfig != currentUser()->reticle || m_userSettingsWindow->visible()) {
bool updateReticlePreview = false;
// Slider was used to change the reticle
if (!trialConfig->reticle.indexSpecified) { // Only allow reticle change if it isn't specified in experiment config
setReticle(currentUser()->reticle.index);
m_userSettingsWindow->updateReticlePreview();
updateReticlePreview = true;
}
if (!trialConfig->reticle.scaleSpecified) {
reticleConfig.scale = currentUser()->reticle.scale;
updateReticlePreview = true;
}
if (!trialConfig->reticle.colorSpecified) {
reticleConfig.color = currentUser()->reticle.color;
updateReticlePreview = true;
}
if (!trialConfig->reticle.changeTimeSpecified) {
reticleConfig.changeTimeS = currentUser()->reticle.changeTimeS;
updateReticlePreview = true;
}
if(updateReticlePreview) m_userSettingsWindow->updateReticlePreview();

}

playerCamera->filmSettings().setSensitivity(sceneBrightness);
Expand Down
23 changes: 15 additions & 8 deletions source/GuiElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@ UserMenu::UserMenu(FPSciApp* app, UserTable& users, UserStatusTable& userStatus,
// User Settings Pane
if (config.showUserSettings && !needUser) {
m_currentUserPane = m_parent->addPane("Current User Settings");
// Update config based on what is specified at the trial-level
if (app->trialConfig->reticle.indexSpecified) config.allowReticleIdxChange = false;
if (app->trialConfig->reticle.scaleSpecified) config.allowReticleSizeChange = false;
if (app->trialConfig->reticle.colorSpecified) config.allowReticleColorChange = false;
if (app->trialConfig->reticle.changeTimeSpecified) config.allowReticleChangeTimeChange = false;
config.allowReticleChange = config.allowReticleIdxChange || config.allowReticleSizeChange || config.allowReticleColorChange || config.allowReticleChangeTimeChange;
drawUserPane(config, m_users.users[m_users.getUserIndex(m_userStatus.currentUser)]);
}

Expand Down Expand Up @@ -610,13 +616,14 @@ void UserMenu::drawUserPane(const MenuConfig& config, UserConfig& user)
a->setWidth(m_rgbSliderWidth);
a->moveRightOf(b, rgbCaptionWidth);
} reticleControlPane->endRow();
if (config.allowReticleChangeTimeChange) {
reticleControlPane->beginRow(); {
auto c = reticleControlPane->addNumberBox("Reticle Change Time", &(user.reticle.changeTimeS), "s", GuiTheme::LINEAR_SLIDER, 0.0f, 5.0f, 0.01f);
c->setCaptionWidth(150.0f);
c->setWidth(m_sliderWidth);
} reticleControlPane->endRow();
}
}

if (config.allowReticleChangeTimeChange) {
reticleControlPane->beginRow(); {
auto c = reticleControlPane->addNumberBox("Reticle Change Time", &(user.reticle.changeTimeS), "s", GuiTheme::LINEAR_SLIDER, 0.0f, 5.0f, 0.01f);
c->setCaptionWidth(150.0f);
c->setWidth(m_sliderWidth);
} reticleControlPane->endRow();
}

// Draw a preview of the reticle here
Expand Down Expand Up @@ -761,7 +768,7 @@ void UserMenu::updateReticlePreview() {
m_reticlePreviewPane->removeAllChildren();
// Redraw the preview
shared_ptr<Texture> reticleTex = m_app->reticleTexture;
Color4 rColor = m_users.getUserById(m_userStatus.currentUser)->reticle.color[0];
Color4 rColor = m_app->reticleConfig.color[0];

RenderDevice* rd = m_app->renderDevice;
rd->push2D(m_reticleBuffer); {
Expand Down
7 changes: 7 additions & 0 deletions source/UserConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class ReticleConfig {

void load(FPSciAnyTableReader reader, int settingsVersion = 1);
Any addToAny(Any a, bool forceAll = false) const;
bool operator!=(ReticleConfig other) {
return index != other.index ||
scale[0] != other.scale[0] || scale[1] != other.scale[1] ||
color[0] != other.color[0] || color[1] != other.color[1] ||
changeTimeS != other.changeTimeS;
}

};

/**Class for managing user configuration*/
Expand Down

0 comments on commit fa4f7c8

Please sign in to comment.