码迷,mamicode.com
首页 > 其他好文 > 详细

Minecraft Client 教程 #6 添加Setting

时间:2020-02-25 20:15:57      阅读:19      评论:0      收藏:0      [点我收藏+]

标签:博客   oid   min   href   ref   list()   tar   his   nec   

首发于Enaium的个人博客


一. 写Setting类

package cn.enaium.coreium.setting;

import cn.enaium.coreium.module.Module;

import java.util.ArrayList;

public class Setting {

    private Module module;
    private String name;
    private boolean toggle;
    private double currentValueDouble, minValueDouble, maxValueDouble;
    private int currentValueInt, minValueInt, maxValueInt;
    private float currentValueFloat, minValueFloat, maxValueFloat;
    private ArrayList<String> modes;
    private String currentMode;
    private Category category;

    public enum Category {
        BOOLEAN,
        VALUE,
        MODE;
    }

    public Setting(Module module, String name, boolean toggle) {
        this.module = module;
        this.name = name;
        this.toggle = toggle;
        this.category = Category.BOOLEAN;
    }

    public Setting(Module module, String name, int currentValueInt, int minValueInt, int maxValueInt) {
        this.module = module;
        this.name = name;
        this.currentValueInt = currentValueInt;
        this.minValueInt = minValueInt;
        this.maxValueInt = maxValueInt;
        this.category = Category.VALUE;
    }

    public Setting(Module module, String name, double currentValueDouble, double minValueDouble, double maxValueDouble) {
        this.module = module;
        this.name = name;
        this.currentValueDouble = currentValueDouble;
        this.minValueDouble = minValueDouble;
        this.maxValueDouble = maxValueDouble;
        this.category = Category.VALUE;
    }

    public Setting(Module module, String name, float currentValueFloat, float minValueFloat, float maxValueFloat) {
        this.module = module;
        this.name = name;
        this.currentValueFloat = currentValueFloat;
        this.minValueFloat = minValueFloat;
        this.maxValueFloat = maxValueFloat;
        this.category = Category.VALUE;
    }

    public Setting(Module m, String n, String currentOption, ArrayList<String> options) {
        this.module = m;
        this.name = n;
        this.currentMode = currentOption;
        this.modes = options;
        this.category = Category.MODE;
    }

    public void setToggle(boolean toggle) {
        this.toggle = toggle;
    }

    public void setCurrentValueDouble(double currentValueDouble) {
        this.currentValueDouble = currentValueDouble;
    }

    public void setCurrentValueInt(int currentValueInt) {
        this.currentValueInt = currentValueInt;
    }

    public void setCurrentValueFloat(float currentValueFloat) {
        this.currentValueFloat = currentValueFloat;
    }

    public Module getModule() {
        return module;
    }

    public String getName() {
        return name;
    }

    public boolean isToggle() {
        return toggle;
    }

    public double getCurrentValueDouble() {
        return currentValueDouble;
    }

    public double getMinValueDouble() {
        return minValueDouble;
    }

    public double getMaxValueDouble() {
        return maxValueDouble;
    }

    public int getCurrentValueInt() {
        return currentValueInt;
    }

    public int getMinValueInt() {
        return minValueInt;
    }

    public int getMaxValueInt() {
        return maxValueInt;
    }

    public float getCurrentValueFloat() {
        return currentValueFloat;
    }

    public float getMinValueFloat() {
        return minValueFloat;
    }

    public float getMaxValueFloat() {
        return maxValueFloat;
    }

    public ArrayList<String> getModes() {
        return modes;
    }

    public String getCurrentMode() {
        return currentMode;
    }

    public boolean isBoolean() {
        return this.category.equals(Category.BOOLEAN);
    }

    public boolean isValue() {
        return this.category.equals(Category.VALUE);
    }

    public boolean isMode() {
        return this.category.equals(Category.MODE);
    }
}

二. 写SettingManager

package cn.enaium.coreium.setting;

import cn.enaium.coreium.module.Module;

import java.util.ArrayList;

public class SettingManager {
    private ArrayList<Setting> settings;

    public SettingManager() {
        this.settings = new ArrayList();
    }

    public void addSetting(Setting s) {
        this.settings.add(s);
    }

    public ArrayList<Setting> getSettings() {
        return this.settings;
    }
    
    public ArrayList<Setting> getSettingsForModule(Module m) {
        ArrayList<Setting> settings = new ArrayList<Setting>();

        for (Setting s : this.settings) {
            if (s.getModule().equals(m))
                settings.add(s);
        }

        if (settings.isEmpty())
            return null;

        return settings;
    }
}

二. 添加在Start

    [...]
    public SettingManager settingManager;

    public void start() {
        [...]
        settingManager = new SettingManager();
        [...]
    }

Minecraft Client 教程 #6 添加Setting

标签:博客   oid   min   href   ref   list()   tar   his   nec   

原文地址:https://www.cnblogs.com/Enaium/p/12363253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!