Exemplo n.º 1
0
    public static void LoadFromJson(string jsonFileContents, InputConfig inputConfig)
    {
        var saveableInputConfig = JsonUtility.FromJson <SaveableInputConfig>(jsonFileContents);

        inputConfig.shortcutInputs = new ShortcutInputConfig[EnumX <MSChartEditorInputActions> .Count];

        foreach (var inputProperty in saveableInputConfig.actionProperties)
        {
            MSChartEditorInputActions action;
            if (System.Enum.TryParse(inputProperty.mSChartEditorInputAction, out action))
            {
                ShortcutInputConfig scInputConfig = new ShortcutInputConfig();
                scInputConfig.shortcut   = action;
                scInputConfig.properties = inputProperty.properties;
                inputConfig.shortcutInputs[(int)action] = scInputConfig;
            }
        }

        foreach (MSChartEditorInputActions msAction in EnumX <MSChartEditorInputActions> .Values)
        {
            if (inputConfig.shortcutInputs[(int)msAction] == null)
            {
                // Populate a default onto it
                ShortcutInputConfig scInputConfig = new ShortcutInputConfig();
                scInputConfig.shortcut = msAction;

                inputConfig.shortcutInputs[(int)msAction] = scInputConfig;
            }

            Debug.Assert(inputConfig.shortcutInputs[(int)msAction].shortcut == msAction);
        }
    }
    void InsertForNewActionAt(InputConfig inputConfigDatabase, int index)
    {
        List <ShortcutInputConfig> list      = new List <ShortcutInputConfig>(inputConfigDatabase.shortcutInputs);
        ShortcutInputConfig        newConfig = new ShortcutInputConfig();

        newConfig.shortcut = (MSChartEditorInputActions)index;

        list.Insert(index, newConfig);

        for (int i = index + 1; i < list.Count; ++i)
        {
            list[i].shortcut = list[i].shortcut + 1;
        }

        inputConfigDatabase.shortcutInputs = list.ToArray();
    }
Exemplo n.º 3
0
    void RepopulateInput(InputConfig inputConfigDatabase, bool preserveDisplayNames = false)
    {
        MSChartEditorInput.MSChartEditorActionContainer controls = new MSChartEditorInput.MSChartEditorActionContainer();

        ShortcutInputConfig[] shortcutInputs = new ShortcutInputConfig[EnumX <MSChartEditorInputActions> .Count];

        for (int i = 0; i < shortcutInputs.Length; ++i)
        {
            MSChartEditorInputActions scEnum = (MSChartEditorInputActions)i;

            InputConfig.Properties properties;
            if (!inputExplicitProperties.TryGetValue(scEnum, out properties))
            {
                properties = kDefaultProperties;
            }

            if (string.IsNullOrEmpty(properties.displayName))
            {
                properties.displayName = scEnum.ToString();
            }

            ShortcutInputConfig config = new ShortcutInputConfig();
            var defaultConfig          = controls.GetActionConfig(scEnum);
            var defaultProperties      = defaultConfig.properties;

            config.shortcut   = scEnum;
            config.properties = properties;

            if (preserveDisplayNames && i < inputConfigDatabase.shortcutInputs.Length)
            {
                config.properties.displayName = inputConfigDatabase.shortcutInputs[i].properties.displayName;
            }

            shortcutInputs[i] = config;
        }

        inputConfigDatabase.shortcutInputs = shortcutInputs;
    }