net.minecraft.client.gui.widget.Widget Java Examples

The following examples show how to use net.minecraft.client.gui.widget.Widget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuiSprint.java    From Better-Sprinting with Mozilla Public License 2.0 6 votes vote down vote up
private void updateButtonState(){
	for(Widget button:buttons){
		if (button instanceof GuiButtonInputBinding){
			KeyBinding binding = ((GuiButtonInputBinding)button).binding;
			
			if (binding == ClientModManager.keyBindSprintToggle || binding == ClientModManager.keyBindSneakToggle){
				button.active = !ClientModManager.isModDisabled();
			}
		}
	}
	
	btnSprintMode.active = !ClientModManager.isModDisabled();
	btnDoubleTap.active = !ClientModManager.isModDisabled();
	btnAllDirs.active = Feature.RUN_IN_ALL_DIRS.isAvailable();
	btnFlyBoost.active = Feature.FLY_BOOST.isAvailable();
	btnFlyOnGround.active = Feature.FLY_ON_GROUND.isAvailable();
	btnDisableMod.active = ClientModManager.canManuallyEnableMod();
}
 
Example #2
Source File: GuiSprint.java    From Better-Sprinting with Mozilla Public License 2.0 6 votes vote down vote up
private void onSelectedBindingUpdated(){
	if (!selectedBinding.isSelected()){
		selectedBinding = null;
	}
	
	for(Widget button:buttons){
		if (button instanceof GuiButtonInputBinding){
			((GuiButtonInputBinding)button).updateKeyBindingText();
		}
	}
	
	ClientSettings.keyInfoSprintHold.readFrom(ClientModManager.keyBindSprintHold);
	ClientSettings.keyInfoSprintToggle.readFrom(ClientModManager.keyBindSprintToggle);
	ClientSettings.keyInfoSneakToggle.readFrom(ClientModManager.keyBindSneakToggle);
	ClientSettings.keyInfoOptionsMenu.readFrom(ClientModManager.keyBindOptionsMenu);
	KeyBinding.resetKeyBindingArrayAndHash();
	
	mc.gameSettings.saveOptions();
	BetterSprintingMod.config.save();
}
 
Example #3
Source File: GuiSprint.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void render(int mouseX, int mouseY, float partialTickTime){
	final int top = height / 6;
	final int middle = width / 2;
	
	renderBackground();
	drawCenteredString(font, "Better Sprinting", middle, 20, 16777215);
	
	super.render(mouseX, mouseY, partialTickTime);
	
	final int maxWidthLeft = 82;
	final int maxWidthRight = 124;
	
	for(Widget button:buttons){
		if (button instanceof GuiButtonCustomInput){
			drawButtonTitle(((GuiButtonCustomInput)button).getTitle(), button, button.x < middle ? maxWidthLeft : maxWidthRight);
			
			if (button.isMouseOver(mouseX, mouseY)){
				String[] spl = ((GuiButtonCustomInput)button).getInfo();
				
				for(int line = 0; line < spl.length; line++){
					drawCenteredString(font, spl[line], middle, top + 148 + (10 * line - (font.FONT_HEIGHT * spl.length / 2)), -1);
				}
			}
		}
	}
}
 
