add camera settings in option screen (#4273)

* add camera settings in option screen

* Remove camera settings (distance, backward/forward angles, smoothing) from kart characteristics

Co-authored-by: luffah <luffah@runbox.com>
This commit is contained in:
Luffah 2020-07-10 05:39:19 +02:00 committed by GitHub
parent 039a4ac233
commit 0a6a487b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 476 additions and 128 deletions

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<stkgui>
<div x="2%" y="1%" width="96%" height="98%" layout="vertical-row" >
<header id="title" width="100%" height="fit" text_align="center" word_wrap="true" text="Camera Settings" />
<spacer width="100%" height="3%"/>
<div width="100%" height="91%" layout="vertical-row" >
<label width="100%" I18N="In the ui/camera settings" text="Player camera"/>
<spacer width="5" height="1%"/>
<div width="100%" height="fit" layout="horizontal-row">
<spacer width="3%" height="100%" />
<div proportion="1" height="fit" layout="horizontal-row" >
<label width="20%" height="100%" I18N="In the ui/camera screen" text="FOV"/>
<gauge id="fov" proportion="1"/>
</div>
</div>
<spacer height="2%" width="100%" />
<div width="100%" height="fit" layout="horizontal-row">
<spacer width="3%" height="100%" />
<div proportion="1" height="fit" layout="horizontal-row" >
<label width="20%" height="100%" text_align="left" I18N="In the ui/camera screen" text="Distance"/>
<gauge id="camera_distance" proportion="1"/>
</div>
</div>
<spacer height="2%" width="100%" />
<div width="100%" height="fit" layout="horizontal-row">
<spacer width="3%" height="100%" />
<div proportion="1" height="fit" layout="horizontal-row" >
<label width="20%" height="100%" text_align="left" I18N="In the ui/camera screen" text="Angle"/>
<gauge id="camera_angle" proportion="1"/>
</div>
</div>
<spacer height="2%" width="100%" />
<div width="100%" height="fit" layout="horizontal-row">
<spacer width="3%" height="100%" />
<div proportion="1" height="fit" layout="horizontal-row" >
<checkbox id="camera_smoothing"/>
<spacer width="1%" height="100%" />
<label height="100%" text_align="left" I18N="In the ui/camera screen" text="Smoothing"/>
</div>
</div>
<spacer width="5" height="2%"/>
<label width="100%" I18N="In the ui/camera settings" text="Backward camera"/>
<spacer width="5" height="1%"/>
<spacer height="2%" width="100%" />
<div width="100%" height="fit" layout="horizontal-row">
<spacer width="3%" height="100%" />
<div proportion="1" height="fit" layout="horizontal-row" >
<label width="20%" height="100%" text_align="left" I18N="In the ui/camera screen" text="Angle"/>
<gauge id="backward_camera_angle" proportion="1"/>
</div>
</div>
<spacer height="2%" width="100%" />
<div width="100%" height="fit" layout="horizontal-row">
<spacer width="3%" height="100%" />
<div proportion="1" height="fit" layout="horizontal-row" >
<checkbox id="use_soccer_camera"/>
<spacer width="1%" height="100%" />
<label height="100%" text_align="left" I18N="In the ui/camera screen" text="Follow ball in soccer mode"/>
</div>
</div>
<spacer width="100%" height="2%"/>
<button id="close" text="Apply" align="center"/>
<spacer width="100%" height="1%"/>
</div>
</div>
</stkgui>

View File

@ -75,6 +75,21 @@
<spacer width="5" height="2%"/> <spacer width="5" height="2%"/>
<!-- ************ GRAPHICAL EFFECTS SETTINGS ************ -->
<div width="100%" height="fit" layout="horizontal-row">
<div layout="vertical-row" width="10f" height="fit">
<spinner id="camera_preset" width="100%" align="center" />
</div>
<div layout="vertical-row" proportion="1" height="100%">
<label height="100%" I18N="In the ui settings" text="Camera" align="left"/>
</div>
<div layout="vertical-row" proportion="1" height="100%" id="outer_box" >
<button id="custom_camera" text="Custom..." I18N="In the ui settings" align="center"/>
</div>
</div>
<spacer width="5" height="2%"/>
<div layout="horizontal-row" width="100%" height="fit"> <div layout="horizontal-row" width="100%" height="fit">
<checkbox id="showfps"/> <checkbox id="showfps"/>
<spacer width="1%" height="100%" /> <spacer width="1%" height="100%" />
@ -91,7 +106,6 @@
<spacer width="5" height="2%"/> <spacer width="5" height="2%"/>
<div layout="horizontal-row" width="100%" height="fit"> <div layout="horizontal-row" width="100%" height="fit">
<checkbox id="story-mode-timer"/> <checkbox id="story-mode-timer"/>
<spacer width="1%" height="100%" /> <spacer width="1%" height="100%" />

View File

@ -937,6 +937,38 @@ namespace UserConfigParams
PARAM_DEFAULT( BoolUserConfigParam(false, "crashed") ); PARAM_DEFAULT( BoolUserConfigParam(false, "crashed") );
// ---- Camera // ---- Camera
PARAM_PREFIX GroupUserConfigParam m_camera_normal
PARAM_DEFAULT( GroupUserConfigParam(
"camera-normal",
"Camera settings for player.") );
PARAM_PREFIX FloatUserConfigParam m_camera_distance
PARAM_DEFAULT( FloatUserConfigParam(1.0, "distance",
&m_camera_normal,
"Distance between kart and camera"));
PARAM_PREFIX FloatUserConfigParam m_camera_forward_up_angle
PARAM_DEFAULT( FloatUserConfigParam(0, "forward-up-angle",
&m_camera_normal,
"Angle between camera and plane of kart (pitch) when the camera is pointing forward"));
PARAM_PREFIX BoolUserConfigParam m_camera_forward_smoothing
PARAM_DEFAULT( BoolUserConfigParam(true, "forward-smoothing",
&m_camera_normal,
"if true, use smoothing (forward-up-angle become relative to speed) when pointing forward"));
PARAM_PREFIX FloatUserConfigParam m_camera_backward_up_angle
PARAM_DEFAULT( FloatUserConfigParam(5, "backward-up-angle",
&m_camera_normal,
"Angle between camera and plane of kart (pitch) when the camera is pointing backwards. This is usually larger than the forward-up-angle, since the kart itself otherwise obstricts too much of the view"));
PARAM_PREFIX IntUserConfigParam m_camera_fov
PARAM_DEFAULT( IntUserConfigParam(80, "fov",
&m_camera_normal,
"Focal distance (single player)"));
// camera in artist mode
PARAM_PREFIX GroupUserConfigParam m_camera PARAM_PREFIX GroupUserConfigParam m_camera
PARAM_DEFAULT( GroupUserConfigParam("camera", PARAM_DEFAULT( GroupUserConfigParam("camera",
"(Debug) camera settings.") ); "(Debug) camera settings.") );

View File

@ -175,9 +175,15 @@ void Camera::setupCamera()
float(irr_driver->getActualScreenSize().Width) / m_viewport.getWidth() , float(irr_driver->getActualScreenSize().Width) / m_viewport.getWidth() ,
float(irr_driver->getActualScreenSize().Height) / m_viewport.getHeight()); float(irr_driver->getActualScreenSize().Height) / m_viewport.getHeight());
if (RaceManager::get()->getNumLocalPlayers() > 0)
{
m_fov = DEGREE_TO_RAD * stk_config->m_camera_fov m_fov = DEGREE_TO_RAD * stk_config->m_camera_fov
[RaceManager::get()->getNumLocalPlayers() > 0 ? [RaceManager::get()->getNumLocalPlayers() - 1];
RaceManager::get()->getNumLocalPlayers() - 1 : 0]; }
else
{
m_fov = DEGREE_TO_RAD * UserConfigParams::m_camera_fov;
}
m_camera->setFOV(m_fov); m_camera->setFOV(m_fov);
m_camera->setAspectRatio(m_aspect); m_camera->setAspectRatio(m_aspect);

