Skip to content

Commit

Permalink
rmlui: Also ignore the first change event for the select form.
Browse files Browse the repository at this point in the history
This always sets the value, even when it hasn't changed, or sets it to
the wrong value.
  • Loading branch information
DolceTriade committed Aug 11, 2022
1 parent 622186c commit f5d89ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/cgame/rocket/rocketFormControlSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ Maryland 20850 USA.
class CvarElementFormControlSelect : public Rml::ElementFormControlSelect, public Rml::EventListener
{
public:
CvarElementFormControlSelect( const Rml::String &tag ) : Rml::ElementFormControlSelect( tag ), owner( nullptr ) { }
CvarElementFormControlSelect( const Rml::String &tag ) :
Rml::ElementFormControlSelect( tag ),
owner( nullptr ),
// Ignore the first value change since that is the one that is set by default.
ignore_value_change( true ) { }

virtual void OnAttributeChange( const Rml::ElementAttributes &changed_attributes )
{
Expand Down Expand Up @@ -93,6 +97,11 @@ class CvarElementFormControlSelect : public Rml::ElementFormControlSelect, publi
}
else if ( this == event.GetTargetElement() && event == "change" )
{
if ( ignore_value_change )
{
ignore_value_change = false;
return;
}
Cvar::SetValue( cvar.c_str(), GetValue().c_str() );
Cvar::AddFlags( cvar.c_str(), Cvar::USER_ARCHIVE );
}
Expand All @@ -108,19 +117,22 @@ class CvarElementFormControlSelect : public Rml::ElementFormControlSelect, publi
Rml::String value = e->GetAttribute<Rml::String>( "value", Rml::String() );
if ( value == cvarValue )
{
// If the selection is already correct, do not force set the cvar.
ignore_value_change = GetSelection() != i;
SetSelection( i );
return;
}
}
// No matches...Let's add an option for our current value.
Add( Str::Format( "Custom Value (%s)", cvarValue ), cvarValue, 0, false );
SetSelection(0);
SetSelection( 0 );
ignore_value_change = true;
}

private:
Rml::String cvar;
Rml::String type;
Rml::Element *owner;
bool ignore_value_change;
};

#endif

0 comments on commit f5d89ca

Please sign in to comment.