[MENUDEF] Toggle one option with another

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

[MENUDEF] Toggle one option with another

Post by NightFright »

So my MENUDEF looks like this:

Code: Select all

AddOptionMenu "HUDOptions"
{
   StaticText ""     
   Submenu "Fullscreen Status Bar", "FullscreenStatusbarOptions"
}

OptionValue "FS_Position"
{
   0, "Normal"
   1, "Split"
}

OptionValue "FS_Transparency"
{
   0, "Opaque"
   1, "Transparent"
}

OptionValue "FS_Boom"
{
   0, "Default"
   1, "Boom Style"
}

OptionValue "FS_Levelstats"
{
   0, "Hide"
   1, "Show"
}

OptionMenu "FullscreenStatusbarOptions"
{
   Position -15
   Title "Fullscreen Status Bar"
   StaticText ""
   StaticText "Customize the fullscreen status bar."
   StaticText "Resize automap status bar in 'Scaling Options'."
   StaticText ""
   ScaleSlider "Status Bar Scale", "hud_scale", -1.0, 8.0, 1.0, "$SCALEMNU_USEUI", "$SCALEMNU_USEFS"
   Option "Status Bar Positioning", "fullhud_split", "FS_Position"
   Option "Status Bar Rendering", "fullhud_trans", "FS_Transparency"
   StaticText ""
   IfGame(Doom, Chex) 
   { 
      Option "Doom Status Bar Colors", "fullhud_boom", "FS_Boom" 
   }
   Option "Level Stats Display", "fullhud_stats", "FS_Levelstats"
}
What I would like to do is to set am_drawmapback to 0 if you set fullhud_split to 1 - and vice versa. Can this be done and if so, how?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49223
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [MENUDEF] Toggle one option with another

Post by Graf Zahl »

You may have to write a special control item in ZScript for this. The CVARs do not know about any relationship so they cannot set each other.
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

Re: [MENUDEF] Toggle one option with another

Post by NightFright »

I see. I have recently written a script for a level stats counter with percentages, but this is apparently a different thing.

Would it be as easy as this (I know this is wrong and incomplete, but it's to show the general idea)?

Code: Select all

#library "amsplit"
#include "zcommon.acs"

script "automap_split" void
{
	if (fullhud_split = 0) { am_drawmapback = 1 }
	else { am_drawmapback = 0 }
}
What would be the general approach? I am not exactly versatile with ZDoom scripting, I am afraid...
User avatar
m8f
 
 
Posts: 1454
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)

Re: [MENUDEF] Toggle one option with another

Post by m8f »

Beware, the solution that is inferior to ZScript is described below. It may be easier to implement, though.

Part I. KEYCONF

Code: Select all

alias make_thing_1 "fullhud_split 0; am_drawmapback 1"
alias make_thing_2 "fullhud_split 1; am_drawmapback 0"
Here you define two command aliases. First action turns fullhud_split off and am_drawmapback on, the second action does the opposite.

Part II. MENUDEF

Code: Select all

Command "Make Thing 1", "make_thing_1"
Command "Make Thing 2", "make_thing_2"
StaticTextSwitchable "fullhud_split is off, am_drawmapback is on", "fullhud_split is on, am_drawmapback is off", "fullhud_split" 
Here, instead of defining an Option, you define two commands that call the corresponding aliases, and a text that displays either the first string or the second string, depending on the fullhud_split value.

Disadvantages:
1. If someone changes one of the mentioned CVars not by options menu, but through a console, the other CVar won't change automatically.

Edit: wait, if you have to variables that are always the opposite of each other, cannot you just replace one of the variables with the opposite value of the other variable?
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

Re: [MENUDEF] Toggle one option with another

Post by NightFright »

That's the idea. I want this since I am using a cover graphics to hide a gap in the automap status bar when using fullscreenoffsets mode, with status bar graphics aligned to the left and right (leaving a gap in the center). It's only needed for Heretic and Hexen since they use a textured automap background by default, not the black one from Doom which is easy to cover. I need to turn off the automap background to have just one color to deal with.

Basically it's like am_drawmapback would always be the opposite of fullhud_split. If one is 0, the other is always 1.
User avatar
m8f
 
 
Posts: 1454
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)

Re: [MENUDEF] Toggle one option with another

Post by m8f »

I should mention that a user can change black background automap color in options to any other color. And the illusion of gap covering will break. Maybe a classic continuous status bar is a better solution for automap.
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

Re: [MENUDEF] Toggle one option with another

Post by NightFright »

In Doom it's easy, but Heretic and Hexen are different calibers. I don't want to use a fullscreen automap either since that would mean having to set status bar height to 0, which is a crime. Besides that, I do not want to break the normal status bar.

At the end of the day, it's not an absolute must to have this work, but the idea was that you should have the same kind of status bar when playing fullscreen and when opening the automap.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: [MENUDEF] Toggle one option with another

Post by Pixel Eater »

I tried something to see if it works but it doesn't do anything, not even error out :?
It might work though if someone knows what's wrong?

Code: Select all

version "2.4"

class MapHudToggle : StaticEventHandler
{
	PlayerInfo plyr ;
	CVar hudsplit ;
	CVar mapback ;
	CVar toggle ;
	
	override void WorldTick()
	{
		plyr		= players[ consoleplayer ];
		hudsplit	= CVar.GetCvar( "fullhud_split", plyr );
		mapback	= CVar.GetCvar( "am_drawmapback", plyr );
		toggle		= CVar.GetCvar( "maphud_toggle", plyr );
		
		if( toggle.GetBool() == true )
		{
			if( hudsplit.GetInt() == 0 ) //fullhud_split has changed to 0
			{
				mapback.SetInt( 1 );
				toggle.SetBool( false );
			}
			else if( mapback.GetInt() == 1 ) //am_drawmapback has changed to 1
			{
				hudsplit.SetInt( 0 );
				toggle.SetBool( false );
			}
		}
		else
		{
			if( hudsplit.GetInt() == 1 ) //fullhud_split has changed to 1
			{
				mapback.SetInt( 0 );
				toggle.SetBool( true );
			}
			else if( mapback.GetInt() == 0 ) //am_drawmapback has changed to 0
			{
				hudsplit.SetInt( 1 );
				toggle.SetBool( true );
			}
		}
	}
}
You do not have the required permissions to view the files attached to this post.
Blue Shadow
Posts: 5039
Joined: Sun Nov 14, 2010 12:59 am

Re: [MENUDEF] Toggle one option with another

Post by Blue Shadow »

I imagine this is the problem or at least part of it: GZDoom doesn't allow you to change its own CVARs from non-menu code.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: [MENUDEF] Toggle one option with another

Post by Pixel Eater »

Aw shoot. Now I remember having that problem awhile back too :|

Return to “Scripting”