SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SH5 Mods Workshop
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 03-23-10, 04:42 PM   #1
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,280
Downloads: 258
Uploads: 30
Default [TEC] Adding Items in the Menu Editor Tutorial

Hi I have been trying for the last few weeks to get my head around using the Editor and scripting to create useable object ingame for Modding.
I was getting nowhere fast till ThedarkWraith stepped in and offered me his help. I have used his expertise advice to create a Tutorial on getting started with Modding for Silent Hunter 5 via the use of The Built in Menu Editor, editing of cfg files and the generation of script files.

Most of the work here is from TheDarkWraith checking and correcting the work I was doing to learn these steps.
I have decided to do up what I've learned so far in the hope it well help others that were in the same situation as me (Banging there heads and getting nowhere fast).

First This is available to download in PDF format here: The PDF version includes some notes on top of Pics to show whats going on.
(Not in the online version)
http://rapidshare.com/files/367306675/Adding_Items_in_the_SH5_Editor_Tutorial.pdf
Also the files that were created in this tutorial are availabe here also:
http://rapidshare.com/files/367307917/Tutorial_Files.rar

Now then on to the Tutorial:



Adding Dial’s via the Menu Editor


Adding a single dial is a very simple evolution. If you want to teach yourself how do this:

using the Menu Editor: We want to add the heading/rudder dial to PageTDC.

In Page layout find the Heading group (it's under Group feedback)





Now copy its entire tree over to PageTDC. ( You can right click on Heading and select Copy then right click on Page TDC and select Paste.)
Now when I say the entire tree I'm talking about its anchor group. What denotes an anchor group? The big 'G' in the box. For heading it's 'Heading'. Now if you just copy over heading and think you got a dial you are wrong.
The 'whole' dial consists of 'Heading' - a Group, 'Rudder' - a Group, 'Toggle Rudder Heading Around' - a button, and 'Toggle Rudder Heading' - a button.
How do I know this? Two ways. One is that when I click on each one I get a yellow outline box on the editor that shows me graphically that it's part of the whole dial. Two, as I click on each one in the menu editor and I look in the zone section I see that the anchor refers to some part of the dial (it doesn't have to but doing so keeps the coherency of the object). You'll notice that the button 'Toggle Rudder Heading' anchor is 'Bkgr'.




You should end up with 2 Groups Rudder and Heading and 2 Buttons (Bt) Toggle Rudder Heading and Toggle Rudder Heading Around.
Now after you've copied all those items over to PageTDC you need to check their anchors. You'll notice that 'Toggle Rudder Heading' anchor is set to Null now. Why? Well before it referenced an item in Page layout but we're now in PageTDC so obviously that page doesn't exist here.



I would set the 'Toggle Rudder Heading' anchor to the object on PageTDC that you want this dial to be anchored to. Best thing to do is set the anchors of all the copied objects to reflect the values of the object you copied from in the other page. After setting all the anchors to the values they should be, moving the 'Toggle Rudder Heading' will cause the whole dial to move with it (if all the anchors are setup to reference one another in the object). If one of the anchors is set to reference some other object then that part won't move when you move 'Toggle Rudder Heading'.



Okay so now we have a new dial on PageTDC. But how do we get the game to update it? That's the easy part. Go back to the page you copied this new dial from. I'll use the Heading/Rudder here as an example. For the game to update a dial it needs 3 pieces of information: the dial, the current value, and the new value. Open up the file \data\Menu\cfg\Dials.cfg.



This is where we define the dials. Do a search for 'CompassFdbk'. This dial, [Dial22] is responsible for updating the 'Heading' dial in Page layout. How do I know this? Easy. Look at the values for CrtVal (current value), NewVal (new value), and Dial.
They start with 3F (0x just means this is a hex value). If we go back to the menu editor and go to Page layout we see that its ID is 3F000000.
If we find the values for CrtVal, NewVal, and Dial on Page layout we see that they reference objects of the dial in question (parts of the Heading dial).



