Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some trouble to get what I expect with UI #126

Closed
lefouvert opened this issue Feb 12, 2024 · 14 comments
Closed

Some trouble to get what I expect with UI #126

lefouvert opened this issue Feb 12, 2024 · 14 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation probably fixed Probably fixed, but should be confirmed stale Issue has not seen activity for 60 days

Comments

@lefouvert
Copy link

lefouvert commented Feb 12, 2024

version 0.5.2.7 (Ckan)
assumed tag : question

Hi !
I want to do a screen who synthetize some real time datas about my flight, usefull for information or debug.

What I think i have understood about ksp::ui module :

  • If a container is too short for what it contain, it will be stretched at the correct size
  • A vertical container adds items verticaly, panel ones give a nice border to the container
    • First argument of a vertical container seems match with the number of line it contain
    • Second argument of a vertical container (Align) seems match with the position the container will have inside his parent container.
      • if it's a vertical one, Start will be up, Center will be middle height, End will be down. If their is several children with Align.Start arguments, they will be added in the order where they were processed. (It can be a different order than the one you write them : example : records are processed alphabeticaly)
      • Stretch will stretch the width of the vertical container to the width of it's parent container
    • Third argument of a vertical container seems to be the uncompressible size added to the height of a vertical container
  • An horizontal container adds items horizontaly, panel ones give a nice border to the container
    • First argument of a horizontal container seems match with width in pixels
    • Second argument of a horizontal container (Align) seems match with the position the container will have inside his parent container.
      • if it's a horizontal one, Start will be left, Center will be middle width, End will be right. If their is several children with Align.Start arguments, they will be added in the order where they were processed.
      • Stretch will stretch the height of the horizontal container to the height of it's parent container
    • Third argument of a horizontal container seems to be the uncompressible size added to the width of a vertical horizontal
      I'm probably wrong somewhere since I'm not able to get what I expect.

This is what I expect to get (at first):
gitUi1
And how I think it should be built :
gitUi2

Here the work in progress code:
ui::monitor.to2

use { Vessel } from ksp::vessel
use { wait_until, yield } from ksp::game
use { format } from core::str
use { open_window, open_centered_window, screen_size, Align } from ksp::ui

use { ThrustSituation } from ship::constant
use { Ship } from ship::ship
use { compassFromDirection, compassFromOrbit } from ship::navigation

const sName: Cell<string> = Cell("")
const sStages: Cell<int> = Cell(0)
const sCurrentStage: Cell<int> = Cell(0)
const sFts: Cell<string> = Cell("")
const sThrust: Cell<float> = Cell(0)
const sMass: Cell<float> = Cell(0)
const sTwr: Cell<float> = Cell(0)
const sIsp: Cell<float> = Cell(0)
const sBurnTime: Cell<float> = Cell(0)
const sDeltaV: Cell<float> = Cell(0)

const nLongitude: Cell<float> = Cell(0)
const nLatitude: Cell<float> = Cell(0)
const nCompass: Cell<float> = Cell(0)

const oBody: Cell<string> = Cell("")
const oPeriapsis: Cell<float> = Cell(0)
const oApoapsis: Cell<string> = Cell("")
const oInclination: Cell<float> = Cell(0)
const oLongitutdeAscendingNode: Cell<float> = Cell(0)
const oArgumentOfPeriapsis: Cell<float> = Cell(0)
const oCompassFromLongitude: Cell<float> = Cell(0)

