Esempio n. 1
0
 public static void CloneKillerFloat(KillerFloat targetFloat, KillerFloat sourceFloat)
 {
     targetFloat.curModMode        = sourceFloat.curModMode;
     targetFloat.selfValue         = sourceFloat.selfValue;
     targetFloat.worldVariableName = sourceFloat.worldVariableName;
     targetFloat.variableSource    = sourceFloat.variableSource;
 }
Esempio n. 2
0
    public static DTInspectorUtility.FunctionButtons DisplayKillerFloat(ref bool isDirty, KillerFloat killFloat, string fieldLabel, Object srcObject, bool showDeleteButton = false, bool indent = false)
    {
        var oldBg = GUI.backgroundColor;

        var allStatNames = AllStatNamesOfType(WorldVariableTracker.VariableType._float);

        EditorGUILayout.BeginHorizontal();

        if (indent)
        {
            GUILayout.Space(12);
        }

        GUILayout.Label(fieldLabel, GUILayout.MinWidth(50));

        GUILayout.FlexibleSpace();

        var newVarIndex = -1;

        var unfoundVariableName = string.Empty;

        if (showDeleteButton)
        {
            var newModMode = (KillerVariable.ModMode)EditorGUILayout.EnumPopup("", killFloat.curModMode, GUILayout.Width(ModModeFieldWidth));
            if (newModMode != killFloat.curModMode)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change Mod Mode for " + fieldLabel);
                killFloat.curModMode = newModMode;
            }
        }

        var fieldWidth    = showDeleteButton ? ShortFieldWidth : FieldWidth;
        var oldLabelWidth = EditorGUIUtility.labelWidth;

        EditorGUIUtility.labelWidth = TinyLabelWidth;

        switch (killFloat.variableSource)
        {
        case LevelSettings.VariableSource.Self:
            var newVal = EditorGUILayout.FloatField("F", killFloat.selfValue, GUILayout.MinWidth(fieldWidth));
            if (newVal != killFloat.selfValue)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change " + fieldLabel);
                killFloat.Value = newVal;
            }
            break;

        case LevelSettings.VariableSource.Variable:
            var oldIndex = allStatNames.IndexOf(killFloat.worldVariableName);
            if (oldIndex < 0)
            {
                unfoundVariableName = killFloat.worldVariableName;
                oldIndex            = 0;
            }

            newVarIndex = EditorGUILayout.Popup("F", oldIndex, allStatNames.ToArray(), GUILayout.MinWidth(fieldWidth));
            if (oldIndex != newVarIndex)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change Variable for " + fieldLabel);
                killFloat.worldVariableName = allStatNames[newVarIndex];
            }
            break;
        }

        EditorGUIUtility.labelWidth = oldLabelWidth;

        GUI.backgroundColor = DTInspectorUtility.BrightButtonColor;
        var newSource = (LevelSettings.VariableSource)EditorGUILayout.EnumPopup(killFloat.variableSource, GUILayout.Width(70));

        if (newSource != killFloat.variableSource)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref isDirty, srcObject, "change source of " + fieldLabel);
            killFloat.variableSource = newSource;
        }
        GUI.backgroundColor = oldBg;

        var deletePressed = false;

        if (showDeleteButton)
        {
            GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor;
            if (GUILayout.Button(new GUIContent("Delete", "Remove this mod"), EditorStyles.miniButton, GUILayout.Width(50)))
            {
                deletePressed = true;
            }
            GUI.backgroundColor = oldBg;
        }

        EditorGUILayout.EndHorizontal();

        if (killFloat.variableSource != LevelSettings.VariableSource.Variable ||
            (killFloat.worldVariableName != LevelSettings.DropDownNoneOption && newVarIndex > 0))
        {
            return(deletePressed ? DTInspectorUtility.FunctionButtons.Remove : DTInspectorUtility.FunctionButtons.None);
        }
        if (string.IsNullOrEmpty(unfoundVariableName))
        {
            DTInspectorUtility.ShowLargeBarAlertBox("No variable has been selected. " + fieldLabel + " will get a value of " + KillerFloat.DefaultValue + ".");
        }
        else
        {
            DTInspectorUtility.ShowRedErrorBox("Could not find variable '" + unfoundVariableName + "' to assign to " + fieldLabel + ". Please select another.");
        }

        return(deletePressed ? DTInspectorUtility.FunctionButtons.Remove : DTInspectorUtility.FunctionButtons.None);
    }