220 lines
7.3 KiB
Python
220 lines
7.3 KiB
Python
"""
|
|
EU-Utility - Inventory Manager Plugin
|
|
|
|
Track inventory items, value, and weight.
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from collections import defaultdict
|
|
|
|
from PyQt6.QtWidgets import (
|
|
QWidget, QVBoxLayout, QHBoxLayout, QLabel,
|
|
QPushButton, QTableWidget, QTableWidgetItem,
|
|
QLineEdit, QProgressBar, QFrame
|
|
)
|
|
from PyQt6.QtCore import Qt
|
|
|
|
from plugins.base_plugin import BasePlugin
|
|
|
|
|
|
class InventoryManagerPlugin(BasePlugin):
|
|
"""Track and manage inventory."""
|
|
|
|
name = "Inventory"
|
|
version = "1.0.0"
|
|
author = "ImpulsiveFPS"
|
|
description = "Track items, TT value, and weight"
|
|
hotkey = "ctrl+shift+i"
|
|
|
|
def initialize(self):
|
|
"""Setup inventory manager."""
|
|
self.data_file = Path("data/inventory.json")
|
|
self.data_file.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
self.items = []
|
|
self.max_slots = 200
|
|
self.max_weight = 355.0
|
|
|
|
self._load_data()
|
|
|
|
def _load_data(self):
|
|
"""Load inventory data."""
|
|
if self.data_file.exists():
|
|
try:
|
|
with open(self.data_file, 'r') as f:
|
|
data = json.load(f)
|
|
self.items = data.get('items', [])
|
|
except:
|
|
pass
|
|
|
|
def _save_data(self):
|
|
"""Save inventory data."""
|
|
with open(self.data_file, 'w') as f:
|
|
json.dump({'items': self.items}, f, indent=2)
|
|
|
|
def get_ui(self):
|
|
"""Create inventory UI."""
|
|
widget = QWidget()
|
|
widget.setStyleSheet("background: transparent;")
|
|
layout = QVBoxLayout(widget)
|
|
layout.setSpacing(15)
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
# Title
|
|
title = QLabel("🎒 Inventory Manager")
|
|
title.setStyleSheet("color: white; font-size: 16px; font-weight: bold;")
|
|
layout.addWidget(title)
|
|
|
|
# Stats
|
|
stats_frame = QFrame()
|
|
stats_frame.setStyleSheet("""
|
|
QFrame {
|
|
background-color: rgba(30, 35, 45, 200);
|
|
border: 1px solid rgba(100, 110, 130, 80);
|
|
border-radius: 6px;
|
|
}
|
|
""")
|
|
stats_layout = QVBoxLayout(stats_frame)
|
|
|
|
# Slots
|
|
slots_used = len(self.items)
|
|
slots_layout = QHBoxLayout()
|
|
slots_layout.addWidget(QLabel("Slots:"))
|
|
self.slots_progress = QProgressBar()
|
|
self.slots_progress.setMaximum(self.max_slots)
|
|
self.slots_progress.setValue(slots_used)
|
|
self.slots_progress.setStyleSheet("""
|
|
QProgressBar {
|
|
background-color: rgba(60, 70, 90, 150);
|
|
border: none;
|
|
border-radius: 3px;
|
|
text-align: center;
|
|
color: white;
|
|
}
|
|
QProgressBar::chunk {
|
|
background-color: #4a9eff;
|
|
border-radius: 3px;
|
|
}
|
|
""")
|
|
slots_layout.addWidget(self.slots_progress)
|
|
self.slots_label = QLabel(f"{slots_used}/{self.max_slots}")
|
|
self.slots_label.setStyleSheet("color: white;")
|
|
slots_layout.addWidget(self.slots_label)
|
|
stats_layout.addLayout(slots_layout)
|
|
|
|
# Weight
|
|
total_weight = sum(item.get('weight', 0) for item in self.items)
|
|
weight_layout = QHBoxLayout()
|
|
weight_layout.addWidget(QLabel("Weight:"))
|
|
self.weight_progress = QProgressBar()
|
|
self.weight_progress.setMaximum(int(self.max_weight))
|
|
self.weight_progress.setValue(int(total_weight))
|
|
self.weight_progress.setStyleSheet("""
|
|
QProgressBar {
|
|
background-color: rgba(60, 70, 90, 150);
|
|
border: none;
|
|
border-radius: 3px;
|
|
text-align: center;
|
|
color: white;
|
|
}
|
|
QProgressBar::chunk {
|
|
background-color: #ffc107;
|
|
border-radius: 3px;
|
|
}
|
|
""")
|
|
weight_layout.addWidget(self.weight_progress)
|
|
self.weight_label = QLabel(f"{total_weight:.1f}/{self.max_weight} kg")
|
|
self.weight_label.setStyleSheet("color: white;")
|
|
weight_layout.addWidget(self.weight_label)
|
|
stats_layout.addLayout(weight_layout)
|
|
|
|
# PED value
|
|
total_tt = sum(item.get('tt', 0) for item in self.items)
|
|
ped_label = QLabel(f"💰 Total TT: {total_tt:.2f} PED")
|
|
ped_label.setStyleSheet("color: #ffc107; font-weight: bold;")
|
|
stats_layout.addWidget(ped_label)
|
|
|
|
layout.addWidget(stats_frame)
|
|
|
|
# Items table
|
|
self.items_table = QTableWidget()
|
|
self.items_table.setColumnCount(5)
|
|
self.items_table.setHorizontalHeaderLabels(["Item", "Qty", "TT", "Weight", "Container"])
|
|
self.items_table.setStyleSheet("""
|
|
QTableWidget {
|
|
background-color: rgba(30, 35, 45, 200);
|
|
color: white;
|
|
border: 1px solid rgba(100, 110, 130, 80);
|
|
border-radius: 6px;
|
|
}
|
|
QHeaderView::section {
|
|
background-color: rgba(35, 40, 55, 200);
|
|
color: rgba(255,255,255,180);
|
|
padding: 8px;
|
|
font-weight: bold;
|
|
font-size: 11px;
|
|
}
|
|
""")
|
|
self.items_table.horizontalHeader().setStretchLastSection(True)
|
|
layout.addWidget(self.items_table)
|
|
|
|
self._refresh_items()
|
|
|
|
# Scan button
|
|
scan_btn = QPushButton("📸 Scan Inventory")
|
|
scan_btn.setStyleSheet("""
|
|
QPushButton {
|
|
background-color: #ff8c42;
|
|
color: white;
|
|
padding: 12px;
|
|
border: none;
|
|
border-radius: 4px;
|
|
font-weight: bold;
|
|
}
|
|
""")
|
|
scan_btn.clicked.connect(self._scan_inventory)
|
|
layout.addWidget(scan_btn)
|
|
|
|
layout.addStretch()
|
|
return widget
|
|
|
|
def _refresh_items(self):
|
|
"""Refresh items table."""
|
|
self.items_table.setRowCount(len(self.items))
|
|
|
|
for i, item in enumerate(self.items):
|
|
self.items_table.setItem(i, 0, QTableWidgetItem(item.get('name', 'Unknown')))
|
|
self.items_table.setItem(i, 1, QTableWidgetItem(str(item.get('quantity', 1))))
|
|
self.items_table.setItem(i, 2, QTableWidgetItem(f"{item.get('tt', 0):.2f}"))
|
|
self.items_table.setItem(i, 3, QTableWidgetItem(f"{item.get('weight', 0):.2f}"))
|
|
self.items_table.setItem(i, 4, QTableWidgetItem(item.get('container', 'Main')))
|
|
|
|
def _scan_inventory(self):
|
|
"""Scan inventory with OCR."""
|
|
# TODO: Implement OCR
|
|
pass
|
|
|
|
def add_item(self, name, quantity=1, tt=0.0, weight=0.0, container='Main'):
|
|
"""Add item to inventory."""
|
|
# Check if exists
|
|
for item in self.items:
|
|
if item['name'] == name and item['container'] == container:
|
|
item['quantity'] += quantity
|
|
item['tt'] += tt
|
|
item['weight'] += weight
|
|
self._save_data()
|
|
self._refresh_items()
|
|
return
|
|
|
|
# New item
|
|
self.items.append({
|
|
'name': name,
|
|
'quantity': quantity,
|
|
'tt': tt,
|
|
'weight': weight,
|
|
'container': container
|
|
})
|
|
self._save_data()
|
|
self._refresh_items()
|