Make initial scoreboard values editable

master
krzys-h 2017-05-24 12:39:05 +02:00
parent f60108f367
commit 08d87fa975
7 changed files with 83 additions and 24 deletions

View File

@ -1854,9 +1854,10 @@ bool CApplication::GetSceneTestMode()
return m_sceneTest; return m_sceneTest;
} }
void CApplication::SetTextInput(bool textInputEnabled) void CApplication::SetTextInput(bool textInputEnabled, int id)
{ {
if (textInputEnabled) m_textInputEnabled[id] = textInputEnabled;
if (std::any_of(m_textInputEnabled.begin(), m_textInputEnabled.end(), [](std::pair<int, bool> v) { return v.second; }))
{ {
SDL_StartTextInput(); SDL_StartTextInput();
} }

View File

@ -35,6 +35,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
class CEventQueue; class CEventQueue;
@ -245,7 +246,7 @@ public:
//! Enable/disable text input, this toggles the on-screen keyboard on some platforms //! Enable/disable text input, this toggles the on-screen keyboard on some platforms
/** This also allows for writing in CJK languages (not tested!), see https://wiki.libsdl.org/Tutorials/TextInput for detailed explanation */ /** This also allows for writing in CJK languages (not tested!), see https://wiki.libsdl.org/Tutorials/TextInput for detailed explanation */
void SetTextInput(bool textInputEnabled); void SetTextInput(bool textInputEnabled, int id);
//! Moves (warps) the mouse cursor to the specified position (in interface coords) //! Moves (warps) the mouse cursor to the specified position (in interface coords)
void MoveMouse(Math::Point pos); void MoveMouse(Math::Point pos);
@ -403,6 +404,8 @@ protected:
//! Static buffer for putenv locale //! Static buffer for putenv locale
static char m_languageLocale[50]; static char m_languageLocale[50];
std::map<int, bool> m_textInputEnabled;
}; };
template<> CApplication* CSingleton<CApplication>::m_instance; template<> CApplication* CSingleton<CApplication>::m_instance;

View File

