Minor fixes

This commit is contained in:
Pax1601
2023-05-24 15:15:44 +02:00
parent 5f2f2a83dd
commit ec872e181d
7 changed files with 70 additions and 72 deletions

View File

@@ -165,7 +165,7 @@ form>div {
align-items: center; align-items: center;
background-color: var(--background-grey); background-color: var(--background-grey);
border-radius: var(--border-radius-sm); border-radius: var(--border-radius-sm);
height: 32px; height: 40px;
overflow: hidden; overflow: hidden;
padding-left: 20px; padding-left: 20px;
padding-right: 30px; padding-right: 30px;
@@ -225,7 +225,7 @@ form>div {
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25); box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25);
display: flex; display: flex;
justify-content: left; justify-content: left;
padding: 2px 10px; padding: 2px 15px;
width: 100%; width: 100%;
} }
@@ -251,8 +251,9 @@ form>div {
border-radius: var(--border-radius-sm); border-radius: var(--border-radius-sm);
color: white; color: white;
display: block; display: block;
font-size: 12px; font-size: 13px;
font-weight: normal; font-weight: normal;
height: 32px;
padding: 6px 2px; padding: 6px 2px;
padding: 5px; padding: 5px;
text-align: left; text-align: left;

View File

@@ -33,8 +33,8 @@ export class Dropdown {
this.#options.classList.add("ol-scrollable"); this.#options.classList.add("ol-scrollable");
} }
setOptions(optionsList: string[]) { setOptions(optionsList: string[], sortAlphabetically: boolean = true) {
this.#optionsList = optionsList; this.#optionsList = optionsList.sort();
this.#options.replaceChildren(...optionsList.map((option: string, idx: number) => { this.#options.replaceChildren(...optionsList.map((option: string, idx: number) => {
var div = document.createElement("div"); var div = document.createElement("div");
var button = document.createElement("button"); var button = document.createElement("button");
@@ -70,6 +70,7 @@ export class Dropdown {
var el = document.createElement("div"); var el = document.createElement("div");
el.classList.add("ol-ellipsed"); el.classList.add("ol-ellipsed");
el.innerText = option; el.innerText = option;
this.#value.replaceChildren();
this.#value.appendChild(el); this.#value.appendChild(el);
this.#index = idx; this.#index = idx;
this.#close(); this.#close();

View File

@@ -188,8 +188,6 @@ export class MapContextMenu extends ContextMenu {
this.#resetGroundUnitType(); this.#resetGroundUnitType();
const types = groundUnitsDatabase.getByRole(role).map((blueprint) => { return blueprint.label }); const types = groundUnitsDatabase.getByRole(role).map((blueprint) => { return blueprint.label });
types.sort();
this.#groundUnitTypeDropdown.setOptions(types); this.#groundUnitTypeDropdown.setOptions(types);
this.#groundUnitTypeDropdown.selectValue(0); this.#groundUnitTypeDropdown.selectValue(0);
this.clip(); this.clip();
@@ -202,8 +200,6 @@ export class MapContextMenu extends ContextMenu {
this.#groundUnitTypeDropdown.reset(); this.#groundUnitTypeDropdown.reset();
const roles = groundUnitsDatabase.getRoles(); const roles = groundUnitsDatabase.getRoles();
roles.sort();
this.#groundUnitRoleDropdown.setOptions(roles); this.#groundUnitRoleDropdown.setOptions(roles);
this.clip(); this.clip();
} }

View File

@@ -18,7 +18,7 @@ export class LogPanel extends Panel
if (parseInt(idx) >= this.#logs.length) { if (parseInt(idx) >= this.#logs.length) {
this.#logs.push(logs[idx]); this.#logs.push(logs[idx]);
var el = document.createElement("div"); var el = document.createElement("div");
el.innerHTML = logs[idx]; el.innerText = logs[idx];
el.classList.add("js-log-element", "ol-log-element"); el.classList.add("js-log-element", "ol-log-element");
this.getElement().appendChild(el); this.getElement().appendChild(el);
this.getElement().scrollTop = this.getElement().scrollHeight; this.getElement().scrollTop = this.getElement().scrollHeight;

View File

@@ -1,5 +1,5 @@
<form class="ol-strip-board-add-flight"> <form class="ol-strip-board-add-flight">
<div class="ol-auto-suggest"></div> <div class="ol-auto-suggest"></div>
<input type="text" name="unitName" placeholder="Flight search" /> <input type="text" name="unitName" placeholder="Flight search" />
<button class="add-flight-by-click" title="Add unit via click"><img src="/images/icons/bullseye-solid.svg" /></button> <button class="add-flight-by-click" title="Add unit via click"><img src="/resources/theme/images/icons/bullseye-solid.svg" /></button>
</form> </form>

View File

@@ -4,6 +4,7 @@
#include "dcstools.h" #include "dcstools.h"
#include "luatools.h" #include "luatools.h"
#include "measure.h" #include "measure.h"
#include "logger.h"
namespace State namespace State
{ {
@@ -93,7 +94,7 @@ public:
void setFuel(double newFuel) { fuel = newFuel; addMeasure(L"fuel", json::value(newFuel));} void setFuel(double newFuel) { fuel = newFuel; addMeasure(L"fuel", json::value(newFuel));}
void setAmmo(json::value newAmmo) { ammo = newAmmo; addMeasure(L"ammo", json::value(newAmmo));} void setAmmo(json::value newAmmo) { ammo = newAmmo; addMeasure(L"ammo", json::value(newAmmo));}
void setTargets(json::value newTargets) {targets = newTargets; addMeasure(L"targets", json::value(newTargets));} void setTargets(json::value newTargets) {targets = newTargets; addMeasure(L"targets", json::value(newTargets));}
void setHasTask(bool newHasTask) { hasTask = newHasTask; addMeasure(L"hasTask", json::value(newHasTask));} void setHasTask(bool newHasTask) { hasTask = newHasTask; addMeasure(L"hasTask", json::value(newHasTask)); }
void setCoalitionID(int newCoalitionID); void setCoalitionID(int newCoalitionID);
void setFlags(json::value newFlags) { flags = newFlags; addMeasure(L"flags", json::value(newFlags));} void setFlags(json::value newFlags) { flags = newFlags; addMeasure(L"flags", json::value(newFlags));}
double getFuel() { return fuel; } double getFuel() { return fuel; }

View File

@@ -20,9 +20,8 @@ AirUnit::AirUnit(json::value json, int ID) : Unit(json, ID)
void AirUnit::setState(int newState) void AirUnit::setState(int newState)
{ {
if (state != newState) /************ Perform any action required when LEAVING a certain state ************/
{ if (newState != state) {
/************ Perform any action required when LEAVING a certain state ************/
switch (state) { switch (state) {
case State::IDLE: { case State::IDLE: {
break; break;
@@ -47,58 +46,58 @@ void AirUnit::setState(int newState)
default: default:
break; break;
} }
/************ Perform any action required when ENTERING a certain state ************/
switch (newState) {
case State::IDLE: {
clearActivePath();
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Idle"));
break;
}
case State::REACH_DESTINATION: {
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Reach destination"));
break;
}
case State::ATTACK: {
if (isTargetAlive()) {
Unit* target = unitsManager->getUnit(targetID);
Coords targetPosition = Coords(target->getLatitude(), target->getLongitude(), 0);
clearActivePath();
pushActivePathFront(targetPosition);
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Attack"));
}
break;
}
case State::FOLLOW: {
clearActivePath();
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Follow"));
break;
}
case State::LAND: {
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Land"));
break;
}
case State::REFUEL: {
initialFuel = fuel;
clearActivePath();
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Refuel"));
break;
}
default:
break;
}
resetTask();
log(unitName + L" setting state from " + to_wstring(state) + L" to " + to_wstring(newState));
state = newState;
} }
/************ Perform any action required when ENTERING a certain state ************/
switch (newState) {
case State::IDLE: {
clearActivePath();
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Idle"));
break;
}
case State::REACH_DESTINATION: {
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Reach destination"));
break;
}
case State::ATTACK: {
if (isTargetAlive()) {
Unit* target = unitsManager->getUnit(targetID);
Coords targetPosition = Coords(target->getLatitude(), target->getLongitude(), 0);
clearActivePath();
pushActivePathFront(targetPosition);
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Attack"));
}
break;
}
case State::FOLLOW: {
clearActivePath();
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Follow"));
break;
}
case State::LAND: {
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Land"));
break;
}
case State::REFUEL: {
initialFuel = fuel;
clearActivePath();
resetActiveDestination();
addMeasure(L"currentState", json::value(L"Refuel"));
break;
}
default:
break;
}
resetTask();
log(unitName + L" setting state from " + to_wstring(state) + L" to " + to_wstring(newState));
state = newState;
} }
bool AirUnit::isDestinationReached() bool AirUnit::isDestinationReached()
@@ -158,7 +157,7 @@ void AirUnit::goToDestination(wstring enrouteTask)
{ {
Command* command = dynamic_cast<Command*>(new Move(ID, activeDestination, getTargetSpeed(), getTargetAltitude(), enrouteTask)); Command* command = dynamic_cast<Command*>(new Move(ID, activeDestination, getTargetSpeed(), getTargetAltitude(), enrouteTask));
scheduler->appendCommand(command); scheduler->appendCommand(command);
hasTask = true; setHasTask(true);
} }
else else
log(unitName + L" error, no active destination!"); log(unitName + L" error, no active destination!");
@@ -211,17 +210,17 @@ void AirUnit::AIloop()
if (activeDestination == NULL || !hasTask) if (activeDestination == NULL || !hasTask)
{ {
setActiveDestination(); if (!setActiveDestination())
goToDestination(enrouteTask); setState(State::IDLE);
else
goToDestination(enrouteTask);
} }
else { else {
if (isDestinationReached()) { if (isDestinationReached()) {
if (updateActivePath(looping) && setActiveDestination()) if (updateActivePath(looping) && setActiveDestination())
goToDestination(enrouteTask); goToDestination(enrouteTask);
else { else
setState(State::IDLE); setState(State::IDLE);
break;
}
} }
} }
break; break;