/// Entry Point
pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    const ship = Ship(vessel)
    const stages: (activation_number: Cell<int>, has_engine: Cell<bool>, flameout: Cell<bool>, partial_flameout: Cell<bool>, thrust: Cell<float>, twr: Cell<float>, isp: Cell<float>, burntime: Cell<float>, deltaV: Cell<float>, engine_by_activation: Cell<string[]>, engine_by_decouple: Cell<string[]>)[] =
        ship.stages
            .map(fn(s) -> {(
                activation_number: Cell(s.activation_number),
                has_engine: Cell(s.has_engine()),
                flameout: Cell(s.flameout()),
                partial_flameout: Cell(s.partial_flameout()),
                thrust: Cell(s.thrust(ThrustSituation.Current)),
                twr: Cell(s.twr(ThrustSituation.Current)),
                isp: Cell(s.isp(ThrustSituation.Current)),
                burntime: Cell(s.burntime()),
                deltaV: Cell(s.deltaV()),
                engine_by_activation: Cell(s.engines.activation.map(fn(e) -> e.part_name)),
                engine_by_decouple: Cell(s.engines.decouple.map(fn(e) -> e.part_name))
            )})

    const fontSize = 12
    const pRight = 20
    const pLeft = 10
    const blockWidth = 450
    const blockGap = 10

    const dialog = open_centered_window("Monitor", 0, 0)
        const blockRoot = dialog.add_horizontal(blockGap + 2 * blockWidth, Align.Start, 0.0)
            const blockHardwareHConstraint = blockRoot.add_horizontal(blockWidth, Align.Start, 0.0)
                // const blockHardware = blockHardwareHConstraint.add_vertical(0, Align.Stretch, 0.0)
                const blockHardware = blockHardwareHConstraint.add_vertical(0, Align.Start, 0.0)
                    // const shipField = blockHardware.add_vertical_panel(0, Align.Stretch, 0.0)
                    const shipField = blockHardware.add_vertical_panel(0, Align.Start, 0.0)
                        const shipTitle = shipField.add_label("Ship", Align.Center)
                            shipTitle.font_size = fontSize
                        const shipName = shipField
                            .add_label("", Align.Start)
                            .bind(sName, "name".pad_right(pRight) + " : {0:" + pLeft.to_string() + "}")
                            shipName.font_size = fontSize
                        const shipStages = shipField
                            .add_label("", Align.Start)
                            .bind(sStages, "stages number".pad_right(pRight) + " : {0:###,##0}")
                            shipStages.font_size = fontSize
                        const shipCurrentStage = shipField
                            .add_label("", Align.Start)
                            .bind(sCurrentStage, "current stage".pad_right(pRight) + " : {0:###,##0}")
                            shipCurrentStage.font_size = fontSize
                        const shipFts = shipField
                            .add_label("", Align.Start)
                            .bind(sFts, "first thrust stage".pad_right(pRight) + " : {0:" + pLeft.to_string() + "}")
                            shipFts.font_size = fontSize
                        const shipThrust = shipField
                            .add_label("", Align.Start)
                            .bind(sThrust, "thrust".pad_right(pRight) + " : {0:###,##0.0#} N")
                            shipThrust.font_size = fontSize
                        const shipMass = shipField
                            .add_label("", Align.Start)
                            .bind(sMass, "mass".pad_right(pRight) + " : {0:###,##0.0#} t")
                            shipMass.font_size = fontSize
                        const shipTwr = shipField
                            .add_label("", Align.Start)
                            .bind(sTwr, "twr".pad_right(pRight) + " : {0:###,##0.0#}")
                            shipTwr.font_size = fontSize
                        const shipIsp = shipField
                            .add_label("", Align.Start)
                            .bind(sIsp, "isp".pad_right(pRight) + " : {0:###,##0.0#} s")
                            shipIsp.font_size = fontSize
                        const shipBurntime = shipField
                            .add_label("", Align.Start)
                            .bind(sBurnTime, "burntime".pad_right(pRight) + " : {0:###,##0.0#} s")
                            shipBurntime.font_size = fontSize
                        const shipDeltaV = shipField
                            .add_label("", Align.Start)
                            .bind(sDeltaV, "vacuum deltaV".pad_right(pRight) + " : {0:###,##0.0#} m/s")
                            shipDeltaV.font_size = fontSize
                    // const stageField = blockHardware.add_vertical_panel(0, Align.Stretch, 0.0)
                    const stageField = blockHardware.add_vertical_panel(0, Align.Start, 0.0)
                        const stageTitle = stageField.add_label("Stage", Align.Center)
                            stageTitle.font_size = fontSize
                        // _0_ in order to sort labels as intended
                        const stagesDatas = stages .map(fn(s) -> {(
                            _0_activation_number: stageField
                                .add_label("", Align.Start)
                                .bind(s.activation_number, "============ STAGE {0:###,##0} ============"),
                            _1_has_engine: stageField
                                .add_label("", Align.Start)
                                .bind(s.has_engine, "has engine".pad_right(pRight) + " : {0:G" + pLeft.to_string() + "}"),
                            _2_flameout: stageField
                                .add_label("", Align.Start)
                                .bind(s.flameout, "flameout".pad_right(pRight) + " : {0:G" + pLeft.to_string() + "}"),
                            _3_partial_flameout: stageField
                                .add_label("", Align.Start)
                                .bind(s.partial_flameout, "partial flameout".pad_right(pRight) + " : {0:G" + pLeft.to_string() + "}"),
                            _4_thrust: stageField
                                .add_label("", Align.Start)
                                .bind(s.thrust, "thrust".pad_right(pRight) + " : {0:###,##0.0#} N"),
                            _5_twr: stageField
                                .add_label("", Align.Start)
                                .bind(s.twr, "twr".pad_right(pRight) + " : {0:###,##0.0#}"),
                            _6_isp: stageField
                                .add_label("", Align.Start)
                                .bind(s.isp, "isp".pad_right(pRight) + " : {0:###,##0.0#} s"),
                            _7_burntime: stageField
                                .add_label("", Align.Start)
                                .bind(s.burntime, "burntime".pad_right(pRight) + " : {0:###,##0.0#} s"),
                            _8_deltaV: stageField
                                .add_label("", Align.Start)
                                .bind(s.deltaV, "vacuum deltaV".pad_right(pRight) + " : {0:###,##0.0#} m/s")
                        )})
                        for (sd in stagesDatas) {
                            sd._0_activation_number.font_size = fontSize
                            sd._1_has_engine.font_size = fontSize
                            sd._2_flameout.font_size = fontSize
                            sd._3_partial_flameout.font_size = fontSize
                            sd._4_thrust.font_size = fontSize
                            sd._5_twr.font_size = fontSize
                            sd._6_isp.font_size = fontSize
                            sd._7_burntime.font_size = fontSize
                            sd._8_deltaV.font_size = fontSize
                        }
            blockRoot.add_horizontal(0, Align.Start, blockGap) //gap
            const blockGeolocHConstraint = blockRoot.add_horizontal(blockWidth, Align.Start, 0.0)
                // const blockGeoloc = blockGeolocHConstraint.add_vertical(0, Align.Stretch, 0.0)
                const blockGeoloc = blockGeolocHConstraint.add_vertical(0, Align.Start, 0.0)
                    // const navigationField = blockGeoloc.add_vertical_panel(0, Align.Stretch, 0.0)
                    const navigationField = blockGeoloc.add_vertical_panel(0, Align.Start, 0.0)
                        const navigationTitle = navigationField.add_label("Navigation", Align.Center)
                            navigationTitle.font_size = fontSize
                        const navigationLongitude = navigationField
                            .add_label("", Align.Start)
                            .bind(nLongitude, "longitude".pad_right(pRight) + " : {0:###,##0.0#} °")
                            navigationLongitude.font_size = fontSize
                        const navigationLatitude = navigationField
                            .add_label("", Align.Start)
                            .bind(nLatitude, "latitude".pad_right(pRight) + " : {0:###,##0.0#} °")
                            navigationLatitude.font_size = fontSize
                        const navigationCompass = navigationField
                            .add_label("", Align.Start)
                            .bind(nCompass, "compass".pad_right(pRight) + " : {0:###,##0.0#} °")
                            navigationCompass.font_size = fontSize
                    // const orbitalField = blockGeoloc.add_vertical_panel(0, Align.Stretch, 0.0)
                    const orbitalField = blockGeoloc.add_vertical_panel(0, Align.Start, 0.0)
                        const orbitalTitle = orbitalField.add_label("Orbital", Align.Center)
                            orbitalTitle.font_size = fontSize
                        const orbitalBody = orbitalField
                            .add_label("", Align.Start)
                            .bind(oBody, "body".pad_right(pRight) + " : {0:" + pLeft.to_string() + "}")
                            orbitalBody.font_size = fontSize
                        const orbitalPeriapsis = orbitalField
                            .add_label("", Align.Start)
                            .bind(oPeriapsis, "periapsis".pad_right(pRight) + " : {0:###,##0.0#} m")
                            orbitalPeriapsis.font_size = fontSize
                        const orbitalApoapsis = orbitalField
                            .add_label("", Align.Start)
                            .bind(oApoapsis, "apoapsis".pad_right(pRight) + " : {0:" + pLeft.to_string() + "}")
                            orbitalApoapsis.font_size = fontSize
                        const orbitalInclination = orbitalField
                            .add_label("", Align.Start)
                            .bind(oInclination, "inclination".pad_right(pRight) + " : {0:###,##0.0#} °")
                            orbitalInclination.font_size = fontSize
                        const orbitalLAN = orbitalField
                            .add_label("", Align.Start)
                            .bind(oLongitutdeAscendingNode, "longitude ascendnode".pad_right(pRight) + " : {0:###,##0.0#} °")
                            orbitalLAN.font_size = fontSize
                        const orbitalArgumentPeriapsis = orbitalField
                            .add_label("", Align.Start)
                            .bind(oArgumentOfPeriapsis, "argument periapsis".pad_right(pRight) + " : {0:###,##0.0#} °")
                            orbitalArgumentPeriapsis.font_size = fontSize
                        const orbitalCompass = orbitalField
                            .add_label("", Align.Start)
                            .bind(oCompassFromLongitude, "compass at longitude".pad_right(pRight) + " : {0:###,##0.0#} °")
                            orbitalCompass.font_size = fontSize

    // update
    while(!dialog.is_closed) {
        sName.value = ship.ship.name
        sStages.value = ship.stages.length
        sCurrentStage.value = ship.current_stage
        sFts.value = if(ship.firstThrustStage().defined) ship.firstThrustStage().value.to_string() else "None"
        sThrust.value = ship.thrust(ThrustSituation.Current)
        sMass.value = ship.mass()
        sTwr.value = ship.twr(ThrustSituation.Current)
        sIsp.value = ship.isp(ThrustSituation.Current)
        sBurnTime.value = ship.burntime()
        sDeltaV.value = ship.deltaV()

        nLongitude.value = ship.ship.geo_coordinates.longitude
        nLatitude.value = ship.ship.geo_coordinates.latitude
        nCompass.value = compassFromDirection(ship.ship, ship.ship.facing)

        oBody.value = ship.ship.orbit.reference_body.name
        oPeriapsis.value = ship.ship.orbit.periapsis
        oApoapsis.value = if(ship.ship.orbit.apoapsis.defined) (ship.ship.orbit.apoapsis.value.to_fixed(2) + " m") else "None"
        oInclination.value = ship.ship.orbit.inclination
        oLongitutdeAscendingNode.value = ship.ship.orbit.LAN
        oArgumentOfPeriapsis.value = ship.ship.orbit.argument_of_periapsis
        oCompassFromLongitude.value = compassFromOrbit(ship.ship, ship.ship.orbit)

        for(s in stages) {
            if(s.activation_number.value < ship.stages.length){
                s.activation_number.value = ship.stages[s.activation_number.value].activation_number
                s.has_engine.value = ship.stages[s.activation_number.value].has_engine()
                s.flameout.value = ship.stages[s.activation_number.value].flameout()
                s.partial_flameout.value = ship.stages[s.activation_number.value].partial_flameout()
                s.thrust.value = ship.stages[s.activation_number.value].thrust(ThrustSituation.Current)
                s.twr.value = ship.stages[s.activation_number.value].twr(ThrustSituation.Current)
                s.isp.value = ship.stages[s.activation_number.value].isp(ThrustSituation.Current)
                s.burntime.value = ship.stages[s.activation_number.value].burntime()
                s.deltaV.value = ship.stages[s.activation_number.value].deltaV()
            } else if(stagesDatas[s.activation_number.value]._0_activation_number.text != "") {
                stagesDatas[s.activation_number.value]._0_activation_number.text = ""
                stagesDatas[s.activation_number.value]._1_has_engine.text = ""
                stagesDatas[s.activation_number.value]._2_flameout.text = ""
                stagesDatas[s.activation_number.value]._3_partial_flameout.text = ""
                stagesDatas[s.activation_number.value]._4_thrust.text = ""
                stagesDatas[s.activation_number.value]._5_twr.text = ""
                stagesDatas[s.activation_number.value]._6_isp.text = ""
                stagesDatas[s.activation_number.value]._7_burntime.text = ""
                stagesDatas[s.activation_number.value]._8_deltaV.text = ""
            }
        }
        yield()
    }
}

