Skip to content

Commit

Permalink
Merge pull request #16 from strubium/config_parser
Browse files Browse the repository at this point in the history
Config parser
  • Loading branch information
strubium authored Jun 18, 2024
2 parents d6ac0d6 + 7a5d96c commit e6b0908
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 45 deletions.
14 changes: 8 additions & 6 deletions QtPyHammer/ui/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class browser(QtWidgets.QDialog):
def __init__(self, parent):
super(browser, self).__init__(parent, QtCore.Qt.Tool)

self.setWindowTitle("Run Map")

# Add QLabel widgets
Expand All @@ -16,7 +17,7 @@ def __init__(self, parent):
self.bsp_combo_box.addItem(lang.langNo())
self.bsp_combo_box.addItem(lang.langNormal())
self.bsp_combo_box.addItem("Only Entities")
self.bsp_combo_box.setCurrentIndex(self.bsp_combo_box.findText("Normal"))
self.bsp_combo_box.setCurrentIndex(self.bsp_combo_box.findText(lang.langNormal()))

self.box2 = QtWidgets.QLabel("Run VIS:")
self.vis_combo_box = QtWidgets.QComboBox()
Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(self, parent):
cancel_button = QtWidgets.QPushButton("Cancel")
cancel_button.clicked.connect(self.reject)
bottom_row.addWidget(cancel_button)
ok_button = QtWidgets.QPushButton("Ok")
ok_button = QtWidgets.QPushButton(lang.langOk())
ok_button.clicked.connect(self.on_ok_clicked)
ok_button.setDefault(True)
bottom_row.addWidget(ok_button)
Expand All @@ -64,11 +65,12 @@ def __init__(self, parent):
self.adjustSize()

def on_ok_clicked(self):
vbsp_path = r'C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\bin\vbsp.exe'
vvis_path = r'C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\bin\vvis.exe'
vrad_path = r'C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\bin\vrad.exe'
preferences = QtWidgets.QApplication.instance().game_config
vbsp_path = preferences.value("Hammer/BSP", r"C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2/bin/vbsp.exe")
vvis_path = preferences.value("Hammer/Vis", r"C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2/bin/vvis.exe")
vrad_path = preferences.value("Hammer/Light", r"C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2/bin/vrad.exe")

game_path = r'C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\tf'
game_path = preferences.value("General/GameDir", r"C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\tf")
file_path = self.textbox.text()

if not file_path:
Expand Down
52 changes: 31 additions & 21 deletions QtPyHammer/ui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QIcon


from .. import ops
from ..ui import entity, popup, texture_browser, compile, properties
from ..ui import workspace
from ..utilities import lang



class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):


super(QtWidgets.QMainWindow, self).__init__(parent)
global current_dir
self.setWindowIcon(QtGui.QIcon('HammerLogo.png'))
Expand All @@ -38,16 +34,28 @@ def __init__(self, parent=None):
self.main_menu = QtWidgets.QMenuBar()
file_menu = self.main_menu.addMenu(lang.langFile())
self.actions["File/New"] = file_menu.addAction("&New")
def new_file(): ops.new_file(self)

def new_file():
ops.new_file(self)

self.actions["File/New"].triggered.connect(new_file)
self.actions["File/Open"] = file_menu.addAction("&Open")
def open_files(): ops.open_files(self, self.map_browser)

def open_files():
ops.open_files(self, self.map_browser)

self.actions["File/Open"].triggered.connect(open_files)
self.actions["File/Save"] = file_menu.addAction("&Save")
def save_file(): ops.save_file(self, self.map_browser)

def save_file():
ops.save_file(self, self.map_browser)

self.actions["File/Save"].triggered.connect(save_file)
self.actions["File/Save As"] = file_menu.addAction("Save &As")
def save_file_as(): ops.save_file_as(self, self.map_browser)

def save_file_as():
ops.save_file_as(self, self.map_browser)

