Skip to content

Commit

Permalink
2.0 Release Candidate III
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 6, 2015
1 parent f1fa57a commit 38ce067
Show file tree
Hide file tree
Showing 31 changed files with 2,505 additions and 16 deletions.
11 changes: 9 additions & 2 deletions Robot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ macx
ICON = icon.icns
}

TRANSLATIONS += res/Simplified_Chinese.ts \
res/Traditional_Chinese.ts \
res/English.ts \
res/Japanese.ts

SOURCES += \
main.cpp \
mainwindow.cpp \
Expand All @@ -40,7 +45,8 @@ SOURCES += \
enemy.cpp \
enemyaddwidget.cpp \
enemymanagewidget.cpp \
enemymanagement.cpp
enemymanagement.cpp \
languagemanager.cpp

HEADERS += \
mainwindow.h \
Expand All @@ -67,7 +73,8 @@ HEADERS += \
enemy.h \
enemyaddwidget.h \
enemymanagewidget.h \
enemymanagement.h
enemymanagement.h \
languagemanager.h

RESOURCES += \
res.qrc
8 changes: 4 additions & 4 deletions enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "enemy.h"

#include <QDebug>

Enemy::Enemy() :
m_destory(false)
{
Expand All @@ -44,7 +46,8 @@ QPointF Enemy::target()

void Enemy::setTarget(const QPointF &target)
{
m_target = target;
//Save the target point.
m_target=target;
}

QPointF Enemy::nextStep(bool &reachTarget)
Expand Down Expand Up @@ -75,6 +78,3 @@ void Enemy::setMissionComplete(bool missionAccept)
{
m_missionComplete = missionAccept;
}



3 changes: 2 additions & 1 deletion enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class Enemy : public RobotBase
static QPointF target();

/*!
* \brief Set the target point of the enemy.
* \brief Set the target point of the enemy. All the enemies will move to
* the target point.
* \param target Enemy's target point.
*/
static void setTarget(const QPointF &target);
Expand Down
6 changes: 5 additions & 1 deletion enemyaddwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <QLabel>
#include <QGroupBox>

#include "languagemanager.h"

#include "enemyaddwidget.h"

EnemyAddWidget::EnemyAddWidget(QWidget *parent) :
Expand Down Expand Up @@ -85,6 +87,8 @@ EnemyAddWidget::EnemyAddWidget(QWidget *parent) :
static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
[=]{emit requireClose();});

connect(LanguageManager::instance(), SIGNAL(languageChanged()),
this, SLOT(retranslate()));
retranslate();
}

Expand Down Expand Up @@ -120,7 +124,7 @@ void EnemyAddWidget::retranslate()
m_labels[0]->setText(tr("X:"));
m_labels[1]->setText(tr("Y:"));

m_editArea->setTitle(tr("Robot Initial Status"));
m_editArea->setTitle(tr("Enemy Initial Status"));
}

void EnemyAddWidget::onActionParameterChange()
Expand Down
5 changes: 4 additions & 1 deletion enemymanagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "enemyaddwidget.h"
#include "enemymanagewidget.h"
#include "groundrealtimepreviewer.h"
#include "languagemanager.h"

#include "enemymanagement.h"

Expand Down Expand Up @@ -102,6 +103,8 @@ EnemyManagement::EnemyManagement(QWidget *parent) :
m_stackLayout->addWidget(m_enemyManage);

//Retranslate.
connect(LanguageManager::instance(), SIGNAL(languageChanged()),
this, SLOT(retranslate()));
retranslate();
}

Expand Down Expand Up @@ -171,7 +174,7 @@ void EnemyManagement::setMenuBar(MenuBar *menuBar)
void EnemyManagement::retranslate()
{
m_actions[AddEnemy]->setText(tr("Add enemy"));
m_actions[ManageEnemy]->setText(tr("Manage enemys"));
m_actions[ManageEnemy]->setText(tr("Manage enemies"));

m_previewGroup->setTitle(tr("Previewer"));
}
Expand Down
5 changes: 4 additions & 1 deletion enemymanagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "enemy.h"
#include "groundbase.h"
#include "languagemanager.h"

#include "enemymanagewidget.h"

Expand Down Expand Up @@ -151,6 +152,8 @@ EnemyManageWidget::EnemyManageWidget(QWidget *parent) :
static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
[=]{emit requireClose();});

connect(LanguageManager::instance(), SIGNAL(languageChanged()),
this, SLOT(retranslate()));
retranslate();
}

Expand All @@ -168,7 +171,7 @@ void EnemyManageWidget::retranslate()
m_cancel->setText(tr("Cancel"));
m_deletePoint->setText(tr("Delete"));

m_manageBox->setTitle(tr("Robots Force"));
m_manageBox->setTitle(tr("Enemies Force"));

updateHeader();
}
Expand Down
5 changes: 4 additions & 1 deletion generateground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "groundbase.h"
#include "polygoneditor.h"
#include "groundpreviewer.h"
#include "languagemanager.h"

#include "generateground.h"

