OXPConfig

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 546
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: OXPConfig

Post by Lone_Wolf »

small error in readme : there are 24 oxps recognized by oxpconfig, not 19 (my shieldcycler is one of the missing oxps).

Maybe only oxps with a wiki page are listed ?

Added :

OXPConfig_Doc still doesn't list the .hide property, is my oxp the only one using that property ?

If so, i guess ShieldCycler is more unique then i thought :D
OS : Arch Linux 64-bit - rolling release

OXPs : My user page

Retired, reachable at [email protected]
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: OXPConfig

Post by Svengali »

Lone_Wolf wrote:
small error in readme : there are 24 oxps recognized by oxpconfig, not 19 (my shieldcycler is one of the missing oxps).

Maybe only oxps with a wiki page are listed ?
Yes, and only if the [[Category:OXPConfig-compatible OXPs]] is used. The number is just the value of entries in that Category.
I'm simply to lazy to do such a list manually.
Lone_Wolf wrote:
OXPConfig_Doc still doesn't list the .hide property, is my oxp the only one using that property ?

If so, i guess ShieldCycler is more unique then i thought :D
As far as I'm aware - yes .-)
Oops. I really should add the property and the searchtree rebuild...
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: OXPConfig

Post by Svengali »

OXPConfig 2.2.4 is online.

Changes:
- Added cims 'Skilled NPCs'.
- Added new 'Dump declared sounds.' option.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: OXPConfig

Post by Svengali »

A mirror for [EliteWiki] OXPConfig2.2.4 is available.
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

use of script variables in oxpcsettings?

Post by GGShinobi »

Hello!

I'm using OXPConfig for my planned Long Range Scanner (for which, btw, suggestions are always very welcome!), and I've got a question:

I'm using OXPConfig to allow the user to define which key-combo (e.g. F7-F6-F7) he wants to use to enter the LRS-configuration-screen. Therefore, I'd like to use the value of a variable to be printed as part of the InfoS-String, because I'd like to show it the current settings (since the hexadecimal representation of the sliders might be a little hard to read for normal users). So what I did was:

Code: Select all

this.oxpcSettings = {
  Info: {
    Name:this.name,
    Display:"GGIndustries LRS",
    Notify: true,
    InfoB:"Setup how to access the LRS configuration screen. If alwaysPrimable=true, the specials can be ignored. If not, they are used and default to F6-F6-F7.",
    InfoS:"Current Setting: "+$getKeyComboAsString()+"\nSetup which key combo you want to use to open the LRS configuration screen.\nValues: 0->F5, 1->F6, 2->F7, 3->F8.\nKeys1-3 have to be set, Key4 is optional
  },
  Bool0: {Name:"$alwaysPrimable",Def:false,Desc:"access LRS configScreen through priming?"},
  SInt0: {Name:"$key1st", Def:0x01, Max:0x03, Desc:"1st key of key combo."},
  SInt1: {Name:"$key2nd", Def:0x01, Max:0x03, Desc:"2nd key of key combo."},
  SInt2: {Name:"$key3rd", Def:0x02, Max:0x03, Desc:"3rd key of key combo."},
  SInt3: {Name:"$key4th", Def:0x04, Max:0x04, Desc:"4th key of key combo."}
};
Note the embedded function call: InfoS:"Current Setting: "+$getKeyComboAsString()+"\nSetup which key combo...
The called function looks like this:

Code: Select all

this.$getKeyComboAsString = function() {
  var last = "";
  if ($key4th <= 3) { last = "-F"+($key4th+5); }
  return "F"+($key1st+5)+"-F"+($key2nd+5)+"-F"+($key3rd+5)+last
}
This works perfectly, but only one time (at start). :!: The value never gets updated, so when I change the key-combo, the InfoS-String still shows the old value :(

I've also tried to use a variable instead of a function call, but the results are the same. The shown InfoS-String is not updated after I've changed some values with OXPConfig.

:?: Am I missing something? Or is it not possible?

Oooh, and while I'm at it, a short question: How did you manage to display text in different font sizes and on different positions on the screen? :?: I would like to have my configuration screen use such features, too (but I haven't looked into the OXPConfig-source for this yet, I admit) :oops:

EDIT: If you wanna have a look at my full script, you can find it here: https://www.box.com/s/n2jwh3v10ymkovd3erzr
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: use of script variables in oxpcsettings?

Post by Svengali »

