Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/src/main/java/oxy/bascenario/api/effects/Weather.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package oxy.bascenario.api.effects;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum Weather {
CLEAR("Clear"), RAIN("Rain"), SNOW("Snow");

private final String name;

public static String[] getAlls() {
String[] strings = new String[values().length];
for (int i = 0; i < values().length; i++) {
strings[i] = values()[i].name;
}
return strings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package oxy.bascenario.api.event;

import oxy.bascenario.api.effects.Weather;
import oxy.bascenario.api.event.api.Event;

public record SetWeatherEvent(Weather weather) implements Event {
}
4 changes: 4 additions & 0 deletions core/src/main/java/oxy/bascenario/event/EventRegistries.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oxy.bascenario.event;

import oxy.bascenario.api.event.LockClickEvent;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.api.event.ShowButtonsEvent;
import oxy.bascenario.api.event.background.ClearBackgroundEvent;
import oxy.bascenario.api.event.animation.PlayAnimationEvent;
Expand All @@ -22,6 +23,7 @@
import oxy.bascenario.api.event.sound.StopSoundEvent;
import oxy.bascenario.event.base.FunctionEvent;
import oxy.bascenario.event.impl.FunctionLockClick;
import oxy.bascenario.event.impl.FunctionSetWeather;
import oxy.bascenario.event.impl.FunctionShowButtons;
import oxy.bascenario.event.impl.animation.FunctionPlayAnimation;
import oxy.bascenario.event.impl.animation.FunctionSpriteAnimation;
Expand Down Expand Up @@ -88,6 +90,8 @@ public class EventRegistries {
EVENT_TO_FUNCTION.put(LockClickEvent.class, FunctionLockClick.class);
EVENT_TO_FUNCTION.put(ShowButtonsEvent.class, FunctionShowButtons.class);

EVENT_TO_FUNCTION.put(SetWeatherEvent.class, FunctionSetWeather.class);

EVENT_TO_FUNCTION = Collections.unmodifiableMap(EVENT_TO_FUNCTION);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package oxy.bascenario.event.impl;

import oxy.bascenario.api.effects.Weather;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.event.base.FunctionEvent;
import oxy.bascenario.screens.ScenarioScreen;

public class FunctionSetWeather extends FunctionEvent<SetWeatherEvent> {
public FunctionSetWeather(SetWeatherEvent event) {
super(event);
}

@Override
public void run(ScenarioScreen screen) {
screen.setWeather(event.weather() == null ? Weather.CLEAR : event.weather());
}
}
11 changes: 11 additions & 0 deletions core/src/main/java/oxy/bascenario/screens/ScenarioScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
import oxy.bascenario.Base;
import oxy.bascenario.api.Scenario;
import oxy.bascenario.api.Timestamp;
import oxy.bascenario.api.effects.Weather;
import oxy.bascenario.api.render.RenderLayer;
import oxy.bascenario.api.render.elements.text.font.FontStyle;
import oxy.bascenario.api.render.elements.text.font.FontType;
import oxy.bascenario.api.utils.FileInfo;
import oxy.bascenario.event.base.FunctionEvent;
import oxy.bascenario.event.EventRegistries;
import oxy.bascenario.managers.AudioManager;
import oxy.bascenario.screens.renderer.weather.RainRenderer;
import oxy.bascenario.screens.renderer.element.ColorOverlayRenderer;
import oxy.bascenario.screens.renderer.dialogue.DialogueRenderer;
import oxy.bascenario.screens.renderer.dialogue.OptionsRenderer;
import oxy.bascenario.screens.renderer.element.base.ElementRenderer;
import oxy.bascenario.screens.renderer.dialogue.BaseDialogueRenderer;
import oxy.bascenario.screens.renderer.weather.SnowRenderer;
import oxy.bascenario.utils.animation.DynamicAnimation;
import oxy.bascenario.utils.TimeUtils;
import oxy.bascenario.utils.ExtendableScreen;
Expand Down Expand Up @@ -182,6 +185,11 @@ public void show() {
}
}

@Setter
private Weather weather = Weather.CLEAR;
private final RainRenderer rainRenderer = new RainRenderer();
private final SnowRenderer snowRenderer = new SnowRenderer();

@Setter
private boolean showButtons;
@Override
Expand Down Expand Up @@ -232,6 +240,9 @@ public void render(float delta) {
RendererText.VerticalOrigin.BASELINE, RendererText.HorizontalOrigin.LOGICAL_LEFT);
}

rainRenderer.render(weather == Weather.RAIN);
snowRenderer.render(weather == Weather.SNOW);

elements.stream().filter(element -> element.getLayer() == RenderLayer.TOP).forEach(ElementRenderer::renderAll);

ThinGLUtils.end();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package oxy.bascenario.screens.renderer.weather;

import net.lenni0451.commons.RandomUtils;
import net.lenni0451.commons.color.Color;
import net.raphimc.thingl.ThinGL;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import static oxy.bascenario.utils.thingl.ThinGLUtils.GLOBAL_RENDER_STACK;

public class RainRenderer {
private final Queue<RainDrop> drops = new ConcurrentLinkedQueue<>();

public void render(boolean add) {
if (add) {
while (drops.size() < 10) {
drops.add(new RainDrop(RandomUtils.randomInt(200, 1000), RandomUtils.randomInt(0, 1920), RandomUtils.randomInt(20, 200)));
}
}

drops.forEach(RainDrop::render);
drops.removeIf(RainDrop::remove);
}

private static class RainDrop {
private final float height;
private final float x;
private final float speed;
private float y;

private RainDrop(float height, float x, float speed) {
this.height = height;
this.x = x;
this.speed = speed;
this.y = -height;
}

public void render() {
y += speed;

ThinGL.renderer2D().filledRectangle(GLOBAL_RENDER_STACK, x, y, x + 5, y + height, Color.WHITE.withAlphaF(0.4f));
}

public boolean remove() {
return y > 1080;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package oxy.bascenario.screens.renderer.weather;

import net.lenni0451.commons.RandomUtils;
import net.lenni0451.commons.color.Color;
import net.raphimc.thingl.ThinGL;
import oxy.bascenario.Base;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import static oxy.bascenario.utils.thingl.ThinGLUtils.GLOBAL_RENDER_STACK;

public class SnowRenderer {
private final Queue<SnowDrop> snows = new ConcurrentLinkedQueue<>();

private long time = System.currentTimeMillis();
public void render(boolean add) {
if (System.currentTimeMillis() - time > 200 && add) {
snows.add(new SnowDrop(RandomUtils.randomInt(20, 120), RandomUtils.randomInt(0, 1920), RandomUtils.randomInt(1, 4)));
time = System.currentTimeMillis();
}

snows.forEach(SnowDrop::render);
snows.removeIf(SnowDrop::remove);
}

private static class SnowDrop {
private final int size;
private float x, y;
private final int direction;
private final int speedY;

public SnowDrop(int size, float x, int speedY) {
this.size = size;
this.x = x;
this.y = -size;
this.speedY = speedY;

this.direction = RandomUtils.randomInt(0, 2);
}

public void render() {
this.y += speedY;
this.x += (this.direction == 0 ? -2 : this.direction == 1 ? 2 : 0);

ThinGL.renderer2D().coloredTexture(GLOBAL_RENDER_STACK,
Base.instance().assetsManager().texture("assets/base/snow.png"),
x, y, size, size, Color.WHITE.withAlphaF(0.4f));
}

public boolean remove() {
return y > 1080;
}
}
}
Binary file added core/src/main/resources/assets/base/snow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions core/src/test/java/WeatherTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import oxy.bascenario.api.Scenario;
import oxy.bascenario.api.effects.Weather;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.api.event.background.SetBackgroundEvent;
import oxy.bascenario.api.utils.FileInfo;
import oxy.bascenario.screens.ScenarioScreen;
import oxy.bascenario.utils.Launcher;

public class WeatherTest {
public static void main(String[] args) {
final Scenario.Builder scenario = new Scenario.Builder();
scenario.add(0, new SetBackgroundEvent(FileInfo.internal("bg_cs_trinity_14_2.jpg"), 0));
scenario.add(0, new SetWeatherEvent(Weather.SNOW));

Launcher.launch(new ScenarioScreen(scenario.build()));
}
}
Binary file added core/src/test/resources/bg_cs_trinity_14_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import imgui.ImColor;
import imgui.ImGui;
import lombok.RequiredArgsConstructor;
import oxy.bascenario.api.effects.Weather;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.api.event.ShowButtonsEvent;
import oxy.bascenario.api.event.background.ClearBackgroundEvent;
import oxy.bascenario.api.event.background.SetBackgroundEvent;
Expand Down Expand Up @@ -117,6 +119,8 @@ public void render() {
case FocusElementEvent event -> new FocusElementEvent(ImGuiUtils.inputInt("Track Id", event.id()));

case ShowButtonsEvent event -> new ShowButtonsEvent(ImGuiUtils.checkbox("Show", event.show()));

case SetWeatherEvent event -> new SetWeatherEvent(Weather.values()[ImGuiUtils.combo("Weather", event.weather().ordinal(), Weather.getAlls())]);
default -> old;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import net.lenni0451.commons.color.Color;
import oxy.bascenario.api.effects.Easing;
import oxy.bascenario.api.effects.Effect;
import oxy.bascenario.api.effects.Weather;
import oxy.bascenario.api.event.LockClickEvent;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.api.event.ShowButtonsEvent;
import oxy.bascenario.api.event.background.ClearBackgroundEvent;
import oxy.bascenario.api.event.background.SetBackgroundEvent;
Expand Down Expand Up @@ -110,6 +112,10 @@ private void otherTab() {
add("Show Buttons",
"Choose to hide/show the auto/menu button at the top right of the screen.",
new ShowButtonsEvent(true));

add("Set Weather",
"Set the current weather",
new SetWeatherEvent(Weather.RAIN));
}

private void soundTab() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oxy.bascenario.editor.utils;

import oxy.bascenario.api.event.LockClickEvent;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.api.event.ShowButtonsEvent;
import oxy.bascenario.api.event.animation.PlayAnimationEvent;
import oxy.bascenario.api.event.animation.SpriteAnimationEvent;
Expand Down Expand Up @@ -70,6 +71,8 @@ public static String name(Object object) {
case FocusElementEvent ignored -> "Focus Object";
case UnfocusElementEvent ignored -> "Un-focus Object";

case SetWeatherEvent ignored -> "Set Weather";

default -> object.getClass().getSimpleName();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.JsonObject;

import oxy.bascenario.api.event.LockClickEvent;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.api.event.ShowButtonsEvent;
import oxy.bascenario.api.event.background.ClearBackgroundEvent;
import oxy.bascenario.api.event.background.SetBackgroundEvent;
Expand All @@ -23,6 +24,7 @@
import oxy.bascenario.serializers.base.Type;
import oxy.bascenario.serializers.base.TypeWithName;
import oxy.bascenario.serializers.types.event.impl.LockClickType;
import oxy.bascenario.serializers.types.event.impl.SetWeatherType;
import oxy.bascenario.serializers.types.event.impl.ShowButtonsType;
import oxy.bascenario.serializers.types.event.impl.animation.PlayAnimationType;
import oxy.bascenario.serializers.types.event.impl.animation.SpriteAnimationType;
Expand Down Expand Up @@ -87,6 +89,8 @@ private static void put(Class<? extends Event> klass, TypeWithName<?> type) {

put(LockClickEvent.class, new LockClickType());
put(ShowButtonsEvent.class, new ShowButtonsType());

put(SetWeatherEvent.class, new SetWeatherType());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package oxy.bascenario.serializers.types.event.impl;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import oxy.bascenario.api.effects.Weather;
import oxy.bascenario.api.event.SetWeatherEvent;
import oxy.bascenario.serializers.base.TypeWithName;

public class SetWeatherType implements TypeWithName<SetWeatherEvent> {
@Override
public String type() {
return "set-weather";
}

@Override
public JsonElement write(SetWeatherEvent setWeatherEvent) {
return new JsonPrimitive(setWeatherEvent.weather().name());
}

@Override
public SetWeatherEvent read(JsonElement element) {
return new SetWeatherEvent(Weather.valueOf(element.getAsString()));
}
}