309 lines
12 KiB
C++
309 lines
12 KiB
C++
// This file is part of c-evo-evo.
|
|
//
|
|
// This software is governed by the CeCILL license under French law and
|
|
// abiding by the rules of distribution of free software. You can use,
|
|
// modify and/or redistribute the software under the terms of the CeCILL
|
|
// license as circulated by CEA, CNRS and INRIA at the following URL
|
|
// "http://www.cecill.info".
|
|
//
|
|
// As a counterpart to the access to the source code and rights to copy,
|
|
// modify and redistribute granted by the license, users are provided only
|
|
// with a limited warranty and the software's author, the holder of the
|
|
// economic rights, and the successive licensors have only limited
|
|
// liability.
|
|
//
|
|
// In this respect, the user's attention is drawn to the risks associated
|
|
// with loading, using, modifying and/or developing or reproducing the
|
|
// software by the user in light of its specific status of free software,
|
|
// that may mean that it is complicated to manipulate, and that also
|
|
// therefore means that it is reserved for developers and experienced
|
|
// professionals having in-depth computer knowledge. Users are therefore
|
|
// encouraged to load and test the software's suitability as regards their
|
|
// requirements in conditions enabling the security of their systems and/or
|
|
// data to be ensured and, more generally, to use and operate it in the
|
|
// same conditions as regards security.
|
|
//
|
|
// The fact that you are presently reading this means that you have had
|
|
// knowledge of the CeCILL license and that you accept its terms.
|
|
|
|
#pragma once
|
|
|
|
// TMainScreen equivalent - PARTIAL PORT (session 1 of what will be a many-
|
|
// session effort, see /memories/repo/cevo-evo-game.md for the full 183-
|
|
// method inventory + proposed 10-file split). This slice only covers: the
|
|
// 17 lazy dialog accessors, arrangeDialog()/arrangeDialogs(), and the
|
|
// handful of small cross-dialog methods (dipCall/offerCall/
|
|
// contactRefused/updateViews/setAIName/rememberPeaceViolation) that every
|
|
// other LocalPlayer dialog already has a `Term::mainScreenXxx`
|
|
// std::function injection point standing in for - this class's
|
|
// constructor wires all of those through to real methods below. The full
|
|
// map/panel/menu system (MainOffscreenPaint/PanelPaint/Client() etc.) is
|
|
// NOT part of this slice and remains future work - this header is kept
|
|
// SEPARATE from the widely-included Term.h specifically so consumers that
|
|
// only need the `Term::mainScreen` pointer don't have to transitively
|
|
// include all 17 dialog headers below.
|
|
|
|
#include "Battle.h"
|
|
#include "Cevo/CevoArea.h"
|
|
#include "Cevo/CevoButtonB.h"
|
|
#include "Cevo/CevoButtonC.h"
|
|
#include "Cevo/CevoEOTButton.h"
|
|
#include "Cevo/CevoPVScrollBar.h"
|
|
#include "CityScreen.h"
|
|
#include "CityType.h"
|
|
#include "Diagram.h"
|
|
#include "Draft.h"
|
|
#include "Enhance.h"
|
|
#include "Help.h"
|
|
#include "IsoEngine.h"
|
|
#include "Log.h"
|
|
#include "MiniMap.h"
|
|
#include "MessgEx.h"
|
|
#include "NatStat.h"
|
|
#include "Nego.h"
|
|
#include "Rates.h"
|
|
#include "Select.h"
|
|
#include "TechTree.h"
|
|
#include "Term.h"
|
|
#include "UnitStat.h"
|
|
#include "Wonders.h"
|
|
|
|
#include <QPoint>
|
|
#include <QRegion>
|
|
#include <QTimer>
|
|
|
|
#include <array>
|
|
#include <memory>
|
|
|
|
namespace Cevo {
|
|
namespace Term {
|
|
|
|
class MainScreen : public DrawDlg {
|
|
Q_OBJECT
|
|
public:
|
|
explicit MainScreen(QWidget *parent = nullptr);
|
|
~MainScreen() override;
|
|
|
|
Wonders::WondersDlg &wondersDlg();
|
|
TechTree::TechTreeDlg &techTreeDlg();
|
|
Enhance::EnhanceDlg &enhanceDlg();
|
|
Nego::NegoDlg &negoDlg();
|
|
CityType::CityTypeDlg &cityTypeDlg();
|
|
Diagram::DiaDlg &diaDlg();
|
|
CityScreen::CityDlg &cityDlg();
|
|
Rates::RatesDlg &ratesDlg();
|
|
Battle::BattleDlg &battleDlg();
|
|
NatStat::NatStatDlg &natStatDlg();
|
|
UnitStat::UnitStatDlg &unitStatDlg();
|
|
Draft::DraftDlg &draftDlg();
|
|
Select::ModalSelectDlg &modalSelectDlg();
|
|
Select::ListDlg &listDlg();
|
|
MessgEx::MessgExDlg &messgExDlg();
|
|
Help::HelpDlg &helpDlg();
|
|
Cevo::LogDlg &logDlg();
|
|
|
|
// Positions a just-created persistent dialog relative to the (not yet
|
|
// ported) main screen's primary monitor - self-contained, doesn't
|
|
// need the real map/panel to exist.
|
|
void arrangeDialog(BufferedDrawDlg *form);
|
|
void arrangeDialogs();
|
|
|
|
int dipCall(int command);
|
|
int offerCall(TOffer &offer);
|
|
// TODO: needs PanelPaint/the real main map (not ported yet) - only
|
|
// the already-portable side (ListDlg::ecoChange()/NatStatDlg::
|
|
// ecoChange()/CityDlg::smartUpdateContent()) runs for now.
|
|
void updateViews(bool updateCityScreen = false);
|
|
bool contactRefused(int p, const QString &item);
|
|
// Repaints the map, minimap and panel from scratch.
|
|
void repaintAll();
|
|
void setAIName(int p, const QString &name);
|
|
void rememberPeaceViolation();
|
|
// Term.pas's GetTribeList(): fills unusedTribeFiles from the Tribes directory.
|
|
void getTribeList();
|
|
// Picks (at random among the best) the unused tribe whose colour differs most from the tribes in play.
|
|
int chooseUnusedTribe();
|
|
void showEnemyShipChange(const TShowShipChange &showShipChange);
|
|
// Term.pas's InitModule()/DoneModule(): one-time asset/table setup
|
|
// (advance icons, StdUnits graphics, smallImp).
|
|
void initModule();
|
|
void doneModule();
|
|
// Term.pas's TMainScreen.Client(): the in-process client entry point the
|
|
// server calls for the human player. See Term.MainScreen.Client.cpp for
|
|
// which commands are served so far.
|
|
void client(int command, int newPlayer, void *data);
|
|
// Term.pas's EndNego(): leaves the negotiation screen.
|
|
void endNego();
|
|
// Term.pas's ZoomToCity()/CityClosed(): open the city screen for a city
|
|
// and refocus once it is closed.
|
|
bool zoomToCity(int loc, bool nextUnitOnClose = false, int showEvent = 0);
|
|
void cityClosed(int activateUix, bool stepFocus = false, bool selectFocus = false);
|
|
|
|
// ---- Map view (Term.MainScreen.Window.cpp) ----
|
|
// Scrolls the base map position by (dx, dy) tiles and repaints.
|
|
void scroll(int dx, int dy);
|
|
// Puts location `loc` at pixel `mapPos` of the map view.
|
|
void setMapPos(int loc, QPoint mapPos);
|
|
void centre(int loc);
|
|
int locationOfScreenPixel(int x, int y) const;
|
|
int getCenterLoc() const;
|
|
void setTroopLoc(int loc);
|
|
void paintLoc(int loc, int radius = 0);
|
|
void paintLocBeforeMove(int fromLoc);
|
|
void paintLocTemp(int loc, PaintLocTempStyle style = PaintLocTempStyle::Normal);
|
|
void paintDestination();
|
|
void paintAll();
|
|
void paintAllMaps();
|
|
void panelPaint();
|
|
void setUnFocus(int uix);
|
|
void focusOnLoc(int loc, int options = 0);
|
|
void setTileSize(IsoEngine::TileSize tileSize, int loc, QPoint mapPos);
|
|
void setTileSizeCenter(IsoEngine::TileSize tileSize);
|
|
void checkTerrainBtnVisible();
|
|
void checkMovieSpeedBtnState();
|
|
void setMapOptions();
|
|
|
|
protected:
|
|
void paintEvent(QPaintEvent *event) override;
|
|
void resizeEvent(QResizeEvent *event) override;
|
|
void showEvent(QShowEvent *event) override;
|
|
void closeEvent(QCloseEvent *event) override;
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
|
|
private:
|
|
void createControls();
|
|
void resizeControls();
|
|
void arrangeMidPanel();
|
|
void mainOffscreenPaint();
|
|
void miniMapPaint();
|
|
void copyMiniToPanel();
|
|
void processRect(int x0, int y0, int nx, int ny, int options);
|
|
void timerTick();
|
|
void invalidateRect(int left, int top, int right, int bottom);
|
|
void invalidateMiniMap();
|
|
void initTurn(int newPlayer);
|
|
void nextUnit(int nearLoc, bool autoTurn);
|
|
bool endTurn(bool wasSkipped = false);
|
|
void paintTopBar();
|
|
void paintPanelBackground();
|
|
void paintPanelBrushes();
|
|
void paintPanelSelectedUnit();
|
|
void paintPanelTroops();
|
|
void paintPanelTerrain();
|
|
void paintPanelButtons();
|
|
void paintZoomedTile(Dpi::Bitmap &dst, int x, int y, int loc);
|
|
// Immediately repaints what invalidateRect() collected (Pascal's Update).
|
|
void updateNow();
|
|
|
|
// Map view state (Term.pas's private fields of the same names).
|
|
int m_xw = 0; // base map x
|
|
int m_yw = 0; // base map y
|
|
int m_xwd = 0;
|
|
int m_ywd = 0;
|
|
int m_xwMini = 0;
|
|
int m_ywMini = 0;
|
|
int m_xMidPanel = 0;
|
|
int m_xRightPanel = 0;
|
|
int m_xTroop = 0;
|
|
int m_xTerrain = 0;
|
|
int m_xMini = 0;
|
|
int m_yMini = 0;
|
|
int m_ywmax = 0;
|
|
int m_ywcenter = 0;
|
|
int m_troopLoc = -1;
|
|
int m_trCnt = 0;
|
|
int m_trRow = 0;
|
|
int m_trPitch = 66;
|
|
int m_mapWidth = 0;
|
|
int m_mapOffset = 0;
|
|
int m_mapHeight = 0;
|
|
int m_blinkTime = 0;
|
|
int m_markCityLoc = -1;
|
|
int m_brushLoc = -1;
|
|
bool m_edited = false;
|
|
std::uint32_t m_brushType = fGrass;
|
|
std::array<int, 64> m_trix{}; // what each visible panel slot shows (unit index or brush)
|
|
bool m_mapValid = false;
|
|
bool m_smallScreen = false;
|
|
bool m_turnComplete = false;
|
|
bool m_tracking = false;
|
|
bool m_skipped = false;
|
|
bool m_goOnPhase = false;
|
|
bool m_haveStrategyAdvice = false;
|
|
int m_pTurn = -1;
|
|
bool m_repaintOnResize = false;
|
|
bool m_locCodesChecked = false;
|
|
QRegion m_dirty;
|
|
std::array<std::unique_ptr<Dpi::Bitmap>, nPl> m_aiLogo;
|
|
int m_lastResizeWidth = 0;
|
|
int m_lastResizeHeight = 0;
|
|
|
|
Dpi::Bitmap m_offscreen; // the map view, window-sized
|
|
Dpi::Bitmap m_panel;
|
|
Dpi::Bitmap m_topBar;
|
|
// Temporarily painted tile (unit blink), drawn over the map layer.
|
|
Dpi::Bitmap m_blinkTile;
|
|
QPoint m_blinkTilePos;
|
|
bool m_blinkTileValid = false;
|
|
std::unique_ptr<IsoEngine::IsoMap> m_mainMap;
|
|
std::unique_ptr<IsoEngine::IsoMap> m_noMap;
|
|
std::unique_ptr<IsoEngine::IsoMap> m_noMapPanel;
|
|
std::unique_ptr<MiniMap> m_miniMap;
|
|
std::unique_ptr<PVScrollBar> m_verticalScrollBar;
|
|
ButtonB *m_unitBtn = nullptr;
|
|
ButtonB *m_unitInfoBtn = nullptr;
|
|
ButtonB *m_terrainBtn = nullptr;
|
|
std::array<ButtonB *, 4> m_movieSpeedBtn{};
|
|
ButtonC *m_mapBtn0 = nullptr;
|
|
ButtonC *m_mapBtn1 = nullptr;
|
|
ButtonC *m_mapBtn4 = nullptr;
|
|
ButtonC *m_mapBtn5 = nullptr;
|
|
ButtonC *m_mapBtn6 = nullptr;
|
|
EOTButton *m_eot = nullptr;
|
|
Area *m_menuArea = nullptr;
|
|
Area *m_treasuryArea = nullptr;
|
|
Area *m_researchArea = nullptr;
|
|
Area *m_managementArea = nullptr;
|
|
QTimer *m_timer = nullptr;
|
|
// Term.pas's implementation-level state (Jump/pLogo/GameOK/Idle/...).
|
|
std::array<int, nPl> m_jump{};
|
|
int m_pLogo = -1;
|
|
bool m_gameOK = true;
|
|
bool m_idle = false;
|
|
bool m_startRunning = false;
|
|
bool m_firstMovieTurn = true;
|
|
bool m_closable = false;
|
|
int m_movieSpeed = 1;
|
|
std::unique_ptr<Wonders::WondersDlg> m_wondersDlg;
|
|
std::unique_ptr<TechTree::TechTreeDlg> m_techTreeDlg;
|
|
std::unique_ptr<Enhance::EnhanceDlg> m_enhanceDlg;
|
|
std::unique_ptr<Nego::NegoDlg> m_negoDlg;
|
|
std::unique_ptr<CityType::CityTypeDlg> m_cityTypeDlg;
|
|
std::unique_ptr<Diagram::DiaDlg> m_diaDlg;
|
|
std::unique_ptr<CityScreen::CityDlg> m_cityDlg;
|
|
std::unique_ptr<Rates::RatesDlg> m_ratesDlg;
|
|
std::unique_ptr<Battle::BattleDlg> m_battleDlg;
|
|
std::unique_ptr<NatStat::NatStatDlg> m_natStatDlg;
|
|
std::unique_ptr<UnitStat::UnitStatDlg> m_unitStatDlg;
|
|
std::unique_ptr<Draft::DraftDlg> m_draftDlg;
|
|
std::unique_ptr<Select::ModalSelectDlg> m_modalSelectDlg;
|
|
std::unique_ptr<Select::ListDlg> m_listDlg;
|
|
std::unique_ptr<MessgEx::MessgExDlg> m_messgExDlg;
|
|
std::unique_ptr<Help::HelpDlg> m_helpDlg;
|
|
std::unique_ptr<Cevo::LogDlg> m_logDlg;
|
|
};
|
|
|
|
enum class FormAction { Close, Enable, Disable, Update, SmartUpdateContent };
|
|
|
|
// Term.pas's ApplyToVisibleForms(): applies the action to every visible
|
|
// BufferedDrawDlg window.
|
|
void applyToVisibleForms(FormAction formAction);
|
|
|
|
// Term.pas's ChooseResearch(): lets the player pick the next research
|
|
// (including the draft of a new military unit class / far advance). Returns
|
|
// false if the player cancelled.
|
|
bool chooseResearch();
|
|
|
|
} // namespace Term
|
|
} // namespace Cevo
|