I don't think it's revelant to give details about how ship and stages are built to understand how Monitor should work. For the most, it's custom methods to thrust, isp, twr, deltaV etc which are able to give me reliable data even when I should't get thoses, and some shorteners for usefull datas : (deltaV for separatrons, expected thrust even when the engine is off, thoses kind of things)

And now, with this nice bunch of code, this is what I get :
gitUi0

An oversized window, panels shifted and streched in ways I'm not able to understand, even outer the window, labels greater than their parent panels, in short, a mess.
So I have undoubtly done something wrong, but here the trick : I don't have a clue what about.

At least, datas are corrects ! :)
Edit : still not fluent in english

@untoldwind
Copy link
Owner

First thing I noticed is that the big section of empty space is coming from this:

const blockRoot = dialog.add_horizontal(blockGap + 2 * blockWidth, Align.Start, 0.0)

The first parameter of add_horizontal is the gap between each child not the overall width (I will improve the documention for this)
So

const blockRoot = dialog.add_horizontal(blockGap, Align.Start, 0.0)

Has a much better result.

But I am still trying to figure out where the empty space in the "stage" section it coming from, this looks more like a bug.

@untoldwind
Copy link
Owner

With

const blockRoot = dialog.add_horizontal(blockGap, Align.Start, 0.0)

