mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
build 170715. custom sounds for cab lights, optional fallback on legacy sounds for controls without their own sound definitions
This commit is contained in:
158
Button.cpp
158
Button.cpp
@@ -9,11 +9,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Button.h"
|
||||
#include "parser.h"
|
||||
#include "Model3d.h"
|
||||
#include "Console.h"
|
||||
#include "logs.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
TButton::TButton()
|
||||
{
|
||||
iFeedbackBit = 0;
|
||||
@@ -21,13 +21,11 @@ TButton::TButton()
|
||||
Clear();
|
||||
};
|
||||
|
||||
TButton::~TButton(){};
|
||||
|
||||
void TButton::Clear(int i)
|
||||
{
|
||||
pModelOn = NULL;
|
||||
pModelOff = NULL;
|
||||
bOn = false;
|
||||
pModelOn = nullptr;
|
||||
pModelOff = nullptr;
|
||||
m_state = false;
|
||||
if (i >= 0)
|
||||
FeedbackBitSet(i);
|
||||
Update(); // kasowanie bitu Feedback, o ile jakiś ustawiony
|
||||
@@ -35,52 +33,134 @@ void TButton::Clear(int i)
|
||||
|
||||
void TButton::Init(std::string const &asName, TModel3d *pModel, bool bNewOn)
|
||||
{
|
||||
if (!pModel)
|
||||
return; // nie ma w czym szukać
|
||||
if( pModel == nullptr ) { return; }
|
||||
|
||||
pModelOn = pModel->GetFromName( (asName + "_on").c_str() );
|
||||
pModelOff = pModel->GetFromName( (asName + "_off").c_str() );
|
||||
bOn = bNewOn;
|
||||
m_state = bNewOn;
|
||||
Update();
|
||||
};
|
||||
|
||||
void TButton::Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2)
|
||||
{
|
||||
std::string const token = Parser.getToken<std::string>();
|
||||
if (pModel1)
|
||||
{ // poszukiwanie submodeli w modelu
|
||||
Init(token, pModel1, false);
|
||||
if (pModel2)
|
||||
if (!pModelOn && !pModelOff)
|
||||
Init(token, pModel2, false); // może w drugim będzie (jak nie w kabinie,
|
||||
// to w zewnętrznym)
|
||||
}
|
||||
else
|
||||
{
|
||||
pModelOn = NULL;
|
||||
pModelOff = NULL;
|
||||
void TButton::Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2) {
|
||||
|
||||
ErrorLog( "Failed to locate sub-model \"" + token + "\" in 3d model \"" + pModel1->NameGet() + "\"" );
|
||||
std::string submodelname;
|
||||
|
||||
Parser.getTokens();
|
||||
if( Parser.peek() != "{" ) {
|
||||
// old fixed size config
|
||||
Parser >> submodelname;
|
||||
}
|
||||
else {
|
||||
// new, block type config
|
||||
// TODO: rework the base part into yaml-compatible flow style mapping
|
||||
cParser mappingparser( Parser.getToken<std::string>( false, "}" ) );
|
||||
submodelname = mappingparser.getToken<std::string>( false );
|
||||
// new, variable length section
|
||||
while( true == Load_mapping( mappingparser ) ) {
|
||||
; // all work done by while()
|
||||
}
|
||||
}
|
||||
|
||||
if( pModel1 ) {
|
||||
// poszukiwanie submodeli w modelu
|
||||
Init( submodelname, pModel1, false );
|
||||
if( ( pModelOn != nullptr ) || ( pModelOff != nullptr ) ) {
|
||||
// we got our models, bail out
|
||||
return;
|
||||
}
|
||||
}
|
||||
if( pModel2 ) {
|
||||
// poszukiwanie submodeli w modelu
|
||||
Init( submodelname, pModel2, false );
|
||||
if( ( pModelOn != nullptr ) || ( pModelOff != nullptr ) ) {
|
||||
// we got our models, bail out
|
||||
return;
|
||||
}
|
||||
}
|
||||
// if we failed to locate even one state submodel, cry
|
||||
ErrorLog( "Failed to locate sub-model \"" + submodelname + "\" in 3d model \"" + pModel1->NameGet() + "\"" );
|
||||
};
|
||||
|
||||
void TButton::Update()
|
||||
{
|
||||
if (bData != NULL)
|
||||
bOn = (*bData);
|
||||
if (pModelOn)
|
||||
pModelOn->iVisible = bOn;
|
||||
if (pModelOff)
|
||||
pModelOff->iVisible = !bOn;
|
||||
if (iFeedbackBit) // jeżeli generuje informację zwrotną
|
||||
{
|
||||
if (bOn) // zapalenie
|
||||
bool
|
||||
TButton::Load_mapping( cParser &Input ) {
|
||||
|
||||
if( false == Input.getTokens( 2, true, ", " ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string key, value;
|
||||
Input
|
||||
>> key
|
||||
>> value;
|
||||
|
||||
if( key == "soundinc:" ) {
|
||||
m_soundfxincrease = (
|
||||
value != "none" ?
|
||||
TSoundsManager::GetFromName( value, true ) :
|
||||
nullptr );
|
||||
}
|
||||
else if( key == "sounddec:" ) {
|
||||
m_soundfxdecrease = (
|
||||
value != "none" ?
|
||||
TSoundsManager::GetFromName( value, true ) :
|
||||
nullptr );
|
||||
}
|
||||
return true; // return value marks a key: value pair was extracted, nothing about whether it's recognized
|
||||
}
|
||||
|
||||
void
|
||||
TButton::Turn( bool const State ) {
|
||||
|
||||
if( State != m_state ) {
|
||||
|
||||
m_state = State;
|
||||
play();
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
void TButton::Update() {
|
||||
|
||||
if( ( bData != nullptr )
|
||||
&& ( *bData != m_state ) ) {
|
||||
|
||||
m_state = ( *bData );
|
||||
play();
|
||||
}
|
||||
|
||||
if( pModelOn != nullptr ) { pModelOn->iVisible = m_state; }
|
||||
if( pModelOff != nullptr ) { pModelOff->iVisible = (!m_state); }
|
||||
|
||||
if (iFeedbackBit) {
|
||||
// jeżeli generuje informację zwrotną
|
||||
if (m_state) // zapalenie
|
||||
Console::BitsSet(iFeedbackBit);
|
||||
else
|
||||
Console::BitsClear(iFeedbackBit);
|
||||
}
|
||||
};
|
||||
|
||||
void TButton::AssignBool(bool *bValue)
|
||||
{
|
||||
void TButton::AssignBool(bool const *bValue) {
|
||||
|
||||
bData = bValue;
|
||||
}
|
||||
|
||||
void
|
||||
TButton::play() {
|
||||
|
||||
play(
|
||||
m_state == true ?
|
||||
m_soundfxincrease :
|
||||
m_soundfxdecrease );
|
||||
}
|
||||
|
||||
void
|
||||
TButton::play( PSound Sound ) {
|
||||
|
||||
if( Sound == nullptr ) { return; }
|
||||
|
||||
Sound->SetCurrentPosition( 0 );
|
||||
Sound->SetVolume( DSBVOLUME_MAX );
|
||||
Sound->Play( 0, 0, 0 );
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user