Hiding helpWindow property of choiceWindow on Window_Message

Discussion in 'Learning Javascript' started by Occupant, Dec 11, 2017.

  1. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    Hello again,

    So I am displaying a help window on choice selection for certain Show Choices events. I'm doing this by assigning a new Window_Help instance to the _helpWindow property of the _choiceWindow instance of current Window_Message. This is happening by way of the following functions (the script is heavily simplified from the original to focus on the question at hand):

    Code:
      // adding a method to Window_Message to actually create the help window with specified text
      // and assign it to the current scene's _choiceWindow._helpWindow property
      // passing null or an empty array should result in an empty, hidden message window
      Window_Message.prototype.createHelpWindow = function(text) {
        var lines = (text && text.length) || 0;
        var helpWindow = new Window_Help(lines);
        helpWindow.visible = lines > 0;
        this._choiceWindow.setHelpWindow(helpWindow);
        helpWindow.setText((text && text.join("\n")) || "");
        SceneManager._scene.addWindow(this._choiceWindow._helpWindow);
      };
    
      // create a default help window so that the updateHelp event will trigger
      OT_Testing_Window_Message_createSubWindows = Window_Message.prototype.createSubWindows;
      Window_Message.prototype.createSubWindows = function () {
        OT_Testing_Window_Message_createSubWindows.call(this);
        this.createHelpWindow();
      };
    
      // this sets up the help window text for the specified choice
      var OT_Testing_Window_ChoiceList_select = Window_ChoiceList.prototype.select;
      Window_ChoiceList.prototype.select = function (args) {
        OT_Testing_Window_ChoiceList_select.call(this, args);
        if (SceneManager._scene._messageWindow && // skip if we don't have a messageWindow yet, such as with the title screen choice list
            this._list[this._index]) // skip if we aren't in a valid choice, such as if there is no default choie for the list when it is first created
          SceneManager._scene._messageWindow.createHelpWindow([
            "Hello", "World", this._list[this._index].name
          ]); // if everything is ready, build the window for this specific choice
      };
    
    And this works great. I tried to attach an empty project with a simple demonstration of this script, but the file was too large to upload. Not sure how to shrink it, but using the above code in a plugin with any Show Choices will demonstrate the functionality.

    The question I have is, after I display the help window, how do I hide it once a selection in the choice list is made? As you can see above, the createHelpWindow function tries to hide the window if it is passed nothing or an empty array. My hope was that I could put a createHelpWindow() call in some event to cause the window to disappear. Here are some that I've tried:

    Code:
      // trying to clear the help window, method 1
      var OT_Testing_Window_Message_terminateMessage = Window_Message.prototype.terminateMessage;
      Window_Message.prototype.terminateMessage = function() {
        if (this._choiceWindow)
          if (this._choiceWindow._helpWindow)
            this.createHelpWindow();
        OT_Testing_Window_Message_terminateMessage.call(this);
      };
    
      // trying to clear the help window, method 2
      var OT_Testing_Window_ChoiceList_callOkHandler = Window_ChoiceList.prototype.callOkHandler;
      Window_ChoiceList.prototype.callOkHandler = function() {
        SceneManager._scene._messageWindow.createHelpWindow();
        OT_Testing_Window_ChoiceList_callOkHandler.call(this);
      };
    First I tried the terminateMessage function, since that seemed to be the closest to the "end of message" chain. But when that didn't work, I thought I'd try a little sooner in the event chain, by using the Window_ChoiceList.callOkHandler function.

    In addition to the createHelpWindow() call with no arguments, I've also tried to simply _choiceWindow._helpWindow.close() to no avail.

    Could anyone shed light on what I'm missing to hide the help window when a selection is made?

    Thanks!
    Occupant
     
    Last edited: Dec 11, 2017
    #1
    Joy Diamond likes this.
  2. Seajiha

    Seajiha Villager Member

    Messages:
    20
    Likes Received:
    7
    First Language:
    German
    Primarily Uses:
    RMMV
    Maybe try to run this function?

    this._choiceWindow._helpWindow.deactivate();
     
    #2
  3. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    Thanks for the reply. Unfortunately it didn't seem to work. I tried it with both approaches, but neither closed the window:

    Code:
      // trying to clear the help window, method 1
      var OT_Testing_Window_Message_terminateMessage = Window_Message.prototype.terminateMessage;
      Window_Message.prototype.terminateMessage = function() {
        if (this._choiceWindow)
          if (this._choiceWindow._helpWindow)
            this._choiceWindow._helpWindow.deactivate();
        OT_Testing_Window_Message_terminateMessage.call(this);
      };
    
      // trying to clear the help window, method 2
      var OT_Testing_Window_ChoiceList_callOkHandler = Window_ChoiceList.prototype.callOkHandler;
      Window_ChoiceList.prototype.callOkHandler = function() {
        if (SceneManager._scene._messageWindow._choiceWindow._helpWindow)
            SceneManager._scene._messageWindow._choiceWindow._helpWindow.deactivate();
        OT_Testing_Window_ChoiceList_callOkHandler.call(this);
      };
     
    #3
  4. Seajiha

    Seajiha Villager Member

    Messages:
    20
    Likes Received:
    7
    First Language:
    German
    Primarily Uses:
    RMMV
    Well thats a bit weird. The function is defined in WindowBasePrototype. Sadly I have no time to test it myself currently.

    My advise: assign the helpWindow for debug purposes to a global variable.
    During playtest open the console (F8) and type the name of the global variable. Then you can experiment a bit with it.
    I would advise to check if setting active = false or a similar variable has an effect.
    If true (it should be that way) you can overwrite the deactivate function for the help window in your code with the commands you used in the console and it will work.
     
    #4
    Joy Diamond likes this.
  5. Joy Diamond

    Joy Diamond Talkative Veteran

    Messages:
    135
    Likes Received:
    172
    First Language:
    English
    Primarily Uses:
    RMMV
    @Occupant,

    First: Welcome to the Forums :cool:

    Second, Do you know how to use Developer Tools?​

    Joy Diamond.
     
    #5
  6. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    Thanks for the follow up, @Seajiha !

    Ahh, I didn't realize that a runtime inspector was available in the console window! I had just been using console.log to inspect things, but a runtime inspector would be much more helpful. I will give that a try.
     
    Last edited: Dec 16, 2017
    #6
    Joy Diamond likes this.
  7. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    Thank you!

    No! That isn't a feature I had bumped into yet! Is it something other than the console feature of F8?
     
    #7
    Joy Diamond likes this.
  8. Joy Diamond

    Joy Diamond Talkative Veteran

    Messages:
    135
    Likes Received:
    172
    First Language:
    English
    Primarily Uses:
    RMMV

    That was really helpful advice, @Seajiha -- I had not read it fully the first time -- sorry :oops:

    @Occupant,

    F8= Developer Tools.

    The console is one of the tabs of the developer tools -- probably the most useful tab:
    • However, the other tabs are really useful also.
    • Once you are used to the console, you'll eventually start to use the other tabs.
    Joy Diamond.
     
    #8
  9. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    Wow, @Joy Diamond - I am so blind. I didn't even see the menu bar at the top of the window! There are so many features to the toolset! Thank you for bringing that to my attention! I will take a look at all of my different approaches to hiding the help window using the runtime inspection feature and any of these other tools.
     
    Last edited: Dec 16, 2017
    #9
    Joy Diamond likes this.
  10. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    @Seajiha

    I still haven't figured out the issue, but I thought I would share an interesting development I was able to discover through the runtime inspection of the SceneManager._scene._messageWindow._choiceWindow._helpWindow instance:
    • The "active" property toggled by the .deactivate() method does not seem related to visibility, apparently. When I first create the default help window, it is not visible but its "active" property is true. Similarly, after a choice is selected, I force the help window active property to be false, and the help window is still visible.
    • The "visible = false" and "hide()" approaches BOTH WORKED, but not in the way I expected. The issue is that my logic adds a new help window to the Window Message on the Scene, and if appropriate, sets that new help window to be invisible and hidden. Apparently that approach doesn't actually do anything to the previously visible help window that was added to the scene, so the invisible help window is sitting right there on top of the previously visible help window.
    Equipped with that information, I am no longer creating a new Window_Help instance to "hide" the previous choice's help window. But calling ".hide()" on the existing instance or setting it to "visible = false" doesn't seem to do what I expect either. So I think I'm closer, but still not finding the right hook into hiding the help window.
     
    #10
    Joy Diamond likes this.
  11. Seajiha

    Seajiha Villager Member

    Messages:
    20
    Likes Received:
    7
    First Language:
    German
    Primarily Uses:
    RMMV
    You write, that hide() will hide the current instance of the window. If you now only build one help_window and just hide/unhide it if needed, what's your remaining problem?
     
    #11
    Joy Diamond likes this.
  12. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    @Seajiha

    Fair question! The reason I went down the path of creating multiple Window_Help instances is that I want each choice in the choice list to have a help window with a potentially different number of lines (based on how much help text there is).

    Since the Window_Help constructor expects the number lines, I thought the easiest way would be to instantiate a new help window with the correct number of lines for the selected choice on the select() function of the Window_ChoiceList. And that was working perfectly, except for the disposal problem that was mentioned in my original post.

    Now that I know that it might be much easier to implement a single help window, I will spend some time looking for other ways to resize the Window_Help during the select() event. Perhaps calling its initialize function again, and then refresh()? We shall see!
     
    #12
  13. Occupant

    Occupant Hypothetical Member

    Messages:
    15
    Likes Received:
    8
    First Language:
    English
    Primarily Uses:
    RMMV
    Hooray! Calling .initialize() function on the Window_Help instance with the new number of lines I want to display worked! I now have a plugin for a variable line help window that can be displayed with text easily defined in the Show Choices event!

    Thank you so much for the help!
     
    #13
    Joy Diamond and Seajiha like this.

Share This Page