GGShinobi wrote:
This works perfectly, but only one time (at start). :!: The value never gets updated, so when I change the key-combo, the InfoS-String still shows the old value :(

I've also tried to use a variable instead of a function call, but the results are the same. The shown InfoS-String is not updated after I've changed some values with OXPConfig.

:?: Am I missing something? Or is it not possible?
Dynamic switching of texts is not supported. OXPConfig collects the objects and builds its binary search trees. If (and only if) the .LeaveData flag is true the object won't be deleted after collecting it and OXPConfig uses a reference. Changing the object at runtime automagically updates OXPConfigs used texts. But still - it doesn't support dynamic switching of texts as your script doesn't know when to apply changes.

The callback (.oxpcNotifyOnChange) is only sent when stored settings are loaded, default settings are loaded by the user and when the player exits OXPConfig or switches to the OXP list. Changing a setting itself does not trigger a notification - it only stores a flag internally.

It would be possible to add a flag to change this behaviour for specific OXPs (maybe .dynamicNotify) to send notifications for any settings change. I'll have a peek in your script to see what would be required.
GGShinobi wrote:
How did you manage to display text in different font sizes and on different positions on the screen?
The colored texts are done via HUD.
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: use of script variables in oxpcsettings?

Post by GGShinobi »

Svengali, thanks for your reply.
Svengali wrote:
Dynamic switching of texts is not supported. OXPConfig collects the objects and builds its binary search trees. If (and only if) the .LeaveData flag is true the object won't be deleted after collecting it and OXPConfig uses a reference. Changing the object at runtime automagically updates OXPConfigs used texts. But still - it doesn't support dynamic switching of texts as your script doesn't know when to apply changes.

The callback (.oxpcNotifyOnChange) is only sent when stored settings are loaded, default settings are loaded by the user and when the player exits OXPConfig or switches to the OXP list. Changing a setting itself does not trigger a notification - it only stores a flag internally.
Then I'll update my script so that it uses the .LeaveData flag. This is better than nothing! :D
Svengali wrote:
It would be possible to add a flag to change this behaviour for specific OXPs (maybe .dynamicNotify) to send notifications for any settings change.
While not a pressing matter, I think such a functionality would be useful. Before diving into the matter, I was quite confused by the possibilities OXPConfig offers on how to setup the oxps. Some text that explains what is done and that is updated "live" (like I tried in my example) could help.
Svengali wrote:
GGShinobi wrote:
How did you manage to display text in different font sizes and on different positions on the screen?
The colored texts are done via HUD.
Aaah, I see I see... Nice! 8)
I hope I find a way to manipulate the text that is displayed there dynamically.
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: use of script variables in oxpcsettings?

Post by Svengali »

GGShinobi wrote:
Svengali wrote:
It would be possible to add a flag to change this behaviour for specific OXPs (maybe .dynamicNotify) to send notifications for any settings change.
While not a pressing matter, I think such a functionality would be useful. Before diving into the matter, I was quite confused by the possibilities OXPConfig offers on how to setup the oxps. Some text that explains what is done and that is updated "live" (like I tried in my example) could help.
I've implemented it now - will test and measure a bit before uploading though (together a small test.oxp) .-)
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: use of script variables in oxpcsettings?

Post by GGShinobi »

Svengali wrote:
I've implemented it now - will test and measure a bit before uploading though (together a small test.oxp) .-)
Cool! :D I'm looking forward to the release! :D
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: OXPConfig

Post by Svengali »

OXPConfig 2.3 is online.

Changes:
- Added .DynamicNotify flag (calls .oxpcNotifyOnChange like .Notify)
- Docs updated

A quick and dirty demo for the .Hide and .DynamicNotify flag is available at [EliteWiki] OXPConfigs documentation page. The demo (ab)uses the entry for OXPShipRegulator, so it has full support by OXPConfig (loading and saving is enabled).
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: OXPConfig

Post by GGShinobi »

Cool! Thank you very much! :lol:

I'll test the new version soon! :mrgreen:
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: OXPConfig

Post by GGShinobi »

Hi Svengali,

I've made some tests and it works pretty well! Very good work on that! :D I noticed only 2 things:
  • .Notify seems to have no effect if .DynamicNotify is true. (I thought setting it to false would prevent the oxpcNotifyOnChange-function to get called on start, so that, for example, at first the string "1st key of key combo." is used. But instead, the string has already been substituted by the value from oxpcNotifyOnChange even the first time I enter OXPConfig.)
  • this.oxpcSettings.Info.InfoS didn't use the fresh values from the variables. No matter how I changed key1-key4, the string shown is always the same (always: "CHANGED: ...")
