Skip to content

Commit

Permalink
openmwplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kezyma committed Feb 13, 2023
1 parent 385040f commit c34f567
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 25 deletions.
12 changes: 9 additions & 3 deletions src/openmwplayer/modules/openmwplayer_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
from ...shared.shared_paths import SharedPaths
from .openmwplayer_settings import OpenMWPlayerSettings
from pathlib import Path
try:
from PyQt5.QtCore import QCoreApplication, QStandardPaths
from PyQt5.QtWidgets import QFileDialog
except:
from PyQt6.QtCore import QCoreApplication, QStandardPaths
from PyQt6.QtWidgets import QFileDialog
import os

class OpenMWPlayerPaths(SharedPaths):
Expand All @@ -21,12 +27,12 @@ def openMWCfgPath(self):
# Grab the default path if it exists.
defaultLocation = Path(QStandardPaths.locate(QStandardPaths.DocumentsLocation, str(Path("My Games", "OpenMW", "openmw.cfg"))))
if defaultLocation.is_file():
self.__organizer.setPluginSetting(self.name(), "openmwcfgpath", str(defaultLocation))
self.organiser.setPluginSetting("OpenMWPlayer", "openmwcfgpath", str(defaultLocation))
return defaultLocation

# Otherwise, get the user to provide a path.
manualPath = Path(QFileDialog.getOpenFileName(self._parentWidget(), self.__tr("Locate OpenMW Config File"), ".", "OpenMW Config File (openmw.cfg)")[0])
self.__organizer.setPluginSetting(self.name(), "openmwcfgpath", str(manualPath))
manualPath = Path(QFileDialog.getOpenFileName(None, "Locate OpenMW Config File", ".", "OpenMW Config File (openmw.cfg)")[0])
self.organiser.setPluginSetting("OpenMWPlayer", "openmwcfgpath", str(manualPath))
return manualPath

def openMwCustomSettingsPath(self, profile):
Expand Down
6 changes: 5 additions & 1 deletion src/openmwplayer/openmwplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ def runOpenMW(self, appName):
fileName = appPath.name
if fileName in self._openMwExeNames:
# Export settings to OpenMW
qInfo("OpenMWPlayer: OpenMW exe detected, exporting setup.")
self.exportMOSetup()

qInfo("OpenMWPlayer: OpenMW setup export complete.")

# Run app separately.
qInfo("OpenMWPlayer: Running selected exe.")
os.startfile(appName)

return False
else:
return True
Expand Down
22 changes: 4 additions & 18 deletions src/openmwplayer/openmwplayer_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,20 @@
except:
from PyQt6.QtCore import QCoreApplication, qInfo

class OpenMWPlayerPlugin(SharedPlugin, mobase.IPlugin):
class OpenMWPlayerPlugin(SharedPlugin):

def __init__(self):
super().__init__("OpenMWPlayer", "OpenMW Player", mobase.VersionInfo(0, 0, 3, mobase.ReleaseType.ALPHA))
super().__init__("OpenMWPlayer", "OpenMW Player", mobase.VersionInfo(0, 0, 4, mobase.ReleaseType.ALPHA))

def init(self, organiser=mobase.IOrganizer):
self.organiser = organiser
self.openMWPlayer = OpenMWPlayer(self.organiser)
self.organiser.onAboutToRun(lambda appName: self.runOpenMW(appName))
self.openMWPlayer = OpenMWPlayer(organiser)
return super().init(organiser)

def name(self):
return self.baseName()

def displayName(self):
return "OpenMW Player"

def description(self):
return self.__tr("Launches OpenMW executables using the current mod setup enabled in Mod Organizer 2.")

def __tr(self, trstr):
return QCoreApplication.translate(self.pluginName, trstr)

def settings(self):
""" Current list of game settings for Mod Organizer. """
return [
mobase.PluginSetting("openmwcfgpath",self.__tr("Path to openmw.cfg"),"/Path/To/OpenMW/openmw.cfg")
]

def runOpenMW(self, appName):
self.openMWPlayer.runOpenMW(appName)
]
28 changes: 28 additions & 0 deletions src/openmwplayer/plugins/openmwplayer_plugin_launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import mobase
from pathlib import Path
from ..openmwplayer_plugin import OpenMWPlayerPlugin
try:
from PyQt5.QtCore import QCoreApplication, qInfo
except:
from PyQt6.QtCore import QCoreApplication, qInfo

