• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Text Input

Because of course it's not like I'm overflowing in projects... :]

A thought I've been kicking around for, oh, probably six months, is to make a text input module for POTC.
That is, create a function that will save input config somewhere, create a temporary mapping of all alphanumeric keys (and shift/delete/enter etc.), create a handler for reading their input, and then a function to replace that with the normal input config saved at the start.

Then you'd simply call a function like StartTextInput() and pass it an aref to the place where the string will be stored (usually a string under GameInterface, I'd think). And when you hit enter, text input stops and everything goes back to normal.

Now, the really _freaky_ thing is that, because of the call command, we can have a /real/ console.
The call command is used to call a function whose name is the string given to call.
example:
string tmp = "reinit"
call tmp(true, true);

will execute reinit(true, true).
Which means that we can, using text input, tell the game _exactly_ what function we want it to call (as long as the function has no arguments since those are not strings).
Well, we /could/ make a handler for even that, using the init_interface() commands as an example of the way.
That is, support a few base forms of console-callable functions, i.e. "Chr, float" would have you type in the character ID and the float as inputs first, and other data types similarly.
No way to tell it what _variables_ to use, though (unless we have a preset list of choosable variables to pass).
Though probably if someone had time and inclination to write a little program that would find the names of all globals, write a giant switch statement that has the name of the variable as the case and returns the &variable as the codeblock, we could get around even that.

But a true in-game console would be a side benefit; the major thing would be being actually able to _type in_ a name, say, rather than using the idiotic console system of choose-caps, choose-letter, go-to-lower-case, choose-next-letter and so forth.
 
By input config you mean how keys are mapped ?
Capturing the alpha keys is something I've also been wishing for, but dropped it because I thought nothing else would work then. But with what you suggest (if I get that right) the old mappings could ne mapped back when text input is done ?
Having a real console would be cool, and there are other applications for text input, too.
 
Wow, that would be immensely helpful in modding, I'd think, Nathan! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" />
 