Here is the code:

Code: Select all

this.name           = "GGIndustries_LongRangeScanner_MainScript.js";
this.author         = "GGShinobi";
this.copyright      = "© 2013 GGShinobi, Creative Commons: attribution, non-commercial, sharealike.";
this.description    = "Main Script for the GGIndustries Long Range Scanner.";
this.version        = "0.0.1";
"use strict";


// =============================================================================
// local global variables / switches, configure as desired:

this.$showDebug = true;

// configuration / declare OXPConfig-variables:
this.$alwaysPrimable = false; // if true, keyCombos will be ignored, enter setup screen through priming instead

// the keys for key combination to open LRS config screen. 0=F5, 1=F6, 2=F7, 3=F8
this.$key1st = 2; // 1 => F7                  }\
this.$key2nd = 1; // 1 => F6                  } => default combo: 
this.$key3rd = 2; // 2 => F7                  } =>   F7-F6-F7
this.$key4th = 4; // 4 => disabled by default }/


// =============================================================================
// OXPConfig:

this.$getKeyComboAsString = function() {
  var last = "";
  if ($key4th <= 3) { last = "-F"+($key4th+5); }
  return "F"+($key1st+5)+"-F"+($key2nd+5)+"-F"+($key3rd+5)+last
}

this.oxpcSettings = {
  Info: {
    Name:this.name,
    Display:"GGIndustries LRS",
    LeaveData: true,
    Notify: false, // seems to have no effect if DynamicNotify is true
    DynamicNotify: true,
    InfoB:"Setup how to access the LRS configuration screen. If alwaysPrimable=true, the specials can be ignored. If not, they are used and default to F7-F6-F7.",
    InfoS:"Current Setting: "+$getKeyComboAsString()+"\nSetup which key combo you want to use to open the LRS configuration screen.\nValues: 0->F5, 1->F6, 2->F7, 3->F8.\nKeys1-3 have to be set, Key4 is optional. Set it to 4 to deactivate."
  },
  Bool0: {Name:"$alwaysPrimable",Def:false,Desc:"access LRS configScreen through priming?"},
  SInt0: {Name:"$key1st", Def:0x01, Max:0x03, Desc:"1st key of key combo."},
  SInt1: {Name:"$key2nd", Def:0x01, Max:0x03, Desc:"2nd key of key combo."},
  SInt2: {Name:"$key3rd", Def:0x02, Max:0x03, Desc:"3rd key of key combo."},
  SInt3: {Name:"$key4th", Def:0x04, Max:0x04, Desc:"4th key of key combo."}
};

this.oxpcNotifyOnChange = this.$setupKeyArrays = function(n) {
  // TODO: make use of n for more efficency
  // prepare vars used for configuration screen access:
  this.$guiStage = 0;             // remembers pos of key combo. Always between 0 and 3.
  this.$keyCombo = [$key1st, $key2nd, $key3rd, $key4th];

  var key1 = "F-" + ($key1st+5); var key2 = "F-" + ($key2nd+5); var key3 = "F-" + ($key3rd+5);
  var key4; if ($key4th <= 3) key4 = "F-" + ($key4th+5); else key4 = "disabled";
  this.oxpcSettings.SInt0.Desc = "1. key: " + key1;
  this.oxpcSettings.SInt1.Desc = "2. key: " + key2;
  this.oxpcSettings.SInt2.Desc = "3. key: " + key3;
  this.oxpcSettings.SInt3.Desc = "4. key: " + key4;
  if ($key4th <= 3) key4 = "-" + key4; else key4 = "";
  // the following line doesn't update / use the "fresh" values from the variables, but the values they had upon game start.
  this.oxpcSettings.Info.InfoS = "CHANGED: Current Setting: "+key1 + "-" + key2 + "-" + key3 + key4+"\nSetup which key combo you want to use to open the LRS configuration screen.\nValues: 0->F5, 1->F6, 2->F7, 3->F8.\nKeys1-3 have to be set, Key4 is optional. Set it to 4 to deactivate.";
}

// =============================================================================
// Helpers:

// show message on destination
// dest: 0 none, 1 logfile, 2 console
this.$showDebugInfo = function(message, dest) {
  if ($showDebug) {
    if ((dest&1)) { log("SmellyDebug", message); }
    if ((dest&2)) { player.consoleMessage(message); }
  }
}