Now if you correlate the CrtVal, NewVal, and Dial to the objects on the screen you can see what is controlling what. After you denote the correlation then add another entry to Dials.cfg at the bottom. Copy the whole entry for [Dial22] to the bottom and give it the next number in the chain (if you're using the stock file the next number will be 75. Now change the CrtVal, NewVal, and Dial IDs on this new entry to reflect the IDs of the dial on PageTDC.



But wait we're not done yet !!!
This dial has two states - Heading and Rudder. We have to create another entry in Dials.cfg. But what is this entry? Well I know that rudder needs to look like the entry [Dial21] (RudderFdbk). So copy the whole entry for [Dial21] to the bottom of Dials.cfg and give it the next number in the chain (would be 76 with stock file).
Now these names - RudderFdbk, SpeedFdbk, etc. can be anything you want to call them for your new dials. Change the IDs of the new dial entry to reflect the object in PageTDC (parts of the Rudder dial).



Don't forget to change the Dials.cfg's top number 'DialsNo=' to one plus the last entry in the chain of dials (its zero based). For our example that line should read 'DialsNo=77'. Save the file.



So far we have only edited 2 files:
Page TDC.ini - (\data\Menu\PagesPage TDC.ini) and Dials.cfg - (\data\Menu\cfg\Dials.cfg).
You can back these up into another folder for use in your own Mod.

Now before we can see our newly placed dial on screen we need a way for the page to tell the TDC to load up. To do that were going to need the help of Scripting.



End of Part 1



Last edited by reaper7; 03-23-10 at 06:00 PM. Reason: Changed Font Colour
reaper7 is offline   Reply With Quote
Old 03-23-10, 04:43 PM   #2
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,280
Downloads: 258
Uploads: 30
Default Part 2 Tutorial

Ok onto Scripting:

Open up an empty script like:- Periscope.py (\data\Scripts\Menu\Page Attack Periscope.py)
The reason for this is that we need to tell the periscope to display the TDC Page when we go to that station.

Note: Do not just copy and paste as the scripts will not work unless proper formatted, use of proper tabbing must be used (Not spaces).


This is what is displayed when opened

**IMPORTANT NOTE** Where [TAB] is shown in scripts is just to show here in the forum that a Tab is used to indentate that line in the script to not type in [TAB]. Tabulation is very importatnat in pyton scripting to work correctly.

def InitializeScript():
[TAB] pass

def StartGame():
[TAB] pass

def EndGame():
[TAB] pass

def UnloadScript():
[TAB] pass


Nowsave a copy of this as Page TDC.py, That will setup the TDC page to be used as an overlay screen that can be imported into other screens like the Periscope and UZO.

Next open up the Script file for the screen you want your new TDC script to open in.
For example if you want your Dial that you created in the TDC Page to show in the Periscope view, we need to tell the Attack Periscope script to import our TDC page as follows:
Ok lets open up (\data\Scripts\Menu\Page Attack Periscope.py) and change it to this:

Note: Do not just copy and paste as the scripts will not work unless proper formatted, use of proper tabbing must be used (Not spaces).


# Globals

ShowTDC = True

#Page attack periscope.py

from menu import *

def InitializeScript():
[TAB] Menu.PageActivated += Menu_PageActivated
[TAB] Menu.PageDeactivated += Menu_PageDeactivated
[TAB] Menu_PageActivated( Pageattackperiscope )

def StartGame():
[TAB] pass

def Menu_PageActivated( page ):
[TAB] if page == Pageattackperiscope:
[TAB] global ShowTDC
[TAB] if ShowTDC:
[TAB] [TAB] from PageTDC import PageTDC
[TAB] [TAB] PageTDC.Visible = True

def Menu_PageDeactivated( page ):
[TAB] if page == Pageattackperiscope:
[TAB] global ShowTDC
[TAB] if ShowTDC:
[TAB] [TAB] from PageTDC import PageTDC
[TAB] [TAB] PageTDC.Visible = False

def EndGame():
[TAB] pass

def UnloadScript():
[TAB] Menu.PageActivated -= Menu_PageActivated
[TAB] Menu.PageDeactivated -= Menu_PageDeactivated


Now what’s that all about then...... Let’s break up into all its bits:

First of all anything with a # in front of it is a comment and is ignored by the script.
e.g:
#Page attack periscope.py

This is just a note showing the name of the script.
Next we have:
# Globals

Here were going to set our Globals (Variables).
We have set up one global – ShowTDC and have given it the Value True (ShowTDC = True).
Next:
def InitializeScript():
[TAB] Menu.PageActivated += Menu_PageActivated
[TAB] Menu.PageDeactivated += Menu_PageDeactivated
[TAB] Menu_PageActivated( Pageattackperiscope )

This is just initialising the script.
def Menu_PageActivated( page ):
[TAB] if page == Pageattackperiscope:
[TAB] global ShowTDC
[TAB] if ShowTDC:
[TAB] [TAB] from PageTDC import PageTDC
[TAB] [TAB] PageTDC.Visible = True

Here we are telling are importing the Page TDC into the Page Attack Periscope and making it visible.
def Menu_PageDeactivated( page ):
[TAB] if page == Pageattackperiscope:
[TAB] global ShowTDC
[TAB] if ShowTDC:
[TAB] [TAB] from PageTDC import PageTDC
[TAB] [TAB] PageTDC.Visible = False

Now the opposite we are unloading The Page TDC and making it hidden, for when we close the Page Attack Periscope screen.
def UnloadScript():
[TAB] Menu.PageActivated -= Menu_PageActivated
[TAB] Menu.PageDeactivated -= Menu_PageDeactivated

And last of all we unload the script.

So far we have only edited 2 script files:
Page TDC.py - (\data\Scripts\Menu\Page TDC.py) and,
Page Attack Periscope - (\data\Scripts\Menu\Page Attack Periscope.py)
You can back these up into another folder for use in your own Mod.


Ok that’s done let’s launch the game and head to the Periscope to see our newly installed Dial.





Are we done yet? Nope. We have a new dial on PageTDC. The game will update it. But the game will not switch it between states - Heading/Rudder.
Why? Because the original dial's 'Toggle Rudder Heading' ID is hard coded in the game. The game recognizes 'events' from that ID and responds to them. Your new 'Toggle Rudder Heading' ID means nothing to it. So you have to get creative and create some python code to make it switch states!
Where do you place this python code? In PageTDC.py.
Reopen the Page TDC.py file from earlier and edit to look like the following:
#Page TDC.py

# Globals

HeadingShown = False

def InitializeScript():

[TAB] PageTDC_HeadingRudder.Visible = True
[TAB] PageTDC_HeadingRudder_ToggleRudderHeading.Clicked += ToggleRudderHeading
[TAB] PageTDC_HeadingRudder_ToggleRudderHeading.Visible = True
# set the dial to Heading mode
[TAB] ToggleRudderHeading( None )

def StartGame():
[TAB] pass

def ToggleRudderHeading( sender ):
[TAB] global HeadingShown
[TAB] HeadingShown = not HeadingShown
[TAB] PageTDC_HeadingRudder_Heading.Visible = HeadingShown
[TAB] for item in PageTDC_HeadingRudder_Heading.Controls:
[TAB] [TAB] item.Visible = HeadingShown
[TAB] PageTDC_HeadingRudder_Rudder.Visible = not HeadingShown
[TAB] for item in PageTDC_HeadingRudder_Rudder.Controls:
[TAB] [TAB] item.Visible = not HeadingShown

def EndGame():
[TAB] pass

def UnloadScript():
[TAB] PageTDC_HeadingRudder_ToggleRudderHeading.Clicked -= ToggleRudderHeading
[TAB] Pass


Now on going back into the Game you should have a fully toggle type Dial. Click in the bow just under the Dial to switch between Heading and Rudder.


If you run the game in windowed mode and set the following file to
allow developing mode:
(\*Your User Name*\Documents\SH5\data\cfg\Main.cfg)


[DEVELOPING]
Modding=Yes
MenuEditor=Yes
DebugScripts=Yes


Now if you run the Game you can right click the Top bar and select Scripting Editor, this allows you to edit your scripts ingame.



And here’s Your fully clickable dial in game on the Periscope Screen.





Good Luck. And keep the Mod’s flowing.



Written by Reaper7 for the Silent Hunter 5 Community.



This was all possible by the continued help of TheDarkWraith


Check out his excellent Mod’s on the SH5 Mod’s Forum.



Last edited by reaper7; 03-24-10 at 09:36 AM. Reason: Inserted The following [TAB] to show use of tabs
reaper7 is offline   Reply With Quote
Old 03-23-10, 05:49 PM   #3
bigboywooly
Rear Admiral
 
Join Date: Apr 2006
Location: Swindon, England
Posts: 10,151
Downloads: 35
Uploads: 0
Default

Interesting and thanx for posting
Will have a look through it

Though the black text in your post is impossible to read
Had to highlight it to see it
Guess we have different forum skins chosen
__________________


My mediafire page http://www.mediafire.com/?11eoq19bq9r41
bigboywooly is offline   Reply With Quote
Old 03-23-10, 05:56 PM   #4
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,280
Downloads: 258
Uploads: 30
Default

No problem can change the text colour -The PDF version is a more readable format and has some overlay text on the pics that didn't seem to convert from the PDF version when uploading to photobucket..
reaper7 is offline   Reply With Quote
Old 03-23-10, 08:10 PM   #5
TheDarkWraith
Black Magic
 
Join Date: Jun 2007
Posts: 11,962
Downloads: 147
Uploads: 5


Default

the only comment I have to make is Python is very picky about identation as it defines the flow. With no identation in the examples users will have a hard time getting files to work correctly. Othen than that
TheDarkWraith is offline   Reply With Quote
Old 03-24-10, 07:02 AM   #6
cothyso
Sailor man
 
Join Date: May 2005
Posts: 50
Downloads: 169
Uploads: 0
Default

Guys, do yourself a favour and forget editing in notepad.

Use UltraEdit, is the BEST editor out-there. And it also has language words for Python, as in it recognizes Python script files and displays them in a special way.

You can also write you own custom language files for it, as in a SH5 scripting language file.
cothyso is offline   Reply With Quote
Old 03-24-10, 08:57 AM   #7
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,280
Downloads: 258
Uploads: 30
Default

Quote:
Originally Posted by TheDarkWraith View Post
the only comment I have to make is Python is very picky about identation as it defines the flow. With no identation in the examples users will have a hard time getting files to work correctly. Othen than that
Yes its critiacl that indentation is used, I've noted that in the tutorial. The PDF version shows it correctly as does the screenshot. However the forum removed them when copying and pasting, I even tried putting them in with spaces but it removed them as well.

I recommend that ye download the Files in the rar files also as this has the actual files created with the proper indentation included.

I have reedited the script section above placing the word [TAB] to show where to place an indentation using the tab key on the keyboard.

Last edited by reaper7; 03-24-10 at 09:29 AM.
reaper7 is offline   Reply With Quote
Old 03-24-10, 09:14 AM   #8
gutted
The Old Man
 
Join Date: Apr 2005
Location: New Orleans, LA.
Posts: 1,353
Downloads: 470
Uploads: 10
Default

Quote:
Originally Posted by cothyso View Post
Guys, do yourself a favour and forget editing in notepad.

Use UltraEdit, is the BEST editor out-there. And it also has language words for Python, as in it recognizes Python script files and displays them in a special way.

You can also write you own custom language files for it, as in a SH5 scripting language file.

use notepad++, its free. and has all the features you'd want.
__________________

Solution Solver 2.3.2 - Visual Targeting Tools & Aids
gutted is offline   Reply With Quote
Old 03-24-10, 02:39 PM   #9
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,280
Downloads: 258
Uploads: 30
Default

Quote:
Originally Posted by cothyso View Post
Guys, do yourself a favour and forget editing in notepad.

Use UltraEdit, is the BEST editor out-there. And it also has language words for Python, as in it recognizes Python script files and displays them in a special way.

You can also write you own custom language files for it, as in a SH5 scripting language file.
Quote:
Originally Posted by gutted View Post
use notepad++, its free. and has all the features you'd want.
Cheers for the suggestions, will check em' both out.
reaper7 is offline   Reply With Quote
Old 03-25-10, 08:39 PM   #10
Notagged
Nub
 
Join Date: Mar 2010
Posts: 3
Downloads: 63
Uploads: 0
Default

Sorry for stupid question, but where i can find Menu Editor? Or how can i launch it?
Notagged is offline   Reply With Quote
Old 03-26-10, 05:26 AM   #11
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,280
Downloads: 258
Uploads: 30
Default

Quote:
Originally Posted by Notagged View Post
Sorry for stupid question, but where i can find Menu Editor? Or how can i launch it?
Go to the following file and open it up with a notepad or similar.

\Documents\SH5\data\cfg\Main.cfg

Change the following lines to whats shown here:

[DEVELOPING]
;Modding=Yes

;MenuEditor=Yes
;DebugScripts=Yes

To:

[DEVELOPING]
Modding=Yes
MenuEditor=Yes
DebugScripts=Yes

Now when you start the Game a dialog box will ask if you want to run the Editor.
Just select yes to run or No to run the game.
reaper7 is offline   Reply With Quote
Old 03-26-10, 06:03 AM   #12
Notagged
Nub
 
Join Date: Mar 2010
Posts: 3
Downloads: 63
Uploads: 0
Default

Thank you very much, reaper7! For manual and for help. It very useful.
Notagged is offline   Reply With Quote
Old 04-07-10, 12:07 AM   #13
vonTorpitz
Seaman
 
Join Date: Apr 2010
Location: an island in the Pacific
Posts: 42
Downloads: 23
Uploads: 0
Default

This is just what I what looking for to cut my modding teeth. Thanks a million guys.
__________________
God damn them all. I was told, we'd cruise the seas for American gold. We'd fire no guns, shed no tears. Now I'm a broken man on a Halifax pier.
The last of Barrett's privateers.

vonTorpitz is offline   Reply With Quote
Old 04-07-10, 01:14 AM   #14
karamazovnew
The Old Man
 
Join Date: Mar 2009
Location: Bucharest, Romania
Posts: 1,403
Downloads: 151
Uploads: 0


Default

Cool... bookmarked
karamazovnew is offline   Reply With Quote
Old 04-07-10, 01:36 AM   #15
kylania
Silent Hunter
 
Join Date: Aug 2006
Posts: 3,528
Downloads: 117
Uploads: 0
Default

Quote:
Originally Posted by reaper7 View Post
Cheers for the suggestions, will check em' both out.
Use ConTEXT!
__________________

kylania is offline   Reply With Quote
Reply

Tags
dials, editor, scripting, tutorial

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:10 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 1995- 2024 Subsim®
"Subsim" is a registered trademark, all rights reserved.