| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- import QtQuick 2.15
- import QtQuick.Controls 2.15
- import QtQuick.Window 2.15
- import StandardOfIron 1.0
- ApplicationWindow {
- id: mainWindow
- property alias gameView: gameViewItem
- property bool menuVisible: true
- property bool gameStarted: false
- property bool gamePaused: false
- property bool edgeScrollDisabled: false
- property string missionAnnouncementText: ""
- width: 1280
- height: 720
- visibility: Window.FullScreen
- visible: true
- title: qsTr("Standard of Iron - RTS Game")
- color: Theme.bg
- GameView {
- id: gameViewItem
- anchors.fill: parent
- z: 0
- focus: !mainWindow.menuVisible
- visible: gameStarted
- }
- HUD {
- id: hud
- anchors.fill: parent
- z: 1
- visible: !mainWindow.menuVisible && gameStarted
- onActiveFocusChanged: {
- if (activeFocus)
- gameViewItem.forceActiveFocus();
- }
- onPauseToggled: {
- mainWindow.gamePaused = !mainWindow.gamePaused;
- gameViewItem.setPaused(mainWindow.gamePaused);
- gameViewItem.forceActiveFocus();
- }
- onSpeedChanged: function(speed) {
- gameViewItem.setGameSpeed(speed);
- gameViewItem.forceActiveFocus();
- }
- onCommandModeChanged: function(mode) {
- console.log("Main: Command mode changed to:", mode);
- if (typeof game !== 'undefined') {
- console.log("Main: Setting game.cursor_mode property to", mode);
- game.cursor_mode = mode;
- } else {
- console.log("Main: game is undefined");
- }
- gameViewItem.forceActiveFocus();
- }
- onRecruit: function(unitType) {
- if (typeof game !== 'undefined' && game.recruit_near_selected)
- game.recruit_near_selected(unitType);
- gameViewItem.forceActiveFocus();
- }
- onReturnToMainMenuRequested: {
- mainWindow.menuVisible = true;
- }
- }
- Rectangle {
- id: missionAnnouncementToast
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.top: parent.top
- anchors.topMargin: 26
- z: 12
- visible: gameStarted && opacity > 0.01
- opacity: 0
- radius: 8
- color: "#cc1f1f1f"
- border.color: "#d9d9d9"
- border.width: 1
- width: Math.min(parent.width * 0.7, 700)
- height: missionAnnouncementLabel.implicitHeight + 22
- Text {
- id: missionAnnouncementLabel
- anchors.centerIn: parent
- width: parent.width - 28
- text: mainWindow.missionAnnouncementText
- color: "#f5f5f5"
- font.pixelSize: 18
- font.bold: true
- horizontalAlignment: Text.AlignHCenter
- wrapMode: Text.WordWrap
- }
- Behavior on opacity {
- NumberAnimation {
- duration: 220
- }
- }
- }
- Timer {
- id: missionAnnouncementTimer
- interval: 3600
- repeat: false
- onTriggered: missionAnnouncementToast.opacity = 0
- }
- Rectangle {
- id: pauseOverlay
- anchors.fill: parent
- z: 10
- visible: mainWindow.gamePaused && gameStarted
- color: "#80000000"
- Rectangle {
- anchors.centerIn: parent
- width: 300
- height: 150
- color: "#2c3e50"
- radius: 8
- border.color: "#34495e"
- border.width: 2
- Column {
- anchors.centerIn: parent
- spacing: 20
- Text {
- text: qsTr("PAUSED")
- color: "#ecf0f1"
- font.pixelSize: 36
- font.bold: true
- anchors.horizontalCenter: parent.horizontalCenter
- }
- Text {
- text: qsTr("Press Space to resume")
- color: "#bdc3c7"
- font.pixelSize: 14
- anchors.horizontalCenter: parent.horizontalCenter
- }
- }
- }
- }
- LoadScreen {
- id: load_screen
- anchors.fill: parent
- z: 15
- is_loading: (typeof game !== 'undefined') ? game.is_loading : false
- progress: (typeof game !== 'undefined') ? game.loading_progress : 0
- stage_text: (typeof game !== 'undefined') ? game.loading_stage_text : "Loading..."
- Connections {
- function onIs_loading_changed() {
- if (!game.is_loading)
- load_screen.complete_loading();
- }
- target: game
- }
- }
- MainMenu {
- id: mainMenu
- anchors.fill: parent
- z: 20
- visible: mainWindow.menuVisible
- gameStarted: mainWindow.gameStarted
- Component.onCompleted: {
- if (mainWindow.menuVisible)
- mainMenu.forceActiveFocus();
- }
- onVisibleChanged: {
- if (visible) {
- mainMenu.forceActiveFocus();
- gameViewItem.focus = false;
- } else if (gameStarted) {
- gameViewItem.forceActiveFocus();
- }
- }
- onOpenSkirmish: function() {
- mapSelect.visible = true;
- mainWindow.menuVisible = false;
- }
- onOpenCampaign: function() {
- campaign_screen.visible = true;
- mainWindow.menuVisible = false;
- }
- onSaveGame: function() {
- if (mainWindow.gameStarted) {
- saveGamePanel.visible = true;
- mainWindow.menuVisible = false;
- }
- }
- onLoadSave: function() {
- loadGamePanel.visible = true;
- mainWindow.menuVisible = false;
- }
- onOpenSettings: function() {
- settingsPanel.visible = true;
- mainWindow.menuVisible = false;
- }
- onOpenObjectives: function() {
- objectivesPanel.visible = true;
- mainWindow.menuVisible = false;
- }
- onExitRequested: function() {
- if (typeof game !== 'undefined' && game.exit_game)
- game.exit_game();
- }
- }
- MapSelect {
- id: mapSelect
- anchors.fill: parent
- z: 21
- visible: false
- onVisibleChanged: {
- if (visible) {
- mapSelect.forceActiveFocus();
- gameViewItem.focus = false;
- }
- }
- onMapChosen: function(map_path, playerConfigs) {
- console.log("Main: onMapChosen received", map_path, "with", playerConfigs.length, "player configs");
- if (typeof game !== 'undefined' && game.start_skirmish)
- game.start_skirmish(map_path, playerConfigs);
- mapSelect.visible = false;
- mainWindow.menuVisible = false;
- mainWindow.gameStarted = true;
- mainWindow.gamePaused = false;
- gameViewItem.forceActiveFocus();
- }
- onCancelled: function() {
- mapSelect.visible = false;
- mainWindow.menuVisible = true;
- }
- }
- CampaignScreen {
- id: campaign_screen
- anchors.fill: parent
- z: 21
- visible: false
- onVisibleChanged: {
- if (visible) {
- campaign_screen.forceActiveFocus();
- gameViewItem.focus = false;
- }
- }
- onMission_selected: function(campaign_id, mission_id) {
- console.log("Main: Campaign mission selected:", campaign_id + "/" + mission_id);
- if (typeof game !== 'undefined' && game.start_campaign_mission) {
- game.start_campaign_mission(campaign_id + "/" + mission_id);
- campaign_screen.visible = false;
- mainWindow.menuVisible = false;
- mainWindow.gameStarted = true;
- mainWindow.gamePaused = false;
- gameViewItem.forceActiveFocus();
- }
- }
- onCancelled: function() {
- campaign_screen.visible = false;
- mainWindow.menuVisible = true;
- }
- }
- SaveGamePanel {
- id: saveGamePanel
- anchors.fill: parent
- z: 22
- visible: false
- onVisibleChanged: {
- if (visible) {
- saveGamePanel.forceActiveFocus();
- gameViewItem.focus = false;
- }
- }
- onSaveRequested: function(slotName) {
- console.log("Main: Save requested for slot:", slotName);
- if (typeof game !== 'undefined' && game.save_gameToSlot)
- game.save_gameToSlot(slotName);
- saveGamePanel.visible = false;
- mainWindow.menuVisible = true;
- }
- onCancelled: function() {
- saveGamePanel.visible = false;
- mainWindow.menuVisible = true;
- }
- }
- LoadGamePanel {
- id: loadGamePanel
- anchors.fill: parent
- z: 22
- visible: false
- onVisibleChanged: {
- if (visible) {
- loadGamePanel.forceActiveFocus();
- gameViewItem.focus = false;
- }
- }
- onLoadRequested: function(slotName) {
- console.log("Main: Load requested for slot:", slotName);
- if (typeof game !== 'undefined' && game.load_game_from_slot) {
- game.load_game_from_slot(slotName);
- loadGamePanel.visible = false;
- mainWindow.menuVisible = false;
- mainWindow.gameStarted = true;
- mainWindow.gamePaused = false;
- gameViewItem.forceActiveFocus();
- }
- }
- onCancelled: function() {
- loadGamePanel.visible = false;
- mainWindow.menuVisible = true;
- }
- }
- SettingsPanel {
- id: settingsPanel
- anchors.fill: parent
- z: 22
- visible: false
- onVisibleChanged: {
- if (visible) {
- settingsPanel.forceActiveFocus();
- gameViewItem.focus = false;
- }
- }
- onCancelled: function() {
- settingsPanel.visible = false;
- mainWindow.menuVisible = true;
- }
- }
- ObjectivesPanel {
- id: objectivesPanel
- anchors.fill: parent
- z: 22
- visible: false
- onVisibleChanged: {
- if (visible) {
- objectivesPanel.forceActiveFocus();
- gameViewItem.focus = false;
- }
- }
- onCloseRequested: function() {
- objectivesPanel.visible = false;
- if (typeof game !== 'undefined' && typeof game.is_campaign_mission !== 'undefined' && game.is_campaign_mission && mainWindow.gameStarted) {
- mainWindow.gamePaused = false;
- gameViewItem.setPaused(false);
- gameViewItem.forceActiveFocus();
- } else {
- mainWindow.menuVisible = true;
- }
- }
- }
- Item {
- id: edgeScrollOverlay
- property real horzThreshold: 12
- property real horzMaxSpeed: 0.15
- property real vertThreshold: 10
- property real vertMaxSpeed: 0.01
- property real xPos: -1
- property real yPos: -1
- property int verticalShift: 6
- function inHudZone(x, y) {
- var topH = (typeof hud !== 'undefined' && hud && hud.topPanelHeight) ? hud.topPanelHeight : 0;
- var bottomH = (typeof hud !== 'undefined' && hud && hud.bottomPanelHeight) ? hud.bottomPanelHeight : 0;
- if (y < topH)
- return true;
- if (y > (height - bottomH))
- return true;
- return false;
- }
- anchors.fill: parent
- z: 2
- visible: !mainWindow.menuVisible && !mapSelect.visible
- enabled: visible
- MouseArea {
- anchors.fill: parent
- hoverEnabled: true
- acceptedButtons: Qt.NoButton
- propagateComposedEvents: true
- preventStealing: false
- onPositionChanged: function(mouse) {
- edgeScrollOverlay.xPos = mouse.x;
- edgeScrollOverlay.yPos = mouse.y;
- if (typeof game !== 'undefined' && game.set_hover_at_screen) {
- if (!edgeScrollOverlay.inHudZone(mouse.x, mouse.y))
- game.set_hover_at_screen(mouse.x, mouse.y);
- else
- game.set_hover_at_screen(-1, -1);
- }
- if (typeof game !== 'undefined' && game.is_placing_formation && game.on_formation_mouse_move) {
- if (!edgeScrollOverlay.inHudZone(mouse.x, mouse.y))
- game.on_formation_mouse_move(mouse.x, mouse.y);
- }
- if (typeof game !== 'undefined' && game.is_placing_construction && game.on_construction_mouse_move) {
- if (!edgeScrollOverlay.inHudZone(mouse.x, mouse.y))
- game.on_construction_mouse_move(mouse.x, mouse.y);
- }
- }
- onWheel: function(w) {
- if (typeof game !== 'undefined' && game.is_placing_formation && game.on_formation_scroll) {
- var dy = (w.angleDelta ? w.angleDelta.y / 120 : w.delta / 120);
- if (dy !== 0)
- game.on_formation_scroll(dy);
- w.accepted = true;
- return ;
- }
- w.accepted = false;
- }
- onEntered: function() {
- edgeScrollTimer.start();
- if (typeof game !== 'undefined' && game.set_hover_at_screen) {
- if (!edgeScrollOverlay.inHudZone(edgeScrollOverlay.xPos, edgeScrollOverlay.yPos))
- game.set_hover_at_screen(edgeScrollOverlay.xPos, edgeScrollOverlay.yPos);
- else
- game.set_hover_at_screen(-1, -1);
- }
- }
- onExited: function() {
- edgeScrollTimer.stop();
- edgeScrollOverlay.xPos = -1;
- edgeScrollOverlay.yPos = -1;
- if (typeof game !== 'undefined' && game.set_hover_at_screen)
- game.set_hover_at_screen(-1, -1);
- }
- }
- Timer {
- id: edgeScrollTimer
- interval: 16
- repeat: true
- onTriggered: {
- if (typeof game === 'undefined')
- return ;
- const w = edgeScrollOverlay.width;
- const h = edgeScrollOverlay.height;
- const x = edgeScrollOverlay.xPos;
- const y = edgeScrollOverlay.yPos;
- if (x < 0 || y < 0)
- return ;
- if (mainWindow.edgeScrollDisabled) {
- if (game.set_hover_at_screen)
- game.set_hover_at_screen(-1, -1);
- return ;
- }
- if (game.set_hover_at_screen)
- game.set_hover_at_screen(x, y);
- const th = edgeScrollOverlay.horzThreshold;
- const tv = edgeScrollOverlay.vertThreshold;
- const clamp = function clamp(v, lo, hi) {
- return Math.max(lo, Math.min(hi, v));
- };
- const dl = x;
- const dr = w - x;
- const dt = y;
- const db = h - y;
- const il = clamp(1 - dl / th, 0, 1);
- const ir = clamp(1 - dr / th, 0, 1);
- const iu = clamp(1 - dt / tv, 0, 1);
- const id = clamp(1 - db / tv, 0, 1);
- if (il === 0 && ir === 0 && iu === 0 && id === 0)
- return ;
- const curveH = function curveH(a) {
- return a * a;
- };
- const curveV = function curveV(a) {
- return a * a * a;
- };
- const rawDx = (curveH(ir) - curveH(il)) * edgeScrollOverlay.horzMaxSpeed;
- const rawDz = (curveV(iu) - curveV(id)) * edgeScrollOverlay.vertMaxSpeed;
- const dx = rawDx / edgeScrollOverlay.horzMaxSpeed;
- const dz = rawDz / edgeScrollOverlay.vertMaxSpeed;
- if (dx !== 0 || dz !== 0)
- game.camera_move(dx, dz);
- }
- }
- }
- Dialog {
- id: errorDialog
- anchors.centerIn: parent
- width: Math.min(parent.width * 0.6, 500)
- title: "Error"
- modal: true
- standardButtons: Dialog.Ok
- onAccepted: {
- if (game)
- game.clear_error();
- }
- contentItem: Rectangle {
- color: "#2a2a2a"
- implicitHeight: errorText.implicitHeight + 40
- Text {
- id: errorText
- anchors.centerIn: parent
- width: parent.width - 40
- text: game ? game.last_error : ""
- color: "#ffcccc"
- wrapMode: Text.WordWrap
- font.pixelSize: 14
- }
- }
- }
- Connections {
- function onLast_error_changed() {
- if (game.last_error !== "")
- errorDialog.open();
- }
- target: game
- }
- Connections {
- function onCampaign_mission_changed() {
- if (typeof game !== 'undefined' && typeof game.is_campaign_mission !== 'undefined' && game.is_campaign_mission && !game.is_loading) {
- mainWindow.gamePaused = true;
- gameViewItem.setPaused(true);
- objectivesPanel.visible = true;
- }
- }
- target: game
- }
- Connections {
- function onMission_announcement(text) {
- if (!text || !mainWindow.gameStarted)
- return ;
- mainWindow.missionAnnouncementText = text;
- missionAnnouncementToast.opacity = 1;
- missionAnnouncementTimer.restart();
- }
- target: game
- }
- }
|