Skip to content

Commit

Permalink
New Qml Materia Selector
Browse files Browse the repository at this point in the history
  • Loading branch information
sithlord48 committed Sep 24, 2023
1 parent 5f2186c commit 97486c7
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 52 deletions.
22 changes: 17 additions & 5 deletions demos/ff7tkQmlGallery/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ ApplicationWindow {
ListElement{text: "ItemPreview"}
ListElement{text: "Materia Button"}
ListElement{text: "Materia Editor"}
ListElement{text: "Materia Selector"}
}
onCurrentIndexChanged: {
itemLoader.sourceComponent = Qt.binding(function() {
switch(comboSelector.currentIndex) {
case 1: return textDemoComponent;
case 2: return itemPreviewComponent;
case 3: return materiaButtonComponent;
case 4: return materiaEditorComponent;
case 1: return textDemoComponent
case 2: return itemPreviewComponent
case 3: return materiaButtonComponent
case 4: return materiaEditorComponent
case 5: return materiaSelectorComponent
default: return testComponent;
}
})
Expand Down Expand Up @@ -132,6 +134,16 @@ ApplicationWindow {
id: textDemoComponent
TextDemo { }
}
Component {
id: materiaSelectorComponent
Item{
anchors.fill: parent
MateriaSelector {
anchors.left: parent.left;
anchors.leftMargin: 6
}
}
}

Component {
id: materiaEditorComponent
Expand Down Expand Up @@ -189,7 +201,7 @@ ApplicationWindow {
}
MateriaEditor {
id: materiaEditor
anchors { fill: parent; topMargin: materiaEditorControls.height + 3 }
anchors { fill: parent; topMargin: materiaEditorControls.height + 6; leftMargin: 6; rightMargin: 6 }
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ff7tkQuick/Controls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(${libName}_URI "ff7tkQuick.Controls")

set(${libName}_QMLFILES
ItemPreview.qml
MateriaSelector.qml
MateriaEditor.qml
MateriaSlotButton.qml
Components/ApplicationWindow.qml
Expand Down
56 changes: 9 additions & 47 deletions src/ff7tkQuick/Controls/MateriaEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,19 @@ import "Components" as FFComps

Item {
id: root
implicitWidth: childrenRect.width + 12
property bool showPlaceHolderMateria: true
implicitWidth: mSelector.implicitWidth + (24 * 4)
property alias showPlaceHolderMateria: mSelector.showPlaceHolderMateria
property bool editable: true
property bool fixedHeightSkills: true
property int starHeight: 24
property int currentId: FF7Materia.EmptyId
property alias currentId: mSelector.currentId
property int currentAp: FF7Materia.maxMateriaAp
readonly property bool isEmpty: ((currentId === FF7Materia.EmptyId))
readonly property int level: FF7Materia.materiaLevel(currentId, currentAp)
signal copyActionTriggered(int currentId, int currentAp)
signal cutActionTriggered(int currentId, int currentAp)
signal pasteActionTriggered()

ListModel {
id: typeModel
ListElement { text: qsTr("All Materia"); icon: "qrc:/materia/all" }
ListElement { text: qsTr("Magic"); icon: "qrc:/materia/magic" }
ListElement { text: qsTr("Summon"); icon: "qrc:/materia/summon" }
ListElement { text: qsTr("Independent"); icon: "qrc:/materia/independent" }
ListElement { text: qsTr("Support"); icon: "qrc:/materia/support" }
ListElement { text: qsTr("Command"); icon: "qrc:/materia/command" }
}

ListModel { id: materiaModel }
Component.onCompleted: { setupMateriaModel(0); materiaCombo.modelChanged() }

Rectangle {
anchors.fill: parent
color: palette.base
Expand All @@ -57,27 +44,19 @@ Item {
anchors.right: parent.right
anchors.top: parent.top
height: 24
anchors.margins: 6
anchors.leftMargin: 6
anchors.rightMargin: 6
spacing: 6
FFComps.ComboBox {
id: typeCombo
visible: root.editable
Layout.fillHeight: true
Layout.preferredWidth: implicitWidth
model: typeModel
onCurrentIndexChanged: setupMateriaModel(currentIndex)
}
FFComps.ComboBox {
id: materiaCombo
MateriaSelector {
id: mSelector
visible: root.editable
Layout.fillHeight: true
Layout.fillWidth: true
Layout.minimumWidth: implicitWidth
model: materiaModel
onCurrentIndexChanged: currentId = currentIndex !== -1 ? model.get(currentIndex).data : currentId
Layout.preferredWidth: mSelector.implicitWidth + 12
}
Image {
visible: !root.editable && currentId !== FF7Materia.EmptyId
Layout.margins: 4
Layout.fillHeight: true
Layout.preferredWidth: height
source: FF7Materia.iconResource(currentId)
Expand Down Expand Up @@ -361,21 +340,4 @@ Item {
}
}
}

onShowPlaceHolderMateriaChanged: {
var cI = materiaCombo.currentIndex
typeCombo.currentIndex === 0 ? setupMateriaModel(typeCombo.currentIndex) : null
materiaCombo.currentIndex = cI
}

function setupMateriaModel(type) {
materiaModel.clear()
for (let i = 0 ; i <= 90; i++) {
if( (type === 0 || FF7Materia.type(i) === type) && FF7Materia.name(i) !== "") {
if(String(FF7Materia.name(i)).includes(":") && !root.showPlaceHolderMateria)
continue;
materiaModel.append({ text: FF7Materia.name(i), icon: FF7Materia.iconResource(i), data: i})
}
}
}
}
80 changes: 80 additions & 0 deletions src/ff7tkQuick/Controls/MateriaSelector.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/****************************************************************************/
// copyright 2022 - 2023 Chris Rizzitello <[email protected]> //
// //
// This file is part of FF7tk //
// //
// FF7tk 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 3 of the License, or //
// (at your option) any later version. //
// //
// FF7tk 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. //
/****************************************************************************/

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import ff7tkQuick.DataTypes
import "Components" as FFComps

Item {
id: root
implicitWidth: typeCombo.implicitWidth + materiaCombo.implicitWidth + 18
implicitHeight: 24
property bool showPlaceHolderMateria: true
property int currentId: FF7Materia.EmptyId

ListModel {
id: typeModel
ListElement { text: qsTr("All Materia"); icon: "qrc:/materia/all" }
ListElement { text: qsTr("Magic"); icon: "qrc:/materia/magic" }
ListElement { text: qsTr("Summon"); icon: "qrc:/materia/summon" }
ListElement { text: qsTr("Independent"); icon: "qrc:/materia/independent" }
ListElement { text: qsTr("Support"); icon: "qrc:/materia/support" }
ListElement { text: qsTr("Command"); icon: "qrc:/materia/command" }
}

ListModel { id: materiaModel }
Component.onCompleted: { setupMateriaModel(0); materiaCombo.modelChanged() }
RowLayout {
id: selectorRow
anchors.fill: parent
height: 24
spacing: 6
FFComps.ComboBox {
id: typeCombo
Layout.fillHeight: true
Layout.preferredWidth: typeCombo.implicitWidth
model: typeModel
onCurrentIndexChanged: setupMateriaModel(currentIndex)
}
FFComps.ComboBox {
id: materiaCombo
Layout.fillHeight: true
Layout.fillWidth: true
Layout.minimumWidth: materiaCombo.implicitWidth
model: materiaModel
onCurrentIndexChanged: currentId = currentIndex !== -1 ? model.get(currentIndex).data : currentId
}
}

onShowPlaceHolderMateriaChanged: {
var cI = materiaCombo.currentIndex
typeCombo.currentIndex === 0 ? setupMateriaModel(typeCombo.currentIndex) : null
materiaCombo.currentIndex = cI
}

function setupMateriaModel(type) {
materiaModel.clear()
for (let i = 0 ; i <= 90; i++) {
if( (type === 0 || FF7Materia.type(i) === type) && FF7Materia.name(i) !== "") {
if(String(FF7Materia.name(i)).includes(":") && !root.showPlaceHolderMateria)
continue;
materiaModel.append({ text: FF7Materia.name(i), icon: FF7Materia.iconResource(i), data: i})
}
}
}
}
27 changes: 27 additions & 0 deletions translations/ff7tk_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7282,6 +7282,33 @@ Die km / h beschleunigt berechnet werden während des Spielens </translation>
<translation>Zusatzwirkung</translation>
</message>
</context>
<context>
<name>MateriaSelector</name>
<message>
<source>All Materia</source>
<translation type="unfinished">alle Materia</translation>
</message>
<message>
<source>Magic</source>
<translation type="unfinished">Magie</translation>
</message>
<message>
<source>Summon</source>
<translation type="unfinished">Beschwörung</translation>
</message>
<message>
<source>Independent</source>
<translation type="unfinished">Unabhängig</translation>
</message>
<message>
<source>Support</source>
<translation type="unfinished">Unterstützung</translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished">Befehl</translation>
</message>
</context>
<context>
<name>MenuListWidget</name>
<message>
Expand Down
27 changes: 27 additions & 0 deletions translations/ff7tk_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7282,6 +7282,33 @@ The km/h speeds are calculated while playing </translation>
<translation>Added Effect</translation>
</message>
</context>
<context>
<name>MateriaSelector</name>
<message>
<source>All Materia</source>
<translation type="unfinished">All Materia</translation>
</message>
<message>
<source>Magic</source>
<translation type="unfinished">Magic</translation>
</message>
<message>
<source>Summon</source>
<translation type="unfinished">Summon</translation>
</message>
<message>
<source>Independent</source>
<translation type="unfinished">Independent</translation>
</message>
<message>
<source>Support</source>
<translation type="unfinished">Support</translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished">Command</translation>
</message>
</context>
<context>
<name>MenuListWidget</name>
<message>
Expand Down
27 changes: 27 additions & 0 deletions translations/ff7tk_es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7282,6 +7282,33 @@ Los km/h son calculados mientras se juega </translation>
<translation>Efecto añaddo</translation>
</message>
</context>
<context>
<name>MateriaSelector</name>
<message>
<source>All Materia</source>
<translation type="unfinished">Toda la materia</translation>
</message>
<message>
<source>Magic</source>
<translation type="unfinished">Magia</translation>
</message>
<message>
<source>Summon</source>
<translation type="unfinished">Invocación</translation>
</message>
<message>
<source>Independent</source>
<translation type="unfinished">Independiente</translation>
</message>
<message>
<source>Support</source>
<translation type="unfinished">Soporte</translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished">Comando</translation>
</message>
</context>
<context>
<name>MenuListWidget</name>
<message>
Expand Down
27 changes: 27 additions & 0 deletions translations/ff7tk_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7282,6 +7282,33 @@ Les vitesses en km/h sont calculés pendant le jeu </translation>
<translation>Effet suppl</translation>
</message>
</context>
<context>
<name>MateriaSelector</name>
<message>
<source>All Materia</source>
<translation type="unfinished">Toutes les matérias</translation>
</message>
<message>
<source>Magic</source>
<translation type="unfinished">Magie</translation>
</message>
<message>
<source>Summon</source>
<translation type="unfinished">Invocation</translation>
</message>
<message>
<source>Independent</source>
<translation type="unfinished">Indépendante</translation>
</message>
<message>
<source>Support</source>
<translation type="unfinished">Soutien</translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished">Commande</translation>
</message>
</context>
<context>
<name>MenuListWidget</name>
<message>
Expand Down
27 changes: 27 additions & 0 deletions translations/ff7tk_it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7293,6 +7293,33 @@ Battaglia %1</translation>
<translation type="unfinished">Ripristina</translation>
</message>
</context>
<context>
<name>MateriaSelector</name>
<message>
<source>All Materia</source>
<translation type="unfinished">Tutte le materie</translation>
</message>
<message>
<source>Magic</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Summon</source>
<translation type="unfinished">Di invocazione</translation>
</message>
<message>
<source>Independent</source>
<translation type="unfinished">Indipendenti</translation>
</message>
<message>
<source>Support</source>
<translation type="unfinished">Supporto</translation>
</message>
<message>
<source>Command</source>
<translation type="unfinished">Comando</translation>
</message>
</context>
<context>
<name>MenuListWidget</name>
<message>
Expand Down
Loading

0 comments on commit 97486c7

Please sign in to comment.