View File

@ -20,6 +20,7 @@
#include "graphics/camera_debug.hpp" #include "graphics/camera_debug.hpp"
#include "config/stk_config.hpp" #include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "karts/abstract_kart.hpp" #include "karts/abstract_kart.hpp"
#include "karts/explosion_animation.hpp" #include "karts/explosion_animation.hpp"
#include "karts/kart.hpp" #include "karts/kart.hpp"
@ -55,8 +56,6 @@ CameraDebug::~CameraDebug()
void CameraDebug::getCameraSettings(float *above_kart, float *cam_angle, void CameraDebug::getCameraSettings(float *above_kart, float *cam_angle,
float *sideway, float *distance ) float *sideway, float *distance )
{ {
const KartProperties *kp = getKart()->getKartProperties();
// Set some default values // Set some default values
float steering = m_kart->getSteerPercent() float steering = m_kart->getSteerPercent()
* (1.0f + (m_kart->getSkidding()->getSkidFactor() * (1.0f + (m_kart->getSkidding()->getSkidFactor()
@ -78,7 +77,7 @@ void CameraDebug::getCameraSettings(float *above_kart, float *cam_angle,
case CM_DEBUG_SIDE_OF_KART: case CM_DEBUG_SIDE_OF_KART:
case CM_DEBUG_TOP_OF_KART: case CM_DEBUG_TOP_OF_KART:
*above_kart = 0.75f; *above_kart = 0.75f;
*cam_angle = kp->getCameraForwardUpAngle() * DEGREE_TO_RAD; *cam_angle = UserConfigParams::m_camera_forward_up_angle * DEGREE_TO_RAD;
*distance = -m_distance; *distance = -m_distance;
break; break;
} // switch } // switch

View File

@ -18,6 +18,7 @@
#include "graphics/camera_end.hpp" #include "graphics/camera_end.hpp"
#include "config/user_config.hpp"
#include "karts/abstract_kart.hpp" #include "karts/abstract_kart.hpp"
#include "karts/kart_properties.hpp" #include "karts/kart_properties.hpp"
#include "race/race_manager.hpp" #include "race/race_manager.hpp"
@ -133,7 +134,7 @@ void CameraEnd::update(float dt)
} }
case EndCameraInformation::EC_AHEAD_OF_KART: case EndCameraInformation::EC_AHEAD_OF_KART:
{ {
float cam_angle = m_kart->getKartProperties()->getCameraBackwardUpAngle() float cam_angle = UserConfigParams::m_camera_backward_up_angle
* DEGREE_TO_RAD; * DEGREE_TO_RAD;
positionCamera(dt, /*above_kart*/0.75f, positionCamera(dt, /*above_kart*/0.75f,

View File

@ -46,7 +46,7 @@ CameraNormal::CameraNormal(Camera::CameraType type, int camera_index,
AbstractKart* kart) AbstractKart* kart)
: Camera(type, camera_index, kart), m_camera_offset(0, 0, -15.0f) : Camera(type, camera_index, kart), m_camera_offset(0, 0, -15.0f)
{ {
m_distance = kart ? kart->getKartProperties()->getCameraDistance() : 1000.0f; m_distance = kart ? UserConfigParams::m_camera_distance : 1000.0f;
m_ambient_light = Track::getCurrentTrack()->getDefaultAmbientColor(); m_ambient_light = Track::getCurrentTrack()->getDefaultAmbientColor();
// TODO: Put these values into a config file // TODO: Put these values into a config file
@ -192,15 +192,13 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
float *sideway, float *distance, float *sideway, float *distance,
bool *smoothing, float *cam_roll_angle) bool *smoothing, float *cam_roll_angle)
{ {
const KartProperties *kp = m_kart->getKartProperties();
switch(getMode()) switch(getMode())
{ {
case CM_NORMAL: case CM_NORMAL:
case CM_FALLING: case CM_FALLING:
{ {
*above_kart = 0.75f; *above_kart = 0.75f;
*cam_angle = kp->getCameraForwardUpAngle() * DEGREE_TO_RAD; *cam_angle = UserConfigParams::m_camera_forward_up_angle * DEGREE_TO_RAD;
*distance = -m_distance; *distance = -m_distance;
float steering = m_kart->getSteerPercent() float steering = m_kart->getSteerPercent()
* (1.0f + (m_kart->getSkidding()->getSkidFactor() * (1.0f + (m_kart->getSkidding()->getSkidFactor()
@ -208,7 +206,7 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
// quadratically to dampen small variations (but keep sign) // quadratically to dampen small variations (but keep sign)
float dampened_steer = fabsf(steering) * steering; float dampened_steer = fabsf(steering) * steering;
*sideway = -m_rotation_range*dampened_steer*0.5f; *sideway = -m_rotation_range*dampened_steer*0.5f;
*smoothing = kp->getCameraForwardSmoothing(); *smoothing = UserConfigParams::m_camera_forward_smoothing;
*cam_roll_angle = 0.0f; *cam_roll_angle = 0.0f;
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE) if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
{ {
@ -223,7 +221,7 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
case CM_REVERSE: // Same as CM_NORMAL except it looks backwards case CM_REVERSE: // Same as CM_NORMAL except it looks backwards
{ {
*above_kart = 0.75f; *above_kart = 0.75f;
*cam_angle = kp->getCameraBackwardUpAngle() * DEGREE_TO_RAD; *cam_angle = UserConfigParams::m_camera_backward_up_angle * DEGREE_TO_RAD;
*sideway = 0; *sideway = 0;
*distance = 2.0f*m_distance; *distance = 2.0f*m_distance;
*smoothing = false; *smoothing = false;

View File

@ -84,6 +84,8 @@ public:
/** Sets the ambient light for this camera. */ /** Sets the ambient light for this camera. */
void setAmbientLight(const video::SColor &color) { m_ambient_light=color; } void setAmbientLight(const video::SColor &color) { m_ambient_light=color; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void setDistanceToKart(float distance) { m_distance = distance; }
// ------------------------------------------------------------------------
float getDistanceToKart() const { return m_distance; } float getDistanceToKart() const { return m_distance; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** Returns the current ambient light. */ /** Returns the current ambient light. */

View File

@ -98,10 +98,20 @@ SpinnerWidget::SpinnerWidget(const bool gauge) : Widget(WTYPE_SPINNER)
m_spinner_widget_player_id=-1; m_spinner_widget_player_id=-1;
m_min = 0; m_min = 0;
m_max = 999; m_max = 999;
m_step = 1.0;
m_left_selected = false; m_left_selected = false;
m_right_selected = false; m_right_selected = false;
} }
// -----------------------------------------------------------------------------
void SpinnerWidget::setRange(int min, int max, float step)
{
clearLabels();
setStep(step);
setMin(min/step);
setMax(max/step);
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void SpinnerWidget::add() void SpinnerWidget::add()
@ -420,9 +430,19 @@ void SpinnerWidget::setValue(const int new_value)
m_children[1].m_element->setText( text.c_str() ); m_children[1].m_element->setText( text.c_str() );
} }
else if (m_children.size() > 0) else if (m_children.size() > 0)
{
if (m_step == 1.0)
{ {
m_children[1].m_element->setText( stringw(m_value).c_str() ); m_children[1].m_element->setText( stringw(m_value).c_str() );
} }
else
{
std::wstringstream ws;
ws << (m_value*m_step);
std::wstring text = ws.str();
m_children[1].m_element->setText( text.c_str() );
}
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -57,6 +57,7 @@ namespace GUIEngine
ISpinnerConfirmListener* m_listener; ISpinnerConfirmListener* m_listener;
int m_value, m_min, m_max; int m_value, m_min, m_max;
float m_step;
int m_spinner_widget_player_id; int m_spinner_widget_player_id;
bool m_use_background_color; bool m_use_background_color;
@ -156,9 +157,6 @@ namespace GUIEngine
return false; return false;
} }
void setListener(ISpinnerConfirmListener* listener) { m_listener = listener; } void setListener(ISpinnerConfirmListener* listener) { m_listener = listener; }
/** \brief implement method from base class Widget */ /** \brief implement method from base class Widget */
@ -170,6 +168,12 @@ namespace GUIEngine
*/ */
void setValue(const int new_value); void setValue(const int new_value);
/**
* \brief sets the float value of the spinner
* \param new_value the new value that will be become the current value of this spinner.
*/
void setFloatValue(const float new_value) { setValue(int(round(new_value/m_step))); }
/** /**
* \brief sets the current value of the spinner * \brief sets the current value of the spinner
* \pre the 'new_value' string passed must be the name of an item * \pre the 'new_value' string passed must be the name of an item
@ -188,6 +192,12 @@ namespace GUIEngine
*/ */
int getValue() const { return m_value; } int getValue() const { return m_value; }
/**
* \brief retrieve the current value of the spinner
* \return the current value of the spinner, in a float form
*/
float getFloatValue() const { return m_value*m_step; }
/** /**
* \brief retrieve the current value of the spinner * \brief retrieve the current value of the spinner
* \return the current value of the spinner, in a string form * \return the current value of the spinner, in a string form
@ -205,6 +215,18 @@ namespace GUIEngine
return m_labels[id]; return m_labels[id];
} }
/**
* \return the step value of the spinner
*/
// --------------------------------------------------------------------
/** Returns the step value. */
float getStep() const { return m_step; }
// --------------------------------------------------------------------
/** \brief Sets the maximum value for a spinner.
* If the current value is larger than the new maximum, the current
* value is set to the new maximum. */
void setStep(float n) { m_step = n; }
// --------------------------------------------------------------------
/** /**
* \return the maximum value the spinner can take * \return the maximum value the spinner can take
*/ */
@ -242,6 +264,11 @@ namespace GUIEngine
/** Display custom text in spinner */ /** Display custom text in spinner */
void setCustomText(const core::stringw& text); void setCustomText(const core::stringw& text);
const core::stringw& getCustomText() const { return m_custom_text; } const core::stringw& getCustomText() const { return m_custom_text; }
/* Set a spinner with numeric values min <= i <= max, with a precision of defined by step */
void setRange(int min, int max, float step);
void setRange(int min, int max) { setRange(min, max, 1.0); }
void onPressed(int x, int y); void onPressed(int x, int y);
void doValueUpdatedCallback() void doValueUpdatedCallback()
{ {
@ -253,6 +280,7 @@ namespace GUIEngine
{ {
m_value_updated_callback = callback; m_value_updated_callback = callback;
} }
}; };
} }

View File

@ -107,14 +107,6 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType(
return TYPE_FLOAT; return TYPE_FLOAT;
case WHEELS_DAMPING_COMPRESSION: case WHEELS_DAMPING_COMPRESSION:
return TYPE_FLOAT; return TYPE_FLOAT;
case CAMERA_DISTANCE:
return TYPE_FLOAT;
case CAMERA_FORWARD_UP_ANGLE:
return TYPE_FLOAT;
case CAMERA_FORWARD_SMOOTHING:
return TYPE_BOOL;
case CAMERA_BACKWARD_UP_ANGLE:
return TYPE_FLOAT;
case JUMP_ANIMATION_TIME: case JUMP_ANIMATION_TIME:
return TYPE_FLOAT; return TYPE_FLOAT;
case LEAN_MAX: case LEAN_MAX:
@ -349,14 +341,6 @@ std::string AbstractCharacteristic::getName(CharacteristicType type)
return "WHEELS_DAMPING_RELAXATION"; return "WHEELS_DAMPING_RELAXATION";
case WHEELS_DAMPING_COMPRESSION: case WHEELS_DAMPING_COMPRESSION:
return "WHEELS_DAMPING_COMPRESSION"; return "WHEELS_DAMPING_COMPRESSION";
case CAMERA_DISTANCE:
return "CAMERA_DISTANCE";
case CAMERA_FORWARD_UP_ANGLE:
return "CAMERA_FORWARD_UP_ANGLE";
case CAMERA_FORWARD_SMOOTHING:
return "CAMERA_FORWARD_SMOOTHING";
case CAMERA_BACKWARD_UP_ANGLE:
return "CAMERA_BACKWARD_UP_ANGLE";
case JUMP_ANIMATION_TIME: case JUMP_ANIMATION_TIME:
return "JUMP_ANIMATION_TIME"; return "JUMP_ANIMATION_TIME";
case LEAN_MAX: case LEAN_MAX:
@ -843,53 +827,6 @@ float AbstractCharacteristic::getWheelsDampingCompression() const
return result; return result;
} // getWheelsDampingCompression } // getWheelsDampingCompression
// ----------------------------------------------------------------------------
float AbstractCharacteristic::getCameraDistance() const
{
float result;
bool is_set = false;
process(CAMERA_DISTANCE, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(CAMERA_DISTANCE).c_str());
return result;
} // getCameraDistance
// ----------------------------------------------------------------------------
float AbstractCharacteristic::getCameraForwardUpAngle() const
{
float result;
bool is_set = false;
process(CAMERA_FORWARD_UP_ANGLE, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(CAMERA_FORWARD_UP_ANGLE).c_str());
return result;
} // getCameraForwardUpAngle
// ----------------------------------------------------------------------------
bool AbstractCharacteristic::getCameraForwardSmoothing() const
{
bool result;
bool is_set = false;
process(CAMERA_FORWARD_SMOOTHING, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(CAMERA_FORWARD_SMOOTHING).c_str());
return result;
} // getCameraForwardSmoothing
// ----------------------------------------------------------------------------
float AbstractCharacteristic::getCameraBackwardUpAngle() const
{
float result;
bool is_set = false;
process(CAMERA_BACKWARD_UP_ANGLE, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(CAMERA_BACKWARD_UP_ANGLE).c_str());
return result;
} // getCameraBackwardUpAngle
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float AbstractCharacteristic::getJumpAnimationTime() const float AbstractCharacteristic::getJumpAnimationTime() const

View File

@ -111,12 +111,6 @@ public:
WHEELS_DAMPING_RELAXATION, WHEELS_DAMPING_RELAXATION,
WHEELS_DAMPING_COMPRESSION, WHEELS_DAMPING_COMPRESSION,
// Camera
CAMERA_DISTANCE,
CAMERA_FORWARD_UP_ANGLE,
CAMERA_FORWARD_SMOOTHING,
CAMERA_BACKWARD_UP_ANGLE,
// Jump // Jump
JUMP_ANIMATION_TIME, JUMP_ANIMATION_TIME,

View File

@ -21,6 +21,7 @@
#include "audio/sfx_manager.hpp" #include "audio/sfx_manager.hpp"
#include "addons/addon.hpp" #include "addons/addon.hpp"
#include "audio/sfx_manager.hpp" #include "audio/sfx_manager.hpp"
#include "config/user_config.hpp"
#include "config/stk_config.hpp" #include "config/stk_config.hpp"
#include "config/player_manager.hpp" #include "config/player_manager.hpp"
#include "graphics/central_settings.hpp" #include "graphics/central_settings.hpp"
@ -354,6 +355,7 @@ void KartProperties::combineCharacteristics(HandicapLevel handicap)
m_combined_characteristic->addCharacteristic(kart_properties_manager-> m_combined_characteristic->addCharacteristic(kart_properties_manager->
getDifficultyCharacteristic(RaceManager::get()->getDifficultyAsString( getDifficultyCharacteristic(RaceManager::get()->getDifficultyAsString(
RaceManager::get()->getDifficulty()))); RaceManager::get()->getDifficulty())));
// FIXME add get user characteristics
// Try to get the kart type // Try to get the kart type
const AbstractCharacteristic *characteristic = kart_properties_manager-> const AbstractCharacteristic *characteristic = kart_properties_manager->
@ -773,29 +775,6 @@ float KartProperties::getWheelsDampingCompression() const
return m_cached_characteristic->getWheelsDampingCompression(); return m_cached_characteristic->getWheelsDampingCompression();
} // getWheelsDampingCompression } // getWheelsDampingCompression
// ----------------------------------------------------------------------------
float KartProperties::getCameraDistance() const
{
return m_cached_characteristic->getCameraDistance();
} // getCameraDistance
// ----------------------------------------------------------------------------
float KartProperties::getCameraForwardUpAngle() const
{
return m_cached_characteristic->getCameraForwardUpAngle();
} // getCameraForwardUpAngle
// ----------------------------------------------------------------------------
bool KartProperties::getCameraForwardSmoothing() const
{
return m_cached_characteristic->getCameraForwardSmoothing();
} // getCameraForwardSmoothing
// ----------------------------------------------------------------------------
float KartProperties::getCameraBackwardUpAngle() const
{
return m_cached_characteristic->getCameraBackwardUpAngle();
} // getCameraBackwardUpAngle
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float KartProperties::getJumpAnimationTime() const float KartProperties::getJumpAnimationTime() const

View File

@ -407,11 +407,6 @@ public:
float getWheelsDampingRelaxation() const; float getWheelsDampingRelaxation() const;
float getWheelsDampingCompression() const; float getWheelsDampingCompression() const;
float getCameraDistance() const;
float getCameraForwardUpAngle() const;
bool getCameraForwardSmoothing() const;
float getCameraBackwardUpAngle() const;
float getJumpAnimationTime() const; float getJumpAnimationTime() const;
float getLeanMax() const; float getLeanMax() const;

View File

@ -1,4 +1,4 @@
//
// SuperTuxKart - a fun racing game with go-kart // SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006-2015 SuperTuxKart-Team // Copyright (C) 2006-2015 SuperTuxKart-Team
// //
@ -397,18 +397,6 @@ void XmlCharacteristic::load(const XMLNode *node)
&m_values[WHEELS_DAMPING_COMPRESSION]); &m_values[WHEELS_DAMPING_COMPRESSION]);
} }
if (const XMLNode *sub_node = node->getNode("camera"))
{
sub_node->get("distance",
&m_values[CAMERA_DISTANCE]);
sub_node->get("forward-up-angle",
&m_values[CAMERA_FORWARD_UP_ANGLE]);
sub_node->get("forward-smoothing",
&m_values[CAMERA_FORWARD_SMOOTHING]);
sub_node->get("backward-up-angle",
&m_values[CAMERA_BACKWARD_UP_ANGLE]);
}
if (const XMLNode *sub_node = node->getNode("jump")) if (const XMLNode *sub_node = node->getNode("jump"))
{ {
sub_node->get("animation-time", sub_node->get("animation-time",

View File

@ -0,0 +1,97 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009-2015 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "states_screens/dialogs/custom_camera_settings.hpp"
#include "config/user_config.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/spinner_widget.hpp"
#include "states_screens/options/options_screen_ui.hpp"
#include "utils/translation.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "utils/string_utils.hpp"
#include "utils/translation.hpp"
#include <IGUIEnvironment.h>
using namespace GUIEngine;
using namespace irr;
using namespace irr::core;
using namespace irr::gui;
// -----------------------------------------------------------------------------
CustomCameraSettingsDialog::CustomCameraSettingsDialog(const float w, const float h) :
ModalDialog(w, h)
{
m_self_destroy = false;
loadFromFile("custom_camera_settings.stkgui");
getWidget<SpinnerWidget>("fov")->setValue(UserConfigParams::m_camera_fov);
getWidget<SpinnerWidget>("camera_distance")->setFloatValue(UserConfigParams::m_camera_distance);
getWidget<SpinnerWidget>("camera_angle")->setValue(UserConfigParams::m_camera_forward_up_angle);
getWidget<CheckBoxWidget>("camera_smoothing")->setState(UserConfigParams::m_camera_forward_smoothing);
getWidget<SpinnerWidget>("backward_camera_angle")->setValue(UserConfigParams::m_camera_backward_up_angle);
// updateActivation();
}
// -----------------------------------------------------------------------------
CustomCameraSettingsDialog::~CustomCameraSettingsDialog()
{
}
// -----------------------------------------------------------------------------
void CustomCameraSettingsDialog::beforeAddingWidgets()
{
#ifndef SERVER_ONLY
getWidget<SpinnerWidget>("fov")->setRange(75, 115);
getWidget<SpinnerWidget>("fov")->setValue(UserConfigParams::m_camera_fov);
getWidget<SpinnerWidget>("camera_distance")->setRange(0 , 20, 0.1);
getWidget<SpinnerWidget>("camera_distance")->setFloatValue(UserConfigParams::m_camera_distance);
getWidget<SpinnerWidget>("camera_angle")->setRange(0 , 45);
getWidget<SpinnerWidget>("camera_angle")->setValue(UserConfigParams::m_camera_forward_up_angle);
getWidget<CheckBoxWidget>("camera_smoothing")->setState(UserConfigParams::m_camera_forward_smoothing);
getWidget<SpinnerWidget>("backward_camera_angle")->setRange(0 , 45);
getWidget<SpinnerWidget>("backward_camera_angle")->setValue(UserConfigParams::m_camera_backward_up_angle);
getWidget<CheckBoxWidget>("use_soccer_camera")->setState(UserConfigParams::m_reverse_look_use_soccer_cam);
#endif
}
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation CustomCameraSettingsDialog::processEvent(const std::string& eventSource)
{
#ifndef SERVER_ONLY
if (eventSource == "close")
{
UserConfigParams::m_camera_fov = getWidget<SpinnerWidget>("fov")->getValue();
UserConfigParams::m_camera_distance = getWidget<SpinnerWidget>("camera_distance")->getFloatValue();
UserConfigParams::m_camera_forward_up_angle = getWidget<SpinnerWidget>("camera_angle")->getValue();
UserConfigParams::m_camera_forward_smoothing = getWidget<CheckBoxWidget>("camera_smoothing")->getState();
UserConfigParams::m_camera_backward_up_angle = getWidget<SpinnerWidget>("backward_camera_angle")->getValue();
UserConfigParams::m_reverse_look_use_soccer_cam = getWidget<CheckBoxWidget>("use_soccer_camera")->getState();
OptionsScreenUI::getInstance()->updateCameraPresetSpinner();
m_self_destroy = true;
return GUIEngine::EVENT_BLOCK;
}
#endif
return GUIEngine::EVENT_LET;
} // processEvent

View File

@ -0,0 +1,63 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009-2015 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_CUSTOM_CAMERA_SETTINGS_HPP
#define HEADER_CUSTOM_CAMERA_SETTINGS_HPP
#include "guiengine/modaldialog.hpp"
/**
* \brief Dialog that allows the player to select custom video settings
* \ingroup states_screens
*/
class CustomCameraSettingsDialog : public GUIEngine::ModalDialog
{
private:
bool m_self_destroy;
public:
/**
* Creates a modal dialog with given percentage of screen width and height
*/
CustomCameraSettingsDialog(const float percentWidth, const float percentHeight);
~CustomCameraSettingsDialog();
virtual void beforeAddingWidgets();
void updateActivation();
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
virtual bool onEscapePressed()
{
m_self_destroy = true;
return false;
}
virtual void onUpdate(float dt)
{
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
{
ModalDialog::dismiss();
return;
}
}
};
#endif

View File

@ -20,10 +20,13 @@
#include "addons/news_manager.hpp" #include "addons/news_manager.hpp"
#include "audio/sfx_manager.hpp" #include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp" #include "audio/sfx_base.hpp"
#include "graphics/camera.hpp"
#include "graphics/camera_normal.hpp"
#include "challenges/story_mode_timer.hpp" #include "challenges/story_mode_timer.hpp"
#include "config/hardware_stats.hpp" #include "config/hardware_stats.hpp"
#include "config/player_manager.hpp" #include "config/player_manager.hpp"
#include "config/user_config.hpp" #include "config/user_config.hpp"
#include "config/stk_config.hpp"
#include "font/bold_face.hpp" #include "font/bold_face.hpp"
#include "font/font_manager.hpp" #include "font/font_manager.hpp"
#include "font/regular_face.hpp" #include "font/regular_face.hpp"
@ -41,6 +44,7 @@
#include "online/request_manager.hpp" #include "online/request_manager.hpp"
#include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/dialogs/message_dialog.hpp"
#include "states_screens/main_menu_screen.hpp" #include "states_screens/main_menu_screen.hpp"
#include "states_screens/dialogs/custom_camera_settings.hpp"
#include "states_screens/options/options_screen_audio.hpp" #include "states_screens/options/options_screen_audio.hpp"
#include "states_screens/options/options_screen_general.hpp" #include "states_screens/options/options_screen_general.hpp"
#include "states_screens/options/options_screen_input.hpp" #include "states_screens/options/options_screen_input.hpp"
@ -143,6 +147,9 @@ void OptionsScreenUI::loadedFromFile()
font_size->m_properties[GUIEngine::PROP_MIN_VALUE] = "1"; font_size->m_properties[GUIEngine::PROP_MIN_VALUE] = "1";
font_size->m_properties[GUIEngine::PROP_MAX_VALUE] = "5"; font_size->m_properties[GUIEngine::PROP_MAX_VALUE] = "5";
} }
updateCameraPresetSpinner();
font_size->setValueUpdatedCallback([this](SpinnerWidget* spinner) font_size->setValueUpdatedCallback([this](SpinnerWidget* spinner)
{ {
// Add a special value updated callback so font size is updated when // Add a special value updated callback so font size is updated when
@ -155,6 +162,7 @@ void OptionsScreenUI::loadedFromFile()
m_reload_option->m_focus_name = "font_size"; m_reload_option->m_focus_name = "font_size";
m_reload_option->m_focus_right = right; m_reload_option->m_focus_right = right;
}); });
} // loadedFromFile } // loadedFromFile
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -328,8 +336,81 @@ void OptionsScreenUI::init()
GUIEngine::reloadSkin(); GUIEngine::reloadSkin();
irr_driver->setMaxTextureSize(); irr_driver->setMaxTextureSize();
} }
// Camera presets
m_camera_presets.push_back // Standard
({
80 /* fov */, 1.0f /* distance */, 0.0f /* angle */, true /* smoothing */, 5.0f /* backward angle */,
});
m_camera_presets.push_back // Drone chase
({
100 /* fov */, 2.6f /* distance */, 33.0f /* angle */, false /* smoothing */, 10.0f /* backward angle */,
});
GUIEngine::SpinnerWidget* camera_preset = getWidget<GUIEngine::SpinnerWidget>("camera_preset");
assert( camera_preset != NULL );
camera_preset->m_properties[PROP_WRAP_AROUND] = "true";
camera_preset->clearLabels();
//I18N: custom camera setting
camera_preset->addLabel( core::stringw(_("Custom")));
//I18N: In the UI options,litscreen_method in the race UI
camera_preset->addLabel( core::stringw(_("Standard")));
//I18N: In the UI options, splitscreen_method position in the race UI
camera_preset->addLabel( core::stringw(_("Drone chase")));
camera_preset->m_properties[GUIEngine::PROP_MIN_VALUE] = "1";
camera_preset->m_properties[GUIEngine::PROP_MAX_VALUE] = "2";
updateCameraPresetSpinner();
} // init } // init
void updateCamera()
{
bool in_game = StateManager::get()->getGameState() == GUIEngine::INGAME_MENU;
if (in_game)
{
(Camera::getActiveCamera()->getCameraSceneNode())->setFOV(DEGREE_TO_RAD * UserConfigParams::m_camera_fov);
CameraNormal *camera = dynamic_cast<CameraNormal*>(Camera::getActiveCamera());
if (camera)
{
camera->setDistanceToKart(UserConfigParams::m_camera_distance);
}
}
}
void OptionsScreenUI::updateCameraPresetSpinner()
{
GUIEngine::SpinnerWidget* camera_preset = getWidget<GUIEngine::SpinnerWidget>("camera_preset");
assert( camera_preset != NULL );
#define FLOAT_EPSILON 0.001
bool found = false;
unsigned int i = 0;
for (; i < m_camera_presets.size(); i++)
{
if (m_camera_presets[i].fov == UserConfigParams::m_camera_fov &&
m_camera_presets[i].smoothing == UserConfigParams::m_camera_forward_smoothing &&
fabs(m_camera_presets[i].distance - UserConfigParams::m_camera_distance) < FLOAT_EPSILON &&
fabs(m_camera_presets[i].angle - UserConfigParams::m_camera_forward_up_angle) < FLOAT_EPSILON &&
fabs(m_camera_presets[i].backward_angle - UserConfigParams::m_camera_backward_up_angle) < FLOAT_EPSILON)
{
camera_preset->setValue(i + 1);
found = true;
break;
}
}
if (!found)
{
camera_preset->setValue(0);
camera_preset->m_properties[GUIEngine::PROP_MIN_VALUE] = std::to_string(0);
}
updateCamera();
} // updateCameraPresetSpinner
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, const int playerID) void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, const int playerID)
@ -456,6 +537,24 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
} }
UserConfigParams::m_speedrun_mode = speedrun_timer->getState(); UserConfigParams::m_speedrun_mode = speedrun_timer->getState();
} }
else if (name == "camera_preset")
{
GUIEngine::SpinnerWidget* camera_preset = getWidget<GUIEngine::SpinnerWidget>("camera_preset");
assert( camera_preset != NULL );
unsigned int i = camera_preset->getValue();
if (i != 0) {
UserConfigParams::m_camera_fov = m_camera_presets[i-1].fov;
UserConfigParams::m_camera_distance = m_camera_presets[i-1].distance;
UserConfigParams::m_camera_forward_up_angle = m_camera_presets[i-1].angle;
UserConfigParams::m_camera_forward_smoothing = m_camera_presets[i-1].smoothing;
UserConfigParams::m_camera_backward_up_angle = m_camera_presets[i-1].backward_angle;
}
updateCamera();
}
else if(name == "custom_camera")
{
new CustomCameraSettingsDialog(0.8f, 0.9f);
}
#endif #endif
} // eventCallback } // eventCallback

View File

@ -26,6 +26,15 @@
namespace GUIEngine { class Widget; } namespace GUIEngine { class Widget; }
struct CameraPreset
{
int fov;
float distance;
float angle;
bool smoothing;
float backward_angle;
};
struct Input; struct Input;
/** /**
@ -45,6 +54,8 @@ class OptionsScreenUI : public GUIEngine::Screen, public GUIEngine::ScreenSingle
OptionsScreenUI(); OptionsScreenUI();
bool m_inited; bool m_inited;
std::vector<CameraPreset> m_camera_presets;
std::map<core::stringw, std::string> m_skins; std::map<core::stringw, std::string> m_skins;
public: public:
@ -66,6 +77,8 @@ public:
/** \brief implement optional callback from parent class GUIEngine::Screen */ /** \brief implement optional callback from parent class GUIEngine::Screen */
virtual void unloaded() OVERRIDE; virtual void unloaded() OVERRIDE;
void updateCameraPresetSpinner();
virtual void onUpdate(float delta) OVERRIDE; virtual void onUpdate(float delta) OVERRIDE;
void reloadGUIEngine(); void reloadGUIEngine();