1

ユーザーがスライディングをやめたかどうかを検出する方法はありますか? 多分bijマウス入力チェックか何か。onSliderChange イベントでマウスの isButton0Release と hasFocus を試して、ユーザーがスライドを停止したかどうかを確認しましたが、これは機能しません。

これまでに得たもの

@NiftyEventSubscriber(id = "speedSlider")
public void onSliderChange(String id, SliderChangedEvent event) 
{   boolean test2 = event.getSlider().hasFocus();
    boolean test = nifty.getMouseInputEventQueue().getLastMouseDownEvent().isButton0Release();
    System.out.println("before " + test2);
    int speed = (int)event.getValue();
    speedTextField.getRenderer(TextRenderer.class).setText(speed + "");
    if(test2){
        System.out.println("after " + test2);
        main.setSimSpeed(speed);
    }
}

そしてxmlのスライダー

                <panel id="speed_up_down_panel" height="30px" width="180px" childLayout="center">         
                <control id="speedSlider" name="horizontalSlider" width="150px" min="1" initial="1" buttonStepSize="1">
                    <image id="#position" filename="Interface/sliderbutton.png" visibleToMouse="true" width="40px" height="40px"></image>
                </control>
            </panel> 

私がテストしているため、コードは少し面倒です。

4

1 に答える 1

0

私が考える最も簡単な方法は、onReleaseイベント ハンドラーを追加する独自のコントロールを定義することです。

<?xml version="1.0" encoding="UTF-8"?>
<nifty-controls xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
<controlDefinition name="horizontalSlider" style="nifty-horizontal-slider"
    controller="de.lessvoid.nifty.controls.slider.SliderControl"
    inputMapping="de.lessvoid.nifty.controls.scrollbar.ScrollbarInputMapping">

    <panel style="#panel">
        <interact onMouseWheel="mouseWheel()"/>
        <image style="#left">
            <interact onClickRepeat="upClick()"/>
        </image>
        <image id="#background" style="#background">
            <interact onClick="mouseClick()" onClickMouseMove="mouseClick()"/>
            <image id="#position" style="#position">
                <interact onClick="mouseClick()" onClickMouseMove="mouseClick()"
                    onRelease="onRelease()"/>
                    <!-- ^ ^ ^ ADD THIS ^ ^ ^ -->
            </image>
        </image>
        <image style="#right">
            <interact onClickRepeat="downClick()"/>
        </image>
    </panel>
</controlDefinition>

注: SliderControl の元の定義をコピーしonReleaseて、<interact>タグに追加しました。参照: https://github.com/nifty-gui/nifty-gui/blob/1.4/nifty-controls/src/main/resources/nifty-controls/nifty-slider.xml

XML で次の行を使用して、この新しいコントロールをロードします:
(ロードする行の後に挿入しますnifty-default-controls.xml)

<useControls filename="Interface/NewSlider.xml" />

public void onRelease()次に、コントローラーにメソッドを追加します。

于 2016-01-10T22:07:07.187 に答える