Skip to content

Commit

Permalink
Trains (#110)
Browse files Browse the repository at this point in the history
* More functionality in the roadbuild tools

Straight for road and rail:
Based on the start and end MapProject, a dot will appear that indicates a
straight connection from the selected MapProject.

Curved connection ProjectState:
When clicking on any MapProject and Ground or Intersection, a straight
road would be created. Now an interpolation point needs to be set.

Function for line line intersection
With four points, representing two lines, the intersection of these two
lines is calculated

Function for line closed point
Given two points representing one line and one point, the closed point
on the line from the third point is calculated.

* Substitute functions with excisting functions

Substitute functions Vec2::{line_line_intersection, line_closed_point}
with Line::{intersection_point, project}

* Cool new features for trains.

Make costum trains of any length for any persose. Make commuter, freight
or high speed trains.

* Changes to the trains

* Changes

* Adding comments and information about trains

* More height offset options.
reletive to ground and reletive to start

* Forgot to commit icons

* Fixing typos and substitute functions
  • Loading branch information
Groneschild committed Jun 20, 2024
1 parent cac060a commit eae0275
Show file tree
Hide file tree
Showing 26 changed files with 888 additions and 239 deletions.
3 changes: 3 additions & 0 deletions assets/models/passenger-emu-front.glb
Git LFS file not shown
3 changes: 3 additions & 0 deletions assets/models/passenger-emu-middle.glb
Git LFS file not shown
3 changes: 3 additions & 0 deletions assets/models/passenger-emu-rear.glb
Git LFS file not shown
3 changes: 3 additions & 0 deletions assets/ui/icons/height_reference_decline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/ui/icons/height_reference_ground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/ui/icons/height_reference_incline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/ui/icons/height_reference_start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/ui/icons/snap_angle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/ui/icons/snap_notting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions base_mod/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ require("items")
require("companies")
require("leisure")
require("colors")
require("roadvehicles")
require("rollingstock")

data:extend {
{
Expand Down
27 changes: 27 additions & 0 deletions base_mod/roadvehicles.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
data:extend {
{
type = "road-vehicle",
order = "a-1",
name = "simple_car",
label = "Simple Car",
max_speed = 50.0,
acceleration = 8.0,
deceleration = 12.0,
asset = "simple_car.glb",
price = 100.0,
},
{
type = "road-vehicle",
order = "b-1",
name = "simple_truck",
label = "simple truck",
max_speed = 22.0,
acceleration = 6.0,
deceleration = 10.0,
asset = "truck.glb",
price = 100.0,
}
}



83 changes: 83 additions & 0 deletions base_mod/rollingstock.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
data:extend {
{
type = "rolling-stock",
order = "l-1",
name = "locomotive",
label = "Locomotive",
length = 16.75,
mass = 60,
max_speed = 200.0,
acc_force = 2000.0,
dec_force = 360.0,
asset = "train.glb",
price = 100,
},
{
type = "rolling-stock",
order = "p-1",
name = "passenger-wagon",
label = "Passenger Wagon",
length = 16.75,
mass = 40,
max_speed = 200.0,
acc_force = 0.0,
dec_force = 240.0,
asset = "wagon.glb",
price = 100,
},
{
type = "rolling-stock",
order = "f-1",
name = "freight-wagon",
label = "Freight Wagon",
length = 16.75,
mass = 80,
max_speed = 160.0,
acc_force = 0.0,
dec_force = 480.0,
asset = "wagon_freight.glb",
price = 100,
},
{
type = "rolling-stock",
order = "e-1",
name = "passenger-emu-front",
label = "Passenger EMU Front",
length = 28.0,
mass = 60,
max_speed = 360.0,
acc_force = 240.0,
dec_force = 360.0,
asset = "passenger-emu-front.glb",
price = 500,
},
{
type = "rolling-stock",
order = "e-2",
name = "passenger-emu-middle",
label = "Passenger EMU Middle",
length = 28.0,
mass = 60,
max_speed = 360.0,
acc_force = 240.0,
dec_force = 360.0,
asset = "passenger-emu-middle.glb",
price = 200,
},
{
type = "rolling-stock",
order = "e-3",
name = "passenger-emu-rear",
label = "Passenger EMU Rear",
length = 28.0,
mass = 60,
max_speed = 360.0,
acc_force = 240.0,
dec_force = 360.0,
asset = "passenger-emu-rear.glb",
price = 500,
},
}



2 changes: 2 additions & 0 deletions native_app/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::newgui::lotbrush::LotBrushResource;
use crate::newgui::roadbuild::RoadBuildResource;
use crate::newgui::roadeditor::RoadEditorResource;
use crate::newgui::specialbuilding::SpecialBuildingResource;
use crate::newgui::addtrain::TrainSpawnResource;
use crate::newgui::terraforming::TerraformingResource;
use crate::newgui::toolbox::building::BuildingIcons;
use crate::newgui::windows::economy::EconomyState;
Expand Down Expand Up @@ -60,6 +61,7 @@ pub fn init() {
register_resource_noserialize::<RoadBuildResource>();
register_resource_noserialize::<RoadEditorResource>();
register_resource_noserialize::<SpecialBuildingResource>();
register_resource_noserialize::<TrainSpawnResource>();
register_resource_noserialize::<Timings>();
register_resource_noserialize::<Tool>();
register_resource_noserialize::<WorldCommands>();
Expand Down
89 changes: 66 additions & 23 deletions native_app/src/newgui/hud/toolbox/roadbuild.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use yakui::widgets::List;
use yakui::{
image, reflow, Alignment, Color, CrossAxisAlignment, Dim2, MainAxisAlignment, MainAxisSize,
Vec2,
image, reflow, Alignment, Color, CrossAxisAlignment, Dim2, MainAxisAlignment, MainAxisSize, Vec2
};

use goryak::{image_button, padxy, primary};
use goryak::{image_button, mincolumn, minrow, padxy, primary};
use simulation::map::LanePatternBuilder;

use crate::newgui::hud::toolbox::updown_value;
use crate::newgui::roadbuild::RoadBuildResource;
use crate::newgui::roadbuild::{HeightReference, RoadBuildResource, Snapping};
use crate::newgui::textures::UiTextures;
use crate::uiworld::UiWorld;

Expand All @@ -21,26 +20,70 @@ pub fn roadbuild_properties(uiw: &UiWorld) {
l.cross_axis_alignment = CrossAxisAlignment::Center;
l.item_spacing = 10.0;
l.show(|| {
// Snap to grid
let (default_col, hover_col) = if state.snap_to_grid {
let c = primary().lerp(&Color::WHITE, 0.3);
(c, c.with_alpha(0.7))
} else {
(Color::WHITE.with_alpha(0.3), Color::WHITE.with_alpha(0.5))
};
if image_button(
uiw.read::<UiTextures>().get("snap_grid"),
Vec2::new(32.0, 32.0),
default_col,
hover_col,
primary(),
"snap to grid",
)
.clicked
{
state.snap_to_grid = !state.snap_to_grid;
}
let c = primary().lerp(&Color::WHITE, 0.3);
let active = (c, c.with_alpha(0.7));
let default = (Color::WHITE.with_alpha(0.3), Color::WHITE.with_alpha(0.5));

mincolumn(4.0, || {
minrow(2.0, || {
let (snapping_none, snapping_grid, snapping_angel) = match state.snapping {
Snapping::None => {(active, default, default)},
Snapping::SnapToGrid => {(default, active, default)},
Snapping::SnapToAngle => {(default, default, active)},
};
if image_button(
uiw.read::<UiTextures>().get("snap_notting"),
Vec2::new(30.0, 30.0),
snapping_none.0, snapping_none.1,
primary(), "no snapping",
).clicked { state.snapping = Snapping::None; }
if image_button(
uiw.read::<UiTextures>().get("snap_grid"),
Vec2::new(30.0, 30.0),
snapping_grid.0, snapping_grid.1,
primary(), "snap to grid",
).clicked { state.snapping = Snapping::SnapToGrid; }
if image_button(
uiw.read::<UiTextures>().get("snap_angle"),
Vec2::new(30.0, 30.0),
snapping_angel.0, snapping_angel.1,
primary(), "snap to angle",
).clicked { state.snapping = Snapping::SnapToAngle; }
});

minrow(2.0, || {
let (hos_ground, hos_start, hos_incline, hos_decline) = match state.height_reference {
HeightReference::Ground => {(active, default, default, default)},
HeightReference::Start => {(default, active, default, default)},
HeightReference::MaxIncline => {(default, default, active, default)},
HeightReference::MaxDecline => {(default, default, default, active)},
};
if image_button(
uiw.read::<UiTextures>().get("height_reference_ground"),
Vec2::new(30.0, 30.0),
hos_ground.0, hos_ground.1,
primary(), "Relative to ground",
).clicked { state.height_reference = HeightReference::Ground; }
if image_button(
uiw.read::<UiTextures>().get("height_reference_start"),
Vec2::new(30.0, 30.0),
hos_start.0, hos_start.1,
primary(), "Relative to start",
).clicked { state.height_reference = HeightReference::Start; }
if image_button(
uiw.read::<UiTextures>().get("height_reference_incline"),
Vec2::new(30.0, 30.0),
hos_incline.0, hos_incline.1,
primary(), "Maximum incline",
).clicked { state.height_reference = HeightReference::MaxIncline; }
if image_button(
uiw.read::<UiTextures>().get("height_reference_decline"),
Vec2::new(30.0, 30.0),
hos_decline.0, hos_decline.1,
primary(), "Maximum decline",
).clicked { state.height_reference = HeightReference::MaxDecline; }
});
});
// Road elevation
updown_value(&mut state.height_offset, 2.0, "m");

Expand Down
57 changes: 55 additions & 2 deletions native_app/src/newgui/hud/toolbox/train.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
use goryak::{mincolumn, minrow, padxy, outline};
use prototypes::{prototypes_iter, RollingStockID, RollingStockPrototype};
use yakui::widgets::List;
use yakui::{button, divider, label, CrossAxisAlignment, MainAxisAlignment};

use crate::newgui::addtrain::TrainSpawnResource;
use crate::uiworld::UiWorld;

pub fn train_properties(_uiw: &UiWorld) {}
pub fn train_properties(uiw: &UiWorld) {
let mut state = uiw.write::<TrainSpawnResource>();

padxy(0.0, 0.0, || {
let mut l = List::row();
l.main_axis_alignment = MainAxisAlignment::Start;
l.cross_axis_alignment = CrossAxisAlignment::Center;
l.item_spacing = 10.0;
l.show(|| {
mincolumn(0.1, || {
if button("remove trian").clicked {
state.wagons.clear();
state.set_zero();
}
label(format!("Acceleration: {:.1} m/s^2", state.acceleration));
label(format!("Deceleration: {:.1} m/s^2", state.deceleration));
label(format!("Total Lenght: {} m", state.total_lenght.ceil()));
});

mincolumn(0.5, || {
minrow(0.0, || {
let mut remove: Option<usize>= None;
for (i, rs) in state.wagons.iter()
.map(|id| RollingStockID::prototype(*id))
.enumerate() {
if button(rs.label.clone()).clicked { remove = Some(i); }
}
if let Some(i) = remove {
state.wagons.remove(i);
state.calculate();
}
});

divider(outline(), 10.0, 1.0);

minrow(0.0, || {
for rolling_stock in prototypes_iter::<RollingStockPrototype>() {
let resp = button(rolling_stock.label.clone());
if resp.clicked {
state.wagons.push(rolling_stock.id);
state.calculate();
}
}
});
});
});
});
}

/*
if ui.button(freightstation).clicked() {
Expand Down Expand Up @@ -41,4 +94,4 @@ if ui.button(freightstation).clicked() {
road_snap: false,
});
}
*/
*/
Loading

0 comments on commit eae0275

Please sign in to comment.