Expand Down Expand Up @@ -91,7 +92,7 @@ GenerateGround::GenerateGround(QWidget *parent) :
tr("Barracks border invalid"),
tr("The barracks border must be inside the border.\n"
"You may:\n"
" 1. Enlarge the border."
" 1. Enlarge the border.\n"
" 2. Reduce the barracks."));
return;
}
Expand Down Expand Up @@ -132,6 +133,8 @@ GenerateGround::GenerateGround(QWidget *parent) :
buttonLayout->addWidget(m_cancel);
buttonLayout->addStretch();

connect(LanguageManager::instance(), SIGNAL(languageChanged()),
this, SLOT(retranslate()));
retranslate();
}

Expand Down
25 changes: 20 additions & 5 deletions ground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "menubar.h"
#include "generategroundbase.h"
#include "groundglobal.h"
#include "languagemanager.h"

#include "ground.h"

Expand Down Expand Up @@ -127,6 +128,8 @@ Ground::Ground(QWidget *parent) :
static_cast<void (QAction::*)(bool)>(&QAction::triggered),
[=]{update();});

connect(LanguageManager::instance(), SIGNAL(languageChanged()),
this, SLOT(retranslate()));
retranslate();
}

Expand Down Expand Up @@ -353,29 +356,36 @@ void Ground::onActionUpdateRobot()
{
bool reachTarget=false;
QPointF nextStep=enemy->nextStep(reachTarget);
if((!Enemy::missionComplete()) && reachTarget)

if(reachTarget)
{
if(Enemy::missionComplete())
{
continue;
}
//Set mission complete flag.
Enemy::setMissionComplete(true);
//Generate the four target point.
QList<QPointF> targetPoints;
targetPoints << QPointF(0, 0)
<< QPointF(width(), 0)
<< QPointF(0, height())
<< QPointF(width(), height());
<< QPointF(width(), 0)
<< QPointF(0, height())
<< QPointF(width(), height());
//Set the new target.
for(QPointF point : targetPoints)
{
if(!m_border.containsPoint(point,
Qt::WindingFill))
{
Enemy::setTarget(point);
break;
}
}
//Get the new next step.
nextStep=enemy->nextStep(reachTarget);
//Add next step to steps list.
enemy->setPos(nextStep);
}
//Add next step to steps list.
enemy->setPos(nextStep);
}
}
Expand Down Expand Up @@ -1206,6 +1216,11 @@ void Ground::reset()
update();
}

bool Ground::closeFile()
{
return onActionClose();
}

QList<Robot *> Ground::robotList() const
{
return m_robotList;
Expand Down
6 changes: 6 additions & 0 deletions ground.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public slots:
*/
void reset();

/*!
* \brief Close the current open file.
* \return Success or not.
*/
bool closeFile();

protected:
/*!
* \brief This event handler can be reimplemented in a subclass to receive
Expand Down
93 changes: 93 additions & 0 deletions languagemanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (C) Kreogist Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QAction>
#include <QTranslator>
#include <QSignalMapper>
#include <QApplication>

#include "menubar.h"

#include "languagemanager.h"

#include <QDebug>

LanguageManager *LanguageManager::m_instance=nullptr;

LanguageManager *LanguageManager::instance()
{
return m_instance==nullptr?m_instance=new LanguageManager:m_instance;
}

void LanguageManager::loadLanguages()
{
//Open language list.
QFile languageListFile("://res/languages.json");
if(!languageListFile.open(QIODevice::ReadOnly))
{
return;
}
//Get language translations.
QJsonArray languages=
QJsonDocument::fromJson(languageListFile.readAll()).array();
for(QJsonValue languageData : languages)
{
QJsonArray langaugeArray=languageData.toArray();
//Generate the language action.
QAction *languageAction=new QAction(langaugeArray.at(0).toString(),
this);
//Link the action with the mapper.
connect(languageAction, SIGNAL(triggered()),
m_langaugeMapper, SLOT(map()));
m_langaugeMapper->setMapping(languageAction,
langaugeArray.at(1).toString());
//Add to action list.
m_languageActions.append(languageAction);
}
}

void LanguageManager::setMenuBar(MenuBar *menuBar)
{
//Give the action to menubar.
for(QAction *languageAction : m_languageActions)
{
menuBar->addCategoryAction(MenuBar::Language, languageAction);
}
}

void LanguageManager::onActionLoadLanguage(const QString &languagePath)
{
qApp->removeTranslator(m_translator);
//Load new file.
m_translator->load("://res/"+languagePath);
//Install the new translator.
qApp->installTranslator(m_translator);
//Emit language change signal.
emit languageChanged();
}

LanguageManager::LanguageManager(QObject *parent) :
QObject(parent),
m_langaugeMapper(new QSignalMapper(this)),
m_translator(new QTranslator(this))
{
connect(m_langaugeMapper, SIGNAL(mapped(QString)),
this, SLOT(onActionLoadLanguage(QString)));
}
Loading

0 comments on commit 38ce067

Please sign in to comment.