// =============================================================================
// startup - called when OXP is loaded (on game start, load game,...)
this.startUp = function () {
  // setup key combo catcher:
  // GUI_SCREEN_MAIN, GUI_SCREEN_STATUS F5, GUI_SCREEN_MANIFEST F5-F5,
  // GUI_SCREEN_SYSTEM_DATA F7, GUI_SCREEN_OPTIONS, GUI_SCREEN_EQUIP_SHIP,
  // GUI_SCREEN_SHIPYARD, GUI_SCREEN_SHORT_RANGE_CHART F6,  GUI_SCREEN_REPORT,
  // GUI_SCREEN_LONG_RANGE_CHART F6-F6, GUI_SCREEN_MARKET F8, GUI_SCREEN_CONTRACTS
  this.$F5    = ["GUI_SCREEN_STATUS", "GUI_SCREEN_MANIFEST"];
  this.$F6    = ["GUI_SCREEN_SHORT_RANGE_CHART", "GUI_SCREEN_LONG_RANGE_CHART"];
  this.$F7    = ["GUI_SCREEN_SYSTEM_DATA"];
  this.$F8    = ["GUI_SCREEN_MARKET"];
  this.$FKeys = [$F5, $F6, $F7, $F8];
  $setupKeyArrays();
}

// =============================================================================
// show the GGIndustries LRS configuration screen:

this.$showLRSConfigScreen = function() {
  var LRSConfigScreen = new Object();
  LRSConfigScreen.title = "GGIndustries Long Range Scanner Configuration";
  LRSConfigScreen.screenID = "GGIndustries-LRS-configuration-screen"
  LRSConfigScreen.allowInterrupt = true;
  //LRSConfigScreen.model = "GGIndustries-LRS";
  //LRSConfigScreen.model = "flying-dutchman";
  // LRSConfigScreen.model = "thargoid";
  // LRSConfigScreen.spinModel = true; // false;
  // LRSConfigScreen.backgroundSpecial = "SHORT_RANGE_CHART";
  LRSConfigScreen.choicesKey = "activate_LRS_Scanner?";
  LRSConfigScreen.message = "spawn the dutchman scanner?";

  function $callback(choice) {
    if (choice === "1_YES") player.commsMessage("Yay!");
    else if (choice === "2_NO")  player.commsMessage("Boo.");
    else  player.commsMessage("Whut?");
  }

  // mission.runScreen(LRSConfigScreen);
  mission.runScreen(LRSConfigScreen, $callback);
}

// =============================================================================
// key combo catcher:

// check if given guiScreen (either to or from from guiScreenChanged()) can be reached by pressing
// the given key. Key is intended to be $keyCombo[$guiStage].
this.$guiScreenMatchesKey = function(guiScreen, key) {
  for (var i = 0; i < $FKeys[key].length; i++) {
//  $showDebugInfo("  Comparing: "+guiScreen+" <-> "+$FKeys[key][i], 1);
    if (guiScreen == $FKeys[key][i]) {
//    $showDebugInfo("FKeys["+key+"]["+i+"] match: "+guiScreen, 1);
      return true;
    } 
  }
  return false;
}

this.$guiScreenChangeMatchesStage = function(to, from, stage) {
//$showDebugInfo(from + "->"+to+"@$keyCombo["+stage+"]="+$keyCombo[stage], 3);
  if ($guiScreenMatchesKey(to, $keyCombo[stage])) {
    // combo button pressed => check if previous button was correct, too:
    if (stage == 0 || $guiScreenMatchesKey(from,$keyCombo[stage - 1])) { // WARNING: order of tests is important here! (or else (stage - 1) could be negative)
//    $showDebugInfo("stage match: " + stage, 3);
      return true;
    }
  }
  return false;
}

this.$isFinalGUIStage = function() {
  return ($guiStage == 4 || ($guiStage == 3 && $key4th >= 4));
}

this.guiScreenChanged = function(to, from) {
  if ($alwaysPrimable) { return; } // key combo not used anyway
  // if (player.ship.docked) { return; } // only in-flight
  // if (player.ship.equipmentStatus("EQ_GGINDUSTRIES_LONG_RANGE_SCANNER") !== "EQUIPMENT_OK") { return; } // TODO: activate when equipment exists
  if ($guiScreenChangeMatchesStage(to, from, $guiStage)) {
    // yep, we've entered the next stage! increase stage, then check if this is the final stage:
    $guiStage++;
    if ($isFinalGUIStage()) {
      $guiStage = 0; // reset
      $showDebugInfo("entering GGIndustries LRS configuration menu...", 3);
      $showLRSConfigScreen()
    }
  } else {
    $guiStage = 0; // reset
  }
}
You can also download the whole oxp from my box if you want to test it: https://www.box.com/s/h7hbn1vanuq7wzlh5090

