mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Add some demo player shortcuts
This commit is contained in:
parent
3ac2e0a06a
commit
6e880644af
|
@ -61,7 +61,9 @@ public:
|
|||
~IDemoPlayer() {}
|
||||
virtual void SetSpeed(float Speed) = 0;
|
||||
virtual void SetSpeedIndex(int Offset) = 0;
|
||||
virtual int SetPos(float Percent) = 0;
|
||||
virtual int SeekPercent(float Percent) = 0;
|
||||
virtual int SeekTime(float Seconds) = 0;
|
||||
virtual int SetPos(int WantedTick) = 0;
|
||||
virtual void Pause() = 0;
|
||||
virtual void Unpause() = 0;
|
||||
virtual bool IsPlaying() const = 0;
|
||||
|
|
|
@ -778,33 +778,40 @@ int CDemoPlayer::Play()
|
|||
return 0;
|
||||
}
|
||||
|
||||
int CDemoPlayer::SetPos(float Percent)
|
||||
int CDemoPlayer::SeekPercent(float Percent)
|
||||
{
|
||||
int WantedTick = m_Info.m_Info.m_FirstTick + ((m_Info.m_Info.m_LastTick - m_Info.m_Info.m_FirstTick) * Percent);
|
||||
return SetPos(WantedTick);
|
||||
}
|
||||
|
||||
int CDemoPlayer::SeekTime(float Seconds)
|
||||
{
|
||||
int WantedTick = m_Info.m_Info.m_CurrentTick + (Seconds * SERVER_TICK_SPEED);
|
||||
return SetPos(WantedTick);
|
||||
}
|
||||
|
||||
int CDemoPlayer::SetPos(int WantedTick)
|
||||
{
|
||||
int Keyframe;
|
||||
int WantedTick;
|
||||
if(!m_File)
|
||||
return -1;
|
||||
|
||||
// -5 because we have to have a current tick and previous tick when we do the playback
|
||||
WantedTick = m_Info.m_Info.m_FirstTick + (int)((m_Info.m_Info.m_LastTick-m_Info.m_Info.m_FirstTick)*Percent) - 5;
|
||||
|
||||
Keyframe = (int)(m_Info.m_SeekablePoints*Percent);
|
||||
|
||||
if(Keyframe < 0 || Keyframe >= m_Info.m_SeekablePoints)
|
||||
return -1;
|
||||
WantedTick = clamp(WantedTick, m_Info.m_Info.m_FirstTick, m_Info.m_Info.m_LastTick) - 5;
|
||||
|
||||
// get correct key frame
|
||||
if(m_pKeyFrames[Keyframe].m_Tick < WantedTick)
|
||||
while(Keyframe < m_Info.m_SeekablePoints-1 && m_pKeyFrames[Keyframe].m_Tick < WantedTick)
|
||||
Keyframe++;
|
||||
int KeyFrame = 0;
|
||||
while(KeyFrame < m_Info.m_SeekablePoints - 1 && m_pKeyFrames[KeyFrame].m_Tick < WantedTick)
|
||||
{
|
||||
KeyFrame++;
|
||||
}
|
||||
while(KeyFrame > 0 && m_pKeyFrames[KeyFrame].m_Tick > WantedTick)
|
||||
{
|
||||
KeyFrame--;
|
||||
}
|
||||
|
||||
while(Keyframe && m_pKeyFrames[Keyframe].m_Tick > WantedTick)
|
||||
Keyframe--;
|
||||
// seek to the correct key frame
|
||||
io_seek(m_File, m_pKeyFrames[KeyFrame].m_Filepos, IOSEEK_START);
|
||||
|
||||
// seek to the correct keyframe
|
||||
io_seek(m_File, m_pKeyFrames[Keyframe].m_Filepos, IOSEEK_START);
|
||||
|
||||
//m_Info.start_tick = -1;
|
||||
m_Info.m_NextTick = -1;
|
||||
m_Info.m_Info.m_CurrentTick = -1;
|
||||
m_Info.m_PreviousTick = -1;
|
||||
|
|
|
@ -132,7 +132,9 @@ public:
|
|||
int Stop();
|
||||
void SetSpeed(float Speed);
|
||||
void SetSpeedIndex(int Offset);
|
||||
int SetPos(float Percent);
|
||||
int SeekPercent(float Percent);
|
||||
int SeekTime(float Seconds);
|
||||
int SetPos(int WantedTick);
|
||||
const CInfo *BaseInfo() const { return &m_Info.m_Info; }
|
||||
void GetDemoName(char *pBuffer, int BufferSize) const;
|
||||
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers) const;
|
||||
|
|
|
@ -162,18 +162,72 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
}
|
||||
}
|
||||
|
||||
// handle mousewheel independent of active menu
|
||||
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP))
|
||||
// handle keyboard shortcuts independent of active menu
|
||||
|
||||
// increase/decrease speed
|
||||
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP) || Input()->KeyPress(KEY_UP))
|
||||
{
|
||||
DemoPlayer()->SetSpeedIndex(+1);
|
||||
LastSpeedChange = time_get();
|
||||
}
|
||||
else if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN))
|
||||
else if(Input()->KeyPress(KEY_MOUSE_WHEEL_DOWN) || Input()->KeyPress(KEY_DOWN))
|
||||
{
|
||||
DemoPlayer()->SetSpeedIndex(-1);
|
||||
LastSpeedChange = time_get();
|
||||
}
|
||||
|
||||
// pause/unpause
|
||||
if(Input()->KeyPress(KEY_SPACE) || Input()->KeyPress(KEY_RETURN) || Input()->KeyPress(KEY_K))
|
||||
{
|
||||
if(pInfo->m_Paused)
|
||||
{
|
||||
DemoPlayer()->Unpause();
|
||||
}
|
||||
else
|
||||
{
|
||||
DemoPlayer()->Pause();
|
||||
}
|
||||
}
|
||||
|
||||
// seek backward/forward 10/5 seconds
|
||||
if(Input()->KeyPress(KEY_J))
|
||||
{
|
||||
DemoPlayer()->SeekTime(-10.0f);
|
||||
}
|
||||
else if(Input()->KeyPress(KEY_L))
|
||||
{
|
||||
DemoPlayer()->SeekTime(10.0f);
|
||||
}
|
||||
else if(Input()->KeyPress(KEY_LEFT))
|
||||
{
|
||||
DemoPlayer()->SeekTime(-5.0f);
|
||||
}
|
||||
else if(Input()->KeyPress(KEY_RIGHT))
|
||||
{
|
||||
DemoPlayer()->SeekTime(5.0f);
|
||||
}
|
||||
|
||||
// seek to 0-90%
|
||||
const int SeekPercentKeys[] = {KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9};
|
||||
for(unsigned i = 0; i < sizeof(SeekPercentKeys) / sizeof(SeekPercentKeys[0]); i++)
|
||||
{
|
||||
if(Input()->KeyPress(SeekPercentKeys[i]))
|
||||
{
|
||||
DemoPlayer()->SeekPercent(i * 0.1f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// seek to the beginning/end
|
||||
if(Input()->KeyPress(KEY_HOME))
|
||||
{
|
||||
DemoPlayer()->SeekPercent(0.0f);
|
||||
}
|
||||
else if(Input()->KeyPress(KEY_END))
|
||||
{
|
||||
DemoPlayer()->SeekPercent(1.0f);
|
||||
}
|
||||
|
||||
TotalHeight = SeekBarHeight+ButtonbarHeight+NameBarHeight+Margins*3;
|
||||
|
||||
// render speed info
|
||||
|
@ -286,7 +340,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
//PrevAmount = Amount;
|
||||
m_pClient->OnReset();
|
||||
m_pClient->m_SuppressEvents = true;
|
||||
DemoPlayer()->SetPos(Amount);
|
||||
DemoPlayer()->SeekPercent(Amount);
|
||||
m_pClient->m_SuppressEvents = false;
|
||||
m_pClient->m_pMapLayersBackGround->EnvelopeUpdate();
|
||||
m_pClient->m_pMapLayersForeGround->EnvelopeUpdate();
|
||||
|
@ -299,7 +353,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
PrevAmount = Amount;
|
||||
m_pClient->OnReset();
|
||||
m_pClient->m_SuppressEvents = true;
|
||||
DemoPlayer()->SetPos(Amount);
|
||||
DemoPlayer()->SeekPercent(Amount);
|
||||
m_pClient->m_SuppressEvents = false;
|
||||
m_pClient->m_pMapLayersBackGround->EnvelopeUpdate();
|
||||
m_pClient->m_pMapLayersForeGround->EnvelopeUpdate();
|
||||
|
@ -321,7 +375,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
{
|
||||
m_pClient->OnReset();
|
||||
DemoPlayer()->Pause();
|
||||
DemoPlayer()->SetPos(0);
|
||||
DemoPlayer()->SeekPercent(0.0f);
|
||||
}
|
||||
|
||||
bool IncreaseDemoSpeed = false, DecreaseDemoSpeed = false;
|
||||
|
@ -332,15 +386,16 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
// combined play and pause button
|
||||
ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar);
|
||||
static int s_PlayPauseButton = 0;
|
||||
if(!pInfo->m_Paused)
|
||||
if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_PAUSE, false, &Button, CUI::CORNER_ALL))
|
||||
{
|
||||
if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_PAUSE, false, &Button, CUI::CORNER_ALL))
|
||||
DemoPlayer()->Pause();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_PLAY, false, &Button, CUI::CORNER_ALL))
|
||||
if(pInfo->m_Paused)
|
||||
{
|
||||
DemoPlayer()->Unpause();
|
||||
}
|
||||
else
|
||||
{
|
||||
DemoPlayer()->Pause();
|
||||
}
|
||||
}
|
||||
|
||||
// stop button
|
||||
|
@ -352,7 +407,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
|
|||
{
|
||||
m_pClient->OnReset();
|
||||
DemoPlayer()->Pause();
|
||||
DemoPlayer()->SetPos(0);
|
||||
DemoPlayer()->SeekPercent(0.0f);
|
||||
}
|
||||
|
||||
// slowdown
|
||||
|
|
Loading…
Reference in a new issue