-
Notifications
You must be signed in to change notification settings - Fork 12
Added some features #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6eee2ef
bd23c7b
27ae1a8
8256bc0
be91451
a3242cc
707a447
f81f6b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ This addon adds new features to DynamX : | |
- Klaxon and siren | ||
- Fuel tank | ||
- Immatriculation plates | ||
- Speed display on the vehicle | ||
- Speed, gear and speed limit display on the vehicle | ||
- Needle | ||
|
||
### How to add modules: | ||
|
||
|
@@ -71,6 +72,55 @@ FuelTank#Op{ | |
} | ||
``` | ||
|
||
#### Better speed-display | ||
|
||
``` | ||
TextInfo#Op{ | ||
Position: 0 0 0 | ||
Scale: 1 1 1 | ||
Rotation: 0 0 0 | ||
Color: 0 0 0 | ||
DetailToShow: GEAR | ||
CarStartedReact: True | ||
} | ||
``` | ||
|
||
The `DetailToShow` can be one of the following: | ||
- GEAR | ||
- SPEED | ||
- SPEEDLIMITOR | ||
|
||
It will display the current gear, speed or speedlimitor value at the position. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. speed limiter aussi du coup |
||
|
||
The `CarStartedReact` can be `True` or `False` and will enable or disable the display when the car is started. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ça veut pas dire grand chose "CarStartedReact" |
||
|
||
### DashboardNeedle | ||
|
||
``` | ||
DashboardNeedle_2 { | ||
Position: 0 0 0 | ||
Rotation: 0 0 -120 | ||
ObjectName: speedneedle | ||
NeedleMaxTurn: 160 | ||
DashboardMaxValue: 6000 | ||
NeedleType: RPM | ||
} | ||
``` | ||
|
||
| Key | Value | | ||
|------------------- |------------------------------------------ | | ||
| Rotation | Default rotation | | ||
| Position | Default position | | ||
| ObjectName | Name of the object in the 3D model | | ||
| NeedleMaxTurn | Max rotation in degrees on the dashboard | | ||
| DashboardMaxValue | Max value displayed on dashboard | | ||
| NeedleType | It can be `RPM` or `SPEED` | | ||
|
||
<img src="exemple.png" width="50%"> | ||
<br> | ||
|
||
> Here for RPM, max DashboardMaxValue is 6000 and max NeedleMaxTurn is 160. | ||
|
||
## Links | ||
|
||
DynamX website: https://dynamx.fr | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package fr.dynamx.addons.basics.common.infos; | ||
|
||
import com.jme3.math.Vector3f; | ||
import fr.dynamx.addons.basics.utils.TextUtils; | ||
import fr.dynamx.api.contentpack.object.part.BasePart; | ||
import fr.dynamx.api.contentpack.object.part.IDrawablePart; | ||
import fr.dynamx.api.contentpack.registry.DefinitionType; | ||
import fr.dynamx.api.contentpack.registry.PackFileProperty; | ||
import fr.dynamx.api.contentpack.registry.RegisteredSubInfoType; | ||
import fr.dynamx.api.contentpack.registry.SubInfoTypeRegistries; | ||
import fr.dynamx.api.entities.VehicleEntityProperties; | ||
import fr.dynamx.client.renders.model.renderer.DxModelRenderer; | ||
import fr.dynamx.client.renders.scene.EntityRenderContext; | ||
import fr.dynamx.client.renders.scene.SceneBuilder; | ||
import fr.dynamx.client.renders.scene.SceneGraph; | ||
import fr.dynamx.common.contentpack.type.vehicle.ModularVehicleInfo; | ||
import fr.dynamx.common.entities.BaseVehicleEntity; | ||
import fr.dynamx.common.entities.modules.engines.CarEngineModule; | ||
import fr.dynamx.utils.DynamXUtils; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import org.lwjgl.opengl.GL11; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@RegisteredSubInfoType(name = "DashboardNeedle", registries = SubInfoTypeRegistries.WHEELED_VEHICLES, strictName = false) | ||
public class DashboardNeedleInfo extends BasePart<ModularVehicleInfo> implements IDrawablePart<BaseVehicleEntity<?>, ModularVehicleInfo> { | ||
@PackFileProperty(configNames = "Rotation", type = DefinitionType.DynamXDefinitionTypes.VECTOR3F) | ||
protected Vector3f rotation; | ||
|
||
@PackFileProperty(configNames = "ObjectName", required = false, defaultValue = "speedneedle") | ||
protected String objectName; | ||
|
||
@PackFileProperty(configNames = "NeedleMaxTurn", required = false, defaultValue = "140", description = "common.NeedleMaxTurn") | ||
protected int needleMaxTurn; | ||
|
||
@PackFileProperty(configNames = "DashboardMaxValue", required = false, defaultValue = "140", description = "common.DashboardMaxSpeed") | ||
protected int dashboardMaxValue; | ||
|
||
@PackFileProperty(configNames = "DependsOnNode", required = false, description = "common.DependsOnNode") | ||
protected String nodeDependingOnName; | ||
|
||
@PackFileProperty(configNames = "NeedleType", required = false, defaultValue = "SPEED", description = "common.NeedleType") | ||
protected EnumDashboardNeedleType needleType; | ||
|
||
@Override | ||
public String getNodeName() { | ||
return getPartName(); | ||
} | ||
|
||
@Override | ||
public String getObjectName() { | ||
return this.objectName; | ||
} | ||
|
||
@Override | ||
public void addToSceneGraph(ModularVehicleInfo packInfo, SceneBuilder<BaseVehicleEntity<?>, ModularVehicleInfo> sceneBuilder) { | ||
if (nodeDependingOnName != null) { | ||
sceneBuilder.addNode(this, nodeDependingOnName, getNodeName()); | ||
} else { | ||
sceneBuilder.addNode(this, getNodeName()); | ||
} | ||
} | ||
|
||
@Override | ||
public SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo> createSceneGraph(Vector3f modelScale, List<SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo>> childGraph) { | ||
if (childGraph != null) throw new IllegalArgumentException("DashboardNeedleInfo can't have children parts"); | ||
return new SpeedNeedleNode<>(modelScale, null); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "PartShape named " + getPartName() + " in " + Objects.requireNonNull(getOwner()).getName(); | ||
} | ||
|
||
public int getNeedleMaxTurn() { | ||
return needleMaxTurn; | ||
} | ||
|
||
public int getDashboardMaxValue() { | ||
return dashboardMaxValue; | ||
} | ||
|
||
public EnumDashboardNeedleType getNeedleType() { | ||
return needleType; | ||
} | ||
|
||
public Vector3f getRotation() { | ||
return rotation; | ||
} | ||
|
||
public String getNodeDependingOnName() { | ||
return this.nodeDependingOnName; | ||
} | ||
|
||
Comment on lines
+77
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lombok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Précision : il est pas configuré sur l'env du BasicsAddon, donc on l'ajoutera surement nous-mêmes |
||
public DashboardNeedleInfo(ModularVehicleInfo owner, String partName) { | ||
super(owner, partName); | ||
} | ||
|
||
|
||
class SpeedNeedleNode<T extends BaseVehicleEntity<?>, A extends ModularVehicleInfo> extends SceneGraph.Node<T, A> { | ||
|
||
public SpeedNeedleNode(Vector3f scale, List<SceneGraph<T, A>> linkedChilds) { | ||
super(null, null, scale, linkedChilds); | ||
} | ||
|
||
@Override | ||
public void render(@Nullable T entity, EntityRenderContext entityRenderContext, A packInfo) { | ||
if (entity == null) return; | ||
DxModelRenderer vehicleModel = entityRenderContext.getModel(); | ||
byte b = entityRenderContext.getTextureId(); | ||
if (entityRenderContext.getModel().containsObjectOrNode(DashboardNeedleInfo.this.getObjectName()) && entity.getModuleByType(CarEngineModule.class) != null && DashboardNeedleInfo.this.getPosition() != null) { | ||
GlStateManager.pushMatrix(); | ||
Vector3f pos = DashboardNeedleInfo.this.getPosition(); | ||
GL11.glTranslatef(pos.x, pos.y, pos.z); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GlStateManager au lei de GL11 |
||
TextUtils.makeGLRotation(getRotation()); | ||
switch (DashboardNeedleInfo.this.getNeedleType()) { | ||
case RPM: | ||
int rpms = Math.round(entity.getModuleByType(CarEngineModule.class).getEngineProperty(VehicleEntityProperties.EnumEngineProperties.REVS) * 10000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tu peux faire une variable interne de entity.getModuleByType(CarEngineModule.class) et l'utiliser plusieurs fois au lieu de rappeler chaque fois |
||
GlStateManager.rotate((float) DashboardNeedleInfo.this.needleMaxTurn * rpms / DashboardNeedleInfo.this.dashboardMaxValue, 0, 0, 1); | ||
break; | ||
case SPEED: | ||
GlStateManager.rotate((float) DashboardNeedleInfo.this.needleMaxTurn * DynamXUtils.getSpeed(entity) / DashboardNeedleInfo.this.dashboardMaxValue, 0, 0, 1); | ||
break; | ||
} | ||
vehicleModel.renderGroup(DashboardNeedleInfo.this.getObjectName(), b, entityRenderContext.isUseVanillaRender()); | ||
GlStateManager.popMatrix(); | ||
} | ||
} | ||
} | ||
|
||
public enum EnumDashboardNeedleType { | ||
SPEED, RPM; | ||
|
||
public static EnumDashboardNeedleType fromString(String targetName) { | ||
for (EnumDashboardNeedleType dashboardNeedleType : values()) { | ||
if (dashboardNeedleType.name().equalsIgnoreCase(targetName)) { | ||
return dashboardNeedleType; | ||
} | ||
} | ||
throw new IllegalArgumentException("Invalid DashboardNeedleType value '" + targetName + "'"); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package fr.dynamx.addons.basics.common.infos; | ||
|
||
import com.jme3.math.Vector3f; | ||
import fr.dynamx.addons.basics.BasicsAddon; | ||
import fr.dynamx.addons.basics.utils.TextUtils; | ||
import fr.dynamx.api.contentpack.object.part.BasePart; | ||
import fr.dynamx.api.contentpack.object.part.IDrawablePart; | ||
import fr.dynamx.api.contentpack.registry.DefinitionType; | ||
import fr.dynamx.api.contentpack.registry.PackFileProperty; | ||
import fr.dynamx.api.contentpack.registry.RegisteredSubInfoType; | ||
import fr.dynamx.api.contentpack.registry.SubInfoTypeRegistries; | ||
import fr.dynamx.api.entities.VehicleEntityProperties; | ||
import fr.dynamx.client.renders.scene.EntityRenderContext; | ||
import fr.dynamx.client.renders.scene.SceneBuilder; | ||
import fr.dynamx.client.renders.scene.SceneGraph; | ||
import fr.dynamx.common.contentpack.type.vehicle.ModularVehicleInfo; | ||
import fr.dynamx.common.entities.BaseVehicleEntity; | ||
import fr.dynamx.common.entities.modules.engines.CarEngineModule; | ||
import fr.dynamx.utils.DynamXUtils; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@RegisteredSubInfoType(name = "TextInfo", registries = {SubInfoTypeRegistries.WHEELED_VEHICLES}, strictName = false) | ||
public class DashboardTextInfos extends BasePart<ModularVehicleInfo> implements IDrawablePart<BaseVehicleEntity<?>, ModularVehicleInfo> { | ||
@PackFileProperty(configNames = "Rotation", type = DefinitionType.DynamXDefinitionTypes.VECTOR3F, description = "common.rotation") | ||
protected Vector3f rotation; | ||
|
||
@PackFileProperty(configNames = "Font", required = false) | ||
protected String font = BasicsAddon.ID + ":e"; | ||
|
||
@PackFileProperty(configNames = "DetailToShow", required = false, defaultValue = "GEAR") | ||
protected EnumDashboardTextType detailToShow; | ||
@PackFileProperty(configNames = "CarStartedReact", required = false, defaultValue = "false", type = DefinitionType.DynamXDefinitionTypes.BOOL) | ||
protected boolean carStartedReact; | ||
|
||
@PackFileProperty(configNames = "Color", description = "common.color", required = false) | ||
protected int[] color = new int[]{10, 10, 10}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Utilise un Vector3f please |
||
|
||
@PackFileProperty(configNames = "DependsOnNode", required = false, description = "common.DependsOnNode") | ||
protected String nodeDependingOnName; | ||
|
||
public DashboardTextInfos(ModularVehicleInfo owner, String partName) { | ||
super(owner, partName); | ||
} | ||
|
||
@Override | ||
public void appendTo(ModularVehicleInfo owner) { | ||
owner.addSubProperty(this); | ||
} | ||
|
||
public Vector3f getRotation() { | ||
return rotation; | ||
} | ||
|
||
public int[] getColor() { | ||
return color; | ||
} | ||
|
||
public boolean isCarStartedReact() { | ||
return carStartedReact; | ||
} | ||
|
||
public String getFont() { | ||
return font; | ||
} | ||
|
||
public EnumDashboardTextType getDetailToShow() { | ||
return detailToShow; | ||
} | ||
Comment on lines
+53
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lombok |
||
|
||
@Override | ||
public String getName() { | ||
return "PartShape named " + getPartName() + " in " + getOwner().getName(); | ||
} | ||
|
||
@Override | ||
public String getObjectName() { | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public String getNodeName() { | ||
|
||
return getPartName(); | ||
} | ||
|
||
@Override | ||
public void addToSceneGraph(ModularVehicleInfo packInfo, SceneBuilder<BaseVehicleEntity<?>, ModularVehicleInfo> sceneBuilder) { | ||
if (nodeDependingOnName != null) { | ||
sceneBuilder.addNode(this, nodeDependingOnName, getNodeName()); | ||
} else { | ||
sceneBuilder.addNode(this, getNodeName()); | ||
} | ||
} | ||
|
||
@Override | ||
public SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo> createSceneGraph(Vector3f modelScale, List<SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo>> childGraph) { | ||
if (childGraph != null) throw new IllegalArgumentException("TextInfo can't have children parts"); | ||
return new SpeedDisplayNode<>(modelScale, null); | ||
} | ||
|
||
class SpeedDisplayNode<T extends BaseVehicleEntity<?>, A extends ModularVehicleInfo> extends SceneGraph.Node<T, A> { | ||
public SpeedDisplayNode(Vector3f scale, List<SceneGraph<T, A>> linkedChilds) { | ||
super(null, null, scale, linkedChilds); | ||
} | ||
|
||
@Override | ||
public void render(@Nullable T entity, EntityRenderContext entityRenderContext, A packInfo) { | ||
if (entity == null) return; | ||
if (DashboardTextInfos.this.getRotation() != null) { | ||
if (entity.getModuleByType(CarEngineModule.class).getPhysicsHandler().getEngine().isStarted() && DashboardTextInfos.this.isCarStartedReact()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meme chose pour entity.getModuleByType(CarEngineModule.class) |
||
String value = ""; | ||
switch (DashboardTextInfos.this.getDetailToShow()) { | ||
case GEAR: | ||
float gear = entity.getModuleByType(CarEngineModule.class).getEngineProperty(VehicleEntityProperties.EnumEngineProperties.ACTIVE_GEAR); | ||
if (gear == 0) value = "N"; | ||
else if (gear == -1) value = "R" + (int) Math.abs(gear); | ||
else value = "D" + (int) gear; | ||
break; | ||
case SPEEDLIMITOR: | ||
int tempvalue = Math.round(entity.getModuleByType(CarEngineModule.class).getSpeedLimit()); | ||
if (tempvalue != 0 & tempvalue < 10000000) value = String.valueOf(tempvalue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tu peux utiliser une condition ternaire et peut être utiliser Integer.MAX_VALUE au lieu de 100000 |
||
else value = ""; | ||
break; | ||
case SPEED: | ||
value = String.valueOf(DynamXUtils.getSpeed(entity)); | ||
break; | ||
} | ||
TextUtils.drawText(DashboardTextInfos.this.getPosition(), DashboardTextInfos.this.getScale(), DashboardTextInfos.this.getRotation(), value, getColor(), getFont()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public enum EnumDashboardTextType { | ||
SPEED, GEAR, SPEEDLIMITOR; | ||
|
||
public static EnumDashboardTextType fromString(String targetName) { | ||
for (EnumDashboardTextType dashboardNeedleType : values()) { | ||
if (dashboardNeedleType.name().equalsIgnoreCase(targetName)) { | ||
return dashboardNeedleType; | ||
} | ||
} | ||
throw new IllegalArgumentException("Invalid EnumDashboardTextType value '" + targetName + "'"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPEED_LIMITER*