2020-11-01 16:45:29 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "TLightBargraph.h"
|
2021-01-17 16:26:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "control.h"
|
|
|
|
#include "loader.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "TPinballTable.h"
|
|
|
|
|
|
|
|
TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGroup(table, groupIndex)
|
|
|
|
{
|
|
|
|
TimerTimeArray = nullptr;
|
|
|
|
TLightBargraph::Reset();
|
|
|
|
if (groupIndex > 0)
|
|
|
|
{
|
|
|
|
float* floatArr = loader::query_float_attribute(groupIndex, 0, 904);
|
|
|
|
if (floatArr)
|
|
|
|
{
|
2021-10-02 16:45:31 +02:00
|
|
|
auto count = 2 * List.size();
|
|
|
|
TimerTimeArray = new float[count];
|
2021-01-17 16:26:03 +01:00
|
|
|
if (TimerTimeArray)
|
|
|
|
{
|
2021-10-02 16:45:31 +02:00
|
|
|
for (auto i = 0u; i < count; ++floatArr)
|
2021-01-17 16:26:03 +01:00
|
|
|
TimerTimeArray[i++] = *floatArr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TLightBargraph::~TLightBargraph()
|
|
|
|
{
|
2021-10-02 16:45:31 +02:00
|
|
|
delete[] TimerTimeArray;
|
2021-01-17 16:26:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TLightBargraph::Message(int code, float value)
|
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case 37:
|
|
|
|
return TimeIndex;
|
|
|
|
case 45:
|
|
|
|
{
|
|
|
|
if (TimerBargraph)
|
|
|
|
{
|
|
|
|
timer::kill(TimerBargraph);
|
|
|
|
TimerBargraph = 0;
|
|
|
|
}
|
|
|
|
auto timeIndex = static_cast<int>(floor(value));
|
2021-10-01 17:55:44 +02:00
|
|
|
auto maxCount = static_cast<int>(List.size()) * 2;
|
2021-01-17 16:26:03 +01:00
|
|
|
if (timeIndex >= maxCount)
|
|
|
|
timeIndex = maxCount - 1;
|
|
|
|
if (timeIndex >= 0)
|
|
|
|
{
|
|
|
|
TLightGroup::Message(45, static_cast<float>(timeIndex / 2));
|
|
|
|
if (!(timeIndex & 1))
|
|
|
|
TLightGroup::Message(46, 0.0);
|
2021-10-07 13:17:43 +02:00
|
|
|
if (TimerTimeArray)
|
|
|
|
TimerBargraph = timer::set(TimerTimeArray[timeIndex], this, BargraphTimerExpired);
|
2021-01-17 16:26:03 +01:00
|
|
|
TimeIndex = timeIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TLightGroup::Message(20, 0.0);
|
|
|
|
TimeIndex = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-09-05 09:17:37 +02:00
|
|
|
case ~MessageCode::SetTiltLock:
|
2021-01-17 16:26:03 +01:00
|
|
|
Reset();
|
|
|
|
break;
|
2022-09-05 09:17:37 +02:00
|
|
|
case ~MessageCode::PlayerChanged:
|
2021-01-17 16:26:03 +01:00
|
|
|
if (TimerBargraph)
|
|
|
|
{
|
|
|
|
timer::kill(TimerBargraph);
|
|
|
|
TimerBargraph = 0;
|
|
|
|
}
|
|
|
|
PlayerTimerIndexBackup[PinballTable->CurrentPlayer] = TimeIndex;
|
|
|
|
Reset();
|
|
|
|
TimeIndex = PlayerTimerIndexBackup[static_cast<int>(floor(value))];
|
|
|
|
if (TimeIndex)
|
|
|
|
{
|
|
|
|
TLightBargraph::Message(45, static_cast<float>(TimeIndex));
|
|
|
|
}
|
|
|
|
break;
|
2022-09-05 09:17:37 +02:00
|
|
|
case ~MessageCode::Reset:
|
2021-01-17 16:26:03 +01:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
int* playerPtr = PlayerTimerIndexBackup;
|
|
|
|
for (auto index = 0; index < PinballTable->PlayerCount; ++index)
|
|
|
|
{
|
|
|
|
*playerPtr = TimeIndex;
|
|
|
|
|
|
|
|
++playerPtr;
|
|
|
|
}
|
2022-09-05 09:17:37 +02:00
|
|
|
TLightGroup::Message(~MessageCode::Reset, value);
|
2021-01-17 16:26:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
TLightGroup::Message(code, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TLightBargraph::Reset()
|
|
|
|
{
|
|
|
|
if (TimerBargraph)
|
|
|
|
{
|
|
|
|
timer::kill(TimerBargraph);
|
|
|
|
TimerBargraph = 0;
|
|
|
|
}
|
|
|
|
TimeIndex = 0;
|
|
|
|
TLightGroup::Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TLightBargraph::BargraphTimerExpired(int timerId, void* caller)
|
|
|
|
{
|
|
|
|
auto bar = static_cast<TLightBargraph*>(caller);
|
|
|
|
bar->TimerBargraph = 0;
|
|
|
|
if (bar->TimeIndex)
|
|
|
|
{
|
|
|
|
bar->Message(45, static_cast<float>(bar->TimeIndex - 1));
|
|
|
|
control::handler(60, bar);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bar->Message(20, 0.0);
|
|
|
|
control::handler(47, bar);
|
|
|
|
}
|
|
|
|
}
|