Search in sources :

Example 1 with ModifiedKeyBinding

use of watson.gui.ModifiedKeyBinding in project watson by totemo.

the class Configuration method configureValidator.

// --------------------------------------------------------------------------
/**
   * Perform lazy initialisation of the SnakeValidator used to validate in
   * load().
   */
protected void configureValidator() {
    if (_validator == null) {
        _validator = new SnakeValidator();
        MapValidatorNode root = new MapValidatorNode();
        root.addChild("enabled", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("debug", new TypeValidatorNode(Boolean.class, true, false));
        root.addChild("auto_page", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("region_info_timeout", new TypeValidatorNode(Double.class, true, 5.0));
        root.addChild("vectors_shown", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("billboard_background", new TypeValidatorNode(Integer.class, true, 0x7F000000));
        root.addChild("billboard_foreground", new TypeValidatorNode(Integer.class, true, 0xFFFFFFFF));
        // Default to true until we can distinguish server vs player gamemode.
        root.addChild("group_ores_in_creative", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("teleport_command", new TypeValidatorNode(String.class, true, "/tppos %g %d %g"));
        root.addChild("chat_timeout", new TypeValidatorNode(Double.class, true, 0.1));
        root.addChild("max_auto_pages", new TypeValidatorNode(Integer.class, true, 10));
        root.addChild("pre_count", new TypeValidatorNode(Integer.class, true, 45));
        root.addChild("post_count", new TypeValidatorNode(Integer.class, true, 45));
        root.addChild("watson_prefix", new TypeValidatorNode(String.class, true, "w"));
        root.addChild("ss_player_directory", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("ss_player_suffix", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("ss_date_directory", new TypeValidatorNode(String.class, true, ""));
        root.addChild("reformat_query_results", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("recolour_query_results", new TypeValidatorNode(Boolean.class, true, true));
        root.addChild("time_ordered_deposits", new TypeValidatorNode(Boolean.class, true, false));
        root.addChild("vector_length", new TypeValidatorNode(Double.class, true, 4.0));
        for (Entry<String, ModifiedKeyBinding> entry : getKeyBindingsMap().entrySet()) {
            root.addChild(entry.getKey(), new TypeValidatorNode(String.class, true, entry.getValue().toString()));
        }
        _validator.setRoot(root);
    }
}
Also used : SnakeValidator(watson.yaml.SnakeValidator) MapValidatorNode(watson.yaml.MapValidatorNode) TypeValidatorNode(watson.yaml.TypeValidatorNode) ModifiedKeyBinding(watson.gui.ModifiedKeyBinding)

Example 2 with ModifiedKeyBinding

use of watson.gui.ModifiedKeyBinding in project watson by totemo.

the class Configuration method save.

// load
// --------------------------------------------------------------------------
/**
   * Save the configuration.
   */
public void save() {
    File config = new File(Controller.getModDirectory(), CONFIG_FILE);
    BufferedWriter writer;
    try {
        writer = new BufferedWriter(new FileWriter(config));
        HashMap<String, Object> dom = new HashMap<String, Object>();
        dom.put("enabled", isEnabled());
        dom.put("debug", isDebug());
        dom.put("auto_page", isAutoPage());
        dom.put("region_info_timeout", getRegionInfoTimeoutSeconds());
        dom.put("vectors_shown", getVectorsShown());
        dom.put("billboard_background", getBillboardBackground());
        dom.put("billboard_foreground", getBillboardForeground());
        dom.put("group_ores_in_creative", isGroupingOresInCreative());
        dom.put("teleport_command", getTeleportCommand());
        dom.put("chat_timeout", getChatTimeoutSeconds());
        dom.put("max_auto_pages", getMaxAutoPages());
        dom.put("pre_count", getPreCount());
        dom.put("post_count", getPostCount());
        dom.put("watson_prefix", getWatsonPrefix());
        dom.put("ss_player_directory", _ssPlayerDirectory);
        dom.put("ss_player_suffix", _ssPlayerSuffix);
        dom.put("ss_date_directory", _ssDateDirectory.toPattern());
        dom.put("reformat_query_results", _reformatQueryResults);
        dom.put("recolour_query_results", _recolourQueryResults);
        dom.put("time_ordered_deposits", _timeOrderedDeposits);
        dom.put("vector_length", (double) _vectorLength);
        for (Entry<String, ModifiedKeyBinding> entry : getKeyBindingsMap().entrySet()) {
            dom.put(entry.getKey(), entry.getValue().toString());
        }
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        Yaml yaml = new Yaml(options);
        yaml.dump(dom, writer);
    } catch (IOException ex) {
        Log.exception(Level.SEVERE, "unable to save configuration file", ex);
    }
}
Also used : HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) DumperOptions(org.yaml.snakeyaml.DumperOptions) IOException(java.io.IOException) File(java.io.File) ModifiedKeyBinding(watson.gui.ModifiedKeyBinding) Yaml(org.yaml.snakeyaml.Yaml) BufferedWriter(java.io.BufferedWriter)

Example 3 with ModifiedKeyBinding

use of watson.gui.ModifiedKeyBinding in project watson by totemo.

the class LiteModWatson method onKeyBindingSetKeyBindState.

// --------------------------------------------------------------------------
/**
   * This EventInjectionTransformer listener for KeyBinding.setKeyBindState()
   * intercepts key events and mouse clicks and checks for ModifiedKeyBinding
   * activations.
   */
public static void onKeyBindingSetKeyBindState(EventInfo<?> event, int keyCode, boolean down) {
    ModifiedKeyBinding binding = getActivatedKeyBinding(keyCode);
    if (down && binding != null) {
        // If Watson should handle the key, then cancel Minecraft's normal
        // handling of that key (which may be bound).
        performKeyBinding(binding);
        event.cancel();
    }
}
Also used : ModifiedKeyBinding(watson.gui.ModifiedKeyBinding)

Example 4 with ModifiedKeyBinding

use of watson.gui.ModifiedKeyBinding in project watson by totemo.

the class LiteModWatson method onInventoryPlayerChangeCurrentItem.

// --------------------------------------------------------------------------
/**
   * This EventInjectionTransformer listener for
   * InventoryPlayer.changeCurrentItem() intercepts mouse scrolls events and
   * checks for ModifiedKeyBinding activations.
   */
public static void onInventoryPlayerChangeCurrentItem(EventInfo<InventoryPlayer> event, int wheelDelta) {
    int keyCode = (wheelDelta < 0) ? MouseButton.SCROLL_DOWN.getCode() : (wheelDelta > 0) ? keyCode = MouseButton.SCROLL_UP.getCode() : 0;
    if (keyCode != 0) {
        ModifiedKeyBinding binding = getActivatedKeyBinding(keyCode);
        if (binding != null) {
            performKeyBinding(binding);
            event.cancel();
        }
    }
}
Also used : ModifiedKeyBinding(watson.gui.ModifiedKeyBinding)

Example 5 with ModifiedKeyBinding

use of watson.gui.ModifiedKeyBinding in project watson by totemo.

the class Configuration method load.

// --------------------------------------------------------------------------
/**
   * Load the configuration file.
   */
public void load() {
    configureValidator();
    Log.info("Loading \"" + CONFIG_FILE + "\" from file.");
    File config = new File(Controller.getModDirectory(), CONFIG_FILE);
    BufferedInputStream in;
    try {
        in = new BufferedInputStream(new FileInputStream(config));
        ValidatorMessageSink logSink = new ValidatorMessageSink() {

            @Override
            public void message(String text) {
                Log.config(text);
            }
        };
        @SuppressWarnings("unchecked") HashMap<String, Object> dom = (HashMap<String, Object>) _validator.loadAndValidate(in, logSink);
        // Avoid calling setEnabled() at startup.
        // It would crash in Controller.getBlockEditSet() because server is not
        // set.
        _enabled = (Boolean) dom.get("enabled");
        // Avoid outputting a message in the client here:
        Log.setDebug((Boolean) dom.get("debug"));
        _autoPage = (Boolean) dom.get("auto_page");
        _regionInfoTimeoutSeconds = ((Number) dom.get("region_info_timeout")).doubleValue();
        _vectorsShown = (Boolean) dom.get("vectors_shown");
        _billboardBackground = (Integer) dom.get("billboard_background");
        _billboardForeground = (Integer) dom.get("billboard_foreground");
        _groupingOresInCreative = (Boolean) dom.get("group_ores_in_creative");
        _teleportCommand = (String) dom.get("teleport_command");
        _chatTimeoutSeconds = (Double) dom.get("chat_timeout");
        _maxAutoPages = (Integer) dom.get("max_auto_pages");
        _preCount = (Integer) dom.get("pre_count");
        _postCount = (Integer) dom.get("post_count");
        _watsonPrefix = (String) dom.get("watson_prefix");
        _ssPlayerDirectory = (Boolean) dom.get("ss_player_directory");
        _ssPlayerSuffix = (Boolean) dom.get("ss_player_suffix");
        setSsDateDirectoryImp((String) dom.get("ss_date_directory"));
        _reformatQueryResults = (Boolean) dom.get("reformat_query_results");
        _recolourQueryResults = (Boolean) dom.get("recolour_query_results");
        _timeOrderedDeposits = (Boolean) dom.get("time_ordered_deposits");
        _vectorLength = ((Double) dom.get("vector_length")).floatValue();
        for (Entry<String, ModifiedKeyBinding> entry : getKeyBindingsMap().entrySet()) {
            entry.getValue().parse((String) dom.get(entry.getKey()));
        }
    } catch (Exception ex) {
        Log.config("Missing configuration file (" + config + "). Using defaults.");
        // So save a default config.
        save();
    }
}
Also used : ValidatorMessageSink(watson.yaml.ValidatorMessageSink) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) File(java.io.File) FileInputStream(java.io.FileInputStream) ModifiedKeyBinding(watson.gui.ModifiedKeyBinding) IOException(java.io.IOException)

Aggregations

ModifiedKeyBinding (watson.gui.ModifiedKeyBinding)5 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 DumperOptions (org.yaml.snakeyaml.DumperOptions)1 Yaml (org.yaml.snakeyaml.Yaml)1 MapValidatorNode (watson.yaml.MapValidatorNode)1 SnakeValidator (watson.yaml.SnakeValidator)1 TypeValidatorNode (watson.yaml.TypeValidatorNode)1 ValidatorMessageSink (watson.yaml.ValidatorMessageSink)1