Skip to content

Commit

Permalink
Merge pull request #404 from NVlabs/UserMenuReticleFix
Browse files Browse the repository at this point in the history
Fixes for reticle preview and `allowReticleChange`
  • Loading branch information
jspjutNV committed Jan 6, 2023
2 parents cf613b9 + b1a969c commit 71fd9e8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/general_config.md
Expand Up @@ -474,7 +474,7 @@ In addition to being able to be specified on a per-user basis, the experiment/se
|`reticleColor` |`Array<Color4>` |Provides a range of colors over which to set the reticle color as an `Array` w/ 2 elements (min, max)|
|`reticleChangeTime` |`float` |Provides the time (in seconds) for the reticle to change color and/or size following a shot |

Note that when these values are specified at the experiment or session level the `allowReticleChange` property of the [menu configuration](#menu-config) should be set to `false` as user changes to the reticle will not apply.
Note that when these values are specified at the experiment, session, or trial level the `allowReticleChange` property of the [menu configuration](#menu-config) can still be set to `true` but only fields *not* specified in the experiment/session/trial will be displayed as editable in the user menu. If all config is specified in by the experiment then the reticle pane/preview is not shown in the user menu.

### Weapon Cooldown
| Parameter Name |Units| Description |
Expand Down
21 changes: 19 additions & 2 deletions source/FPSciApp.cpp
Expand Up @@ -711,6 +711,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 @@ -1405,12 +1406,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
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
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 71fd9e8

Please sign in to comment.