From f7ce9d1a41bdeab4f12110c6911f662dc6e06ca3 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 7 Apr 2002 00:26:10 +0000 Subject: [PATCH] Roids/score for planets are now editable --- bs/fleetview.cpp | 32 +++++++++++++++++++++++++++++--- bs/fleetview.h | 1 + bs/planet.cpp | 4 +++- bs/ui/roidseditview.ui | 2 +- bs/ui/roidseditview.ui.h | 38 +++++++++++++++++++------------------- 5 files changed, 53 insertions(+), 24 deletions(-) diff --git a/bs/fleetview.cpp b/bs/fleetview.cpp index d40cfc5..b16c70f 100644 --- a/bs/fleetview.cpp +++ b/bs/fleetview.cpp @@ -55,7 +55,7 @@ FleetView::FleetView(const Fleet* fleet, bool friendly, QWidget *parent, const c m_UnitsLayout = new QGridLayout(m_MainLayout, rows, 6); buildUnitTable(); //QSpacerItem* space = new QSpacerItem(1, 1); - fillTable(); + m_MainLayout->addStretch(10); @@ -63,10 +63,11 @@ FleetView::FleetView(const Fleet* fleet, bool friendly, QWidget *parent, const c { m_RoidsEditView = new RoidsEditView(this); m_MainLayout->addWidget(m_RoidsEditView); + connect(m_RoidsEditView, SIGNAL(changed(const QString&, int)), SLOT(slotRoidsChanged(const QString&, int))); } m_ResourceView = new ResourceView(this); m_MainLayout->addWidget(m_ResourceView); - + fillTable(); } FleetView::~FleetView(){ @@ -189,6 +190,31 @@ void FleetView::fillTable() { m_UnitsEdit[(*i)]->setText(QString("%1").arg(m_Fleet->fleet(i->latin1(), 0))); } + Planet* pl; + if ((pl = dynamic_cast(m_Fleet)) && m_bHome) + { + m_RoidsEditView->setValue(tr("score"),pl->planetScore()); + m_RoidsEditView->setValue(tr("metal"),pl->roids(tr("metal").latin1())); + m_RoidsEditView->setValue(tr("crystal"),pl->roids(tr("crystal").latin1())); + m_RoidsEditView->setValue(tr("eonium"),pl->roids(tr("eonium").latin1())); + m_RoidsEditView->setValue(tr("uninit"),pl->roids(tr("uninit").latin1())); + } +} + +///////////////////////////////////////////////////////////////////// +// +void FleetView::slotRoidsChanged(const QString& type, int value) +{ + Planet* pl; + if ((pl = dynamic_cast(m_Fleet))) + { + if (type == tr("score")) + pl->setPlanetScore(value); + else + { + pl->setRoids(type.latin1(), value); + } + emit fleetChanged(pl); + } } - diff --git a/bs/fleetview.h b/bs/fleetview.h index a2bbaaf..adf5433 100644 --- a/bs/fleetview.h +++ b/bs/fleetview.h @@ -55,6 +55,7 @@ signals: protected slots: void unitsChanged(const QString& number); + void slotRoidsChanged(const QString& type, int value); protected: void findNames(); diff --git a/bs/planet.cpp b/bs/planet.cpp index e0cf514..c72fb4e 100644 --- a/bs/planet.cpp +++ b/bs/planet.cpp @@ -48,7 +48,7 @@ int Planet::roids(std::string type, int tick = 0) const { // const... I would like [] as for const types: int ticks = m_Roids[type].size(); - vectorconst* roids; + vectorconst* roids = 0; for (RoidList::const_iterator i = m_Roids.begin(); i != m_Roids.end(); ++i) { if (i->first == type) @@ -57,6 +57,8 @@ int Planet::roids(std::string type, int tick = 0) const break; } } + if (roids == 0) + return 0; int ticks = roids->size(); diff --git a/bs/ui/roidseditview.ui b/bs/ui/roidseditview.ui index 1df54f1..e64e2a5 100644 --- a/bs/ui/roidseditview.ui +++ b/bs/ui/roidseditview.ui @@ -211,7 +211,7 @@ init() - setValue( const QString & s, unsigned value ) + setValue( const QString & type, unsigned value ) slotValueChanged( const QString & s ) diff --git a/bs/ui/roidseditview.ui.h b/bs/ui/roidseditview.ui.h index d5d8b3b..225af82 100644 --- a/bs/ui/roidseditview.ui.h +++ b/bs/ui/roidseditview.ui.h @@ -11,36 +11,36 @@ void RoidsEditView::init() } -void RoidsEditView::setValue( const QString & s, unsigned value ) +void RoidsEditView::setValue( const QString & type, unsigned value ) { if (type == tr("metal")) - MetalEdit->setText("%1").arg(value); - else if (type == tr("crystall")) - CrystalEdit->setText("%1").arg(value); - else if (type == tr("eoniuml")) - EoniumEdit->setText("%1").arg(value); + MetalEdit->setText(QString("%1").arg(value)); + else if (type == tr("crystal")) + CrystalEdit->setText(QString("%1").arg(value)); + else if (type == tr("eonium")) + EoniumEdit->setText(QString("%1").arg(value)); else if (type == tr("uninit")) - UninitEdit->setText("%1").arg(value); + UninitEdit->setText(QString("%1").arg(value)); else if (type == tr("score")) - ScoreEdit->setText("%1").arg(value); + ScoreEdit->setText(QString("%1").arg(value)); } void RoidsEditView::slotValueChanged( const QString & s ) { - QString type = send()->name(); + QString type = sender()->name(); - if (type == "MetalEdit") - type = tr("metal"); - else if (type == "CrystalEdit") - type = tr("crystal"); - else if (type == "EoniumEdit") - type = tr("eonium"); - else if (type == "UninitEdit") - type = tr("uninit"); - else if (type == "ScoreEdit") - type = tr("score"); + if (type == "MetalEdit") + type = tr("metal"); + else if (type == "CrystalEdit") + type = tr("crystal"); + else if (type == "EoniumEdit") + type = tr("eonium"); + else if (type == "UninitEdit") + type = tr("uninit"); + else if (type == "ScoreEdit") + type = tr("score"); emit changed(type, s.toInt()); } \ No newline at end of file -- 2.39.2