class OpenMWPlayerPluginLauncher(OpenMWPlayerPlugin, mobase.IPlugin):

def __init__(self):
super().__init__()

def init(self, organiser=mobase.IOrganizer):
organiser.onAboutToRun(lambda appName: self.runOpenMW(appName))
return super().init(organiser)

def name(self):
return self.baseName()

def description(self):
return self.__tr("Launches OpenMW executables using the current mod setup enabled in Mod Organizer 2.")

def __tr(self, trstr):
return QCoreApplication.translate(self.pluginName, trstr)

def runOpenMW(self, appName):
return self.openMWPlayer.runOpenMW(appName)
164 changes: 164 additions & 0 deletions src/openmwplayer/plugins/openmwplayer_tool_manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
try:
from PyQt5.QtWidgets import QFileDialog, QFileIconProvider, QInputDialog, QLineEdit, QWidget
from PyQt5.QtCore import QCoreApplication, qInfo, QSize, QStandardPaths
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtWidgets import QFileIconProvider
qtHorizontal = QtCore.Qt.Horizontal
qtCancel = QtWidgets.QDialogButtonBox.Cancel
qtOkay = QtWidgets.QDialogButtonBox.Ok
qtStaysOnTop = QtCore.Qt.WindowStaysOnTopHint
qtSizePolicy = QtWidgets.QSizePolicy
qtItemView = QtWidgets.QAbstractItemView
qtItemFlag = QtCore.Qt
qtCheckState = QtCore.Qt
qtMatchFlag = QtCore.Qt
except:
from PyQt6.QtWidgets import QFileDialog, QFileIconProvider, QInputDialog, QLineEdit, QWidget
from PyQt6.QtCore import QCoreApplication, qInfo, QSize, QStandardPaths
from PyQt6 import QtGui, QtWidgets, QtCore
from PyQt6.QtWidgets import QFileIconProvider
qtHorizontal = QtCore.Qt.Orientation.Horizontal
qtCancel = QtWidgets.QDialogButtonBox.StandardButton.Cancel
qtOkay = QtWidgets.QDialogButtonBox.StandardButton.Ok
qtStaysOnTop = QtCore.Qt.WindowType.WindowStaysOnTopHint
qtSizePolicy = QtWidgets.QSizePolicy.Policy
qtItemView = QtWidgets.QAbstractItemView.SelectionMode
qtItemFlag = QtCore.Qt.ItemFlag
qtCheckState = QtCore.Qt.CheckState
qtMatchFlag = QtCore.Qt.MatchFlag
from ..openmwplayer_plugin import OpenMWPlayerPlugin
from ...shared.shared_icons import SharedIcons
import mobase, re

class OpenMWPlayerManageTool(OpenMWPlayerPlugin, mobase.IPluginTool):

def __init__(self):
super().__init__()

def init(self, organiser=mobase.IOrganizer):
res = super().init(organiser)
self.dialog = self.getDialog()
return res

def __tr(self, trstr):
return QCoreApplication.translate(self.pluginName, trstr)

def master(self):
return self.pluginName

def settings(self):
return []

def icon(self):
return self.icons.openMwIcon()

def name(self):
return self.baseName() + " Manage Tool"

def description(self):
return self.__tr("Manage OpenMW Player settings.")

def display(self):
self.dialog.show()
self.bindPlugins()

def bindPlugins(self):
self.addText.setText(str(self.openMWPlayer.paths.openMWCfgPath()))

profile = self.organiser.profile().name()
groundCoverCustom = self.openMWPlayer.paths.openMwGrassSettingsPath(profile)
groundCoverFiles = []
if not groundCoverCustom.exists():
with groundCoverCustom.open("x") as custNew:
custNew.write("\n")
with groundCoverCustom.open("r") as custGrnd:
for line in custGrnd:
line = line.replace("\n", "")
if len(line) > 0:
groundCoverFiles.append(line)

self.profileSelect.clear()
for name in self.organiser.pluginList().pluginNames():
item = QtWidgets.QListWidgetItem()
item.setText(name)
item.setFlags(qtItemFlag.ItemIsUserCheckable|qtItemFlag.ItemIsEnabled)
item.setCheckState(qtCheckState.Unchecked)
self.profileSelect.addItem(item)

for name in groundCoverFiles:
for itm in self.profileSelect.findItems(name, qtMatchFlag.MatchExactly):
itm.setCheckState(qtCheckState.Checked)


