Custom Dev-tools Objects #24
timofey260
started this conversation in
Resources
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Custom dev tools objects
Summary
This page will try to teach you how to create custom dev-tools objects and make them work as well as show some ways to use already existing dev-tools representations for your needs
this tutorial might suck but i tried
full code will be available
probably need to do
how
To create custom devtools object you need 3 things:
PlacedObjectRepresentation
class what would be showed when you open devtoolsUpdatableAndDeletable
(or any of its children) class to do stuff on roomPlacedObject.Data
class to store any data you needWhile doing so, we would need 3-4 different hooks:
On.DevInterface.ObjectsPage.CreateObjRep
to displayPlacedObjectRepresentation
on dev-tools windowOn.Room.Loaded
to spawn our object to do stuffOn.PlacedObject.GenerateEmptyData
to make object have data we save and load(additionally,
On.DevInterface.ObjectsPage.DevObjectGetCategoryFromPlacedType
used to specify category on objects menu, or else it goes unsorted)1. Registering an object type
To create an object, we need to register it in exenum. better to do all the dev-tools specific hooks and stuff in separate static class
On booting up rw we can see that our custom dev-tool object can be accesed in Unsorted tab
Upon clicking, we spawned a handle that we can move around
2. Creating and hooking an object
This handle works great if we don't need to specify anything so let's create an UpdatableAndDeletable object that would be spawned when we load the room and throw us
Before building code, we should add hook that would actually add object to room
I modified DevtoolsInit class above and added Room_Loaded hook
When building and booting up the game we can see that object we placed throws us up

It works, but what if we want to store some data in it? or store more data? Then the next step is to create dev-tools representation for object
3. Creating and hooking representation
To create representation we just create c# class that is based of PlacedObjectRepresentation or its children
After creating representation class, we need to hook
On.DevInterface.ObjectsPage.CreateObjRep
to change representation of spawned dev-tools objectsi rewrote some of DevtoolsInit code again
The representation we currently have is simple handle we can move around(the same it was before)
Let's add another handle to our representation
Upon loading rw we can see that ourdev tools object now has 2 handles
So it works, when we move "main" handle, "second" handle moves with it, but if we move "second" handle, "main" one doesn't move
It's cool and all, but the position of handle doesn't get saved + our game object has no idea about handle existing + they don't look connected at all
Before going to next steps, it's better to remove custom objects from world so they wouldn't cause any crashes or freezes since we're going to make our object require data that file doesn't have
4. Creating and Hooking Save data
Let's fix first issue by creating
PlacedObject.Data
class to save and load dataTo Save and load data, we need to override
FromString
andToString
methodsThen we need to add hook that would apply
MyObjectData
toPlacedObject
with typemyObject
Again changing DevtoolsInit and adding
On.PlacedObject.GenerateEmptyData
hookAfter that, the last thing we need to do is add the way to update our handlePos with dev-tools object
To do so, we can get data value once we initiated dev-tools object and change it in any other time by overriding
Refresh
methodAlso we can add line between 2 handles
If you kept placed object saved as file up to this point, you probably unable to enter the world, because placed object tries to get data that doesn't exists
To fix this just remove it from settings file
And here we go. the object representation has line and second handle is stored in settings file when we press save button
By creating save data we're also allowing our game object to use that data, so let's make it throw our player in direction of second handle
5. Custom Panels
What if we wanted to have data that we can't just have as a vector handle?
Panels Allows us to change data by using ui blocks
Let's create panel class inside of our representation and also create a variable that would be changed based on panel buttons
First off, adding new data to our Data class(also make sure again to remove any myObject you created in world)
Then adding panel class and line from main handle to our panel
Now we need a way to change Data.mode somehow with panel
Signals
Signals are used to check specific actions of buttons and sliders. All we need to do is implement
IDevUISignals
interface on our panelWe have the
Signal
method that activates when button pressedthis is current panel class
now when spawning our object we can see that panel appeared too
When pressing button we can see that our number goes up to 4 and then back to 0
All the data gets saved and loaded just fine
Panels have a lot of potential. Since panels are uiNodes, that means that you can put panels inside of panels inside of panels and etc
Only the panel with
IDevUISignals
actually recieve all the signals which is good for panels in panelsPanel in panel
Let's create another Panel class near our normal panel and make so you can open and close our new panel when pressing a button
for sake of convenience we will call panel that spawns panel a "Parent" panel and pannel that gets spawned as "Child" parent
When loading into the game we can see that our panel now has a second button, called "open panel"
If we press a button, child panel appears that we can close by pressing "close" button
Sliders
Sliders are used for number input
To create slider, we need to create
Slider
class and override 2 methods:NubDragged
andRefresh
NubDragged
method changes value if we dragged the slider nubRefresh
method does refresh stuff and applies data value to sliderLet's change that we can pick mode by using both slider and button
And add slider to our panel's constructor
When we spawn our object we can see that slider appeared and we can move it to change mode

Slider is fixed to 5 different positions because we make it do so
Slider position gets saved because of
Data.mode
gets savedCustom category
If we have created a lot of dev-tools objects, it would be better to create custom category for all of them
To add custom category we need to hook
On.DevInterface.ObjectsPage.DevObjectGetCategoryFromPlacedType
Again we can add hook to
DevtoolsInit
Now all objects we put in
CategoryItems
will be displayed in our own categoryOther classes
For adding more new objects you should also change 3 other hooks i mentioned before
If you want to use different classes you should change data class too
GridRectObjectRepresentation
GridRectObjectRepresentation
is used for rectanglesIt is important to use
PlacedObject.GridRectObjectData
as data class or inherit from itRepresentation contains 2 handles and a rect sprite that can be dragged like windows select
ResizeableObjectRepresentation
ResizeableObjectRepresentation
is just 2 handles connected with a lineRing can be enabled as on the image
TileObjectRepresentation
TileObjectRepresentation
is just a handlePlacedObject.Data
is used as dataNothing special
QuadObjectRepresentation
QuadObjectRepresentation
is 4 handles, used for decals and other stuffUseful stuff
allstuff.zip - All that i've shown here
this page might require some fixes
Beta Was this translation helpful? Give feedback.
All reactions