Skip to content

Commit

Permalink
Add scroll velocity editor config, close #93
Browse files Browse the repository at this point in the history
  • Loading branch information
fgnm committed Jun 29, 2024
1 parent d4d4f21 commit 0b00d6f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hyperlap2d-common-api
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import games.rednblack.editor.controller.commands.CompositeCameraChangeCommand;
import games.rednblack.editor.controller.commands.RemoveComponentFromItemCommand;
import games.rednblack.editor.proxy.CommandManager;
import games.rednblack.editor.proxy.SettingsManager;
import games.rednblack.editor.renderer.components.NodeComponent;
import games.rednblack.editor.utils.KeyBindingsLayout;
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
Expand Down Expand Up @@ -69,6 +70,8 @@ public class SandboxMediator extends Mediator<Sandbox> {
private static final Vector3 temp = new Vector3();
private static final Vector2 tmp = new Vector2();

private SettingsManager settingsManager;

public SandboxMediator() {
super(NAME, Sandbox.getInstance());
}
Expand All @@ -81,6 +84,8 @@ public void onRegister() {
getViewComponent().addListener(stageListener);

initTools();

settingsManager = facade.retrieveProxy(SettingsManager.NAME);
}

private void initTools() {
Expand Down Expand Up @@ -443,7 +448,8 @@ public boolean scrolled(int entity, float amountX, float amountY) {
} else {
if (currentSelectedTool != null
&& !currentSelectedTool.stageMouseScrolled(amountX, amountY)) {
float scale = 30f / sandbox.getPixelPerWU();

float scale = settingsManager.editorConfigVO.scrollVelocity / sandbox.getPixelPerWU();
viewComponent.panSceneBy(amountX * scale, -amountY * scale);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package games.rednblack.editor.view.ui.settings;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.kotcrab.vis.ui.widget.VisCheckBox;
import com.kotcrab.vis.ui.widget.VisTable;
import com.kotcrab.vis.ui.widget.VisTextButton;
import com.badlogic.gdx.utils.Align;
import com.kotcrab.vis.ui.widget.*;
import com.kotcrab.vis.ui.widget.color.ColorPickerAdapter;
import games.rednblack.editor.utils.RoundUtils;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.view.SettingsNodeValue;
Expand All @@ -20,16 +22,19 @@ public class SandboxSettings extends SettingsNodeValue<EditorConfigVO> {

private final VisCheckBox disableAmbientComposite, showBoundBoxes;
private final TintButton tintButton;
private VisSlider scrollVelocity;

public SandboxSettings() {
super("Sandbox", Facade.getInstance());

getContentTable().add("Composites").left().row();
getContentTable().add("Behavior").left().row();
getContentTable().addSeparator();
disableAmbientComposite = StandardWidgetsFactory.createCheckBox("Disable Ambient light when viewing Composites");
getContentTable().add(disableAmbientComposite).left().padTop(5).padLeft(8).row();

getContentTable().add("Debug").left().row();
getContentTable().add(getScrollVelocityTable()).left().padTop(10).row();

getContentTable().add("Debug").left().padTop(10).row();
getContentTable().addSeparator();
showBoundBoxes = StandardWidgetsFactory.createCheckBox("Show bounding boxes outline");
getContentTable().add(showBoundBoxes).left().padTop(5).padLeft(8).row();
Expand Down Expand Up @@ -83,17 +88,42 @@ public void clicked(InputEvent event, float x, float y) {
getContentTable().add(tintTable).padLeft(8).left().row();
}

private Actor getScrollVelocityTable() {
VisTable scaleTable = new VisTable();

scaleTable.add("Scroll Velocity:").padLeft(8);
scrollVelocity = StandardWidgetsFactory.createSlider(30, 400, 1);
scaleTable.add(scrollVelocity).padLeft(8);
VisLabel labelFactor = StandardWidgetsFactory.createLabel("", "default", Align.left);
scaleTable.add(labelFactor).padLeft(8);
labelFactor.setText(String.valueOf(getScrollVelocity()));
scrollVelocity.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
labelFactor.setText(String.valueOf(getScrollVelocity()));
}
});

return scaleTable;
}

private float getScrollVelocity() {
return RoundUtils.round(scrollVelocity.getValue(), 0);
}

@Override
public void translateSettingsToView() {
disableAmbientComposite.setChecked(getSettings().disableAmbientComposite);
showBoundBoxes.setChecked(getSettings().showBoundingBoxes);
tintButton.setColorValue(getSettings().backgroundColor);
scrollVelocity.setValue(getSettings().scrollVelocity);
}

@Override
public void translateViewToSettings() {
getSettings().disableAmbientComposite = disableAmbientComposite.isChecked();
getSettings().showBoundingBoxes = showBoundBoxes.isChecked();
getSettings().scrollVelocity = getScrollVelocity();
facade.sendNotification(MsgAPI.SAVE_EDITOR_CONFIG);
}

Expand Down

0 comments on commit 0b00d6f

Please sign in to comment.