X Tutup
Skip to content

Add Buy and Sell prices to the Commodity Market#5945

Merged
sturnclaw merged 5 commits intopioneerspacesim:masterfrom
mwerle:feat/commodity_price_display
Nov 12, 2024
Merged

Add Buy and Sell prices to the Commodity Market#5945
sturnclaw merged 5 commits intopioneerspacesim:masterfrom
mwerle:feat/commodity_price_display

Conversation

@mwerle
Copy link
Contributor

@mwerle mwerle commented Nov 1, 2024

Fixes #5903

Replace the "Price" column with a "Buy Price" and "Sell Price" column. This reflects what the user of the commodity market actually needs to know, instead of delegating this information until after the user has started buying or selling a particular commodity.

Also right-aligns all numbers in the table, and middle-aligns the column headings for a much more readable table.

Before:

image

After:

image

@impaktor
Copy link
Member

impaktor commented Nov 1, 2024

From what I can see, I'm fine with not squashing the commits.

As for alignment, ideally they should be aligned on the decimal point, and if they always print with two decimal values, this new alignment achieves the same, so it's better as far as I can tell

While you're here/"there" [in the code], I'd like to open for yet another feature creep: I'm not a fan of player not being able to sell beyond demand. Could it be possible to have the "demand" be just at that price, once it's reached 0, price is adjusted accordingly (and perhaps demand is > 0 again at this new price)? Or just reduce price by half or 20 % or similar if demand has reached constant 0?

Granted I haven't play tested the current market on master, but seems harsh for a trader to arrive and not be able to sell their inventory, but rather to have to jettison it (or fly to another station?).

@mwerle
Copy link
Contributor Author

mwerle commented Nov 1, 2024

I think adjusting price after demand has been met is out-of-scope for this PR and liable to generate some discussion. So I'd prefer to leave that for another PR. I can create a new issue in order to track it. But is it realistic that a market would buy a commodity, even discounted, that they don't want? The risk is on the trader.


Aligning on decimal point would require a fair bit more work. In this case, the only decimal values are "Money", which always have 2 decimal places, so it's a moot point.


Looking at the new display, I'm now thinking instead of "Buy Price" and "Sell Price" to simply head the columns as "Buy" and "Sell". It should be implicitly obvious it's the price given the monetary values. Thoughts?

@bszlrd
Copy link
Contributor

bszlrd commented Nov 1, 2024

Ommiting the Price from the header sounds good. Less clutter. Maybe even "In stock" could be just "Stock" and also "Cargo" could be changed to either "Hold" on In hold".

@mwerle
Copy link
Contributor Author

mwerle commented Nov 1, 2024

image

@sturnclaw
Copy link
Member

This generally looks good. The screen needs to be fully rewritten to use the new ImGui Tables feature, as well as move away from the hardcoded magic-constants design, but for an interim change this works well enough.

A few thoughts:

  • The commodity name field is a bit excessively wide. Is this to accommodate e.g. the German translation?
  • Since the dividing line between the two fields is no longer in the center, it should be at either 62% (golden ratio) or at 2/3rds across the screen.
  • For examples regarding how "modern" UI screens should be structured, look at saveloadwindow.lua or the equipment outfitter UI on the equip-v2 branch. Those are the most up-to-date complete rewrites of a UI screen, and demonstrate the programming patterns I would like to see adopted across the entire UI.

@mwerle
Copy link
Contributor Author

mwerle commented Nov 1, 2024

I can take a look at rewriting it, thanks for the examples of how it should be written, but no idea when I'll get around to a larger-scale rework. I thought I was picking some low-hanging fruit ;)

Changing the ratio to 62%, let alone 2/3, reduces the right-side size even further, which causes the button-bar to look very squashed. Given this will be rewritten "properly" "soon" anyway, can we leave this PR as-is for now?

@sturnclaw
Copy link
Member

I can take a look at rewriting it [...] I thought I was picking some low-hanging fruit ;)

For clarity, I was mentioning it in the abstract rather than suggesting you should do it yourself - feel free to do so if you're interested though!

Displaying buy/sell price separately is definitely a low-hanging fruit and I'm glad you've tackled it.

Given this will be rewritten "properly" "soon" anyway

You're speaking my language now! 😄

can we leave this PR as-is for now?

That's fine. I don't know when exactly we'll want to fully redesign the screen, but likely not before the next release.

Feature request pioneerspacesim#5903 raised by lolo101.

The advertised price in the Commodity Market represents the
"mid-market rate", not the actual buy or sell prices. This information
is not very useful to a trader, who has to click on a commodity and then
buy or sell 1 unit to see the actual price.

This change replaces the "mid-market" rate display with the actual buy
and sell prices.
The additional colum in the Commodity Market screen caused the final
column to be clipped, at least on a traditional 4:3 display.

The left-side of the screen was increased to take up 60% of the display,
with various other elements adjusted as required in order to still
display nicely.
Left-aligned numbers are very difficult to read. Unfortunately there is
no native support for text alignment in PiGui so each cell is manually
adjusted to right-align the number text.
A natural improvemnt of the previous commit was to move the alignment
calculation code into a helper function, which can also middle-align
text. This new feature was then used to middle-align the table column
headings.

This function should probably be added to a utility library where it can
be used by other table-based UIs.
Clean up and declutter the column headings to have shorter or clearer
names to improve the readability of this screenn.

This also necessitated making the commodity name column slightly smaller
in order to accommodate the slightly larger column title for the final
column to prevent it from being clipped.
@mwerle mwerle force-pushed the feat/commodity_price_display branch from dcc0f6f to 2179a93 Compare November 2, 2024 03:01
@mwerle
Copy link
Contributor Author

mwerle commented Nov 4, 2024

~~TODO: the BBS (black) markets need a similar update.. this will be a bit more challenging as they open in a smaller popup window.

Ideally the code also should be refactored so all commodity market displays use the same code.. ie, make a "commodity market" card whose input is the list of commodities and their prices to display, which can then render itself within any parent window.~~

NVM - it appears the BBS markets already use the main market code (I was playing with a branch which did not have these changes when I noticed it) - but it does require some tweaking, at least on 4:3 displays.

@mwerle
Copy link
Contributor Author

mwerle commented Nov 10, 2024

Ok I thought I had introduced the issue on the BBS markets that resizes the window to full-height as soon as a commodity item is selected and the buy/sell part of the interface is populated, but the issue already exists in the current code.

I have tried to fix this but cannot find the reason why the window expands as soon as a commodity item is clicked on. This may need deferring to a future PR when the entire screen is re-written using the new UI paradigm.


Before clicking on Commodity - window takes up partial screen:
image

After clicking on Commodity - window is expanded to take up entire vertical space and "Hang Up" button is not visible (must be scrolled):
image

@sturnclaw
Copy link
Member

I think the commodity market resizing out of control in a BBS ad is a known issue - I recall trying to fix it once before, but that either never made it to a PR or I never got as far as an actual fix.

Go ahead and defer it to another PR - I'll review this code as-is soon.

@sturnclaw sturnclaw self-requested a review November 12, 2024 05:55
Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this - looks good to me!

@sturnclaw sturnclaw merged commit f39d33f into pioneerspacesim:master Nov 12, 2024
@mwerle mwerle deleted the feat/commodity_price_display branch June 20, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selling prices are not displayed until you actually try to sell a commodity

4 participants

X Tutup