Merge pull request #92 from Rubisk/worldmetadeta

Added World-Metadeta
This commit is contained in:
David Vierra 2015-05-22 02:09:37 -10:00
commit 2add2c263e
10 changed files with 768 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -13,6 +13,7 @@ from mcedit2.editorcommands.find_replace import FindReplaceDialog
from mcedit2.editorcommands.analyze import AnalyzeOutputDialog
from mcedit2.editortools.select import SelectCommand
from mcedit2.panels.player import PlayerPanel
from mcedit2.panels.worldmeta import WorldMetaPanel
from mcedit2.util.dialogs import NotImplementedYet
from mcedit2.util.directories import getUserSchematicsDirectory
from mceditlib.util.lazyprop import weakrefprop
@ -278,7 +279,8 @@ class EditorSession(QtCore.QObject):
progress("Loading panels...")
self.playerPanel = PlayerPanel(self)
self.panels = [self.playerPanel]
self.worldMetaPanel = WorldMetaPanel(self)
self.panels = [self.playerPanel, self.worldMetaPanel]
# --- Tools ---

View File

@ -93,7 +93,7 @@ class PlayerPanel(QtGui.QWidget):
action.setCheckable(True)
action.triggered.connect(self.toggleView)
self._toggleViewAction = action
self.editorSession.revisionChanged.connect(self.revisionDidChange)
self.initPropertiesWidget()
@ -172,6 +172,9 @@ class PlayerPanel(QtGui.QWidget):
else:
self.hide()
self._toggleViewAction.setChecked(False)
def closeEvent(self, event):
self.toggleView()
def toggleViewAction(self):
return self._toggleViewAction

View File