def selectOpenMWCfg(self):
manualPath = QFileDialog.getOpenFileName(self._parentWidget(), self.__tr("Locate OpenMW Config File"), ".", "OpenMW Config File (openmw.cfg)")[0]
self.organiser.setPluginSetting(self.name(), "openmwcfgpath", str(manualPath))
self.addText.setText(str(manualPath))

def changePluginState(self):
selected = []
for x in range(self.profileSelect.count()):
p = self.profileSelect.item(x)
if p.checkState() == qtCheckState.Checked:
selected.append(p.text())

profile = self.organiser.profile().name()
groundCoverCustom = self.openMWPlayer.paths.openMwGrassSettingsPath(profile)
with groundCoverCustom.open("w") as custGrnd:
for item in selected:
custGrnd.write(item + "\n")

def getDialog(self):
dialog = QtWidgets.QDialog()
dialog.setObjectName("dialog")
dialog.resize(475, 340)
dialog.setWindowIcon(self.icons.syncIcon())
dialog.setWindowTitle("OpenMW Player")
self.dialogLayout = QtWidgets.QVBoxLayout(dialog)
self.dialogLayout.setContentsMargins(5, 5, 5, 5)
self.dialogLayout.setSpacing(5)
self.dialogLayout.setObjectName("dialogLayout")

self.addWidget = QtWidgets.QWidget(dialog)
self.addWidget.setObjectName("addWidget")
self.addLayout = QtWidgets.QHBoxLayout(self.addWidget)
self.addLayout.setContentsMargins(0, 0, 0, 0)
self.addLayout.setSpacing(5)
self.addLayout.setObjectName("addLayout")
self.addText = QtWidgets.QLabel(self.addWidget)
self.addText.setObjectName("addText")
self.addButton = QtWidgets.QPushButton(self.addWidget)
sizePolicy = QtWidgets.QSizePolicy(qtSizePolicy.Fixed, qtSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.addButton.sizePolicy().hasHeightForWidth())
self.addButton.setSizePolicy(sizePolicy)
self.addButton.setIcon(self.icons.linkIcon())
self.addButton.setObjectName("addButton")
self.addButton.setText("OpenMW.cfg")
self.addButton.clicked.connect(self.selectOpenMWCfg)
self.addLayout.addWidget(self.addButton)
self.addLayout.addWidget(self.addText)
self.dialogLayout.addWidget(self.addWidget)

self.gcvWidget = QtWidgets.QWidget(dialog)
self.gcvWidget.setObjectName("gcvWidget")
self.gcvLayout = QtWidgets.QHBoxLayout(self.gcvWidget)
self.gcvLayout.setContentsMargins(0, 0, 0, 0)
self.gcvLayout.setSpacing(5)
self.gcvLayout.setObjectName("gcvLayout")
self.gcvText = QtWidgets.QLabel(self.gcvWidget)
self.gcvText.setText("Select Groundcover Plugins")
self.gcvText.setObjectName("gcvText")
self.gcvLayout.addWidget(self.gcvText)
self.dialogLayout.addWidget(self.gcvWidget)

self.profileSelect = QtWidgets.QListWidget(dialog)
self.profileSelect.setSelectionMode(qtItemView.MultiSelection)
self.profileSelect.setObjectName("profileSelect")
self.profileSelect.itemChanged.connect(self.changePluginState)
self.dialogLayout.addWidget(self.profileSelect)

QtCore.QMetaObject.connectSlotsByName(dialog)

return dialog
6 changes: 4 additions & 2 deletions src/openmwplayer_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import mobase
from .openmwplayer.openmwplayer_plugin import OpenMWPlayerPlugin
from .openmwplayer.plugins.openmwplayer_plugin_launcher import OpenMWPlayerPluginLauncher
from .openmwplayer.plugins.openmwplayer_tool_manage import OpenMWPlayerManageTool

def createPlugins():
return [
OpenMWPlayerPlugin()
OpenMWPlayerPluginLauncher(),
OpenMWPlayerManageTool()
]
Binary file added src/shared/icons/ui-openmw.ico
Binary file not shown.
5 changes: 4 additions & 1 deletion src/shared/shared_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,7 @@ def filterIcon(self):
return self.icon("ui-filter.ico")

def recycleIcon(self):
return self.icon("ui-recycle.ico")
return self.icon("ui-recycle.ico")

def openMwIcon(self):
return self.icon("ui-openmw.ico")
Binary file modified tools/icons.psd
Binary file not shown.

0 comments on commit c34f567

Please sign in to comment.