it should now look like this in 0.5.2.8

image
(which is probably much closer to what you where aiming for)

Additionally I added an add_spacer helper to add arbitrary gaps between elements. So instead of

blockRoot.add_horizontal(0, Align.Start, blockGap)

you can use

blockRoot.add_spacer(blockGap)

@untoldwind untoldwind added the probably fixed Probably fixed, but should be confirmed label Feb 16, 2024
@untoldwind
Copy link
Owner

untoldwind commented Feb 16, 2024

Additional note:
The empty space at the bottom can be avoided by using a standard for loop in the "stages" section like this:

const stageField = blockHardware.add_vertical_panel(0, Align.Start, 0.0)
                        const stageTitle = stageField.add_label("Stage", Align.Center)
                            stageTitle.font_size = fontSize
                        // _0_ in order to sort labels as intended
                        for ( s in stages) {
                            const _0_activation_number= stageField
                                .add_label("", Align.Start)
                                .bind(s.activation_number, "============ STAGE {0:###,##0} ============")
                            _0_activation_number.font_size = fontSize
                            const _1_has_engine= stageField
                                .add_label("", Align.Start)
                                .bind(s.has_engine, "has engine".pad_right(pRight) + " : {0:G" + pLeft.to_string() + "}")
                            _1_has_engine.font_size = fontSize
                            const _2_flameout= stageField
                                .add_label("", Align.Start)
                                .bind(s.flameout, "flameout".pad_right(pRight) + " : {0:G" + pLeft.to_string() + "}")
                            _2_flameout.font_size = fontSize
                            const _3_partial_flameout= stageField
                                .add_label("", Align.Start)
                                .bind(s.partial_flameout, "partial flameout".pad_right(pRight) + " : {0:G" + pLeft.to_string() + "}")
                            _3_partial_flameout.font_size = fontSize
                            const _4_thrust= stageField
                                .add_label("", Align.Start)
                                .bind(s.thrust, "thrust".pad_right(pRight) + " : {0:###,##0.0#} N")
                            _4_thrust.font_size = fontSize
                            const _5_twr= stageField
                                .add_label("", Align.Start)
                                .bind(s.twr, "twr".pad_right(pRight) + " : {0:###,##0.0#}")
                            _5_twr.font_size = fontSize
                            const _6_isp= stageField
                                .add_label("", Align.Start)
                                .bind(s.isp, "isp".pad_right(pRight) + " : {0:###,##0.0#} s")
                            _6_isp.font_size = fontSize
                            const _7_burntime= stageField
                                .add_label("", Align.Start)
                                .bind(s.burntime, "burntime".pad_right(pRight) + " : {0:###,##0.0#} s")
                            _7_burntime.font_size = fontSize
                            const _8_deltaV= stageField
                                .add_label("", Align.Start)
                                .bind(s.deltaV, "vacuum deltaV".pad_right(pRight) + " : {0:###,##0.0#} m/s")
                            _8_deltaV.font_size = fontSize
                        }