Cat: Besides, my alt-tab keys are getting tired. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
Inez: Yeah. I mean make a temp object and copy the entire structure over, then overwrite with straight-alpha mapping (lord knows how we'll handle shift[fn1]), and then on break (ESC?) copy the old one back.

A quick way would be to just reset to defaults, but that would destroy the old mapping. I'll have to look at quite how control binding is handled because there's certainly some sendmessage'ing involved...
 
Not dropped, but paused certainly...
And the urgency's lessened slightly because of Maximus's new interface supporting renaming characters.
 
Done! <img src="http://instagiber.net/smiliesdotcom/otn/party/party.gif" border="0" class="linked-image" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/w00t.gif" style="vertical-align:middle" emoid=":woot" border="0" alt="w00t.gif" />
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/wavarr.gif" style="vertical-align:middle" emoid=":warr" border="0" alt="wavarr.gif" />
That's immediately among my top ten favourite things!
 
<!--QuoteBegin-CouchcaptainCharles+Jul 22 2005, 08:45 AM--><div class='quotetop'>QUOTE(CouchcaptainCharles @ Jul 22 2005, 08:45 AM)</div><div class='quotemain'><!--QuoteEBegin-->Great !  What ?  Where ??
<div align="right">[snapback]125530[/snapback]</div><!--QuoteEnd--></div><!--QuoteEEnd-->
In the most recent Post Build 12 modpack. Available from the link in my sig. And it's a really cool mod, so thanks a lot Nathan!!! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/bow.gif" style="vertical-align:middle" emoid=":bow" border="0" alt="bow.gif" />
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" />, folks. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
Now, the question is: what do we plug it into?
Oh, I should probably explain how it's implemented, too... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />

Keyboard is implemented as follows:
(And note this is the first, semi-prototype, implementation; I would prefer later to have a cursor/variable insertion point too, and perhaps multi-line support--maybe then have CTRL-Enter end it rather than just enter. For adding notes and stuff)
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->bool bKeyboardEnabled = false; // true when in KB mode, false when out. PLEASE DON'T USE THIS DIRECTLY.
bool bKeyboardShift = false; // true when shift is on (for capitals). Again, please let the shift-key-handler change this, don't change it directly. Note: this is set to false when KB is turned on and when KB is turned off.
string KeyboardString = ""; // the string that keys are written to. Note that this is only added to or removed from via KB functions; the actual reading it (and writing to it before init KB mode) must be done by the end use.

bool KB_SetKeyboardMode(bool onoff); //This will turn on or off the keyboard. It will do nothing if bKeyboardEnabled is the same as the desired state. It will return true if a change is made.<!--c2--></div><!--ec2-->
When KB_SetKeyboardMode is run to turn KB on, it will, after setting bKeyboardEnabled = true and bKeyboardShift = false:
1. Save current control scheme (via SaveGameOptions() so video and other settings will be saved too).
2. Delete all attributes of objControlsState--that is, remove all controls and mappings [fn1]
3. Init keycodes (they too are stored in that object).
4. Manually set some interface-specific controls to null keys [fn1]
5. Create and map the various keyboard controls. They are A-Z and 0-9, space, period, quote, and minus/dash. Most keys have a lowercase and uppercase mode [fn2]. Functional keys are shift (two controls, shift_on and shift_off), enter, esc, and backspace.

When we then turn KB off, the function will, after resetting both bools to false:
1. Wipe and reinit controls from scratch
2. Load old control scheme (via LoadGameOptions() ).

Now I should mention the other handling functions before I talk more about controls. They are:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->void KB_AddCharacter(string c); //this will add the character(s) passed as c to KeyboardString; if bKeyboardShift, the character(s) added will be the shifted character c[fn2]. Note that AFAIK POTC does not have a char variable type so I'm using strings.
bool KB_RemoveCharacter(); // this will remove the rightmost character from KeyboardString, and return true if there was a character to remove (false if there are no characters left to remove)<!--c2--></div><!--ec2-->
Keyboard controls are handled by a special if(bKeyboardEnabled) section in ProcessControls() in Seadogs.c, and via events.
We default to posting the event "KB_update" at the end of the function.
If the control has the string "NK_Key_", it is assumed to be a text key and the final character is passed to KB_AddCharacter().
If the control does not have that string, we switch() for the special-case controls. Backspace runs KB_RemoveCharacter(). Enter will skip update and post the event "KB_End". Esc will clear KeyboardString and also post the event KB_End.
(Lastly if update was not set to skip, we post "KB_update")

KB_End is linked to KB_TurnOff(), which runs KB_SetKeyboardMode(false), which turns off the keyboard.
You can also link KB_End, and KB_Update, to local handler functions. Example, character sheet:
With the other seteventhandler() blocks, we add:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->SetEventHandler("KB_End","WriteName", 0);
SetEventHandler("KB_Update", "UpdateName", 0);<!--c2--></div><!--ec2-->

We also use rewrite Maximus's ProcessCharNameChange() as follows. It now only contains:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->KB_SetKeyboardMode(true);
    if(KB_STARTBLANK) { KeyboardString = ""; UpdateName(); }
    else KeyboardString = GameInterface.strings.CharacterName;<!--c2--></div><!--ec2-->
Which will start KB mode, and if KB_STARTBLANK is not true set the KeyboardString to the already existing name string.

Then we add two new functions:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->void UpdateName()
{
    GameInterface.strings.CharacterName = KeyboardString;
}<!--c2--></div><!--ec2-->
Which gets run on every KB_Update event and simply updates the displayed string to be the KeyboardString.
And:
<!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->void WriteName()
{
    if(KeyboardString != "")
    {
 SetCharName(KeyboardString);
 string namestr = xi_refCharacter.name+" ";
 if(CheckAttribute(xi_refCharacter,"firstname")) namestr += xi_refCharacter.firstname + " ";
 namestr += xi_refCharacter.lastname;
 GameInterface.strings.CharacterName = namestr;
    }
}<!--c2--></div><!--ec2-->
Which will, if KB mode was not cancelled (i.e. Keyboardstring != ""), set the name as KeyboardString and update the visible string.
Note that we don't turn off KB mode here, we let the other function KB_End is tied to do that. (Yes, you can set multiple event handlers to a single event.)

So, there you have it.

[fn1] POTC seems to have trouble unsetting controls. For some reason, even though we wipe clean the controls object (objControlsState), the interface bindings for certain keys (enter, esc, space) are still there. Thus I try to manually unset them. However Pieter noted that even that didn't seem to entirely work. I am today (July 22 05) trying a new method, but that may well not work too. Backspace I have successfully tricked though.
[fn2]I have implemented the functions toupper() and tolower() in utils.c. Only toupper is currently used, because the I built the controls using lower-case letters. Note that toupper() also works on numbers and most other characters (except the quote key, because " ends a string! Don't want to mess with that...)
 
FanTASTic! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/me.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="me.gif" /> WTG, Nathan! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/danse1.gif" style="vertical-align:middle" emoid=":dance" border="0" alt="danse1.gif" />
 
I second, thrid, forth or whatever that! Whee! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/danse1.gif" style="vertical-align:middle" emoid=":dance" border="0" alt="danse1.gif" />

Nathan! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/wavarr.gif" style="vertical-align:middle" emoid=":warr" border="0" alt="wavarr.gif" />
 
Thanks, folks. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" />
 
Back
Top