Equipment “Sell Item” Color
Moderators: winston, another_commander
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Equipment “Sell Item” Color
A small OXP for v1.85/86, which changes the color all the “Sell” or "Remove"-type equipment items on the F3 Ship Outfitting screen to red to make it clear that the particular item will remove something, rather than add something.
Available in the download manager. Wiki
Available in the download manager. Wiki
Last edited by phkb on Sun Jun 06, 2021 7:54 am, edited 1 time in total.
- Cholmondely
- Archivist
- Posts: 5352
- Joined: Tue Jul 07, 2020 11:00 am
- Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
- Contact:
Re: Equipment 'Sell Item' Color
1) as a player, I load up on lots of equipment.oxp's (...not the ships or the weapons). I enjoy the variety and the different uses. I do find this little oxp invaluable for making sense of the F3 ship outfitting pages. Thank you!
2) Can I just ask, if I may, what is involved in changing the name of a published OXP? ie: Equipment Remove Item -> Equipment 'Sell Item'?
In short, how would you recommend others go about it, and what must they not forget to do?
Comments wanted:
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
•Missing OXPs? What do you think is missing?
•Lore: The economics of ship building How many built for Aronar?
•Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: Equipment Remove Item Color
I changed the “title” element of the manifest. But I left the “identifier” the same, so that it will continue to be identified as the same OXP and thus will upgrade successfully.Cholmondely wrote: ↑Sun Jun 06, 2021 6:22 amwhat is involved in changing the name of a published OXP? ie: Equipment Remove Item -> Equipment 'Sell Item'?
Re: Equipment “Sell Item” Color
Could it be possible also show too expensive items (cost more, than I actually have) in gray color?
Example:
Normal start at Lave (100 Cr) the Missile (30) will be yellow (buying possible), Large Cargo Bay (400) and E.C.M. System (600) will be gray (too expensive).
With 1000Cr all three will be yellow, but buing any two will make instantly the third gray, as I will have not money for it.
Selling something will make money, so something will became yellow again.
---
I looked in the code, but the colors are set at start (as descriptions does not change in course of the game).
I do not know, where hook code to recalculate at each entering the F3 screen
Example:
Normal start at Lave (100 Cr) the Missile (30) will be yellow (buying possible), Large Cargo Bay (400) and E.C.M. System (600) will be gray (too expensive).
With 1000Cr all three will be yellow, but buing any two will make instantly the third gray, as I will have not money for it.
Selling something will make money, so something will became yellow again.
---
I looked in the code, but the colors are set at start (as descriptions does not change in course of the game).
I do not know, where hook code to recalculate at each entering the F3 screen
Lady of Fate, we adore you . . .
- Wildeblood
- ---- E L I T E ----
- Posts: 2450
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Equipment “Sell Item” Color
It looks like that should be possible, and I think it's a good idea.
These three paragraphs should be "all you need to know" (enough to get you started) about Oolite-specific javaScript:-
World script event handlers, guiScreenChanged
EquipmentInfo, calculatedPrice
EquipmentInfo, displayColor
https://wiki.alioth.net/index.php/Oolit ... eenChanged
https://wiki.alioth.net/index.php/Oolit ... latedPrice
https://wiki.alioth.net/index.php/Oolit ... splayColor
P.S. I remember now. I was doing this (below) two months ago, and I knew how to check through the player ship's equipment array, but I didn't know where to find the station's equipment for sale array. I found it with a pointer from Cholly, but I didn't write it down.
viewtopic.php?p=297412#p297412
In your heart, you know it's flat.
Re: Equipment “Sell Item” Color
Here is first version for testing http://cobra-mk3.gilhad.cz/Games/oolite ... mColor.oxz
There is still one problem, as I used the event guiScreenChanged for F3, the page is already drawn, when my code start working, so color change is not visible, until the page is refreshed.
Refresh:
Test it: New commander -> Normal start (Lave 100 Cr) -> F3 (all yellow for now) -> F5 F3 (fixed - all above 100Cr is gray) -> remove laser (all above 500Cr is gray all below and same is yellow) -> buy laser again ... All remove and such are red, if you have EquipmentRemoveItemColor active
I tested it on Linux with oolite-1.90-test.linux-x86_64 from https://oolite.space/
Printscreen: ---
Now what next?
There is still one problem, as I used the event guiScreenChanged for F3, the page is already drawn, when my code start working, so color change is not visible, until the page is refreshed.
Refresh:
- press F3 F3 (to shipyard and back), or F5 F3 or any other screen change
- press <right arrow><left arrow> (or click More and Back), colors are already set, but now are redrawn
- buy or sell anything, again all is recomputed, then redrawn
Test it: New commander -> Normal start (Lave 100 Cr) -> F3 (all yellow for now) -> F5 F3 (fixed - all above 100Cr is gray) -> remove laser (all above 500Cr is gray all below and same is yellow) -> buy laser again ... All remove and such are red, if you have EquipmentRemoveItemColor active
I tested it on Linux with oolite-1.90-test.linux-x86_64 from https://oolite.space/
Printscreen: ---
Now what next?
- Is there way to redraw the screen after recalculating the colors?
- It is my first OXP ready for release, should I somehow announce it, upload it somewhere and so on? How, where?
- I do not know Javascript, but I used lot of other langs, so I simply used copy+paste and then improvised without exact knowledge, what I do. It works (somehow) but may the code could be better - can anyone comment on it?
- Basically this is meant as addition to oolite.oxp.phkb.EquipmentRemoveItemColor.oxz - it could work together or independently - if phkb want, he is explicitely allowed and encouraged to simply copy it to his OXP without any restrictions or copyrights
Lady of Fate, we adore you . . .
- Wildeblood
- ---- E L I T E ----
- Posts: 2450
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Equipment “Sell Item” Color
That link does not work.gilhad wrote: ↑Tue Oct 29, 2024 7:46 pmHere is first version for testing http://cobra-mk3.gilhad.cz/Games/oolite ... mColor.oxz
Other possible event listeners to try are guiScreenWillChange - fires before the page is drawn -
In your heart, you know it's flat.
Re: Equipment “Sell Item” Color
Thanks again, I totally missed the guiScreenWillChange which is the right place where it should be. I already used the playerBoughtEquipment, as it does not invoke screen change, so it needs to be managed too.
I tested it with guiScreenWillChange and it works like supposed, so there is new version 1.1
The link works for me, but the problem is, that the target is HTTPonly, not HTTPS and some browsers may complain about it, or even totally ignore it (and do not say anything). Maybe it would accept http page with download? http://cobra-mk3.gilhad.cz/Games/oolite ... Color.html
I looked for some sharing service and here is the new version https://filetransfer.io/data-package/uxlfTUBC#link
----
Edit:
Another problem found: after graying items for F3 page, the Status Screen F5 used the new color (so expensive owned items was also in gray).
Fixed in v.1.2 here
https://filetransfer.io/data-package/6yXMEbwW#link
Info (and download) here on my http pages http://cobra-mk3.gilhad.cz/Games/oolite ... Color.html
I tested it with guiScreenWillChange and it works like supposed, so there is new version 1.1
The link works for me, but the problem is, that the target is HTTPonly, not HTTPS and some browsers may complain about it, or even totally ignore it (and do not say anything). Maybe it would accept http page with download? http://cobra-mk3.gilhad.cz/Games/oolite ... Color.html
I looked for some sharing service and here is the new version https://filetransfer.io/data-package/uxlfTUBC#link
----
Edit:
Another problem found: after graying items for F3 page, the Status Screen F5 used the new color (so expensive owned items was also in gray).
Fixed in v.1.2 here
https://filetransfer.io/data-package/6yXMEbwW#link
Info (and download) here on my http pages http://cobra-mk3.gilhad.cz/Games/oolite ... Color.html
Lady of Fate, we adore you . . .
- Wildeblood
- ---- E L I T E ----
- Posts: 2450
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Equipment “Sell Item” Color
Adding an else in here will supposedly save a millisecond or two.
For an OXZ this small (under 120 kB), you can upload it as an attachment right here, BTW.
Code: Select all
this.guiScreenWillChange = function(to,from) {
// log(this.name,"guiScreenWillChange: "+from+" --> "+to+" ;");
if (to == "GUI_SCREEN_EQUIP_SHIP" ) {
this.$updateColors();
} else if (( to == "GUI_SCREEN_STATUS") && this.$fixF5 ) {
this.$revertColors();
};
}
Re: Equipment “Sell Item” Color
That is true.
I fixed it in the code, but will include it to next version together with some cleaning of comments and other fixes.
So here it go:
cat oolite.oxp.Gilhad.G_EquipmentExpensiveItemColor.oxp/Config/script.js
cat oolite.oxp.Gilhad.G_EquipmentExpensiveItemColor.oxp/manifest.plist
cat oolite.oxp.Gilhad.G_EquipmentExpensiveItemColor.oxp/readme.txt
I fixed it in the code, but will include it to next version together with some cleaning of comments and other fixes.
So here it go:
cat oolite.oxp.Gilhad.G_EquipmentExpensiveItemColor.oxp/Config/script.js
Code: Select all
"use strict";
this.name = "G_EquipmentExpensiveItemColor";
this.author = "gilhad";
this.copyright = "2024 gilhad";
this.description = "Gray color for expensive equipment in F3 Ship Outfitting screen";
this.licence = "CC BY-NC-SA 4.0";
this.guiScreenWillChange = function(to,from) {
// log(this.name,"guiScreenWillChange: "+from+" --> "+to+" ;");
if (to == "GUI_SCREEN_EQUIP_SHIP" ) {
this.$updateColors();
} else if (( to == "GUI_SCREEN_STATUS") && this.$fixF5 ) {
this.$revertColors();
};
}
this.playerBoughtEquipment = function(equipment, paid) {
// log(this.name,"playerBoughtEquipment: "+equipment+" ["+paid+" Cr] ;");
this.$updateColors();
}
this.startUpComplete = function() {
this.$fixF5 = false; // F5 do not need fix
// HACK use missile to set displayColor, read it and revert it back
var missileInfo = EquipmentInfo.infoForKey("EQ_MISSILE");
var tmp = missileInfo.displayColor;
missileInfo.displayColor = "grayColor";
this.$grayColor = missileInfo.displayColor.toString();
//
// log(this.name,"startUpComplete: missileInfo.displayColor ("+missileInfo.displayColor+") ? = this.$grayColor ("+this.$grayColor+") : "+(missileInfo.displayColor.toString() == this.$grayColor));
missileInfo.displayColor = tmp;
// END HACK
}
this.$grayColor = null; // get true color for gray, filled in startUpComplete()
this.$fixF5 = false; // F5 do not need fix
this.$updateColors = function() { // set expensive to gray, cheap to yellow
this.$fixF5 = true; // we play with colors
var credits = Math.floor(player.credits*10);
log(this.name,"$updateColors ["+credits+" dCr] ;");
var eq = EquipmentInfo.allEquipment;
for (var i = 0; i < eq.length; i++) {
var itm = eq[i];
var price = itm.calculatedPrice;
if (price > credits) { // pricey - go to gray
if (itm.displayColor == null) {
itm.displayColor = "grayColor";
}
} else { // cheap - revert
if ( (itm.displayColor != null ) && (itm.displayColor.toString() == this.$grayColor) ) {
itm.displayColor = null;
}
}
}
}
this.$revertColors = function() { // revert everything to yelow
this.$fixF5 = false; // F5 do not need fix
var eq = EquipmentInfo.allEquipment;
for (var i = 0; i < eq.length; i++) {
var itm = eq[i];
if ( (itm.displayColor != null ) && (itm.displayColor.toString() == this.$grayColor) ) {
itm.displayColor = null;
}
}
}
Code: Select all
{
identifier = "oolite.oxp.Gilhad.G_EquipmentExpensiveItemColor";
required_oolite_version = "1.85";
title = "Equipment Expensive Item Color";
// description = "This OXP highlights expensive equipment in gray on the F3 Ship Outfitting screen. An item is considered expensive if its price exceeds your current credits.";
description = "Gray color for expensive equipment in F3 Ship Outfitting screen";
version = "1.2";
category = "Miscellaneous";
author = "gilhad";
license = "CC-BY-NC-SA 4.0";
}
Code: Select all
Equipment Expensive Item Color
By Gilhad
Overview
========
This OXP highlights expensive equipment in gray on the F3 Ship Outfitting screen.
An item is considered expensive if its price exceeds your current credits.
This extension recolors items that are too costly based on the player's current balance, allowing players to see at a glance which items they can't afford. However, if an item already has a "display_color" defined in its equipment.plist file, this OXP will not override it. When your credits increase, items previously marked in grey will automatically revert to yellow.
License
=======
This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 4.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/
Attribution and Acknowledgments
===============================
This OXP was developed as an extension to oolite.oxp.phkb.EquipmentRemoveItemColor.oxz by phkb and is intended for potential integration. Its code is partially based on that work.
Special thanks to Wildeblood for programming assistance.
Compatibility
=============
EquipmentRemoveItemColor does recoloring at startup, this OXP does it later in game, so already recolored items are not affected.
Discussion
==========
This OXP is discussed at this forum link: https://bb.oolite.space/viewtopic.php?p=297992#p297992
Version History
===============
1.2 - 2024.10.30 05:13:29 - fix F5 page colors
1.1 - 2024.10.29 22:33:14 - fix old values on first F3 page
1.0 - 2024.10.29 19:34:25 - Initial release.
Lady of Fate, we adore you . . .
- hiran
- Theorethicist
- Posts: 2402
- Joined: Fri Mar 26, 2021 1:39 pm
- Location: a parallel world I created for myself. Some call it a singularity...
Re: Equipment “Sell Item” Color
If you want this code to be distributed via the expansions manager there is not much left to do:
- wrap up your content into an OXZ file. That essentially means create a zip archive from your oxp folder such that manifest.plist is in the root directory (and all the other files in appropriate directories besides).
- upload this OXZ so that others can download it. The Oolite wiki is a site that is used by many plugins. Once you upload you know the URL where this expansion can be downloaded again.
- Go to https://github.com/OoliteProject/oolite ... on-catalog and open an issue, asking the url from the previous step to be added to the catalog.
That's it!
- wrap up your content into an OXZ file. That essentially means create a zip archive from your oxp folder such that manifest.plist is in the root directory (and all the other files in appropriate directories besides).
- upload this OXZ so that others can download it. The Oolite wiki is a site that is used by many plugins. Once you upload you know the URL where this expansion can be downloaded again.
- Go to https://github.com/OoliteProject/oolite ... on-catalog and open an issue, asking the url from the previous step to be added to the catalog.
That's it!
Sunshine - Moonlight - Good Times - Oolite