HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.
Pages: [1] 2

Author Topic: A Simple SpecOracle Header Editor  (Read 5139 times)

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
A Simple SpecOracle Header Editor
« 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.



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>
« Last Edit: Aug 12, 12, 07:37:29 PM by Jrome90 »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1406
    • View Profile
    • Forever Interactive, Inc.
Re: A Simple SpecOracle Header Editor
« Reply #1 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!
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

JoshHalls

  • Founding Professional
  • *****
  • Posts: 335
    • View Profile
    • The Repopulation
Re: A Simple SpecOracle Header Editor
« Reply #2 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.
Logged
Co-Owner/Programmer - The Repopulation

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #3 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. :-[
Logged

jcsmith562

  • General Accounts
  • *
  • Posts: 190
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #4 on: Oct 30, 11, 07:02:47 PM »

Nice to see someone sharing code also.
Logged

WoE-Byron

  • World Owner
  • ****
  • Posts: 214
  • WoE Online Project Manager
    • View Profile
    • Carbon Studios
Re: A Simple SpecOracle Header Editor
« Reply #5 on: Oct 30, 11, 07:41:43 PM »

I would love to see something like this added to the actual HeroEngine build. :)
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #6 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.
Logged

madz370@hotmail.com

  • General Accounts
  • *
  • Posts: 24
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #7 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?
Logged

JMurdick

  • General Accounts
  • *
  • Posts: 54
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #8 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.
Logged

madz370@hotmail.com

  • General Accounts
  • *
  • Posts: 24
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #9 on: Oct 31, 11, 08:03:26 AM »

awesome man thanks :P didnt think of that !
Logged

Atticus

  • General Accounts
  • *
  • Posts: 30
    • View Profile
    • 610 Labs
Re: A Simple SpecOracle Header Editor
« Reply #10 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>
Logged
Atticus

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #11 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
Logged

Atticus

  • General Accounts
  • *
  • Posts: 30
    • View Profile
    • 610 Labs
Re: A Simple SpecOracle Header Editor
« Reply #12 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.
Logged
Atticus

Gothrek

  • General Accounts
  • *
  • Posts: 92
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #13 on: Jan 23, 12, 01:32:36 AM »

move this thread to tutorial subforum, plz.
Logged

Gothrek

  • General Accounts
  • *
  • Posts: 92
    • View Profile
Re: A Simple SpecOracle Header Editor
« Reply #14 on: Jan 23, 12, 07:11:50 AM »

tks :D
Logged
Pages: [1] 2