self.actions["File/Save As"].triggered.connect(save_file_as)
file_menu.addSeparator()
# self.import_menu = file_menu.addMenu("Import")
Expand Down Expand Up @@ -263,25 +271,27 @@ def save_file_as(): ops.save_file_as(self, self.map_browser)
# self.actions["Help/Offline"].triggered.connect(ui.
help_menu.addSeparator()
self.actions["Help/About QPH"] = help_menu.addAction("About QtPyHammer")
about_popup = popup.browser(parent=self, popuptext="About", msgtext="A Python alternative to Valve Hammer Editor 4.x, forked from QtPyHammer\n\nVersion: v0.0.5forked")
about_popup = popup.browser(parent=self, popuptext="About",
msgtext="A Python alternative to Valve Hammer Editor 4.x, forked from QtPyHammer\n\nVersion: v0.0.5forked")
self.actions["Help/About QPH"].triggered.connect(about_popup.show)
self.actions["Help/About Qt"] = help_menu.addAction("About Qt")
self.actions["Help/About Qt"].triggered.connect(lambda: open_url(QtCore.QUrl(
"https://github.com/spyder-ide/qtpy")))
"https://github.com/spyder-ide/qtpy")))
# self.actions["Help/About Qt"].triggered.connect(ui. #QDialog
self.actions["Help/License"] = help_menu.addAction("License")
self.actions["Help/License"].triggered.connect(lambda: open_url(QtCore.QUrl(
"https://github.com/strubium/QtPyHammer/blob/master/LICENSE")))
"https://github.com/strubium/QtPyHammer/blob/master/LICENSE")))
# self.actions["Help/License"].triggered.connect(ui. #QDialog
self.actions["Help/Contributors"] = help_menu.addAction("Contributors")
self.actions["Help/Contributors"].triggered.connect(lambda: open_url(QtCore.QUrl("https://github.com/QtPyHammer-devs/QtPyHammer/graphs/contributors")))
self.actions["Help/Contributors"].triggered.connect(
lambda: open_url(QtCore.QUrl("https://github.com/QtPyHammer-devs/QtPyHammer/graphs/contributors")))
self.actions["Help/QPH Wiki"] = help_menu.addAction("QtPyHammer Wiki")
self.actions["Help/QPH Wiki"].triggered.connect(lambda: open_url(QtCore.QUrl(
"https://github.com/snake-biscuits/QtPyHammer/wiki")))
"https://github.com/snake-biscuits/QtPyHammer/wiki")))
help_menu.addSeparator()
self.actions["Help/VDC"] = help_menu.addAction("Valve Developer Community")
self.actions["Help/VDC"].triggered.connect(lambda: open_url(QtCore.QUrl(
"https://developer.valvesoftware.com/wiki/Main_Page")))
"https://developer.valvesoftware.com/wiki/Main_Page")))

# attach all actions to hotkeys
app = QtWidgets.QApplication.instance()
Expand All @@ -298,8 +308,8 @@ def save_file_as(): ops.save_file_as(self, self.map_browser)

