HeroEngine Forums

HeroEngine Developers => Developer Created Tutorials => Topic started by: Jrome90 on Oct 30, 11, 04:16:22 AM

Title: A Simple SpecOracle Header Editor
Post by: Jrome90 on Oct 30, 11, 04:16:22 AM
The SpecOracle Header editor is a simple way to add or delete the headers for a SpecOracle.

(http://img269.imageshack.us/img269/6751/headereditor.png) (http://imageshack.us/photo/my-images/269/headereditor.png/)

This can be used to learn how make GUIs or just be used the way it was meant to be used.
Easily add or remove a header for your SpecOracles

Please, If you do use it, let me know. ;D

You can add this to your own project with just a few simple steps. Okay, maybe more than a few

1. Create a new class on the client side named "HeaderEditor" (Archetype: guicontrol)
2. Add the "_GUIBaseWindow" as a parent class
3. Create a Script for the new class, and paste the script below labled "HeaderEditorClassMethods"
4. In the serverside script "MiscUtils" add the script below labled "Add To MiscUtils" (If you dont have a script named "MiscUtils" use a different script, or create the script "MiscUtils")
5. From the script editor, create a new XML prototype, name it "HeaderEditor" and paste the XML below labled "HeaderEditor XML"


HeaderEditorClassMethods
Code: (hsl) [Select]
method OnControlBuild()
  specOracles as List of ID
  specOracles = $SPECORACLEUTILS._GetAllSpecOracles()
  oracles as List of String
  //Loop though all known Spec Oracles to add to a list
  loop i from 1 to specOracles.length
    Specs as NodeRef = specOracles[i]
    sourceString as String = Specs.getSpecOracleClass()
    // Omit any SpecOracles that Start with "_"
    if SubString(sourceString,1,1) <> "_"
      add back Specs.getSpecOracleClass() to Oracles
    .
    // Populate the DropDownBox after it has added all the spec oracles to the List
    if i = specOracles.length
      me.PopulateOracleDropDownBox(oracles)
    .
  .
.

function open()
  c as NodeRef of Class GUIControl = CreateNodeFromPrototype("HeaderEditor")
  c.build = true
  c.centerControlOver(None)
 
 
.

method PopulateOracleDropDownBox(oracles as List of String)
  specOracleBox as NodeRef of Class _GUIDropDownBox = me.OracleDropDownBox()
  specOracleBox._populateDropDownBox(oracles)
.
method OracleDropDownBox() as NodeRef of Class _GUIDropDownBox
  return FindGUIControlByName(me,"scrollable.clientarea.SpecOracle._dropDownBox")
.
//method SpecOracleToUse() as NodeRef of Class GUITextInputBox
//  return FindGUIControlByName(me,"scrollable.clientarea.SpecOracle._textInputBox")
//.

method FieldName() as NodeRef of Class GUITextInputBox
  return FindGUIControlByName(me,"scrollable.clientarea.fieldName._textinputBox")
.

method HeaderDisplayName() as NodeRef of Class GUITextInputBox
  return FindGUIControlByName(me,"scrollable.clientarea.displayName._textInputBox")
.

method Addback() as NodeRef of Class GUICheckBox
  return FindGUIControlByName(me,"scrollable.clientarea._panel._checkBox")
.

method DeleteHeader()
 
.
method _onButtonMouseClick(button as NodeRef of Class _GUIButton, args references Class GUIMouseEvent)
  if button.name = "add_button"
    me.UpdateHeaderAdd()
  .
  if button.name = "remove_button"
    me.UpdateHeaderRemove()
  .
.


method UpdateHeaderAdd()
  specOracle as String = me.OracleDropDownBox()._getDropDownBoxValue()
  headerfieldName as String = me.FieldName().value
  headerDisplayName as String = me.HeaderDisplayName().value
  addBack as Boolean = me.Addback().checked
  //$ALERT._BasicAlert("Added the header " + me.HeaderDisplayName().value + " to " + me.OracleDropDownBox()._getDropDownBoxValue())
  call server MiscUtils:ChangeHeaderAdd(specOracle,headerFieldName,headerDisplayName,addBack)
.

method UpdateHeaderRemove()
  specOracle as String = me.OracleDropDownBox()._getDropDownBoxValue()
  headerfieldName as String = me.FieldName().value
  headerDisplayname as String = me.HeaderDisplayName().value
  //$ALERT._BasicAlert("Removed the header " + me.HeaderDisplayName().value + " from " + me.OracleDropDownBox()._getDropDownBoxValue())
  call server MiscUtils:ChangeHeaderRemove(specOracle,headerFieldName,headerDisplayname)
.
// For if/when added to the hotspot menu
shared function onCollapsableCategoryItemClick(args references Class GUIMouseEvent)
  open()
  args.handled = true
.

remote function Error(error as String)
    $ALERT._BasicAlert(error)
.

remote function Success(sucess as String)
      $ALERT._BasicAlert(sucess)
.

Add To MiscUtils
Code: (hsl) [Select]
untrusted function ChangeHeaderAdd(specOracle as String,headerFieldName as String,headerDisplayName as String, addBack as Boolean)
  var oracle = $SPECORACLEUTILS._GetOracleFromType(specOracle)
  if oracle.IsHeaderDisplayNameInUse(headerDisplayName) or oracle.IsHeaderFieldInList(headerFieldName)
    call reply HeaderEditorClassMethods:Error(headerFieldName + " or " + headerDisplayName + " Is already in use for: " + specOracle )
 
  else
    oracle.AddCollectionHeader(headerFieldName,headerDisplayName,addBack)
    call reply HeaderEditorClassMethods:Success("Added the header: " + headerDisplayName + " to: " + specOracle)

  .
.

untrusted function ChangeHeaderRemove(specOracle as String,headerFieldName as String,headerDisplayName as String)
  var oracle = $SPECORACLEUTILS._GetOracleFromType(specOracle)
  if not oracle.IsHeaderDisplayNameInUse(headerDisplayName) or oracle.IsHeaderFieldInList(headerFieldName)
    call reply HeaderEditorClassMethods:Error(headerFieldName + " or " + headerDisplayName + " Does Not Exist for the SpecOracle: " + specOracle )
  .
  if oracle.IsHeaderDisplayNameInUse(headerDisplayName) or oracle.IsHeaderFieldInList(headerFieldName)
    oracle.RemoveCollectionHeader(headerFieldName )
    call reply HeaderEditorClassMethods:Success("Removed the header: " + headerDisplayName + " From: " + specOracle)
  .
.

HeaderEditor XML
Code: (xml) [Select]
<createControlType inheritFrom='_window' class='HeaderEditor' type='HeaderEditor' description='A GUI to easily edit spec headers' treePath='CleanEngine' name="HeaderEditor" resizeable="NONE" scrollable="NONE">
  <position x="76" y="141"/>
  <size x="471" y="156"/>
  <maximumSize x="200" y="200"/>
  <set name='HeaderEditor.titlebar.title' attribute='text' value="Header Editor"/>
  <set name="HeaderEditor.scrollable.scrollbar">
    <size x="16" y="120"/>
  </set>
  <set name="HeaderEditor.scrollable.scrollbar.corner">
    <size x="16" y="14"/>
  </set>
  <set name="HeaderEditor.scrollable.clientarea">
    <_panel name="SpecOracle" dockMode="TOP">
      <size x="463" y="24"/>
      <_textInputBox name="_textInputBox" visible="false" enabled="false">
        <position x="90"/>
        <size x="300"/>
      </_textInputBox>
      <_label name="_label" text="Spec Oracle:">
        <size x="86"/>
      </_label>
      <_dropDownBox name="_dropDownBox">
        <position x="90"/>
        <size x="300"/>
      </_dropDownBox>
    </_panel>
  </set>
  <set name="HeaderEditor.scrollable.clientarea">
    <_panel name="fieldName" dockMode="TOP">
      <size x="463" y="24"/>
      <_textInputBox name="_textInputBox">
        <position x="90"/>
        <size x="300"/>
      </_textInputBox>
      <_label name="_label" text="Field Name:">
        <size x="77"/>
      </_label>
    </_panel>
  </set>
  <set name="HeaderEditor.scrollable.clientarea">
    <_panel name="displayName" dockMode="TOP">
      <size x="463" y="24"/>
      <_textInputBox name="_textInputBox">
        <position x="148"/>
        <size x="300"/>
      </_textInputBox>
      <_label name="_label" text="Header Display Name:">
        <size x="144"/>
      </_label>
    </_panel>
  </set>
  <set name="HeaderEditor.scrollable.clientarea">
    <_panel name="_panel" dockMode="TOP">
      <size x="463" y="24"/>
      <_checkBox name="_checkBox" checked="true" selected="true">
        <position x="104"/>
      </_checkBox>
      <_label name="_label" text="Add to Back?"/>
    </_panel>
  </set>
  <set name="HeaderEditor.scrollable.clientarea">
    <_panel name="confirm_panel" dockMode="TOP">
      <size x="463" y="24"/>
      <_button name="add_button">
        <position x="145"/>
        <set name='HeaderEditor.scrollable.clientarea.confirm_panel.add_button.text' attribute='text' value="Add"/>
      </_button>
      <_button name="remove_button">
        <position x="245"/>
        <set name='HeaderEditor.scrollable.clientarea.confirm_panel.remove_button.text' attribute='text' value="Remove"/>
      </_button>
    </_panel>
  </set>
</createControlType>
Title: Re: A Simple SpecOracle Header Editor
Post by: FI-ScottZ on Oct 30, 11, 06:36:29 AM
Very interesting.  We had put in similar things just as server commands, but never bothered to create a gui.  Looks like that could definitely be very handy.  Thanks!
Title: Re: A Simple SpecOracle Header Editor
Post by: JoshHalls on Oct 30, 11, 01:52:50 PM
Same here, put in a /register script to do it.  Probably something they could add to clean engine though.
Title: Re: A Simple SpecOracle Header Editor
Post by: Jrome90 on Oct 30, 11, 04:28:19 PM
Yea, the server command that Josh posted in another thread (Thanks Josh) was how I was going to make changes too.
But, then I thought, I dont like commands. I prefer a gui, and other people probably do as well.

This first started out with a text input box for the SpecOracle to use. I liked the thought of having a drop down populated with valid SpecOracles to choose from instead.

I'd like to use a drop down box populated with valid field names to choose from.
But, I am still learning and don't know how to do it yet. :-[
Title: Re: A Simple SpecOracle Header Editor
Post by: jcsmith562 on Oct 30, 11, 07:02:47 PM
Nice to see someone sharing code also.
Title: Re: A Simple SpecOracle Header Editor
Post by: WoE-Byron on Oct 30, 11, 07:41:43 PM
I would love to see something like this added to the actual HeroEngine build. :)
Title: Re: A Simple SpecOracle Header Editor
Post by: Jrome90 on Oct 30, 11, 10:21:16 PM
Nice to see someone sharing code also.

