Пример #1
0
    def __init__(self, tool):
        ToolOptions.__init__(self, name='Panel.BrushToolOptions')
        alphaField = FloatField(ref=ItemRef(tool.settings, 'brushAlpha'),
                                min=0.0,
                                max=1.0,
                                width=60)
        alphaField.increment = 0.1
        alphaRow = Row((Label("Alpha: "), alphaField))
        autoChooseCheckBox = CheckBoxLabel(
            "Choose Block Immediately",
            ref=ItemRef(tool.settings, "chooseBlockImmediately"),
            tooltipText=
            "When the brush tool is chosen, prompt for a block type.")

        updateOffsetCheckBox = CheckBoxLabel(
            "Reset Distance When Brush Size Changes",
            ref=ItemRef(tool.settings, "updateBrushOffset"),
            tooltipText=
            "Whenever the brush size changes, reset the distance to the brush blocks."
        )

        col = Column((Label("Brush Options"), alphaRow, autoChooseCheckBox,
                      updateOffsetCheckBox, Button("OK", action=self.dismiss)))
        self.add(col)
        self.shrink_wrap()
        return
Пример #2
0
 def build_field(itm):
     fields = []
     if type(itm) in field_types.keys():
         f, bounds = field_types[type(itm)]
         if bounds:
             fields = [f(ref=AttrRef(itm, 'value'), min=bounds[0], max=bounds[1]),]
         else:
             fields = [f(ref=AttrRef(itm, 'value')),]
     elif type(itm) in array_types.keys():
         idx = 0
         for _itm in itm.value.tolist():
             f, bounds = array_types[type(itm)]
             fields.append(f(ref=ItemRef(itm.value, idx)))
             idx += 1
     elif type(itm) in (TAG_Compound, TAG_List):
         for _itm in itm.value:
             fields.append(Label("%s"%(_itm.name or "%s #%03d"%(itm.name or _("Item"), itm.value.index(_itm))), align='l', doNotTranslate=True))
             fields += NBTExplorerToolPanel.build_field(_itm)
     elif type(itm) not in (str, unicode):
         if type(getattr(itm, 'value', itm)) not in (str, unicode, int, float):
             fld = Label
             kw = {'align': 'l'}
         else:
             fld = TextFieldWrapped
             kw = {}
         fields = [fld("%s"%getattr(itm, 'value', itm), doNotTranslate=True, **kw),]
     else:
         fields = [TextFieldWrapped("%s"%itm, doNotTranslata=True),]
     return fields
Пример #3
0
 def createField(self, key, value):
     """
     Creates a field matching the input type.
     :param key, key to store the value in, also the name of the label if type is float or int.
     :param value, default value for the field.
     """
     doNotTranslate = bool(hasattr(self.tool.brushMode, "trn"))
     check_value = value
     mi = 0
     ma = 100
     if key in ('W', 'H', 'L'):
         reference = AttrRef(self.tool, key)
     else:
         reference = ItemRef(self.tool.options, key)
     if isinstance(check_value, tuple):
         check_value = value[0]
         mi = value[1]
         ma = value[2]
     if isinstance(check_value, Block):
         if key not in self.tool.recentBlocks:
             self.tool.recentBlocks[key] = []
         wcb = getattr(self.tool.brushMode, 'wildcardBlocks', [])
         aw = False
         if key in wcb:
             aw = True
         field = BlockButton(self.tool.editor.level.materials,
                             ref=reference,
                             recentBlocks=self.tool.recentBlocks[key],
                             allowWildcards=aw)
     elif isinstance(check_value, types.MethodType):
         field = Button(key, action=value)
     else:
         if doNotTranslate:
             key = self.tool.brushMode.trn._(key)
             value = self.tool.brushMode.trn._(value)
         if isinstance(check_value, int):
             field = IntInputRow(key,
                                 ref=reference,
                                 width=50,
                                 min=mi,
                                 max=ma,
                                 doNotTranslate=doNotTranslate)
         elif isinstance(check_value, float):
             field = FloatInputRow(key,
                                   ref=reference,
                                   width=50,
                                   min=mi,
                                   max=ma,
                                   doNotTranslate=doNotTranslate)
         elif isinstance(check_value, bool):
             field = CheckBoxLabel(key,
                                   ref=reference,
                                   doNotTranslate=doNotTranslate)
         elif isinstance(check_value, str):
             field = Label(value, doNotTranslate=doNotTranslate)
         else:
             print(type(check_value))
             field = None
     return field
Пример #4
0
    def __init__(self, tool):
        Panel.__init__(self, name='Panel.BrushPanel')
        self.tool = tool
        """
        presets, modeRow and styleRow are always created, no matter
        what brush is selected. styleRow can be disabled by putting disableStyleButton = True
        in the brush file.
        """
        presets = self.createPresetRow()

        self.brushModeButtonLabel = Label("Mode:")
        self.brushModeButton = ChoiceButton(
            sorted([mode for mode in tool.brushModes]),
            width=150,
            choose=self.brushModeChanged,
            doNotTranslate=True,
        )
        modeRow = Row([self.brushModeButtonLabel, self.brushModeButton])

        self.brushStyleButtonLabel = Label("Style:")
        self.brushStyleButton = ValueButton(ref=ItemRef(
            self.tool.options, "Style"),
                                            action=self.tool.swapBrushStyles,
                                            width=150)

        styleRow = Row([self.brushStyleButtonLabel, self.brushStyleButton])
        self.brushModeButton.selectedChoice = self.tool.selectedBrushMode
        optionsColumn = []
        optionsColumn.extend([presets, modeRow])
        if not getattr(tool.brushMode, 'disableStyleButton', False):
            optionsColumn.append(styleRow)
        """
        We're going over all options in the selected brush module, and making
        a field for all of them.
        """
        for r in tool.brushMode.inputs:
            row = []
            for key, value in r.items():
                field = self.createField(key, value)
                row.append(field)
            row = Row(row)
            optionsColumn.append(row)
        if getattr(tool.brushMode, 'addPasteButton', False):
            importButton = Button("Import", action=tool.importPaste)
            importRow = Row([importButton])
            optionsColumn.append(importRow)
        optionsColumn = Column(optionsColumn, spacing=0)
        self.add(optionsColumn)
        self.shrink_wrap()