# TOOLBARS
key_tools = QtWidgets.QToolBar("Tools")
key_tools.setMovable(False)
button_1 = QtWidgets.QToolButton() # need icons (.png)
key_tools.setMovable(True)
button_1 = QtWidgets.QToolButton() # need icons (.png)
button_1.setToolTip("Toggle 2D grid visibility")
button_1.setIcon(QIcon("icons/2dHammerIcon"))
button_1.setEnabled(False)
Expand All @@ -319,20 +329,20 @@ def save_file_as(): ops.save_file_as(self, self.map_browser)
button_4.setEnabled(False)
key_tools.addWidget(button_4)
key_tools.addSeparator()
button_5= QtWidgets.QToolButton()
button_5 = QtWidgets.QToolButton()
button_5.setToolTip("Load Window State")
button_5.setEnabled(False)
key_tools.addWidget(button_5)
button_6= QtWidgets.QToolButton()
button_6 = QtWidgets.QToolButton()
button_6.setToolTip("Save Window State")
button_6.setEnabled(False)
key_tools.addWidget(button_6)
key_tools.addSeparator()
button_7= QtWidgets.QToolButton()
button_7 = QtWidgets.QToolButton()
button_7.setToolTip("Undo")
button_7.setEnabled(False)
key_tools.addWidget(button_7)
button_8= QtWidgets.QToolButton()
button_8 = QtWidgets.QToolButton()
button_8.setToolTip("Redo")
button_8.setEnabled(False)
key_tools.addWidget(button_8)
Expand All @@ -347,7 +357,7 @@ def save_file_as(): ops.save_file_as(self, self.map_browser)
right_toolbar.setFixedWidth(115)
label_1 = QtWidgets.QLabel("Select:")
right_toolbar.addWidget(label_1)
right_toolbar.setMovable(False)
right_toolbar.setMovable(True)
button_1 = QtWidgets.QPushButton("Groups")
button_1.setFixedSize(100, 25)
button_1.setEnabled(False)
Expand Down
2 changes: 1 addition & 1 deletion QtPyHammer/ui/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def load_entity(self, index): # ADD SmartEdit toggle & tooltips
outputs = [*filter(lambda o: isinstance(o, valvefgd.parser.FgdEntityOutput), entity.properties)]
# split properly in some version of valvefgd (prob 1.0.0 but it's broken?)
if len(inputs) > 0 or len(outputs) > 0: # OR ANY inputs recieved
logic_widget = QtWidgets.QWidget() # <- make it's own class
logic_widget = QtWidgets.QWidget() # <- make it its own class
logic_widget.setLayout(QtWidgets.QVBoxLayout())
logic_widget.layout().addWidget(QtWidgets.QLabel("Inputs"))
logic_widget.layout().addWidget(QtWidgets.QLabel("Outputs"))
Expand Down
1 change: 1 addition & 0 deletions QtPyHammer/ui/popup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from PyQt5 import QtCore, QtGui, QtWidgets
from ..utilities import lang


class browser(QtWidgets.QDialog):
def __init__(self, parent, popuptext="Error", msgtext="Something's wrong, but we don't know what"):
super(browser, self).__init__(parent, QtCore.Qt.Tool)
Expand Down
11 changes: 6 additions & 5 deletions QtPyHammer/ui/properties.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from PyQt5 import QtCore, QtGui, QtWidgets
from ..utilities import lang


class browser(QtWidgets.QDialog):
def __init__(self, parent):
super(browser, self).__init__(parent, QtCore.Qt.Tool)
self.setWindowTitle("QtPyHammer Properties - WIP")

self.box1 = QtWidgets.QLabel("Render Mode:")
self.render_mod_combo_box = QtWidgets.QComboBox()
self.render_mod_combo_box.setGeometry(200, 150, 120, 40)
Expand Down Expand Up @@ -40,9 +42,8 @@ def __init__(self, parent):

# Resize the dialog to fit the text
self.adjustSize()



def on_ok_clicked(self):
# render_mod_index = self.render_mod_combo_box.currentIndex()
# lang.setLanguage(self.lang_combo_box.currentText())
# render_mod_index = self.render_mod_combo_box.currentIndex()
# lang.setLanguage(self.lang_combo_box.currentText())
self.accept()
9 changes: 6 additions & 3 deletions QtPyHammer/ui/texture_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, parent=None):
main_layout = QtWidgets.QVBoxLayout()
self.setWindowTitle("Texture Browser")
self.setGeometry(780, 220, 360, 640)
# now this has scroll bar but it doesnt have flow layout
# now this has scroll bar, but it doesn't have flow layout
scroll = QtWidgets.QScrollArea()
groupbox = QtWidgets.QGroupBox("Textures")
flow_layout = FlowLayout(margin=10)
Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, parent=None):
main_layout.addWidget(QtWidgets.QLabel("Search Options"))
# main_layout.addWidget(QtWidgets.QLabel("Max:"))
# main_layout.addWidget(QtWidgets.QLineEdit(self).setPlaceholderText("400").resize(280,40))

# list of checkboxes?
# colour-range (hue) slider (.vtf reflectivity value)

Expand Down Expand Up @@ -91,6 +91,7 @@ def search(self, keyword):
search_popup.show()
# TODO: doesnt filter yet