@ -2563,6 +2563,7 @@ bool CRobotMain::EventFrame(const Event &event)
if (!m_codeBattleStarted && m_userPause == nullptr) if (!m_codeBattleStarted && m_userPause == nullptr)
{ {
m_codeBattleStarted = true; m_codeBattleStarted = true;
ApplyCodeBattleInterface();
CreateCodeBattleInterface(); CreateCodeBattleInterface();
SetCodeBattleSpectatorMode(true); SetCodeBattleSpectatorMode(true);
@ -5793,7 +5794,7 @@ void CRobotMain::CreateCodeBattleInterface()
int numTeams = m_scoreboard ? GetAllTeams().size() : 0; int numTeams = m_scoreboard ? GetAllTeams().size() : 0;
assert(numTeams < EVENT_SCOREBOARD_MAX-EVENT_SCOREBOARD+1); assert(numTeams < EVENT_SCOREBOARD_MAX-EVENT_SCOREBOARD+1);
float textHeight = m_engine->GetText()->GetAscent(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL); float textHeight = m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL);
ddim.x = 100.0f/640.0f; ddim.x = 100.0f/640.0f;
ddim.y = 100.0f/480.0f + numTeams * textHeight; ddim.y = 100.0f/480.0f + numTeams * textHeight;
@ -5825,18 +5826,59 @@ void CRobotMain::CreateCodeBattleInterface()
pos.y += ddim.y; pos.y += ddim.y;
ddim.y = textHeight; ddim.y = textHeight;
for (int i = 0; i < numTeams; i++) int i = 0;
auto teams = GetAllTeams();
for (auto it = teams.rbegin(); it != teams.rend(); ++it)
{ {
Ui::CLabel* pl; int team = *it;
pl = pw->CreateLabel(pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+0), "XXXXX"); Ui::CControl* pl;
ddim.x = 55.0f/640.0f;
pl = m_codeBattleStarted
? static_cast<Ui::CControl*>(pw->CreateLabel(pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+0), "XXXXX"))
: static_cast<Ui::CControl*>(pw->CreateEdit( pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+0)));
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT); pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pl = pw->CreateLabel(pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+1), "???"); pl->SetFontSize(m_codeBattleStarted ? Gfx::FONT_SIZE_SMALL : Gfx::FONT_SIZE_SMALL*0.75f);
m_codeBattleStarted ? pl->SetName(GetTeamName(team)) : static_cast<Ui::CEdit*>(pl)->SetText(GetTeamName(team));
pos.x += 57.5f/640.0f;
ddim.x = 22.5f/640.0f;
pl = m_codeBattleStarted
? static_cast<Ui::CControl*>(pw->CreateLabel(pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+1), "???"))
: static_cast<Ui::CControl*>(pw->CreateEdit( pos, ddim, 0, static_cast<EventType>(EVENT_SCOREBOARD+2*(numTeams-i-1)+1)));
pl->SetTextAlign(Gfx::TEXT_ALIGN_RIGHT); pl->SetTextAlign(Gfx::TEXT_ALIGN_RIGHT);
pl->SetFontSize(m_codeBattleStarted ? Gfx::FONT_SIZE_SMALL : Gfx::FONT_SIZE_SMALL*0.75f);
m_codeBattleStarted ? pl->SetName(StrUtils::ToString<int>(m_scoreboard->GetScore(team))) : static_cast<Ui::CEdit*>(pl)->SetText(StrUtils::ToString<int>(m_scoreboard->GetScore(team)));
pos.x -= 57.5f/640.0f;
pos.y += ddim.y; pos.y += ddim.y;
i++;
} }
} }
} }
void CRobotMain::ApplyCodeBattleInterface()
{
assert(GetMissionType() == MISSION_CODE_BATTLE);
if (!m_scoreboard) return;
Ui::CWindow* pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW6));
assert(pw != nullptr);
int i = 0;
for (int team : GetAllTeams())
{
Ui::CEdit* pl;
pl = static_cast<Ui::CEdit*>(pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+0)));
assert(pl != nullptr);
m_teamNames[team] = pl->GetText(pl->GetTextLength());
pl = static_cast<Ui::CEdit*>(pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+1)));
assert(pl != nullptr);
m_scoreboard->SetScore(team, StrUtils::FromString<int>(pl->GetText(pl->GetTextLength())));
i++;
}
}
void CRobotMain::UpdateCodeBattleInterface() void CRobotMain::UpdateCodeBattleInterface()
{ {
assert(GetMissionType() == MISSION_CODE_BATTLE); assert(GetMissionType() == MISSION_CODE_BATTLE);
@ -5848,19 +5890,18 @@ void CRobotMain::UpdateCodeBattleInterface()
int i = 0; int i = 0;
for (int team : GetAllTeams()) for (int team : GetAllTeams())
{ {
Ui::CLabel* pl; Ui::CControl* pl;
pl = static_cast<Ui::CLabel*>(pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+0))); pl = pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+0));
assert(pl != nullptr); assert(pl != nullptr);
pl->SetName(GetTeamName(team)); pl->SetName(GetTeamName(team));
pl = static_cast<Ui::CLabel*>(pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+1))); pl = pw->SearchControl(static_cast<EventType>(EVENT_SCOREBOARD+2*i+1));
assert(pl != nullptr); assert(pl != nullptr);
pl->SetName(StrUtils::ToString<int>(m_scoreboard->GetScore(team))); pl->SetName(StrUtils::ToString<int>(m_scoreboard->GetScore(team)));
i++; i++;
} }
} }
void CRobotMain::DestroyCodeBattleInterface() void CRobotMain::DestroyCodeBattleInterface()

View File

@ -518,6 +518,7 @@ protected:
//@{ //@{
void CreateCodeBattleInterface(); void CreateCodeBattleInterface();
void UpdateCodeBattleInterface(); void UpdateCodeBattleInterface();
void ApplyCodeBattleInterface();
void DestroyCodeBattleInterface(); void DestroyCodeBattleInterface();
void SetCodeBattleSpectatorMode(bool mode); void SetCodeBattleSpectatorMode(bool mode);
//@} //@}

View File

@ -106,3 +106,8 @@ int CScoreboard::GetScore(int team)
{ {
return m_score[team]; return m_score[team];
} }
void CScoreboard::SetScore(int team, int points)
{
m_score[team] = points;
}

View File

@ -115,6 +115,7 @@ public:
void AddPoints(int team, int points); void AddPoints(int team, int points);
int GetScore(int team); int GetScore(int team);
void SetScore(int team, int score);
private: private:
std::vector<std::unique_ptr<CScoreboardKillRule>> m_rulesKill = {}; std::vector<std::unique_ptr<CScoreboardKillRule>> m_rulesKill = {};