Example #4
Source File: MiningSettingScreen.java    From MiningGadgets with MIT License 4 votes vote down vote up
@Override
protected void init() {
    List<Widget> leftWidgets = new ArrayList<>();

    int baseX = width / 2, baseY = height / 2;

    // Filters out the non-toggleable options
    toggleableList.clear();
    toggleableList = UpgradeTools.getUpgrades(this.gadget).stream().filter(Upgrade::isToggleable).collect(Collectors.toList());
    containsFreeze = UpgradeTools.containsUpgradeFromList(toggleableList, Upgrade.FREEZING);
    boolean containsVoid = UpgradeTools.containsUpgradeFromList(toggleableList, Upgrade.VOID_JUNK);

    isWhitelist = MiningProperties.getWhiteList(gadget);
    isPrecision = MiningProperties.getPrecisionMode(gadget);

    int top = baseY - (containsFreeze ? 80 : 60);

    // Right size
    // Remove 6 from x to center it as the padding on the right pushes off center... (I'm a ui nerd)
    int index = 0, x = baseX + 10, y = top + (containsVoid ? 45 : 20);
    for (Upgrade upgrade : toggleableList) {
        ToggleButton btn = new ToggleButton(x + (index * 30), y, UpgradeTools.getName(upgrade), new ResourceLocation(MiningGadgets.MOD_ID, "textures/item/upgrade_" + upgrade.getName() + ".png"), send -> this.toggleUpgrade(upgrade, send));
        addButton(btn);
        upgradeButtons.put(upgrade, btn);

        // Spaces the upgrades
        index ++;
        if( index % 4 == 0 ) {
            index = 0;
            y += 35;
        }
    }

    // Don't add if we don't have voids
    if( containsVoid ) {
        addButton(new Button(baseX + 10, top + 20, 95, 20, getTrans("tooltip.screen.edit_filters"), (button) -> {
            PacketHandler.sendToServer(new PacketOpenFilterContainer());
        }));

        addButton(new WhitelistButton(baseX + 10 + (115 - 20), top + 20, 20, 20, isWhitelist, (button) -> {
            isWhitelist = !isWhitelist;
            ((WhitelistButton) button).setWhitelist(isWhitelist);
            PacketHandler.sendToServer(new PacketToggleFilters());
        }));
    }

    // Left size
    currentSize = MiningProperties.getRange(gadget);

    Button sizeButton;
    leftWidgets.add(sizeButton = new Button(baseX - 135, 0, 125, 20, new TranslationTextComponent("mininggadgets.tooltip.screen.size", currentSize).getUnformattedComponentText(), (button) -> {
        currentSize = currentSize == 1 ? 3 : 1;
        button.setMessage(getTrans("tooltip.screen.size", currentSize));
        PacketHandler.sendToServer(new PacketChangeMiningSize());
    }));

    leftWidgets.add(rangeSlider = new Slider(baseX - 135, 0, 125, 20, getTrans("tooltip.screen.range") + ": ", "", 1, MiningProperties.getBeamMaxRange(gadget), this.beamRange, false, true, s -> {}, this));

    leftWidgets.add(new Button(baseX - 135, 0, 125, 20, getTrans("tooltip.screen.visuals_menu"), (button) -> {
        ModScreens.openVisualSettingsScreen(gadget);
    }));

    //Precision Mode
    leftWidgets.add(new Button(baseX - 135, 0, 125, 20, getTrans("tooltip.screen.precision_mode", isPrecision), (button) -> {
        isPrecision = !isPrecision;
        button.setMessage(getTrans("tooltip.screen.precision_mode", isPrecision));
        PacketHandler.sendToServer(new PacketTogglePrecision());
    }));

    // volume slider
    leftWidgets.add(volumeSlider = new Slider(baseX - 135, 0, 125, 20, getTrans("tooltip.screen.volume") + ": ", "%", 0, 100, Math.min(100, volume * 100), false, true, s -> {}, this));

    // Freeze delay
    if( containsFreeze )
        leftWidgets.add(freezeDelaySlider = new Slider(baseX - 135, 0, 125, 20, getTrans("tooltip.screen.freeze_delay") + ": ", " " + getTrans("tooltip.screen.ticks"), 0, 10, MiningProperties.getFreezeDelay(gadget), false, true, s -> {}, this));

    // Button logic
    if( !UpgradeTools.containsActiveUpgrade(gadget, Upgrade.THREE_BY_THREE) )
        sizeButton.active = false;

    // Lay the buttons out, too lazy to figure out the math every damn time.
    // Ordered by where you add them.
    for(int i = 0; i < leftWidgets.size(); i ++) {
        leftWidgets.get(i).y = (top + 20) + (i * 25);
        addButton(leftWidgets.get(i));
    }
}
 
Example #5
Source File: GuiSprint.java    From Better-Sprinting with Mozilla Public License 2.0 4 votes vote down vote up
private void drawButtonTitle(String title, Widget btn, int maxWidth){
	int lines = font.listFormattedStringToWidth(title, maxWidth).size();
	font.drawSplitString(title, btn.x + 76, btn.y + 7 - 5 * (lines - 1), maxWidth, -1);
}
 
Example #6
Source File: GuiBase.java    From XRay-Mod with GNU General Public License v3.0 4 votes vote down vote up
protected <T extends Widget> T addButton(T button) {
    return this.func_230480_a_(button); // @mcp: func_230480_a_ = Widget::addButton
}