81 lines
2.2 KiB
Odin
81 lines
2.2 KiB
Odin
package main
|
|
|
|
import "core:fmt"
|
|
import rl "vendor:raylib"
|
|
|
|
import "common"
|
|
|
|
// Main drawing function
|
|
draw :: proc(self: ^Simulator, pos: rl.Vector2) {
|
|
rl.ClearBackground(rl.LIGHTGRAY)
|
|
|
|
draw_roads(self)
|
|
draw_nodes(self)
|
|
draw_cars(self)
|
|
draw_temp_road(self, pos)
|
|
|
|
draw_ui(self)
|
|
}
|
|
|
|
@(private="file")
|
|
draw_roads :: proc(self: ^Simulator) {
|
|
for &road, index in self.roads {
|
|
start := road.nodes[0]
|
|
end := road.nodes[1]
|
|
|
|
road_colour: rl.Color
|
|
if road, ok := self.highlighted_road.?; ok && road == u32(index) && self.delete_mode {
|
|
road_colour = common.ROAD_HIGHLIGHT_COLOUR
|
|
} else do road_colour = common.ROAD_COLOUR
|
|
|
|
rl.DrawLineEx(self.nodes[start].pos, self.nodes[end].pos, common.ROAD_SIZE, road_colour)
|
|
}
|
|
}
|
|
|
|
@(private="file")
|
|
draw_nodes :: proc(self: ^Simulator) {
|
|
for &node in self.nodes {
|
|
// draws the snapping radius if key is held down
|
|
if self.show_details do rl.DrawCircleV(node.pos, common.NODE_SNAP_RADIUS, common.NODE_SNAP_COLOUR)
|
|
// draws the node
|
|
rl.DrawCircleV(node.pos, common.NODE_RADIUS, common.NODE_DONE_COLOUR)
|
|
}
|
|
}
|
|
|
|
@(private="file")
|
|
draw_cars :: proc(self: ^Simulator) {
|
|
for &car in self.cars {
|
|
ref := car.pos.ref
|
|
// TODO fix in the future
|
|
// let's fix it by tracking length of the road and
|
|
pos := car.pos.type == .Node ? self.nodes[ref].pos : self.nodes[self.roads[ref].nodes[0]].pos
|
|
|
|
rect := rl.Rectangle {
|
|
x = pos.x,
|
|
y = pos.y,
|
|
width = common.CAR_WIDTH,
|
|
height = common.CAR_HEIGHT
|
|
}
|
|
|
|
rl.DrawRectangleRec(rect, common.CAR_COLOUR)
|
|
}
|
|
}
|
|
|
|
@(private="file")
|
|
draw_temp_road :: proc(self: ^Simulator, pos: rl.Vector2) {
|
|
// draw temp road if exists
|
|
val, ok := self.temp_node.?
|
|
if !ok do return
|
|
|
|
rl.DrawLineEx(self.nodes[val].pos, pos, common.ROAD_SIZE, common.ROAD_COLOUR)
|
|
|
|
rl.DrawCircleV(self.nodes[val].pos, common.NODE_RADIUS, common.NODE_BUILD_COLOUR)
|
|
rl.DrawCircleV(pos, common.NODE_RADIUS, common.NODE_CURSOR_COLOUR)
|
|
}
|
|
|
|
// Drawing UI text, mostly for debugging purposes
|
|
@(private="file")
|
|
draw_ui :: proc(self: ^Simulator) {
|
|
entity_count := fmt.ctprintf("Nodes: %d, Roads: %d, Cars: %d", len(self.nodes), len(self.roads), len(self.cars))
|
|
rl.DrawText(entity_count, i32(len(entity_count)), common.HEIGHT - common.TEXT_SIZE, common.TEXT_SIZE, common.TEXT_COLOUR)
|
|
} |