@ -0,0 +1,263 @@
"""
player
"""
from __future__ import absolute_import
import logging
from contextlib import contextmanager
from PySide import QtGui
from PySide.QtCore import Qt
from mcedit2.command import SimpleRevisionCommand
from mcedit2.util.resources import resourcePath
from mcedit2.util.load_ui import load_ui
from mcedit2.util.screen import centerWidgetInScreen
log = logging.getLogger(__name__)
class WorldMetaPanel(QtGui.QWidget):
GENERATOR_TYPES = ['default', 'flat', 'largeBiomes', 'amplified', 'customized', 'debug_all_block_states']
editsDisabled = False
def __init__(self, editorSession):
super(WorldMetaPanel, self).__init__(QtGui.qApp.mainWindow, f=Qt.Tool)
self.editorSession = editorSession
self.worldMeta = self.editorSession.worldEditor.adapter.metadata
callIcon = QtGui.QIcon(resourcePath('mcedit2/assets/mcedit2/icons/edit_metadata.png'))
callButton = QtGui.QAction(callIcon, self.tr('World Info'), self)
callButton.setCheckable(True)
callButton.triggered.connect(self.toggleView)
self._toggleViewAction = callButton
load_ui('panels/worldmeta.ui', baseinstance=self)
self.worldNBTEditor.editorSession = self.editorSession
self.editorSession.revisionChanged.connect(self.revisionDidChange)
self.gamemodes = [self.tr('Survival'), self.tr('Creative'), self.tr('Adventure'), self.tr('Spectator')]
self.difficulties = [self.tr('Peaceful'), self.tr('Easy'), self.tr('Normal'), self.tr('Hard')]
self.generatorNames = [self.tr('Default'), self.tr('Flat'), self.tr('Large Biomes'), self.tr('Amplified'),
self.tr('Customized'), self.tr('Debug All Block States')]
self.defaultGamemodeCombo.addItems(self.gamemodes)
self.defaultGamemodeCombo.currentIndexChanged.connect(self.defaultGamemodeChanged)
self.worldDifficultyCombo.addItems(self.difficulties)
self.worldDifficultyCombo.currentIndexChanged.connect(self.worldDifficultyChanged)
self.generationTypeCombo.addItems(self.generatorNames)
self.generationTypeCombo.currentIndexChanged.connect(self.generationTypeChanged)
self.worldNameLineEdit.editingFinished.connect(self.worldNameChanged)
self.generatorSeedLineEdit.editingFinished.connect(self.seedChanged)
self.generatorOptionsLineEdit.editingFinished.connect(self.generatorOptionsChanged)
self.spawnX.editingFinished.connect(self.spawnChanged)
self.spawnY.editingFinished.connect(self.spawnChanged)
self.spawnZ.editingFinished.connect(self.spawnChanged)
self.timeDays.editingFinished.connect(self.timeChanged)
self.timeSlider.sliderReleased.connect(self.timeChanged)
self.dawnButton.setIcon(QtGui.QIcon(resourcePath('mcedit2/assets/mcedit2/clock/dawn.png')))
self.dawnButton.pressed.connect(self.setTimeDawn)
self.noonButton.setIcon(QtGui.QIcon(resourcePath('mcedit2/assets/mcedit2/clock/noon.png')))
self.noonButton.pressed.connect(self.setTimeNoon)
self.eveningButton.setIcon(QtGui.QIcon(resourcePath('mcedit2/assets/mcedit2/clock/evening.png')))
self.eveningButton.pressed.connect(self.setTimeEvening)
self.nightButton.setIcon(QtGui.QIcon(resourcePath('mcedit2/assets/mcedit2/clock/night.png')))
self.nightButton.pressed.connect(self.setTimeNight)
self.lockedDifficultyBool.stateChanged.connect(self.lockedDifficultyChanged)
self.commandsBool.stateChanged.connect(self.allowCommandsChanged)
self.hardcoreBool.stateChanged.connect(self.hardcoreChanged)
self.updatePanel()
self.updateNBTTree()
centerWidgetInScreen(self)
def updatePanel(self):
self.defaultGamemodeCombo.setCurrentIndex(self.worldMeta.GameType)
self.worldDifficultyCombo.setCurrentIndex(self.worldMeta.Difficulty)
self.generationTypeCombo.setCurrentIndex(self.GENERATOR_TYPES.index(self.worldMeta.generatorName))
self.worldNameLineEdit.setText(self.worldMeta.LevelName)
self.worldNameLineEdit.setText(self.worldMeta.LevelName)
self.generatorSeedLineEdit.setText(str(self.worldMeta.RandomSeed))
self.generatorOptionsLineEdit.setText(self.worldMeta.generatorOptions)
sx, sy, sz = self.worldMeta.worldSpawnPosition()
self.spawnX.setValue(sx)
self.spawnY.setValue(sy)
self.spawnZ.setValue(sz)
time = self.worldMeta.DayTime + 30000 # On time = 0, it's day 1, 6:00. Day 0, 0:00 is -30000
day = time / 24000
hourminute = (time % 24000)
self.timeDays.setValue(day)
h, m = (hourminute / 1000), ((hourminute % 1000) / (1000.0/60.0))
self.timeLabel.setText('{h:02d}:{m:02d}'.format(h=int(h), m=int(m)))
self.timeSlider.setValue(hourminute)
self.lockedDifficultyBool.setChecked(bool(self.worldMeta.DifficultyLocked))
self.commandsBool.setChecked(bool(self.worldMeta.allowCommands))
self.hardcoreBool.setChecked(bool(self.worldMeta.hardcore))
@contextmanager # xxx copied from inventory.py
def disableEdits(self):
self.editsDisabled = True
yield
self.editsDisabled = False
def updateNBTTree(self):
self.worldNBTEditor.undoCommandPrefixText = self.tr('World Metadata: ')
self.worldNBTEditor.setRootTagRef(self.worldMeta)
def revisionDidChange(self):
self.worldMeta = self.editorSession.worldEditor.adapter.metadata
self.updateNBTTree()
self.updatePanel()
def toggleView(self):
if self.isHidden():
self.show()
self._toggleViewAction.setChecked(True)
else:
self.hide()
self._toggleViewAction.setChecked(False)
def closeEvent(self, event):
self.toggleView()
_toggleViewAction = None
def toggleViewAction(self):
return self._toggleViewAction
# -- Listeners to change NBT tags on editing (does it really need a function per tag?)
def worldNameChanged(self):
if self.editsDisabled or self.worldMeta.LevelName == self.worldNameLineEdit.text():
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Level Name'))
with command.begin():
self.worldMeta.LevelName = self.worldNameLineEdit.text()
self.editorSession.pushCommand(command)
def seedChanged(self):
if self.editsDisabled or self.worldMeta.RandomSeed == long(self.generatorSeedLineEdit.text()):
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Generator Random Seed'))
with command.begin():
self.worldMeta.RandomSeed = long(self.generatorSeedLineEdit.text())
self.editorSession.pushCommand(command)
def generatorOptionsChanged(self):
if self.editsDisabled or self.worldMeta.generatorOptions == self.generatorOptionsLineEdit.text():
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Generator Options'))
with command.begin():
self.worldMeta.generatorOptions = self.generatorOptionsLineEdit.text()
self.editorSession.pushCommand(command)
def defaultGamemodeChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Default Gamemode'))
with command.begin():
self.worldMeta.GameType = self.defaultGamemodeCombo.currentIndex()
self.editorSession.pushCommand(command)
def worldDifficultyChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Difficulty'))
with command.begin():
self.worldMeta.Difficulty = self.worldDifficultyCombo.currentIndex()
self.editorSession.pushCommand(command)
def generationTypeChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Generation Type'))
with command.begin():
self.worldMeta.generatorName = self.GENERATOR_TYPES[self.generationTypeCombo.currentIndex()]
self.editorSession.pushCommand(command)
def spawnChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Spawn Coordinates'))
with command.begin():
self.worldMeta.setWorldSpawnPosition(self.spawnX.value(), self.spawnY.value(), self.spawnZ.value())
self.editorSession.pushCommand(command)
def timeChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change DayTime'))
with command.begin():
days, time = self.timeDays.value(), self.timeSlider.value()
print days, time
time = max((days * 24000 + time) - 30000, 0)
self.worldMeta.DayTime = time
self.editorSession.pushCommand(command)
def setTimeDawn(self):
self.timeSlider.setValue(6000)
self.timeChanged()
def setTimeNoon(self):
self.timeSlider.setValue(12000)
self.timeChanged()
def setTimeEvening(self):
self.timeSlider.setValue(18000)
self.timeChanged()
def setTimeNight(self):
self.timeSlider.setValue(0)
self.timeChanged()
def hardcoreChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Hardcore'))
with command.begin():
self.worldMeta.hardcore = self.hardcoreBool.isChecked()
self.editorSession.pushCommand(command)
def lockedDifficultyChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Locked Difficulty'))
with command.begin():
self.worldMeta.DifficultyLocked = self.lockedDifficultyBool.isChecked()
self.editorSession.pushCommand(command)
def allowCommandsChanged(self):
if self.editsDisabled: # xxx copied from inventory.py
return
command = WorldMetaEditCommand(self.editorSession, self.tr('Change Allow Commands'))
with command.begin():
self.worldMeta.allowCommands = self.commandsBool.isChecked()
self.editorSession.pushCommand(command)
class WorldMetaEditCommand(SimpleRevisionCommand):
pass

