Added stats & purchase buttons

master
Mark 2024-02-16 18:27:46 -08:00
parent de07e763c3
commit 7272f2a00a
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
1 changed files with 77 additions and 1 deletions

View File

@ -347,6 +347,9 @@ fn init(state) {
fn event(state, event) { fn event(state, event) {
// TODO: update on ship outfit change only
update_ship_info(state);
if type_of(event) == "MouseHoverEvent" { if type_of(event) == "MouseHoverEvent" {
let element = event.element(); let element = event.element();
@ -394,6 +397,24 @@ fn event(state, event) {
return PlayerDirective::None; return PlayerDirective::None;
} }
if element == "buy_button" {
if selected_outfit != false {
let outfit = ct::get_outfit(selected_outfit);
if outfit.is_some() {
return PlayerDirective::BuyOutfit(outfit, 1);
}
}
}
if element == "sell_button" {
if selected_outfit != false {
let outfit = ct::get_outfit(selected_outfit);
if outfit.is_some() {
return PlayerDirective::SellOutfit(outfit, 1);
}
}
}
if ( if (
element.starts_with("outfit.backg.") && element.starts_with("outfit.backg.") &&
event.element().split("outfit.backg.".len())[1] != selected_outfit event.element().split("outfit.backg.".len())[1] != selected_outfit
@ -475,6 +496,41 @@ fn update_outfit_info(selected_outfit) {
let stats = ""; let stats = "";
let tlen = 20; let tlen = 20;
{
let s = "cost ";
s.pad(tlen, " ");
stats += s + outfit.cost();
stats += "\n";
}
{
let s = "needs gun port ";
s.pad(tlen, " ");
if outfit.stat_is_gun() {
stats += s + "yes";
} else {
stats += s + "no"
}
stats += "\n";
}
{
let s = outfit.required_space();
for k in s.keys() {
let v = s[k];
let s = k + " space needed ";
s.pad(tlen, " ");
if v != 0 {
stats += s + v;
stats += "\n";
}
}
}
stats += "\n";
if outfit.stat_thrust() != 0 { if outfit.stat_thrust() != 0 {
let s = "thrust "; let s = "thrust ";
s.pad(tlen, " "); s.pad(tlen, " ");
@ -527,8 +583,28 @@ fn update_ship_info(state) {
let tlen = 20; let tlen = 20;
{
let u = ship.used_space();
let t = ship.total_space();
for k in u.keys() {
let vu = u[k];
let vt = t[k];
let s = k + " space ";
s.pad(tlen, " ");
stats += s + (vt - vu) + "/" + vt;
stats += "\n";
}
}
{
let s = "gun points ";
s.pad(tlen, " ");
stats += s + ship.free_gun_points() + "/" + ship.total_gun_points();
stats += "\n\n";
}
// TODO: outfits add mass // TODO: outfits add mass
// TODO: calculate radial acceleration // TODO: calculate acceleration
{ {
let s = "shield strength "; let s = "shield strength ";
s.pad(tlen, " "); s.pad(tlen, " ");