Animated Menu Background: Difference between revisions
GamerDude27 (talk | contribs) m (More accurately represented "Problem 4") |
GamerDude27 (talk | contribs) (Squashed some problems, moved to "base" instead of SDK, etc.) |
||
Line 1: | Line 1: | ||
{{todo|This implementation has | {{todo|This implementation has an unsolved issue, please check out "A Deal Breaker" at the bottom of the page.}} | ||
Line 36: | Line 36: | ||
Then at the bottom of the '''PostInit()''' function, add this: | Then at the bottom of the '''PostInit()''' function, add this: | ||
<pre> | <pre> | ||
SwapDisconnectCommand(); | |||
</pre> | </pre> | ||
Now head over to ''' | Now head over to '''baseviewport.cpp''', and add this at the top: | ||
<pre> | <pre> | ||
#include "../menu_background.h" | |||
#include " | |||
</pre> | </pre> | ||
In the same file, add this in the constructor ('''CBaseViewport::CBaseViewport()'''): | |||
<pre> | <pre> | ||
m_pMainMenuPanel = NULL; | |||
</pre> | </pre> | ||
Add this in the destructor ('''CBaseViewport::~CBaseViewport()'''): | |||
<pre> | <pre> | ||
if ( !m_bHasParent && m_pMainMenuPanel ) | |||
{ | { | ||
m_pMainMenuPanel | m_pMainMenuPanel->MarkForDeletion(); | ||
} | } | ||
m_pMainMenuPanel = NULL; | |||
</pre> | |||
Add this in the '''Start''' function ('''CBaseViewport::Start(...)'''): | |||
<pre> | |||
m_pMainMenuPanel = new CMainMenu( NULL, NULL ); | |||
m_pMainMenuPanel->SetZPos( 500 ); | |||
m_pMainMenuPanel->SetVisible( false ); | |||
m_pMainMenuPanel->StartVideo(); | |||
</pre> | </pre> | ||
Add this in the '''OnScreenSizeChanged''' function ('''CBaseViewport::OnScreenSizeChanged()'''): | |||
<pre> | <pre> | ||
bool bRestartMainMenuVideo = false; | |||
if (m_pMainMenuPanel) | |||
bRestartMainMenuVideo = m_pMainMenuPanel->IsVideoPlaying(); | |||
BaseClass::OnScreenSizeChanged(iOldWide, iOldTall); | |||
m_pMainMenuPanel = new CMainMenu( NULL, NULL ); | |||
m_pMainMenuPanel->SetZPos( 500 ); | |||
m_pMainMenuPanel->SetVisible( false ); | |||
if (bRestartMainMenuVideo) | |||
m_pMainMenuPanel->StartVideo(); | |||
</pre> | </pre> | ||
Add this in the '''RemoveAllPanels''' function ('''CBaseViewport::RemoveAllPanels( void )'''): | |||
<pre> | <pre> | ||
if (m_pMainMenuPanel) | |||
{ | { | ||
m_pMainMenuPanel->MarkForDeletion(); | |||
m_pMainMenuPanel = NULL; | |||
} | } | ||
</pre> | </pre> | ||
Below the '''GetDeathMessageStartHeight( void )''' function add these: | |||
<pre> | <pre> | ||
void | void CBaseViewport::StartMainMenuVideo() | ||
{ | { | ||
if (m_pMainMenuPanel) | if (m_pMainMenuPanel) | ||
Line 121: | Line 96: | ||
} | } | ||
void | void CBaseViewport::StopMainMenuVideo() | ||
{ | { | ||
if (m_pMainMenuPanel) | if (m_pMainMenuPanel) | ||
Line 128: | Line 103: | ||
</pre> | </pre> | ||
Now head over to ''' | Now head over to '''baseviewport.h''', add these: | ||
<pre> | <pre> | ||
void StartMainMenuVideo(); | void StartMainMenuVideo(); | ||
void StopMainMenuVideo(); | void StopMainMenuVideo(); | ||
Line 153: | Line 110: | ||
Below | Below | ||
<pre> | <pre> | ||
virtual int GetDeathMessageStartHeight( void ); | |||
</pre> | </pre> | ||
After the last function under '''public:''', add: | After the last function under '''public:''', add: | ||
Line 167: | Line 120: | ||
</pre> | </pre> | ||
Now head over to '''convar.h''', and make this public (protected | Now head over to '''convar.h''', and make this public (protected -> public): | ||
<pre> | <pre> | ||
protected: | protected: | ||
Line 175: | Line 128: | ||
== What Next? == | == What Next? == | ||
=== The Bink File === | |||
Now that you're done with the implementation, you'll need a .bik file to play as your background. | Now that you're done with the implementation, you'll need a .bik file to play as your background. | ||
Line 183: | Line 137: | ||
Once you've got your .bik file ready, rename it to '''mainmenu.bik''', and place it in your mod's media folder. If a media folder doesn't exist, create one. | Once you've got your .bik file ready, rename it to '''mainmenu.bik''', and place it in your mod's media folder. If a media folder doesn't exist, create one. | ||
== The | === The Chapter Images === | ||
You might notice that your chapter images are all white now, this can be fixed by adding this to your to your chapter's VMT file: | |||
<pre> | <pre> | ||
"$ignorez" "1" | |||
</pre> | </pre> | ||
Example of working VMT chapter file: | |||
<pre> | <pre> | ||
"UnlitGeneric" | |||
{ | { | ||
"$baseTexture" "VGUI/chapters/chapterX" | |||
"$vertexalpha" 1 | |||
"$gammaColorRead" "1" | |||
"$linearWrite" "1" | |||
"$ignorez" "1" | |||
} | } | ||
</pre> | </pre> | ||
<gallery caption="Left: $ignorez 0 | Right: $ignorez 1" widths="600" heights="318px" perrow="2" mode="packed"> | |||
File:AnimatedMainMenuBackground-issue02.png | |||
File:AnimatedMainMenuBackground-issue02-fixed-single.png | |||
</gallery> | |||
== | == A Deal Breaker == | ||
Once this is implemented, you'll notice that your main menu's title text is gone | Once this is implemented, you'll notice that your main menu's title text is gone. | ||
If anyone knows how to get | If anyone knows how to get this issues fixed, please contact me on Discord at [https://discordapp.com/users/200767135524323329/ Ian B.#8678], and I'll edit this page with the fix applied! | ||
<gallery widths="800px" heights="600px" perrow=" | <gallery widths="800px" heights="600px" perrow="1" mode="nolines"> | ||
File:AnimatedMainMenuBackground-issue01.gif | File:AnimatedMainMenuBackground-issue01.gif | ||
</gallery> | </gallery> | ||
Line 285: | Line 175: | ||
This is currently only tested on the SP branch of Source SDK 2013. The MP branch and Source SDK 2007 remains untested as of writing this article. | This is currently only tested on the SP branch of Source SDK 2013. The MP branch and Source SDK 2007 remains untested as of writing this article. | ||
== Special Thanks == | |||
Special thanks to OzxyBox, Taz and Gocnak from the Source Modding Community for solving some of the problems this implementation was facing! | |||
[[Category:Programming]] | [[Category:Programming]] | ||
[[Category:Free source code]] | [[Category:Free source code]] |
Revision as of 21:41, 7 September 2018
What Is This?
This implementation allows you to use a .bik file as your main menu's background. Similar to what's seen in Left 4 Dead 2 and Portal 2.
- Examples
The Implementation
First off you'll need these two files:
Which you'll put into src/game/client/
Once that's done, open up cdll_client_int.cpp and add this:
void SwapDisconnectCommand();
Above
void CHLClient::PostInit()
Then at the bottom of the PostInit() function, add this:
SwapDisconnectCommand();
Now head over to baseviewport.cpp, and add this at the top:
#include "../menu_background.h"
In the same file, add this in the constructor (CBaseViewport::CBaseViewport()):
m_pMainMenuPanel = NULL;
Add this in the destructor (CBaseViewport::~CBaseViewport()):
if ( !m_bHasParent && m_pMainMenuPanel ) { m_pMainMenuPanel->MarkForDeletion(); } m_pMainMenuPanel = NULL;
Add this in the Start function (CBaseViewport::Start(...)):
m_pMainMenuPanel = new CMainMenu( NULL, NULL ); m_pMainMenuPanel->SetZPos( 500 ); m_pMainMenuPanel->SetVisible( false ); m_pMainMenuPanel->StartVideo();
Add this in the OnScreenSizeChanged function (CBaseViewport::OnScreenSizeChanged()):
bool bRestartMainMenuVideo = false; if (m_pMainMenuPanel) bRestartMainMenuVideo = m_pMainMenuPanel->IsVideoPlaying(); BaseClass::OnScreenSizeChanged(iOldWide, iOldTall); m_pMainMenuPanel = new CMainMenu( NULL, NULL ); m_pMainMenuPanel->SetZPos( 500 ); m_pMainMenuPanel->SetVisible( false ); if (bRestartMainMenuVideo) m_pMainMenuPanel->StartVideo();
Add this in the RemoveAllPanels function (CBaseViewport::RemoveAllPanels( void )):
if (m_pMainMenuPanel) { m_pMainMenuPanel->MarkForDeletion(); m_pMainMenuPanel = NULL; }
Below the GetDeathMessageStartHeight( void ) function add these:
void CBaseViewport::StartMainMenuVideo() { if (m_pMainMenuPanel) m_pMainMenuPanel->StartVideo(); } void CBaseViewport::StopMainMenuVideo() { if (m_pMainMenuPanel) m_pMainMenuPanel->StopVideo(); }
Now head over to baseviewport.h, add these:
void StartMainMenuVideo(); void StopMainMenuVideo();
Below
virtual int GetDeathMessageStartHeight( void );
After the last function under public:, add:
private: class CMainMenu* m_pMainMenuPanel;
Now head over to convar.h, and make this public (protected -> public):
protected: virtual void Create( const char *pName, const char *pHelpString = 0, int flags = 0 );
What Next?
The Bink File
Now that you're done with the implementation, you'll need a .bik file to play as your background.
I won't show you how to make your own .bik file, but I can recommend following this guide for that:
Once you've got your .bik file ready, rename it to mainmenu.bik, and place it in your mod's media folder. If a media folder doesn't exist, create one.
The Chapter Images
You might notice that your chapter images are all white now, this can be fixed by adding this to your to your chapter's VMT file:
"$ignorez" "1"
Example of working VMT chapter file:
"UnlitGeneric" { "$baseTexture" "VGUI/chapters/chapterX" "$vertexalpha" 1 "$gammaColorRead" "1" "$linearWrite" "1" "$ignorez" "1" }
- Left: $ignorez 0 | Right: $ignorez 1
A Deal Breaker
Once this is implemented, you'll notice that your main menu's title text is gone.
If anyone knows how to get this issues fixed, please contact me on Discord at Ian B.#8678, and I'll edit this page with the fix applied!
Conclusion
And that's it, try launching your mod to see if it works!
This is currently only tested on the SP branch of Source SDK 2013. The MP branch and Source SDK 2007 remains untested as of writing this article.
Special Thanks
Special thanks to OzxyBox, Taz and Gocnak from the Source Modding Community for solving some of the problems this implementation was facing!