From e8b93f6cdaa93b09e5605680958fd18e0526188d Mon Sep 17 00:00:00 2001 From: Fiftytwo Date: Sat, 25 Nov 2017 03:09:47 +0100 Subject: [PATCH] Add Builder interface --- src/common/event.cpp | 1 + src/common/event.h | 1 + src/common/restext.cpp | 1 + src/ui/object_interface.cpp | 137 +++++++++++++++++++++++++++++++++++- src/ui/object_interface.h | 2 + 5 files changed, 141 insertions(+), 1 deletion(-) diff --git a/src/common/event.cpp b/src/common/event.cpp index b1cd84b4..e83bfeb9 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -524,6 +524,7 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_CODE_BATTLE_SPECTATOR] = "EVENT_CODE_BATTLE_SPECTATOR"; EVENT_TYPE_TEXT[EVENT_OBJECT_RBUILDER] = "EVENT_OBJECT_RBUILDER"; + EVENT_TYPE_TEXT[EVENT_OBJECT_BUILD] = "EVENT_OBJECT_BUILD"; } std::string ParseEventType(EventType eventType) diff --git a/src/common/event.h b/src/common/event.h index b1b309b8..95c0fc85 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -595,6 +595,7 @@ enum EventType EVENT_CODE_BATTLE_SPECTATOR = 2201, //!< button that controls the code battle spectator camera EVENT_OBJECT_RBUILDER = 2300, + EVENT_OBJECT_BUILD = 2301, //! Maximum value of standard events EVENT_STD_MAX, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 8d97e0c0..635c56dd 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -378,6 +378,7 @@ void InitializeRestext() stringsEvent[EVENT_OBJECT_TERRAFORM] = TR("Thump (\\key action;)"); stringsEvent[EVENT_OBJECT_FIRE] = TR("Shoot (\\key action;)"); stringsEvent[EVENT_OBJECT_SPIDEREXPLO] = TR("Explode (\\key action;)"); + stringsEvent[EVENT_OBJECT_BUILD] = TR("Build (\\key action;)"); stringsEvent[EVENT_OBJECT_RECOVER] = TR("Recycle (\\key action;)"); stringsEvent[EVENT_OBJECT_BEGSHIELD] = TR("Extend shield (\\key action;)"); stringsEvent[EVENT_OBJECT_ENDSHIELD] = TR("Withdraw shield (\\key action;)"); diff --git a/src/ui/object_interface.cpp b/src/ui/object_interface.cpp index bd2a5be9..d1105a9b 100644 --- a/src/ui/object_interface.cpp +++ b/src/ui/object_interface.cpp @@ -100,6 +100,8 @@ CObjectInterface::CObjectInterface(COldObject* object) m_manipStyle = EVENT_OBJECT_MFRONT; m_selScript = 0; + + m_buildInterface = false; } // Object's destructor. @@ -620,6 +622,12 @@ bool CObjectInterface::EventProcess(const Event &event) { err = m_taskExecutor->StartTaskSpiderExplo(); } + + if ( action == EVENT_OBJECT_BUILD ) + { + m_buildInterface = !m_buildInterface; + UpdateInterface(); + } if ( action == EVENT_OBJECT_PEN0 ) // up { @@ -1409,6 +1417,87 @@ bool CObjectInterface::CreateInterface(bool bSelect) pw->CreateGroup(pos, ddim, 16, EVENT_OBJECT_CORNERdr); } + if ( (type == OBJECT_MOBILEfb || + type == OBJECT_MOBILEtb || + type == OBJECT_MOBILEwb || + type == OBJECT_MOBILEib) && // builder? + !m_object->GetTrainer() ) + { + pos.x = ox+sx*7.7f; + pos.y = oy+sy*0.5f; + pb = pw->CreateButton(pos, dim, 192+4, EVENT_OBJECT_BUILD); + pb->SetImmediat(true); + DefaultEnter(pw, EVENT_OBJECT_BUILD); + + pos.x = 0.0f; + pos.y = oy+sy*2.6f; + ddim.x = 214.5f/640.0f; + ddim.y = 66.0f/480.0f; + pw->CreateGroup(pos, ddim, 6, EVENT_WINDOW3); + + ddim.x = dim.x*0.9f; + ddim.y = dim.y*0.9f; + pos.y = oy+sy*3.6f; + + pos.x = ox+sx*0.0f; + pw->CreateButton(pos, ddim, 128+35, EVENT_OBJECT_BRESEARCH); + DeadInterface(pw, EVENT_OBJECT_BRESEARCH, m_main->CanBuild(OBJECT_RESEARCH, m_object->GetTeam())); + + pos.x = ox+sx*0.9f; + pw->CreateButton(pos, ddim, 128+32, EVENT_OBJECT_BFACTORY); + DeadInterface(pw, EVENT_OBJECT_BFACTORY, m_main->CanBuild(OBJECT_FACTORY, m_object->GetTeam())); + + pos.x = ox+sx*1.8f; + pw->CreateButton(pos, ddim, 128+34, EVENT_OBJECT_BCONVERT); + DeadInterface(pw, EVENT_OBJECT_BCONVERT, m_main->CanBuild(OBJECT_CONVERT, m_object->GetTeam())); + + pos.x = ox+sx*2.7f; + pw->CreateButton(pos, ddim, 128+36, EVENT_OBJECT_BSTATION); + DeadInterface(pw, EVENT_OBJECT_BSTATION, m_main->CanBuild(OBJECT_STATION, m_object->GetTeam())); + + pos.x = ox+sx*3.6f; + pw->CreateButton(pos, ddim, 128+40, EVENT_OBJECT_BRADAR); + DeadInterface(pw, EVENT_OBJECT_BRADAR, m_main->CanBuild(OBJECT_RADAR, m_object->GetTeam())); + + pos.x = ox+sx*4.5f; + pw->CreateButton(pos, ddim, 128+41, EVENT_OBJECT_BREPAIR); + DeadInterface(pw, EVENT_OBJECT_BREPAIR, m_main->CanBuild(OBJECT_REPAIR, m_object->GetTeam())); + + pos.x = ox+sx*5.4f; + pw->CreateButton(pos, ddim, 128+44, EVENT_OBJECT_BINFO); + DeadInterface(pw, EVENT_OBJECT_BINFO, m_main->CanBuild(OBJECT_INFO, m_object->GetTeam())); + + pos.y = oy+sy*2.7f; + + pos.x = ox+sx*0.0f; + pw->CreateButton(pos, ddim, 128+37, EVENT_OBJECT_BTOWER); + DeadInterface(pw, EVENT_OBJECT_BTOWER, m_main->CanBuild(OBJECT_TOWER, m_object->GetTeam())); + + pos.x = ox+sx*0.9f; + pw->CreateButton(pos, ddim, 128+39, EVENT_OBJECT_BENERGY); + DeadInterface(pw, EVENT_OBJECT_BENERGY, m_main->CanBuild(OBJECT_ENERGY, m_object->GetTeam())); + + pos.x = ox+sx*1.8f; + pw->CreateButton(pos, ddim, 128+33, EVENT_OBJECT_BDERRICK); + DeadInterface(pw, EVENT_OBJECT_BDERRICK, m_main->CanBuild(OBJECT_DERRICK, m_object->GetTeam())); + + pos.x = ox+sx*2.7f; + pw->CreateButton(pos, ddim, 128+42, EVENT_OBJECT_BNUCLEAR); + DeadInterface(pw, EVENT_OBJECT_BNUCLEAR, m_main->CanBuild(OBJECT_NUCLEAR, m_object->GetTeam())); + + pos.x = ox+sx*3.6f; + pw->CreateButton(pos, ddim, 128+38, EVENT_OBJECT_BLABO); + DeadInterface(pw, EVENT_OBJECT_BLABO, m_main->CanBuild(OBJECT_LABO, m_object->GetTeam())); + + pos.x = ox+sx*4.5f; + pw->CreateButton(pos, ddim, 128+46, EVENT_OBJECT_BPARA); + DeadInterface(pw, EVENT_OBJECT_BPARA, m_main->CanBuild(OBJECT_PARA, m_object->GetTeam())); + + pos.x = ox+sx*5.4f; + pw->CreateButton(pos, ddim, 128+41, EVENT_OBJECT_BDESTROYER); + DeadInterface(pw, EVENT_OBJECT_BDESTROYER, m_main->CanBuild(OBJECT_DESTROYER, m_object->GetTeam())); + + } UpdateInterface(); m_lastUpdateTime = 0.0f; UpdateInterface(0.0f); @@ -1668,6 +1757,7 @@ void CObjectInterface::UpdateInterface() EnableInterface(pw, EVENT_OBJECT_TERRAFORM, bEnable); EnableInterface(pw, EVENT_OBJECT_RECOVER, bEnable); EnableInterface(pw, EVENT_OBJECT_FIRE, bEnable); + EnableInterface(pw, EVENT_OBJECT_BUILD, bEnable); EnableInterface(pw, EVENT_OBJECT_SPIDEREXPLO, bEnable); EnableInterface(pw, EVENT_OBJECT_RESET, bEnable); EnableInterface(pw, EVENT_OBJECT_PEN0, bEnable); @@ -1682,7 +1772,11 @@ void CObjectInterface::UpdateInterface() EnableInterface(pw, EVENT_OBJECT_REC, bEnable); EnableInterface(pw, EVENT_OBJECT_STOP, bEnable); - if ( type == OBJECT_HUMAN ) // builder? + if ( type == OBJECT_HUMAN || // builder? + type == OBJECT_MOBILEfb || + type == OBJECT_MOBILEtb || + type == OBJECT_MOBILEwb || + type == OBJECT_MOBILEib ) { EnableInterface(pw, EVENT_OBJECT_BFACTORY, bEnable); EnableInterface(pw, EVENT_OBJECT_BDERRICK, bEnable); @@ -1733,6 +1827,47 @@ void CObjectInterface::UpdateInterface() ps->SetVisibleValue((RADIUS_SHIELD_MIN/g_unit)+dynamic_cast(m_object)->GetShieldRadius()*((RADIUS_SHIELD_MAX-RADIUS_SHIELD_MIN)/g_unit)); } } + + if ( type == OBJECT_MOBILEfb || + type == OBJECT_MOBILEtb || + type == OBJECT_MOBILEwb || + type == OBJECT_MOBILEib ) // builder? + { + if(!bEnable) m_buildInterface = false; + CheckInterface(pw, EVENT_OBJECT_BUILD, m_buildInterface); + + pb = static_cast< CButton* >(pw->SearchControl(EVENT_WINDOW3)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BFACTORY)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BDERRICK)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BCONVERT)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BSTATION)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BREPAIR)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BTOWER)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BRESEARCH)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BRADAR)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BENERGY)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BLABO)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BNUCLEAR)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BPARA)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BDESTROYER)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + pb = static_cast< CButton* >(pw->SearchControl(EVENT_OBJECT_BINFO)); + pb->SetState(STATE_VISIBLE, m_buildInterface); + } bFly = bEnable; if ( bFly && (type == OBJECT_HUMAN || type == OBJECT_TECH) ) diff --git a/src/ui/object_interface.h b/src/ui/object_interface.h index a35638a4..84d4fc76 100644 --- a/src/ui/object_interface.h +++ b/src/ui/object_interface.h @@ -120,6 +120,8 @@ protected: float m_lastAlarmTime; int m_soundChannelAlarm; int m_flagColor; + + bool m_buildInterface; }; } // namespace Ui