HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Static Model Tint GUI  (Read 1961 times)

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Static Model Tint GUI
« on: Nov 18, 15, 10:08:34 AM »

This isn't so much a tutorial but an example of how you could create a NON class methods script to edit Static models.

This is a ClientSide side script called :TKR_ModelColorPicker

Code: [Select]

public function createGUI()
 
  var gui = findGUIControlByName(None, "tkr_colorpicker")
  if gui != None
    destroyNode(gui)
  .
  gui = createNodeFromPrototype("_panel")
  gui.build = true
  gui.name = "tkr_colorpicker"
  gui.size.x = 200
  gui.size.y = 400
  hv as Class hv
  hv.horizontal = true
  hv.vertical = true
  gui.autoCenter = hv
 
 
  text as NodeRef of Class SmartTextInputBox = createNodeFromPrototype("FxSmartTextInputBox")
  text.build = true
  add back text to gui.children
  text.dockMode = TOP
  text.size.x = 60
  text.size.y = 20 
  text.name = "tkr_diffuse"
  text.value = "DIFFUSE"
  text.script = SYSTEM.EXEC.THISSCRIPT
 
  text2 as NodeRef of Class SmartTextInputBox = createNodeFromPrototype("FxSmartTextInputBox")
  text2.build = true
  add back text2 to gui.children
  text2.dockMode = TOP
  text2.size.x = 60
  text2.size.y = 20 
  text2.name = "tkr_ambient"
  text2.value = "AMBIENT"
  text2.script = SYSTEM.EXEC.THISSCRIPT
 
  close as NodeRef of Class _GUIButton = createNodeFromPrototype("_button")
  close.build = true
  add back close to gui.children
  close.dockMode = BOTTOM
  close.size.x = 60
  close.size.y = 20
  close.name = "tkr_close"
  buttonText as NodeRef of Class GUILabel = FindGUIControlByName(close, "text")
  buttonText.text = "Close"
  close.script = SYSTEM.EXEC.THISSCRIPT
.

shared function KeyPressedLeavingControl(c as NodeRef of Class GUIControl, keyCode as Integer) as Boolean
  if keyCode = 27
    destroyNode(c.rootParent())
    return true
  .
  color as NodeRef of Class GUITextInputBox = c//FindGUIControlByName(0, "tkr_colorpicker.tkr_diffuse")
  //$CHAT._GotChatMessage( color.value, "Global" )
  when c.name
    is "tkr_diffuse"
      if color.value = "DIFFUSE"
        target as NodeRef = $GameTarget.gtCurrentTarget
        if target != None
          where target is kindof HBNode
            $GUI.LaunchColorPickerDialogForControl(FindGUIControlByName(0, "tkr_colorpicker.tkr_diffuse"), "0,0,0,1")
            return true
          .
        .
      else
        target as NodeRef = $GameTarget.gtCurrentTarget
        if target != None
          target["DiffuseColor"] = color.value
        .
        color.value = "DIFFUSE"
        return false
      .
    .
    is "tkr_ambient"
      if color.value = "AMBIENT"
        target as NodeRef = $GameTarget.gtCurrentTarget
        if target != None
          where target is kindof HBNode
            $GUI.LaunchColorPickerDialogForControl(FindGUIControlByName(0, "tkr_colorpicker.tkr_ambient"), "0,0,0,1")
            return true
          .
        .
      else
        target as NodeRef = $GameTarget.gtCurrentTarget
        if target != None
          target["AmbientColor"] = color.value
        .
        color.value = "AMBIENT"
        return false
      .
    .
  .
 
  return false
.

shared function onButtonClick(button as NodeRef of Class _GUIButton, args references Class GUIMouseEvent)
  when button.name
    is "tkr_close"
      destroyNode(button.rootParent())
      return
    .
  .
.


to use this as is, copy the code, create a Client side script called TKR_ModelColorPicker , and paste this code into it.
compile it, and Submit it.

The script then needs to be called via whatever method you like (button/command etc)
This doesn't cover that.
You can call it from the Console panel with the following command:
Call TKR_ModelColorPicker creategui


Details:
This brings up a very very simple GUI with only two fields atm Diffuse and Ambient.
clicking on one of those fields, and hitting the ENTER key, will bring up the color picker GUI.
Selecting a color and closing the color picker will fill in the field with the values.  Hitting ENTER
AGAIN will set that value on your targeted model. 

NOT COVERED IN THIS CODE:
This code does not include any method of
targeting static models.  You would have to make alterations in the INput_Mouse script as well as
making sure your model is set to "MouseTargetable".   One could add an automatic targeting feature to this
that would set the model to targetable using raycast I think, I'd have to look.

Also not covered in this code is the call to the server to an UnTrusted Function to set the changes
PERMANENTLY on the model.  This code will only change the model on the client side, and will be lost
when you leave the area. 

When I get a chance , the plan is to add the ability to edit models using Dynamic Textures, just like the Character manager does for Characters. (skin morpher). 

if/when I can make any additions I'll post it here.
IF YOU WANT TO ADD TO THIS OR CHANGE IT  .... Feel free, and post your changes/suggestions here!



« Last Edit: Nov 18, 15, 10:22:07 AM by ToY-Krun »
Logged

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Static Model Tint GUI
« Reply #1 on: Nov 18, 15, 10:13:01 AM »

hrm just realized that the GameTarget class isn't a default class.. so you may or may not be using it.
changes will have to be made for targeting anyway, and it should be made so that it uses default
functions/methods to make it universally useable.

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Static Model Tint GUI
« Reply #2 on: Nov 18, 15, 02:29:37 PM »

Quote
hrm just realized that the GameTarget class isn't a default class.. so you may or may not be using it.
If you can identify where you assigned value to $GameTarget.gtCurrentTarget, that could help to point others in the right direction.  This is a good start, anyways.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

ToY-Krun

  • General Accounts
  • *
  • Posts: 677
  • Support Volunteer
    • View Profile
Re: Static Model Tint GUI
« Reply #3 on: Nov 18, 15, 02:42:35 PM »

target is assigned through a mouse click on an object, like targeting a player.  This was requested in chat, and the intent was to create a script which would allow editing textures and tints on static models, similar to the way you can on characters.  ours is a combined function with our editor, which handles tartgets/setting to targetable etc.

I was aiming for a Non class method of doing it but in reality it will require people to create at least one class and set it up to achieve this.  I'll leave this method, and add a class version which will include targeting as well as the additional features.  It also will require scripts on both server and client to handle the entire process.  The request is from non coders so it needs to be a simple set up  :D   When I get a chance, to many irons in the fire.
« Last Edit: Nov 18, 15, 03:03:18 PM by ToY-Krun »
Logged