I agree, it would be nice to have many different examples of HSL on the forums.
If I was experienced, I wouldn't mind posting more.

I made a very simple chat window tutorial that is very basic. But, I dont know if it would be worth posting.
Title: Re: A Simple SpecOracle Header Editor
Post by: madz370@hotmail.com on Oct 31, 11, 05:46:27 AM
Yeah I tried this one out but im getting some errors when compiling the code.. Im not sure why though.

Its for the Call reply HeaderEditorClassMethords:error,success for the two untrusted functions. And then ofcourse im getting the same errrors in the header. Any ideas?
Title: Re: A Simple SpecOracle Header Editor
Post by: JMurdick on Oct 31, 11, 07:40:46 AM
You have to comment out the remote calls to compile.  Then compile the server script.  Then uncomment and recompile the client script.
Title: Re: A Simple SpecOracle Header Editor
Post by: madz370@hotmail.com on Oct 31, 11, 08:03:26 AM
awesome man thanks :P didnt think of that !
Title: Re: A Simple SpecOracle Header Editor
Post by: Atticus on Jan 22, 12, 11:56:25 AM
How would you add this to the hotspot editor. Here is my attempt which results in nothing.

Code: [Select]
<set name='clientarea'>
  <_CollapsableCategoryItem name='Purgatory_SpecOracleHeaderEditor' glomClass='_HotSpotItem' _hotSpotItemCheckable='true' script='Purgatory_SpecOracleHeaderEditorClassMethods'>
    <set name='text' attribute='text' value="{u}Spec Oracle Header Editor{/}"/>
  </_CollapsableCategoryItem>