For my purpose, it is sufficient that I am able to dynamically change the values of this.oxpcSettings.SInt0.Desc-this.oxpcSettings.SInt4.Desc, but it would be nice if it would also be possible to change this.oxpcSettings.Info.InfoS. :)

Anyway, thank you very much, I'll surely use it! :mrgreen:
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: OXPConfig

Post by Svengali »

GGShinobi wrote:
.Notify seems to have no effect if .DynamicNotify is true. (I thought setting it to false would prevent the oxpcNotifyOnChange-function to get called on start, so that, for example, at first the string "1st key of key combo." is used. But instead, the string has already been substituted by the value from oxpcNotifyOnChange even the first time I enter OXPConfig.)
I'm not sure I understand (and sorry for the longer text).

Both flags are working independent and even if both flags are true .oxpcNotifyOnChange won't be called at all when OXPConfig runs its own start routines as long as no settings were stored before. OXPConfig also won't call it if you're just browsing through the settings. If settings were stored before we have a different situation and OXPConfig will call it if the .Notify flag is true when it runs its own start routines. The passed argument will always be 7 (1-boolean + 2-short int + 4-24bit int) to indicate the full range for stored values.

After the startUp procedure:
The next situation is if a user enters the OXPConfig screens and changes settings. OXPConfig uses the .DynamicNotify flag and passes 1, 2 or 4 based on the type of the changed setting if the flag is true. And last but not least if the user has finished his changes and leaves the screens OXPConfig uses the .Notify flag and passes the sum of changed settings, so it can be 1...7 if the flag is true.

And to complete it. If stored values are there OXPConfig will apply the settings regardless of the .Notify flag.

What (probably) happens in your script is another thing. As you are calling this.$setupKeyArrays() in you scripts .startUp the loading order will become important. Specially for these cases OXPConfig has the .EarlyCall, .EarlySet flags. But calling other OXPs .startUp from within OXPConfig has a drawback - it raises the time the function runs and we may hit the timelimiter some day. A approach for your script could be to get rid of the duplicated this.$setupKeyArrays function and call the remaining this.oxpcNotifyOnChange() a bit later (e.g. via the .missionScreenOpportunity handler) or use a init property which gets checked on guiScreenChanged. This way you'd still get your configuration in all cases and don't have to worry about things like loading order or if the user has OXPConfig installed or not.

Edit: Oh, and .EarlySet is probably not a bad idea too. OXPConfig will apply stored settings in its first cycle then.
GGShinobi wrote:
this.oxpcSettings.Info.InfoS didn't use the fresh values from the variables. No matter how I changed key1-key4, the string shown is always the same (always: "CHANGED: ...")
Yep. InfoB, InfoS and InfoE are not part of the dynamic stuff as their meaning was always to describe the settings and not their values. Shouldn't be hard to change it to give OXPs some more room.
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: OXPConfig

Post by GGShinobi »

Thanks Svengali for your excellent explanation. It's now clear to me! :mrgreen:

Indeed your post is so good, I'd even recommend to add it to the wiki or at least place a link there to your post. What do you think?? :)
Svengali wrote:
GGShinobi wrote:
this.oxpcSettings.Info.InfoS didn't use the fresh values from the variables. No matter how I changed key1-key4, the string shown is always the same (always: "CHANGED: ...")
Yep. InfoB, InfoS and InfoE are not part of the dynamic stuff as their meaning was always to describe the settings and not their values. Shouldn't be hard to change it to give OXPs some more room.
Cool! :D That would be nice!
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: OXPConfig

Post by Svengali »

GGShinobi wrote:
Indeed your post is so good, I'd even recommend to add it to the wiki or at least place a link there to your post. What do you think?? :)
You are right - the doc is incomplete. I've reworked it now - hopefully it will be more valuable now. Some things are beyond the scope of OXPConfigs documentation though, because they apply to all OXPs in Oolite (e.g. infos about loading order, access to missionVariables, order of fired handlers, Oolites timelimiter and profiling via console).

Muchas gracias for your input, GGShinobi. I'm not so good at explaning and need some reminders to clarify things :mrgreen:
Post Reply