The problem seems to be that the initial layout still calculates with the larger font size if it is tweaked later.

I am not entirely sure how to fix this behavior yet

@lefouvert
Copy link
Author

lefouvert commented Feb 16, 2024

Lil bit of rework on my side, and this is what I get :
gitUi3

I'm happy !


The first parameter of add_horizontal is the gap between each child not the overall width (I will improve the documention for this)

Hitten by the truck of realisation. With better understanding, it's obvious.


Additionally I added an add_spacer helper to add arbitrary gaps between elements.

Nice ! Thank you !


The empty space at the bottom can be avoided by using a standard for loop in the "stages" section like this:

I see. Now, It's my turn to find a trickery to gather the initial stages' record array AND initialize fontsize.
I need this array because

  • ship stages' array is updated at each stage drop and is smaller and smaller with flight time
  • put "" text in label make them disapear, which is convenient for on the fly resize

The update loop use this two fact to shorten the stage section when it's needed.


Note :
Texts still overflow container, but I assume it's same kind of initialization problem because of custom formating.
(Take a look at the image. I assume it's mitigated in Ship and Stage with the instruction whitch are using

                    const shipName = shipField
                        .add_label("", Align.Start)
                        .bind(sName, "name".pad_right(pRight) + " : {0:" + pLeft.to_string() + "}")

where the size could be actualy initialized right with already known number of characters, but as Navigation and Orbital don't use any pLeft, they occurs to have oversized labels)


Additional question :
Does the window are a vertical or an horizontal container ? (or a his very own kind of container ?)
(From experience, seems to be a vertical container)


Many thanks, I'll keep you in touch ^^

Edit : formating

@lefouvert
Copy link
Author

lefouvert commented Feb 18, 2024

Just a question, which may lead to an idea.
I observe than the outgoings labels can be corrected by updating the content of the window. So I put at first a label with some text, let my first data update completly go, then emptied the text of this first label. This lead the window to update it's size to be able to fit to it's own content. But this trick work only for upscaling, not downscaling.

Frame 1 (game in pause to catch it)
gitUi4

After first update and label trick, window have upscale (without label trick, it don't)
gitUi5

After decouple a stage, container update as intended (with label trick on the labels of the stage 3), but not the window :
gitUi6

How did you manage to automaticly upscale the window after initialization when it's to small for it's containers ?
Is it bad if the same is done to downscale ? (Or maybe autorescale is a bad idea, and the hability to rescale should be given ? )

Edit : typo, as often...

@untoldwind
Copy link
Owner

Yes, the window starts out with a vertical container/layout (I figured this to be the most common use-case), but I guess it should be possible to make this configurable in the open_window functions.

The issue with the empty vertical space boils down to a race-condition. The window actually opens the moment open_window is called and then all the components are added.
The reasoning was that there should be no restriction when to add components.
Problem with that is that it is impossible to predict when a layout is happening (depending on the games update loop).

I'll add some helper functions to resize/compact/recenter a window via script, which should resolve the issue.

@untoldwind
Copy link
Owner

untoldwind commented Feb 18, 2024

Since I did some pretty heavy (long overdue) refactoring as well, I created a pre-release for this:
https://github.com/untoldwind/KontrolSystem2/releases/tag/v0.5.3.0

In you example, adding a :

    dialog.compact()
    dialog.center()

(see: https://kontrolsystem2.readthedocs.io/en/prerelease/reference/ksp/ui.html#center)

after all components have been added should now do the trick.

Additionally I added support for removal of components from the window. So something like this should now work as well:

    const remove_button = blockGeoloc.add_button("Remove")
    remove_button.on_click(fn() -> {
        stageField.remove()
        dialog.compact()
        dialog.center()
    })

@lefouvert
Copy link
Author

You bring Chrismas everyday :)

@lefouvert
Copy link
Author

lefouvert commented Feb 21, 2024

Look at what you have done !
Instead of a comfy unreadable warmfull mess which look like my desk, it's all clear and well aligned ! Scandalous !
image

The only drawback currently is I don't understand why sometimes label's button is inverted with datas. (As pictured : button suggest to switch to datas corresponding 'to full-ignited full-throttle at this pressure' condition when it obviously already show them. It should show 'Switch to Current', corresponding to real time datas, as 0.0N of thrust as intended for offline engines. But Eh... When I click it, data switch, good enought at the time. I'll investigate later, and if I get a deadend, I'll bother you with thoses stuff.

Edit: typo

@untoldwind
Copy link
Owner

I did a very simple test, which worked fine:

use { Vessel } from ksp::vessel
use { CONSOLE } from ksp::console
use { open_window, open_centered_window, screen_size, Align } from ksp::ui
use { wait_until, yield } from ksp::game

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    CONSOLE.clear()

    const dialog = open_centered_window("Monitor", 0, 0)

    const state = Cell(false)
    const remove_button = dialog.add_button("Toggle Off")

    remove_button.on_click(fn() -> {
        if(state.value) {
            remove_button.label = "Toggle Off"
            state.set_value(false)
        } else {
            remove_button.label = "Toggle On"
            state.set_value(true)
        }
    })

    wait_until(fn() -> dialog.is_closed)
}

@lefouvert
Copy link
Author

Hum... I wrote something very close. Or if I didn't, it's a misprint. The only major difference I'm able to notice, is I used the .update() Cell's method because ignorance of the .set_value() Cell's method. I'll take a look.

@untoldwind
Copy link
Owner

Good point, I tried out with a more functional approach:

use { Vessel } from ksp::vessel
use { CONSOLE } from ksp::console
use { open_window, open_centered_window, screen_size, Align } from ksp::ui
use { wait_until, yield } from ksp::game

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    CONSOLE.clear()

    const dialog = open_centered_window("Monitor", 0, 0)

    const state = Cell(false)
    const remove_button = dialog.add_button("Toggle Off")

    remove_button.on_click(fn() -> {
        state.update(fn(current) -> {
            remove_button.label = if(current) "Toggle Off" else "Toggle On"
            !current
        })
    })

    wait_until(fn() -> dialog.is_closed)
}

... which seems to work just the same

Copy link

This issue is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the stale Issue has not seen activity for 60 days label Apr 25, 2024
Copy link

github-actions bot commented May 9, 2024

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation probably fixed Probably fixed, but should be confirmed stale Issue has not seen activity for 60 days
Projects
None yet
Development

No branches or pull requests

2 participants