</set>
Title: Re: A Simple SpecOracle Header Editor
Post by: Jrome90 on Jan 22, 12, 03:06:23 PM
How would you add this to the hotspot editor. Here is my attempt which results in nothing.

Code: [Select]
<set name='clientarea'>
  <_CollapsableCategoryItem name='Purgatory_SpecOracleHeaderEditor' glomClass='_HotSpotItem' _hotSpotItemCheckable='true' script='Purgatory_SpecOracleHeaderEditorClassMethods'>
    <set name='text' attribute='text' value="{u}Spec Oracle Header Editor{/}"/>
  </_CollapsableCategoryItem>
</set>
I notice that you have "<set name="clientarea">". I am not sure if that works or not.
Here is what it looks like for me
Code: [Select]
<set name="hotspotGUI.scrollable.clientarea._tabbedParent.clientarea.Tools.clientarea.Miscellaneous.clientarea">
    <_collapsableCategoryItem name="Header Editor" script="HeaderEditorClassMethods" glomClass="_HotSpotItem" _hotSpotItemCheckable="true">
      <set name='hotspotGUI.scrollable.clientarea._tabbedParent.clientarea.Tools.clientarea.Miscellaneous.clientarea.Header Editor.text' attribute='text' value="{u}SpecOracle Header Editor{/}"/>
    </_collapsableCategoryItem>
  </set>