class FlowLayout(QtWidgets.QLayout):
"""A ``QLayout`` that aranges its child widgets horizontally and
vertically.
Expand Down Expand Up @@ -131,7 +132,8 @@ def takeAt(self, index):
return self._item_list.pop(index)
return None

def expandingDirections(self):
@staticmethod
def expandingDirections():
return QtCore.Qt.Orientations(QtCore.Qt.Orientation(0))

def hasHeightForWidth(self):
Expand Down Expand Up @@ -201,6 +203,7 @@ def except_hook(cls, exception, traceback):
"""Get tracebacks for python called by Qt functions & classes"""
sys.__excepthook__(cls, exception, traceback)


sys.excepthook = except_hook
app = QtWidgets.QApplication(sys.argv)
browser = TextureBrowser()
Expand Down
4 changes: 2 additions & 2 deletions QtPyHammer/ui/viewport.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def initializeGL(self):
self.set_view_mode("textured") # sets shaders & GL state
self.timer.start()

# calling the slot by it's name creates a QVariant Error
# calling the slot by its name creates a QVariant Error
# which for some reason does not trace correctly
@QtCore.pyqtSlot(str, name="setViewMode") # connected to UI
def set_view_mode(self, view_mode): # C++: void setViewMode(QString)
Expand Down Expand Up @@ -146,7 +146,7 @@ def do_raycast(self, click_x, click_y):

# Rebound Qt Methods
def keyPressEvent(self, event): # not registering arrow keys?
# BUG? auto repeat can "give the camera velocity" by jamming a key down virtually?
# BUG? auto-repeat can "give the camera velocity" by jamming a key down virtually?
# ^ obsered once by @snake-biscuits
self.keys.add(event.key())

Expand Down
3 changes: 2 additions & 1 deletion QtPyHammer/ui/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def save_to_file(self):
error_popup = popup.browser(parent=self, popuptext="Error", msgtext="Error when saving")
error_popup.show()
raise exc
print("Saved!")
saved_popup = popup.browser(parent=self, popuptext="Status", msgtext="Saved")
saved_popup.show()
self.never_saved = False

def close(self):
Expand Down
3 changes: 2 additions & 1 deletion QtPyHammer/utilities/lang.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
usingLanguage = "english" # Default language

usingLanguage = "English" # Default language

def setLanguage(language):
global usingLanguage
Expand Down
2 changes: 1 addition & 1 deletion QtPyHammer/utilities/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def raycast_intersects(self, ray_direction, ray_length):

@staticmethod
def load_from_file(filename) -> Obj: # noqa: C901
"""Creates a Obj object from the definition in filename"""
"""Creates an Obj object from the definition in filename"""
vertex_data = {"v": [], "vt": [], "vn": []}
faces = []
current_object = None
Expand Down
2 changes: 2 additions & 0 deletions QtPyHammer/utilities/physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class AxisAlignedBoundingBox:
maxs: vector.vec3

def __init__(self, mins: vector.vec3, maxs: vector.vec3):
self.max = None
self.min = None
self.mins = vector.vec3(*mins)
self.maxs = vector.vec3(*maxs)

Expand Down
8 changes: 4 additions & 4 deletions configs/games/Team Fortress 2.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[General]
GameDir=Team Fortress 2/tf
GameDir=C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\tf

[Hammer]
BSP=Team Fortress 2/bin/vbsp.exe
BSP=C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2/bin/vbsp.exe
BSPDir=Team Fortress 2/tf/maps
CordonTexture=tools/toolsskybox
DefaultLightmapScale=16
Expand All @@ -12,9 +12,9 @@ DefaultTextureScale=0.250000
GameData0=Team Fortress 2/bin/tf-puddy.fgd
GameExe=Team Fortress 2/hl2.exe
GameExeDir=Team Fortress 2
Light=Team Fortress 2/bin/vrad.exe
Light=C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2/bin/vrad.exe
MapDir=Team Fortress 2/tf/mapsrc
MapFormat=4
MaterialExcludeCount=0
TextureFormat=5
Vis=Team Fortress 2/bin/vvis.exe
Vis=C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2/bin/vvis.exe
1 change: 1 addition & 0 deletions configs/preferences.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[General]
Game=Team Fortress 2
Theme=light_mode
Language=English

[Input]
MouseSensitivity=2.0
Expand Down

0 comments on commit e6b0908

Please sign in to comment.