View File

@ -0,0 +1,490 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>558</width>
<height>691</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit World Info</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_1">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="worldMetaTab">
<attribute name="title">
<string>World Info</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="generalGroupBox">
<property name="title">
<string>General</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="worldNameLineEdit"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
</item>
<item>
<widget class="QCheckBox" name="commandsBool">
<property name="text">
<string>Commands</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="settingsGroupBox">
<property name="title">
<string>Game Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Difficulty:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="worldDifficultyCombo"/>
</item>
<item>
<widget class="QCheckBox" name="lockedDifficultyBool">
<property name="text">
<string>Locked</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hardcoreBool">
<property name="text">
<string>Hardcore</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="generatorGroupBox">
<property name="title">
<string>Generator</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Seed:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="generatorSeedLineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="generationTypeCombo"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Options:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="generatorOptionsLineEdit"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Time</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Day: </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="timeDays">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000000000</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="timeLabel">
<property name="text">
<string>11:15</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="nightButton">
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Midnight</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="dawnButton">
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Dawn</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="noonButton">
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Noon</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="eveningButton">
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Evening</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>60</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="timeSlider">
<property name="maximum">
<number>23999</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="sliderPosition">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="spawnGroupBox">
<property name="title">
<string>Spawn</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6" stretch="0,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Default Game Mode (Multiplayer):</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="defaultGamemodeCombo"/>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spawnX"/>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spawnY"/>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spawnZ"/>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="nbtTreeTab">
<attribute name="title">
<string>NBT Tree</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="NBTEditorWidget" name="worldNBTEditor" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>NBTEditorWidget</class>
<extends>QWidget</extends>
<header>nbteditorwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -357,10 +357,17 @@ class AnvilWorldMetadata(object):
SizeOnDisk = nbtattr.NBTAttr('SizeOnDisk', nbt.TAG_Long, 0)
RandomSeed = nbtattr.NBTAttr('RandomSeed', nbt.TAG_Long, 0)
Time = nbtattr.NBTAttr('Time', nbt.TAG_Long, 0) # Age of the world in ticks. 20 ticks per second; 24000 ticks per day.
DayTime = nbtattr.NBTAttr('DayTime', nbt.TAG_Long, 0) # Amount of ticks since Day 1, 6:00
LastPlayed = nbtattr.NBTAttr('LastPlayed', nbt.TAG_Long, time.time() * 1000)
Difficulty = nbtattr.NBTAttr('Difficulty', nbt.TAG_Byte, 0)
LevelName = nbtattr.NBTAttr('LevelName', nbt.TAG_String, "Untitled World")
hardcore = nbtattr.NBTAttr('hardcore', nbt.TAG_Byte, False)
allowCommands = nbtattr.NBTAttr('allowCommands', nbt.TAG_Byte, False)
DifficultyLocked = nbtattr.NBTAttr('DifficultyLocked', nbt.TAG_Byte, False)
generatorName = nbtattr.NBTAttr('generatorName', nbt.TAG_String, "default")
generatorOptions = nbtattr.NBTAttr('generatorOptions', nbt.TAG_String, "") #Default is different for every generatorType
MapFeatures = nbtattr.NBTAttr('MapFeatures', nbt.TAG_Byte, 1)
GameType = nbtattr.NBTAttr('GameType', nbt.TAG_Int, 0) # 0 for survival, 1 for creative