forked from ExplosBlue/RouteEdit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCamWidget.py
116 lines (85 loc) · 3.85 KB
/
CamWidget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import struct
from PyQt5 import QtWidgets, QtGui
class CamEditorWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent=parent)
self.camEntries = []
self.layout = QtWidgets.QVBoxLayout(self)
# Create Widgets
self.scrollArea = QtWidgets.QScrollArea()
self.camEntriesTable = CamEntryTable()
# Default Widgets to disabled
self.scrollArea.setDisabled(True)
# Setup Scroll Area
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.camEntriesTable)
self.layout.addWidget(self.scrollArea)
def loadData(self, camData):
self.camEntries = [camData[i:i+21] for i in range(0, len(camData), 21)]
self.scrollArea.setDisabled(False)
self.camEntriesTable.populateTable(self.camEntries)
def closeData(self):
self.camEntries = []
self.camEntriesTable.clearTable()
self.scrollArea.setDisabled(True)
def saveEntryData(self):
return self.camEntriesTable.save()
class CamEntryTable(QtWidgets.QTableWidget):
def __init__(self):
QtWidgets.QTableWidget.__init__(self)
# Setup Table Properties
self.setColumnCount(5)
self.setAlternatingRowColors(True)
self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
# Setup Header Bar
header = self.horizontalHeader()
header.setStretchLastSection(True)
header.setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
self.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem('Node'))
self.setHorizontalHeaderItem(1, QtWidgets.QTableWidgetItem('X Offset'))
self.setHorizontalHeaderItem(2, QtWidgets.QTableWidgetItem('Y Offset'))
self.setHorizontalHeaderItem(3, QtWidgets.QTableWidgetItem('Z Offset'))
self.setHorizontalHeaderItem(4, QtWidgets.QTableWidgetItem('Unkown'))
# Hide Row Numbers
self.verticalHeader().setVisible(False)
def populateTable(self, camEntries):
s = struct.Struct('<5s f f f I')
for i in range(len(camEntries)):
entryStruct = s.unpack(camEntries[i])
self.insertRow(i)
self.setCellWidget(i, 0, NameEditor(str(entryStruct[0], 'utf-8'))) # Node
self.setCellWidget(i, 1, FloatEditor(float(entryStruct[1]))) # X Offset
self.setCellWidget(i, 2, FloatEditor(float(entryStruct[2]))) # Y Offset
self.setCellWidget(i, 3, FloatEditor(float(entryStruct[3]))) # Z Offset
self.setCellWidget(i, 4, UnkEditor(int(entryStruct[4]))) # Unknown
def clearTable(self):
while self.rowCount() > 0:
self.removeRow(0)
def save(self):
s = struct.Struct('<5s f f f I')
entries = b''
for i in range(self.rowCount()):
entry = []
entry.append(bytes(self.cellWidget(i, 0).text(), 'utf-8'))
entry.append(self.cellWidget(i, 1).value())
entry.append(self.cellWidget(i, 2).value())
entry.append(self.cellWidget(i, 3).value())
entry.append(self.cellWidget(i, 4).value())
entries = entries + s.pack(*entry)
return entries
class NameEditor(QtWidgets.QLineEdit):
def __init__(self, val, parent=None):
QtWidgets.QLineEdit.__init__(self, parent=parent)
self.setMaxLength(4)
self.setText(val)
class FloatEditor(QtWidgets.QDoubleSpinBox):
def __init__(self, val, parent=None):
QtWidgets.QDoubleSpinBox.__init__(self, parent=parent)
self.setRange(-1000000, 1000000)
self.setDecimals(7)
self.setValue(val)
class UnkEditor(QtWidgets.QSpinBox):
def __init__(self, val, parent=None):
QtWidgets.QSpinBox.__init__(self, parent=parent)
self.setRange(0, 0x7FFFFFFF)
self.setValue(val)