Skip to content

Commit 3082304

Browse files
Finally made color trigger editable in-game
I have been fearing this moment but I have finally done it. I did not want to do this but I finally don't have to worry
1 parent 0e2addd commit 3082304

File tree

2 files changed

+142
-58
lines changed

2 files changed

+142
-58
lines changed

src/game/editor.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ pub fn object_ped(
174174
grid_size: u8,
175175

176176
current_tab: u8,
177-
current_obj: u16
177+
current_obj: u16,
178+
selected_obj: &mut u16
178179
) {
179180
if current_tab == 1 {
180181
object_grid.push(ObjectStruct {
@@ -221,6 +222,7 @@ pub fn object_ped(
221222
}
222223

223224
object_grid[obj_index].selected = true;
225+
*selected_obj = object_grid[obj_index].id;
224226
break;
225227
}
226228

@@ -248,7 +250,9 @@ pub fn draw_color_preview_boxes(
248250

249251
grnd_red: &String,
250252
grnd_green: &String,
251-
grnd_blue: &String
253+
grnd_blue: &String,
254+
255+
level_options_type: u8
252256
) {
253257
match (bg_red.parse::<u8>(), bg_green.parse::<u8>(), bg_blue.parse::<u8>()) {
254258
(Ok(bg_red), Ok(bg_green), Ok(bg_blue)) => {
@@ -269,22 +273,24 @@ pub fn draw_color_preview_boxes(
269273
_ => {}
270274
}
271275

272-
match (grnd_red.parse::<u8>(), grnd_green.parse::<u8>(), grnd_blue.parse::<u8>()) {
273-
(Ok(grnd_red), Ok(grnd_green), Ok(grnd_blue)) => {
274-
draw_rectangle(
275-
screen_width() - 450.0,
276-
80.0,
277-
50.0,
278-
50.0,
279-
Color::from_rgba(
280-
grnd_red,
281-
grnd_green,
282-
grnd_blue,
283-
255
284-
)
285-
);
276+
if level_options_type == 1 {
277+
match (grnd_red.parse::<u8>(), grnd_green.parse::<u8>(), grnd_blue.parse::<u8>()) {
278+
(Ok(grnd_red), Ok(grnd_green), Ok(grnd_blue)) => {
279+
draw_rectangle(
280+
screen_width() - 450.0,
281+
80.0,
282+
50.0,
283+
50.0,
284+
Color::from_rgba(
285+
grnd_red,
286+
grnd_green,
287+
grnd_blue,
288+
255
289+
)
290+
);
291+
}
292+
293+
_ => {}
286294
}
287-
288-
_ => {}
289295
}
290296
}

src/main.rs

Lines changed: 118 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ async fn main() {
165165
false
166166
);
167167

168+
let mut edit_obj_button = Button::new(
169+
|| screen_width() - 329.0,
170+
|| 20.0,
171+
|| 150.0,
172+
|| 75.0,
173+
"Edit Obj",
174+
15,
175+
false
176+
);
177+
168178
let mut editor_playtest_button = Button::new(
169179
|| 20.0,
170180
|| screen_height() / 2.0 - 65.0,
@@ -397,8 +407,10 @@ async fn main() {
397407
let mut cam_pos_y: f32 = 0.0;
398408
let mut cam_pos_x: f32 = 0.0;
399409
let mut current_obj: u16 = 1;
410+
let mut selected_obj: u16 = 0;
400411
let grid_size: u8 = 40;
401412
let mut level_mode: u8 = 1;
413+
let mut level_options_type: u8 = 1;
402414

403415
println!("Getting latest version...");
404416
let version: &str = "F-BETA";
@@ -895,6 +907,7 @@ async fn main() {
895907
editor_save_button.update(delta_time);
896908
editor_options_button.update(delta_time);
897909
editor_upload_button.update(delta_time);
910+
edit_obj_button.update(delta_time);
898911
build_tab_button.update(delta_time);
899912
edit_tab_button.update(delta_time);
900913
editor_playtest_button.update(delta_time);
@@ -924,6 +937,27 @@ async fn main() {
924937
grnd_green_textbox.input = (cc_1002.g * 255.0).floor().to_string();
925938
grnd_blue_textbox.input = (cc_1002.b * 255.0).floor().to_string();
926939

940+
level_options_type = 1;
941+
game_state.0.set(GameState::LevelSettings)
942+
}
943+
944+
if edit_obj_button.is_clicked() && selected_obj == 23 {
945+
let mut color_trigger_color = Color::from_rgba(0, 0, 0, 255);
946+
for object in &obj_grid {
947+
if object.selected && object.id == 23 {
948+
let red: u8 = object.properties.clone().unwrap()[0].parse().unwrap();
949+
let green: u8 = object.properties.clone().unwrap()[1].parse().unwrap();
950+
let blue: u8 = object.properties.clone().unwrap()[2].parse().unwrap();
951+
952+
color_trigger_color = Color::from_rgba(red, green, blue, 255)
953+
}
954+
}
955+
956+
bg_red_textbox.input = (color_trigger_color.r * 255.0).floor().to_string();
957+
bg_green_textbox.input = (color_trigger_color.g * 255.0).floor().to_string();
958+
bg_blue_textbox.input = (color_trigger_color.b * 255.0).floor().to_string();
959+
960+
level_options_type = 2;
927961
game_state.0.set(GameState::LevelSettings)
928962
}
929963

@@ -985,7 +1019,8 @@ async fn main() {
9851019
&& !editor_playtest_button.rect.contains(mouse_position().into())
9861020
&& !editor_save_button.rect.contains(mouse_position().into())
9871021
&& !editor_options_button.rect.contains(mouse_position().into())
988-
&& !editor_upload_button.rect.contains(mouse_position().into()) {
1022+
&& !editor_upload_button.rect.contains(mouse_position().into())
1023+
&& !edit_obj_button.rect.contains(mouse_position().into()) {
9891024
editor::object_ped(
9901025
&mut obj_grid,
9911026
snapped_x,
@@ -994,7 +1029,8 @@ async fn main() {
9941029
cam_pos_y,
9951030
grid_size,
9961031
current_tab,
997-
current_obj
1032+
current_obj,
1033+
&mut selected_obj
9981034
);
9991035
}
10001036

@@ -1037,7 +1073,15 @@ async fn main() {
10371073
let mut bg_red_parse_success: bool = false;
10381074
match bg_red_textbox.input.parse::<u8>() {
10391075
Ok(value) => {
1040-
cc_1001.r = value as f32 / 255.0;
1076+
if level_options_type == 1 {
1077+
cc_1001.r = value as f32 / 255.0;
1078+
} else {
1079+
for object in &mut obj_grid {
1080+
if object.selected && object.id == 23 {
1081+
object.properties.as_mut().unwrap()[0] = value.to_string();
1082+
}
1083+
}
1084+
}
10411085
bg_red_parse_success = true;
10421086
}
10431087

@@ -1049,7 +1093,15 @@ async fn main() {
10491093
let mut bg_green_parse_success: bool = false;
10501094
match bg_green_textbox.input.parse::<u8>() {
10511095
Ok(value) => {
1052-
cc_1001.g = value as f32 / 255.0;
1096+
if level_options_type == 1 {
1097+
cc_1001.g = value as f32 / 255.0;
1098+
} else {
1099+
for object in &mut obj_grid {
1100+
if object.selected && object.id == 23 {
1101+
object.properties.as_mut().unwrap()[1] = value.to_string();
1102+
}
1103+
}
1104+
}
10531105
bg_green_parse_success = true;
10541106
}
10551107

@@ -1061,7 +1113,15 @@ async fn main() {
10611113
let mut bg_blue_parse_success: bool = false;
10621114
match bg_blue_textbox.input.parse::<u8>() {
10631115
Ok(value) => {
1064-
cc_1001.b = value as f32 / 255.0;
1116+
if level_options_type == 1 {
1117+
cc_1001.b = value as f32 / 255.0;
1118+
} else {
1119+
for object in &mut obj_grid {
1120+
if object.selected && object.id == 23 {
1121+
object.properties.as_mut().unwrap()[2] = value.to_string();
1122+
}
1123+
}
1124+
}
10651125
bg_blue_parse_success = true;
10661126
}
10671127

@@ -1073,39 +1133,51 @@ async fn main() {
10731133

10741134

10751135
let mut grnd_red_parse_success: bool = false;
1076-
match grnd_red_textbox.input.parse::<u8>() {
1077-
Ok(value) => {
1078-
cc_1002.r = value as f32 / 255.0;
1079-
grnd_red_parse_success = true;
1080-
}
1136+
if level_options_type == 1 {
1137+
match grnd_red_textbox.input.parse::<u8>() {
1138+
Ok(value) => {
1139+
cc_1002.r = value as f32 / 255.0;
1140+
grnd_red_parse_success = true;
1141+
}
10811142

1082-
Err(error) => {
1083-
println!("Error parsing grnd_red: {}", error);
1143+
Err(error) => {
1144+
println!("Error parsing grnd_red: {}", error);
1145+
}
10841146
}
1147+
} else {
1148+
grnd_red_parse_success = true
10851149
}
10861150

10871151
let mut grnd_green_parse_success: bool = false;
1088-
match grnd_green_textbox.input.parse::<u8>() {
1089-
Ok(value) => {
1090-
cc_1002.g = value as f32 / 255.0;
1091-
grnd_green_parse_success = true;
1092-
}
1152+
if level_options_type == 1 {
1153+
match grnd_green_textbox.input.parse::<u8>() {
1154+
Ok(value) => {
1155+
cc_1002.g = value as f32 / 255.0;
1156+
grnd_green_parse_success = true;
1157+
}
10931158

1094-
Err(error) => {
1095-
println!("Error parsing grnd_green: {}", error);
1159+
Err(error) => {
1160+
println!("Error parsing grnd_green: {}", error);
1161+
}
10961162
}
1163+
} else {
1164+
grnd_green_parse_success = true
10971165
}
10981166

10991167
let mut grnd_blue_parse_success: bool = false;
1100-
match grnd_blue_textbox.input.parse::<u8>() {
1101-
Ok(value) => {
1102-
cc_1002.b = value as f32 / 255.0;
1103-
grnd_blue_parse_success = true;
1104-
}
1168+
if level_options_type == 1 {
1169+
match grnd_blue_textbox.input.parse::<u8>() {
1170+
Ok(value) => {
1171+
cc_1002.b = value as f32 / 255.0;
1172+
grnd_blue_parse_success = true;
1173+
}
11051174

1106-
Err(error) => {
1107-
println!("Error parsing grnd_blue: {}", error);
1175+
Err(error) => {
1176+
println!("Error parsing grnd_blue: {}", error);
1177+
}
11081178
}
1179+
} else {
1180+
grnd_blue_parse_success = true
11091181
}
11101182

11111183
if bg_red_parse_success
@@ -1118,12 +1190,12 @@ async fn main() {
11181190
}
11191191
}
11201192

1121-
if is_key_pressed(KeyCode::Left) && current_song_index > 0 {
1193+
if is_key_pressed(KeyCode::Left) && current_song_index > 0 && level_options_type == 1 {
11221194
current_song_index -= 1;
11231195
current_song = main_levels[current_song_index as usize].song.clone();
11241196
}
11251197

1126-
if is_key_pressed(KeyCode::Right) && current_song_index < main_levels.len() as u8 - 1 {
1198+
if is_key_pressed(KeyCode::Right) && current_song_index < main_levels.len() as u8 - 1 && level_options_type == 1 {
11271199
current_song_index += 1;
11281200
current_song = main_levels[current_song_index as usize].song.clone();
11291201
}
@@ -1749,6 +1821,7 @@ async fn main() {
17491821
editor_save_button.draw(false, None, 1.0, false, &font);
17501822
editor_options_button.draw(false, None, 1.0, false, &font);
17511823
editor_upload_button.draw(false, None, 1.0, false, &font);
1824+
edit_obj_button.draw(false, None, 1.0, false, &font);
17521825
build_tab_button.draw(false, None, 1.0, false, &font);
17531826
edit_tab_button.draw(false, None, 1.0, false, &font);
17541827
editor_playtest_button.draw(false, None, 1.0, false, &font);
@@ -1786,31 +1859,36 @@ async fn main() {
17861859
}
17871860

17881861
GameState::LevelSettings => {
1789-
draw_text_pro(
1790-
&main_levels[current_song_index as usize].name,
1791-
screen_width() / 2.0 - measure_text_ex(&main_levels[current_song_index as usize].name, 30, &font) / 2.0,
1792-
screen_height() - 30.0,
1793-
30,
1794-
WHITE,
1795-
&font
1796-
);
1862+
if level_options_type == 1 {
1863+
draw_text_pro(
1864+
&main_levels[current_song_index as usize].name,
1865+
screen_width() / 2.0 - measure_text_ex(&main_levels[current_song_index as usize].name, 30, &font) / 2.0,
1866+
screen_height() - 30.0,
1867+
30,
1868+
WHITE,
1869+
&font
1870+
);
1871+
}
17971872

17981873
editor::draw_color_preview_boxes(
17991874
&bg_red_textbox.input,
18001875
&bg_green_textbox.input,
18011876
&bg_blue_textbox.input,
18021877
&grnd_red_textbox.input,
18031878
&grnd_green_textbox.input,
1804-
&grnd_blue_textbox.input
1879+
&grnd_blue_textbox.input,
1880+
level_options_type
18051881
);
18061882

18071883
bg_red_textbox.draw(&font);
18081884
bg_green_textbox.draw(&font);
18091885
bg_blue_textbox.draw(&font);
18101886

1811-
grnd_red_textbox.draw(&font);
1812-
grnd_green_textbox.draw(&font);
1813-
grnd_blue_textbox.draw(&font);
1887+
if level_options_type == 1 {
1888+
grnd_red_textbox.draw(&font);
1889+
grnd_green_textbox.draw(&font);
1890+
grnd_blue_textbox.draw(&font);
1891+
}
18141892

18151893
back_button.draw(false, None, 1.0, false, &font);
18161894
}

0 commit comments

Comments
 (0)