1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Player selection menu + major refactoring

This commit is contained in:
nordsoft 2022-09-11 05:03:19 +04:00
parent 480b58c80a
commit 702183c219
26 changed files with 260 additions and 138 deletions

View File

@ -15,16 +15,17 @@ set(editor_SRCS
mapview.cpp
radiopushbutton.cpp
objectbrowser.cpp
inspector.cpp
mapsettings.cpp
playersettings.cpp
playerparams.cpp
scenelayer.cpp
mapcontroller.cpp
validator.cpp
townbulidingswidget.cpp
armywidget.cpp
messagewidget.cpp
inspector/inspector.cpp
inspector/townbulidingswidget.cpp
inspector/armywidget.cpp
inspector/messagewidget.cpp
inspector/rewardswidget.cpp
)
set(editor_HEADERS
@ -43,16 +44,17 @@ set(editor_HEADERS
mapview.h
radiopushbutton.h
objectbrowser.h
inspector.h
mapsettings.h
playersettings.h
playerparams.h
scenelayer.h
mapcontroller.h
validator.h
townbulidingswidget.h
armywidget.h
messagewidget.h
inspector/inspector.h
inspector/townbulidingswidget.h
inspector/armywidget.h
inspector/messagewidget.h
inspector/rewardswidget.h
)
set(editor_FORMS
@ -63,12 +65,13 @@ set(editor_FORMS
playersettings.ui
playerparams.ui
validator.ui
townbulidingswidget.ui
armywidget.ui
messagewidget.ui
inspector/townbulidingswidget.ui
inspector/armywidget.ui
inspector/messagewidget.ui
inspector/rewardswidget.ui
)
assign_source_group(${editor_SRCS} ${editor_HEADERS} VCMI_launcher.rc)
assign_source_group(${editor_SRCS} ${editor_HEADERS} mapeditor.rc)
# Tell CMake to run moc when necessary:
set(CMAKE_AUTOMOC ON)
@ -88,7 +91,7 @@ else()
endif()
if(WIN32)
set(editor_ICON VCMI_launcher.rc)
set(editor_ICON mapeditor.rc)
endif()
add_executable(vcmieditor WIN32 ${editor_SRCS} ${editor_HEADERS} ${editor_UI_HEADERS} ${editor_ICON})

View File

@ -1,110 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="VCMI_launcher" />
<Option pch_mode="0" />
<Option compiler="gcc" />
<Build>
<Target title="Debug Win32">
<Option output="../VCMI_launcher" prefix_auto="1" extension_auto="1" />
<Option working_dir="../" />
<Option object_output="../obj/Launcher/Debug" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add option="-Og" />
</Compiler>
</Target>
<Target title="Release Win32">
<Option output="../VCMI_launcher" prefix_auto="1" extension_auto="1" />
<Option working_dir="../" />
<Option object_output="../obj/Launcher/Release" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-flto" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-flto" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-std=gnu++11" />
<Add option="-isystem $(#boost.include)" />
<Add option="-DBOOST_SYSTEM_NO_DEPRECATED" />
<Add option="-D_WIN32" />
<Add directory="." />
<Add directory="$(#qt.include)" />
<Add directory="$(#qt.include)/QtGui" />
<Add directory="$(#qt.include)/QtCore" />
<Add directory="$(#qt.include)/QtWidgets" />
</Compiler>
<Linker>
<Add option="-lVCMI_lib" />
<Add option="-lQt5Core" />
<Add option="-lQt5Gui" />
<Add option="-lQt5Widgets" />
<Add option="-lQt5Network" />
<Add option="-lboost_filesystem$(#boost.libsuffix)" />
<Add option="-lboost_system$(#boost.libsuffix)" />
<Add directory="../" />
<Add directory="$(#qt.lib)" />
<Add directory="$(#boost.lib)" />
</Linker>
<Unit filename="StdInc.cpp">
<Option compile="0" />
<Option link="0" />
</Unit>
<Unit filename="StdInc.h">
<Option compile="1" />
<Option weight="0" />
</Unit>
<Unit filename="VCMI_launcher.rc">
<Option compilerVar="WINDRES" />
</Unit>
<Unit filename="jsonutils.cpp" />
<Unit filename="jsonutils.h" />
<Unit filename="launcherdirs.cpp" />
<Unit filename="launcherdirs.h" />
<Unit filename="main.cpp" />
<Unit filename="mainwindow_moc.cpp" />
<Unit filename="mainwindow_moc.h" />
<Unit filename="mainwindow_moc.ui" />
<Unit filename="modManager/cdownloadmanager_moc.cpp" />
<Unit filename="modManager/cdownloadmanager_moc.h" />
<Unit filename="modManager/cmodlist.cpp" />
<Unit filename="modManager/cmodlist.h" />
<Unit filename="modManager/cmodlistmodel_moc.cpp" />
<Unit filename="modManager/cmodlistmodel_moc.h" />
<Unit filename="modManager/cmodlistview_moc.cpp" />
<Unit filename="modManager/cmodlistview_moc.h" />
<Unit filename="modManager/cmodlistview_moc.ui" />
<Unit filename="modManager/cmodmanager.cpp" />
<Unit filename="modManager/cmodmanager.h" />
<Unit filename="modManager/imageviewer_moc.cpp" />
<Unit filename="modManager/imageviewer_moc.h" />
<Unit filename="modManager/imageviewer_moc.ui" />
<Unit filename="modManager/qrc_cdownloadmanager_moc.cpp" />
<Unit filename="modManager/qrc_cmodlistmodel_moc.cpp" />
<Unit filename="modManager/qrc_cmodlistview_moc.cpp" />
<Unit filename="modManager/qrc_imageviewer_moc.cpp" />
<Unit filename="qrc_mainwindow_moc.cpp" />
<Unit filename="settingsView/csettingsview_moc.cpp" />
<Unit filename="settingsView/csettingsview_moc.h" />
<Unit filename="settingsView/csettingsview_moc.ui" />
<Unit filename="settingsView/qrc_csettingsview_moc.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

View File

@ -1 +0,0 @@
IDI_ICON1 ICON "VCMI_launcher.ico"

View File

@ -11,7 +11,7 @@
#include "messagewidget.h"
//===============IMPLEMENT OBJECT INITIALIZATION FUNCTIONS================
Initializer::Initializer(CMap * m, CGObjectInstance * o) : map(m)
Initializer::Initializer(CMap * m, CGObjectInstance * o, const PlayerColor & pl) : map(m), defaultPlayer(pl)
{
///IMPORTANT! initialize order should be from base objects to derived objects
INIT_OBJ_TYPE(CGResource);
@ -58,7 +58,7 @@ void Initializer::initialize(CGDwelling * o)
{
if(!o) return;
o->tempOwner = PlayerColor::NEUTRAL;
o->tempOwner = defaultPlayer;
switch(o->ID)
{
@ -73,7 +73,7 @@ void Initializer::initialize(CGGarrison * o)
{
if(!o) return;
o->tempOwner = PlayerColor::NEUTRAL;
o->tempOwner = defaultPlayer;
o->removableUnits = true;
}
@ -81,21 +81,21 @@ void Initializer::initialize(CGShipyard * o)
{
if(!o) return;
o->tempOwner = PlayerColor::NEUTRAL;
o->tempOwner = defaultPlayer;
}
void Initializer::initialize(CGLighthouse * o)
{
if(!o) return;
o->tempOwner = PlayerColor::NEUTRAL;
o->tempOwner = defaultPlayer;
}
void Initializer::initialize(CGHeroInstance * o)
{
if(!o) return;
o->tempOwner = PlayerColor::NEUTRAL;
o->tempOwner = defaultPlayer;
}
void Initializer::initialize(CGTownInstance * o)
@ -141,7 +141,7 @@ void Initializer::initialize(CGMine * o)
{
if(!o) return;
o->tempOwner = PlayerColor::NEUTRAL;
o->tempOwner = defaultPlayer;
o->producedResource = Res::ERes(o->subID);
o->producedQuantity = o->defaultResProduction();
}

View File

@ -37,10 +37,11 @@ public:
DECLARE_OBJ_TYPE(CGLighthouse);
Initializer(CMap *, CGObjectInstance *);
Initializer(CMap *, CGObjectInstance *, const PlayerColor &);
private:
CMap * map;
PlayerColor defaultPlayer;
};
class Inspector

View File

@ -0,0 +1,14 @@
#include "rewardswidget.h"
#include "ui_rewardswidget.h"
RewardsWidget::RewardsWidget(QWidget *parent) :
QDialog(parent),
ui(new Ui::RewardsWidget)
{
ui->setupUi(this);
}
RewardsWidget::~RewardsWidget()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef REWARDSWIDGET_H
#define REWARDSWIDGET_H
#include <QDialog>
namespace Ui {
class RewardsWidget;
}
class RewardsWidget : public QDialog
{
Q_OBJECT
public:
explicit RewardsWidget(QWidget *parent = nullptr);
~RewardsWidget();
private:
Ui::RewardsWidget *ui;
};
#endif // REWARDSWIDGET_H

View File

@ -0,0 +1,18 @@
<ui version="4.0">
<class>RewardsWidget</class>
<widget class="QDialog" name="RewardsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -26,7 +26,7 @@
#include "graphics.h"
#include "windownewmap.h"
#include "objectbrowser.h"
#include "inspector.h"
#include "inspector/inspector.h"
#include "mapsettings.h"
#include "playersettings.h"
#include "validator.h"
@ -137,6 +137,13 @@ MainWindow::MainWindow(QWidget *parent) :
ui->tabWidget->setCurrentIndex(0);
for(int i = 0; i < 8; ++i)
{
connect(getActionPlayer(PlayerColor(i)), &QAction::toggled, this, [&, i](){switchDefaultPlayer(PlayerColor(i));});
}
connect(getActionPlayer(PlayerColor::NEUTRAL), &QAction::toggled, this, [&](){switchDefaultPlayer(PlayerColor::NEUTRAL);});
onPlayersChanged();
show();
}
@ -200,6 +207,8 @@ void MainWindow::initializeMap(bool isNew)
//enable settings
ui->actionMapSettings->setEnabled(true);
ui->actionPlayers_settings->setEnabled(true);
onPlayersChanged();
}
void MainWindow::on_actionOpen_triggered()
@ -869,8 +878,60 @@ void MainWindow::on_actionPlayers_settings_triggered()
auto settingsDialog = new PlayerSettings(controller, this);
settingsDialog->setWindowModality(Qt::WindowModal);
settingsDialog->setModal(true);
connect(settingsDialog, &QDialog::finished, this, &MainWindow::onPlayersChanged);
}
QAction * MainWindow::getActionPlayer(const PlayerColor & player)
{
if(player.getNum() == 0) return ui->actionPlayer_1;
if(player.getNum() == 1) return ui->actionPlayer_2;
if(player.getNum() == 2) return ui->actionPlayer_3;
if(player.getNum() == 3) return ui->actionPlayer_4;
if(player.getNum() == 4) return ui->actionPlayer_5;
if(player.getNum() == 5) return ui->actionPlayer_6;
if(player.getNum() == 6) return ui->actionPlayer_7;
if(player.getNum() == 7) return ui->actionPlayer_8;
return ui->actionNeutral;
}
void MainWindow::switchDefaultPlayer(const PlayerColor & player)
{
if(controller.defaultPlayer == player)
return;
ui->actionNeutral->blockSignals(true);
ui->actionNeutral->setChecked(PlayerColor::NEUTRAL == player);
ui->actionNeutral->blockSignals(false);
for(int i = 0; i < 8; ++i)
{
getActionPlayer(PlayerColor(i))->blockSignals(true);
getActionPlayer(PlayerColor(i))->setChecked(PlayerColor(i) == player);
getActionPlayer(PlayerColor(i))->blockSignals(false);
}
controller.defaultPlayer = player;
}
void MainWindow::onPlayersChanged()
{
if(controller.map())
{
getActionPlayer(PlayerColor::NEUTRAL)->setEnabled(true);
for(int i = 0; i < controller.map()->players.size(); ++i)
getActionPlayer(PlayerColor(i))->setEnabled(controller.map()->players.at(i).canAnyonePlay());
if(!getActionPlayer(controller.defaultPlayer)->isEnabled() || controller.defaultPlayer == PlayerColor::NEUTRAL)
switchDefaultPlayer(PlayerColor::NEUTRAL);
}
else
{
for(int i = 0; i < PlayerColor::PLAYER_LIMIT.getNum(); ++i)
getActionPlayer(PlayerColor(i))->setEnabled(false);
getActionPlayer(PlayerColor::NEUTRAL)->setEnabled(false);
}
}
void MainWindow::enableUndo(bool enable)
{
ui->actionUndo->setEnabled(enable);

View File

@ -91,6 +91,8 @@ private slots:
void on_actionRecreate_obstacles_triggered();
void switchDefaultPlayer(const PlayerColor &);
public slots:
void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected);
@ -99,12 +101,15 @@ public slots:
void enableUndo(bool enable);
void enableRedo(bool enable);
void onSelectionMade(int level, bool anythingSelected);
void onPlayersChanged();
private:
void preparePreview(const QModelIndex &index, bool createNew);
void addGroupIntoCatalog(const std::string & groupName, bool staticOnly);
void addGroupIntoCatalog(const std::string & groupName, bool useCustomName, bool staticOnly, int ID);
QAction * getActionPlayer(const PlayerColor &);
void changeBrushState(int idx);
void setTitle();

View File

@ -81,9 +81,24 @@
<addaction name="actionRedo"/>
<addaction name="actionErase"/>
</widget>
<widget class="QMenu" name="menuPlayer">
<property name="title">
<string>Player</string>
</property>
<addaction name="actionNeutral"/>
<addaction name="actionPlayer_1"/>
<addaction name="actionPlayer_2"/>
<addaction name="actionPlayer_3"/>
<addaction name="actionPlayer_4"/>
<addaction name="actionPlayer_5"/>
<addaction name="actionPlayer_6"/>
<addaction name="actionPlayer_7"/>
<addaction name="actionPlayer_8"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuMap"/>
<addaction name="menuPlayer"/>
</widget>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
@ -902,7 +917,7 @@
<string>Erase</string>
</property>
<property name="shortcut">
<string>Del</string>
<string>Backspace, Del</string>
</property>
</action>
<action name="actionNeutral">
@ -912,6 +927,9 @@
<property name="text">
<string>Neutral</string>
</property>
<property name="shortcut">
<string>Ctrl+0</string>
</property>
</action>
<action name="actionValidate">
<property name="text">
@ -934,6 +952,94 @@
<string>Recreate obstacles</string>
</property>
</action>
<action name="actionPlayer_1">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 1</string>
</property>
<property name="shortcut">
<string>Ctrl+1</string>
</property>
</action>
<action name="actionPlayer_2">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 2</string>
</property>
<property name="shortcut">
<string>Ctrl+2</string>
</property>
</action>
<action name="actionPlayer_3">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 3</string>
</property>
<property name="shortcut">
<string>Ctrl+3</string>
</property>
</action>
<action name="actionPlayer_4">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 4</string>
</property>
<property name="shortcut">
<string>Ctrl+4</string>
</property>
</action>
<action name="actionPlayer_5">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 5</string>
</property>
<property name="shortcut">
<string>Ctrl+5</string>
</property>
</action>
<action name="actionPlayer_6">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 6</string>
</property>
<property name="shortcut">
<string>Ctrl+6</string>
</property>
</action>
<action name="actionPlayer_7">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 7</string>
</property>
<property name="shortcut">
<string>Ctrl+7</string>
</property>
</action>
<action name="actionPlayer_8">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Player 8</string>
</property>
<property name="shortcut">
<string>Ctrl+8</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -13,7 +13,7 @@
#include "scenelayer.h"
#include "maphandler.h"
#include "mainwindow.h"
#include "inspector.h"
#include "inspector/inspector.h"
MapController::MapController(MainWindow * m): main(m)
@ -342,7 +342,7 @@ void MapController::commitObjectCreate(int level)
return; //maplimit reached
}
Initializer init(map(), newObj);
Initializer init(map(), newObj, defaultPlayer);
_map->getEditManager()->insertObject(newObj);
_mapHandler->invalidate(newObj);

View File

@ -45,6 +45,8 @@ public:
void undo();
void redo();
PlayerColor defaultPlayer;
private:
std::unique_ptr<CMap> _map;
std::unique_ptr<MapHandler> _mapHandler;

BIN
mapeditor/mapeditor.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

1
mapeditor/mapeditor.rc Normal file
View File

@ -0,0 +1 @@
IDI_ICON1 ICON "mapeditor.ico"

View File

@ -2,7 +2,7 @@
#include "scenelayer.h"
#include "mainwindow.h"
#include "../lib/mapping/CMapEditManager.h"
#include "inspector.h"
#include "inspector/inspector.h"
#include "mapview.h"
#include "mapcontroller.h"