Don't forget to rebuild the hotspot menu
Title: Re: A Simple SpecOracle Header Editor
Post by: Atticus on Jan 22, 12, 05:16:59 PM
ok thanks. My xml was fine. It was The xml for the headereditor... I was not paying attention. I named my header editor different than yours and did not realize I had to update the xml to reflect it. Once I did it began working when I clicked the link I added.

thanks for the response.
Title: Re: A Simple SpecOracle Header Editor
Post by: Gothrek on Jan 23, 12, 01:32:36 AM
move this thread to tutorial subforum, plz.
Title: Re: A Simple SpecOracle Header Editor
Post by: Gothrek on Jan 23, 12, 07:11:50 AM
tks :D
Title: Re: A Simple SpecOracle Header Editor
Post by: TheRabid on Mar 05, 12, 11:02:31 PM
Getting the following error here...

Code: [Select]
[hsl_error] 4611686018427637930,4: [Clean Test] SCRIPT ERROR: In function ScriptError: could not get SpecOracle:
03/06/2012 05:00:52 UTC
Call trace:
  Script _SpecOracleUtilsClassMethods line 815 me[id=9223372055941831994 class=_SpecOracleUtils,TOW_SpecOracleUtils]
  Script MiscUtils line 80 me[0]
starting method/function CHANGEHEADERADD
starting me[id=0 invalid]

remote call from originating script HeaderEditorClassMethods function UpdateHeaderRemove node 1000000971 client 9223372055763831974
Title: Re: A Simple SpecOracle Header Editor
Post by: Arlohian on Mar 31, 12, 08:56:15 AM
Thanks a lot :D helped me clear a lotta confusion!
Title: Re: A Simple SpecOracle Header Editor
Post by: Songoku on Apr 16, 12, 08:27:35 AM
Do not forget to mention how to run the script - in CLI: call HeaderEditorClassMethods open

Good day !!!
Title: Re: A Simple SpecOracle Header Editor
Post by: Jrome90 on Apr 16, 12, 04:05:35 PM
Do not forget to mention how to run the script - in CLI: call HeaderEditorClassMethods open

Good day !!!

That is one way. I decided to add it to the HotSpot menu instead.
Title: Re: A Simple SpecOracle Header Editor
Post by: LastJudge on Apr 17, 12, 02:41:53 AM
Do not forget to mention how to run the script - in CLI: call HeaderEditorClassMethods open

Good day !!!

That is one way. I decided to add it to the HotSpot menu instead.

I added it to HotSpot menu as well, it's more convenient than using a command to call it ;)