View File

@ -94,7 +94,7 @@ bool IsBreaker(char c)
bool IsDelimiter(char c) bool IsDelimiter(char c)
{ {
return IsSpace( c ) || IsBreaker( c ); return IsSpace( c ) || IsBreaker( c );
} }
//! Object's constructor. //! Object's constructor.
CEdit::CEdit() CEdit::CEdit()
@ -148,7 +148,7 @@ CEdit::~CEdit()
if (m_bFocus) if (m_bFocus)
{ {
CApplication::GetInstancePointer()->SetTextInput(false); CApplication::GetInstancePointer()->SetTextInput(false, EVENT_OBJECT_PEN3);
} }
} }
@ -520,13 +520,20 @@ bool CEdit::EventProcess(const Event &event)
MouseClick(event.mousePos); MouseClick(event.mousePos);
if ( m_bEdit || m_bHilite ) m_bCapture = true; if ( m_bEdit || m_bHilite ) m_bCapture = true;
} }
m_bFocus = true;
UpdateFocus(); if (!m_bFocus)
{
m_bFocus = true;
UpdateFocus();
}
} }
else else
{ {
m_bFocus = false; if (m_bFocus)
UpdateFocus(); {
m_bFocus = false;
UpdateFocus();
}
} }
} }
@ -730,7 +737,7 @@ int CEdit::MouseDetect(Math::Point mouse)
if ( i >= m_lineFirst+m_lineVisible ) break; if ( i >= m_lineFirst+m_lineVisible ) break;
pos.x = m_pos.x+(10.0f/640.0f); pos.x = m_pos.x+(7.5f/640.0f)*(m_fontSize/Gfx::FONT_SIZE_SMALL);
if ( m_bAutoIndent ) if ( m_bAutoIndent )
{ {
pos.x += indentLength*m_lineIndent[i]; pos.x += indentLength*m_lineIndent[i];
@ -945,7 +952,7 @@ void CEdit::Draw()
if ( i >= m_lineFirst+m_lineVisible ) break; if ( i >= m_lineFirst+m_lineVisible ) break;
pos.x = m_pos.x+(10.0f/640.0f); pos.x = m_pos.x+(7.5f/640.0f)*(m_fontSize/Gfx::FONT_SIZE_SMALL);
if ( m_bAutoIndent ) if ( m_bAutoIndent )
{ {
const char *s = "\t"; // line | dotted const char *s = "\t"; // line | dotted
@ -1107,7 +1114,7 @@ void CEdit::Draw()
{ {
if ( i == m_lineTotal-1 || m_cursor1 < m_lineOffset[i+1] ) if ( i == m_lineTotal-1 || m_cursor1 < m_lineOffset[i+1] )
{ {
pos.x = m_pos.x+(10.0f/640.0f); pos.x = m_pos.x+(7.5f/640.0f)*(m_fontSize/Gfx::FONT_SIZE_SMALL);
if ( m_bAutoIndent ) if ( m_bAutoIndent )
{ {
pos.x += indentLength*m_lineIndent[i]; pos.x += indentLength*m_lineIndent[i];
@ -2767,7 +2774,7 @@ void CEdit::DeleteOne(int dir)
} }
m_len -= hole; m_len -= hole;
m_cursor2 = m_cursor1; m_cursor2 = m_cursor1;
} }
// Delete word // Delete word
@ -3003,7 +3010,7 @@ void CEdit::Justif()
{ {
bDual = false; bDual = false;
width = m_dim.x-(10.0f/640.0f)*2.0f-(m_bMulti?MARGX*2.0f+SCROLL_WIDTH:0.0f); width = m_dim.x-(7.5f/640.0f)*(m_fontSize/Gfx::FONT_SIZE_SMALL)*2.0f-(m_bMulti?MARGX*2.0f+SCROLL_WIDTH:0.0f);
if ( m_bAutoIndent ) if ( m_bAutoIndent )
{ {
width -= indentLength*m_lineIndent[m_lineTotal-1]; width -= indentLength*m_lineIndent[m_lineTotal-1];
@ -3276,7 +3283,7 @@ void CEdit::SetFocus(CControl* control)
void CEdit::UpdateFocus() void CEdit::UpdateFocus()
{ {
CApplication::GetInstancePointer()->SetTextInput(m_bFocus); CApplication::GetInstancePointer()->SetTextInput(m_bFocus, m_eventType);
} }
} }