Skip to content

Commit

Permalink
Options menu working perfectly, fixed snake spawns at beginning of le…
Browse files Browse the repository at this point in the history
…vel 3
  • Loading branch information
retrodaredevil committed Oct 28, 2018
1 parent 1a69c18 commit ba3a2a7
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import me.retrodaredevil.game.trackshooter.entity.movement.SmoothOppositePositionTarget;
import me.retrodaredevil.game.trackshooter.entity.movement.SmoothTravelMoveComponent;
import me.retrodaredevil.game.trackshooter.entity.player.Player;
import me.retrodaredevil.game.trackshooter.level.CanLevelEnd;
import me.retrodaredevil.game.trackshooter.level.LevelEndState;
import me.retrodaredevil.game.trackshooter.render.components.ImageRenderComponent;
import me.retrodaredevil.game.trackshooter.world.World;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ private static ControlOption createRotationMultiplier(OptionTracker options, boo
}
private static double getDefaultMouseMultiplier(boolean mobile){
if(mobile) {
double def = 1.5 / (Gdx.graphics.getDensity() + .3);
return Math.round(def * 10.0) / 10.0;
double def = 2.75 / (Gdx.graphics.getDensity() + .3);
return Math.round(def * 10.0) / 10.0; // round to nearest 10%
}
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void update(float delta, World world) {
* @return true if this level is able to end, false otherwise
*/
private boolean shouldLevelEnd(World world){
Collection<CanLevelEnd> endCheckCollection = new ArrayList<>();
endCheckCollection.addAll(world.getEntities());
Collection<CanLevelEnd> endCheckCollection = new HashSet<>();
endCheckCollection.addAll(world.getAllEntities());
endCheckCollection.addAll(functions);

LevelEndState highest = LevelEndState.CAN_END;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import me.retrodaredevil.game.trackshooter.render.components.RenderComponent;
import me.retrodaredevil.game.trackshooter.render.selection.options.ButtonExitMenuSingleOption;
import me.retrodaredevil.game.trackshooter.render.selection.options.ButtonSingleOption;
import me.retrodaredevil.game.trackshooter.render.selection.options.PlainActorSingleOption;
import me.retrodaredevil.game.trackshooter.render.selection.SelectionMenuRenderComponent;
import me.retrodaredevil.game.trackshooter.render.selection.options.HorizontalSelectionSingleOption;
import me.retrodaredevil.game.trackshooter.render.selection.options.GroupedSelectionSingleOption;
import me.retrodaredevil.game.trackshooter.render.selection.options.providers.BasicOptionProvider;
import me.retrodaredevil.game.trackshooter.render.selection.options.providers.ConfigurableObjectOptionProvider;
import me.retrodaredevil.game.trackshooter.render.selection.options.providers.PageControlOptionVisibility;
Expand Down Expand Up @@ -64,29 +63,42 @@ public void setToController(int configControllerPlayerIndex, ConfigurableControl
renderComponent = null;
return;
}
/*
If you get an index out of bounds exception, it probably has something to do with the scroll pane
*/
final PageControlOptionVisibility pageControlOptionVisibility = new PageControlOptionVisibility();
final Size topSize = Constants.OPTIONS_MENU_TOP_BUTTONS_SIZE;
final Size size = Constants.OPTIONS_MENU_BOTTOM_BUTTONS_SIZE;
renderComponent = new SelectionMenuRenderComponent(renderObject, menuControllerPlayerIndex, menuController,
new DialogTable("Options", renderObject),
Arrays.asList(
new BasicOptionProvider(new HorizontalSelectionSingleOption(Size.widthOnly(400), Arrays.asList(new BasicOptionProvider(
new ButtonSingleOption(new TextButton("Main", renderObject.getUISkin(), "small"), topSize,
Collections.singletonList(new BasicOptionProvider(
new GroupedSelectionSingleOption(Size.widthOnly(400), true, Arrays.asList(new BasicOptionProvider(
new ButtonSingleOption(new TextButton("main", renderObject.getUISkin(), "small"), topSize,
requestingActions -> pageControlOptionVisibility.setPage(PageControlOptionVisibility.Page.MAIN)),
new ButtonSingleOption(new TextButton("Move", renderObject.getUISkin(), "small"), topSize,
new ButtonSingleOption(new TextButton("move", renderObject.getUISkin(), "small"), topSize,
requestingActions -> pageControlOptionVisibility.setPage(PageControlOptionVisibility.Page.MOVEMENT)),
new ButtonSingleOption(new TextButton("Rotate", renderObject.getUISkin(), "small"), topSize,
new ButtonSingleOption(new TextButton("rotate", renderObject.getUISkin(), "small"), topSize,
requestingActions -> pageControlOptionVisibility.setPage(PageControlOptionVisibility.Page.ROTATION)),
new ButtonSingleOption(new TextButton("Shoot", renderObject.getUISkin(), "small"), topSize,
new ButtonSingleOption(new TextButton("shoot", renderObject.getUISkin(), "small"), topSize,
requestingActions -> pageControlOptionVisibility.setPage(PageControlOptionVisibility.Page.SHOOTING)),
new ButtonSingleOption(new TextButton("Misc", renderObject.getUISkin(), "small"), topSize,
requestingActions -> pageControlOptionVisibility.setPage(PageControlOptionVisibility.Page.MISC))
)))),
new ConfigurableObjectOptionProvider(Size.widthOnly(400), configControllerPlayerIndex, menuController, renderObject, saveObject, pageControlOptionVisibility),
new BasicOptionProvider(new HorizontalSelectionSingleOption(Size.widthOnly(400), Arrays.asList(new BasicOptionProvider(
new ButtonExitMenuSingleOption(new TextButton("back", renderObject.getUISkin(), "small"), size)
))))
),
new ButtonSingleOption(new TextButton("misc", renderObject.getUISkin(), "small"), topSize,
requestingActions -> pageControlOptionVisibility.setPage(PageControlOptionVisibility.Page.MISC)),
new ButtonSingleOption(new TextButton("all", renderObject.getUISkin(), "small"), topSize,
requestingActions -> pageControlOptionVisibility.setPage(PageControlOptionVisibility.Page.ALL))
))),
new GroupedSelectionSingleOption(Size.NONE, false, Arrays.asList(
new ConfigurableObjectOptionProvider(Size.widthOnly(400), configControllerPlayerIndex, menuController, renderObject, saveObject, pageControlOptionVisibility))
),
new GroupedSelectionSingleOption(Size.widthOnly(400), true, Arrays.asList(new BasicOptionProvider(
new ButtonExitMenuSingleOption(new TextButton("back", renderObject.getUISkin(), "small"), size),
new ButtonSingleOption(new TextButton("reset", renderObject.getUISkin(), "small"), size,
requestingActions -> {
if(renderComponent != null) {
renderComponent.resetAll();
}
})
)))
)),
this::closeMenu);
currentController = menuController; // TODO I believe I originally set this up to check for errors, but this may be unnecessary
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
public abstract class ContainerSingleOption implements SingleOption {
protected final Table container = new Table();
private final Size size;
private Cell containerCell = null;

private boolean initialized = false;

Expand Down Expand Up @@ -42,7 +41,7 @@ public void renderUpdate(ContentTableProvider contentTableProvider, Collection<?
Table table = contentTableProvider.getContentTable();

if(container.getParent() != table){
containerCell = table.add(container);
Cell containerCell = table.add(container);
size.apply(containerCell);
if(!contentTableProvider.isHorizontal()) {
table.row();
Expand All @@ -54,7 +53,7 @@ public void renderUpdate(ContentTableProvider contentTableProvider, Collection<?
}

@Override
public void reset() {
public void resetOption() {
}

@Override
Expand All @@ -69,10 +68,7 @@ public void remove() {
return;
}

container.remove();
// thanks for simple solution https://stackoverflow.com/a/49285366/5434860
table.getCells().removeValue(containerCell, true);
table.invalidate();
}
table.removeActor(container);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import me.retrodaredevil.controller.input.InputPart;
import me.retrodaredevil.controller.input.JoystickPart;
import me.retrodaredevil.game.trackshooter.util.MathUtil;

public class OptionHolder {
private final ContentTableProvider contentTableProvider;
Expand All @@ -19,7 +19,7 @@ public class OptionHolder {

/**
* @param defaultIndex The default index
* @param contentTableProvider The content table provider. NOTE: This will not be updated automatically
* @param contentTableProvider The content table provider. NOTE: This will not be updated/rendered automatically
* @param optionProviders The collection of option providers
*/
public OptionHolder(int defaultIndex, ContentTableProvider contentTableProvider, Collection<? extends SingleOptionProvider> optionProviders){
Expand All @@ -33,11 +33,12 @@ public int getSelectedOptionIndex(){
return selectedOptionIndex;
}
public void setSelectedOptionIndex(int selectedOptionIndex){
if(!optionPairs.isEmpty()) {
this.selectedOptionIndex = MathUtil.mod(selectedOptionIndex, optionPairs.size());
} else {
this.selectedOptionIndex = selectedOptionIndex;
}
// if(!optionPairs.isEmpty()) {
// this.selectedOptionIndex = MathUtil.mod(selectedOptionIndex, optionPairs.size());
// } else {
// this.selectedOptionIndex = selectedOptionIndex;
// }
this.selectedOptionIndex = Math.max(0, Math.min(selectedOptionIndex, optionPairs.size() - 1));
}
public void setActive(boolean active){
this.active = active;
Expand Down Expand Up @@ -94,7 +95,7 @@ public void updateOptions(Collection<? super SelectAction> requestingActions){
* @param requestingActions The actions that are requesting to be completed. This is allowed to be mutated
*/
public void updateSelection(float delta, JoystickPart selectJoystick,
InputPart selectButton, InputPart backButton, Collection<? super SelectAction> requestingActions){
InputPart selectButton, InputPart backButton, Set<? super SelectAction> requestingActions){
final boolean hasController = selectJoystick != null && selectButton != null && backButton != null;

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import com.badlogic.gdx.scenes.scene2d.Stage;

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import me.retrodaredevil.controller.input.InputPart;
import me.retrodaredevil.controller.input.JoystickPart;
Expand All @@ -29,12 +28,12 @@ public class SelectionMenuRenderComponent implements RenderComponent {

/**
*
* @param renderObject
* @param playerIndex
* @param menuController
* @param renderObject The render object
* @param playerIndex The player index
* @param menuController The controller that will control this menu
* @param contentTableProvider The content table provider. This will automatically be disposed of
* @param optionProviders
* @param exitRequestListener
* @param optionProviders The option providers
* @param exitRequestListener Will be called when the back button is pressed
*/
public SelectionMenuRenderComponent(RenderObject renderObject, Integer playerIndex, GameInput menuController,
ContentTableProvider contentTableProvider,
Expand All @@ -56,13 +55,19 @@ public void clearTable(){
optionHolder.getContentTableProvider().resetTable();
}

public void resetAll(){
for(OptionPair optionPair : optionHolder.getOptionPairs()){
optionPair.getSingleOption().resetOption();
}
}

@Override
public void render(float delta, Stage stage) {

final JoystickPart selectJoystick = menuController == null ? null : Objects.requireNonNull(menuController.getSelectorJoystick());
final InputPart selectButton = menuController == null ? null : Objects.requireNonNull(menuController.getEnterButton());
final InputPart backButton = menuController == null ? null : Objects.requireNonNull(menuController.getBackButton());
final Collection<SelectAction> requestingActions = EnumSet.noneOf(SelectAction.class);
final Set<SelectAction> requestingActions = EnumSet.noneOf(SelectAction.class);
boolean active = optionHolder.isActive();
int newOptionIndex = optionHolder.getSelectedOptionIndex();
if(menuController != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.retrodaredevil.game.trackshooter.render.selection;

import java.util.Collection;
import java.util.Set;

import me.retrodaredevil.controller.input.InputPart;
import me.retrodaredevil.controller.input.JoystickPart;
Expand Down Expand Up @@ -28,7 +29,7 @@ public interface SingleOption {
/**
* Should reset the control option to its original state
*/
void reset();
void resetOption();

/**
* Should remove whatever was added to the table in {@link #renderUpdate(ContentTableProvider, Collection)}
Expand All @@ -43,7 +44,7 @@ public interface SingleOption {
* @param back The back button
* @param requestedActions A collection of actions that the caller would like to do. The implementation should remove actions that are not desired
*/
void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Collection<? super SelectAction> requestedActions);
void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Set<? super SelectAction> requestedActions);

/**
* Called when this option should be deselected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.Button;

import java.util.Collection;
import java.util.Set;

import me.retrodaredevil.controller.input.InputPart;
import me.retrodaredevil.controller.input.JoystickPart;
Expand Down Expand Up @@ -31,7 +32,7 @@ protected void onRequestActions(Collection<? super SelectAction> requestedAction
}

@Override
public void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Collection<? super SelectAction> requestedActions) {
public void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Set<? super SelectAction> requestedActions) {
super.selectUpdate(delta, selector, select, back, requestedActions);
if(select.isPressed()){
onButtonPress.onButtonPress(requestedActions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.utils.Align;

import java.util.Collection;
import java.util.Set;

import me.retrodaredevil.controller.input.InputPart;
import me.retrodaredevil.controller.input.JoystickPart;
Expand Down Expand Up @@ -35,6 +35,11 @@ protected double getSetValue() {
return checkBox.isChecked() ? 1 : 0;
}

@Override
protected void setValueTo(double value) {
checkBox.setChecked( value >= .5);
}

@Override
protected void onInit() {
super.onInit();
Expand All @@ -52,7 +57,7 @@ protected void onUpdate() {
}

@Override
public void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Collection<? super SelectAction> requestedActions) {
public void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Set<? super SelectAction> requestedActions) {
ActorUtil.fireInputEvents(checkBox, InputEvent.Type.enter);
if(select.isPressed()){
checkBox.toggle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.badlogic.gdx.utils.Array;

import java.util.Collection;
import java.util.Set;

import me.retrodaredevil.controller.input.InputPart;
import me.retrodaredevil.controller.input.JoystickPart;
Expand Down Expand Up @@ -46,6 +47,12 @@ protected boolean canSave() {
protected double getSetValue() {
return selectBox.getSelectedIndex();
}

@Override
protected void setValueTo(double value) {
selectBox.setSelectedIndex((int) value);
}

private void updateItems(){
itemsArray.clear();
Collection<? extends RadioOption> options = controlOption.getOptionValue().getRadioOptions();
Expand Down Expand Up @@ -80,7 +87,7 @@ private void hide(){
}

@Override
public void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Collection<? super SelectAction> requestedActions) {
public void selectUpdate(float delta, JoystickPart selector, InputPart select, InputPart back, Set<? super SelectAction> requestedActions) {
ActorUtil.fireInputEvents(selectBox, InputEvent.Type.enter);
// The reason we have the use the 'isShown' variable, is that in a SelectBox, pressing escape
// (sometimes mapped to the back button) closes the drop down (IT'S FREAKING HARD CODED)
Expand Down
Loading

0 comments on commit ba3a2a7

Please sign in to comment.