Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
C#/Lua: fixed InstructionalButtons bugs + add C# UIMenu functions.
  • Loading branch information
manups4e committed Jul 24, 2023
1 parent 1b58bae commit 4a2db4f
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 86 deletions.
12 changes: 6 additions & 6 deletions MenuExample/MenuExample.cs
Expand Up @@ -31,7 +31,6 @@ public void ExampleMenu()
exampleMenu.BuildingAnimation = MenuBuildingAnimation.LEFT_RIGHT;
exampleMenu.AnimationType = MenuAnimationType.BACK_INOUT;
exampleMenu.ScrollingType = ScrollingType.CLASSIC;

//exampleMenu.CounterColor = HudColor.HUD_COLOUR_PINK;
// let's add the menu to the Pool

Expand Down Expand Up @@ -477,7 +476,8 @@ public void ExampleMenu()
new InstructionalButton(Control.FrontendDown, "Accept only with Keyboard", PadCheck.Keyboard),
new InstructionalButton(Control.FrontendY, "Cancel only with GamePad", PadCheck.Controller),
new InstructionalButton(Control.FrontendX, Control.Detonate, "This will change button if you're using gamepad or keyboard"),
new InstructionalButton(new List<Control> { Control.MoveUpOnly, Control.MoveLeftOnly , Control.MoveDownOnly , Control.MoveRightOnly }, "Woow multiple buttons at once??")
new InstructionalButton(new List<Control> { Control.MoveUpOnly, Control.MoveLeftOnly , Control.MoveDownOnly , Control.MoveRightOnly }, "Woow multiple buttons at once??"),
new InstructionalButton(InputGroup.INPUTGROUP_LOOK, "InputGroup example")
};
ScaleformUI.ScaleformUI.Warning.ShowWarningWithButtons("This is the title", "This is the subtitle", "This is the prompt, press any button", buttons, "This is the error message, ScaleformUI Ver. 3.0");
ScaleformUI.ScaleformUI.Warning.OnButtonPressed += (button) =>
Expand All @@ -501,10 +501,10 @@ public void ExampleMenu()
};

customInstr.OnListSelected += (item, index) =>
{
if (ScaleformUI.ScaleformUI.InstructionalButtons.IsSaving) return;
ScaleformUI.ScaleformUI.InstructionalButtons.AddSavingText((LoadingSpinnerType)(index + 1), "I'm a saving text", 3000);
};
{
if (ScaleformUI.ScaleformUI.InstructionalButtons.IsSaving) return;
ScaleformUI.ScaleformUI.InstructionalButtons.AddSavingText((LoadingSpinnerType)(index + 1), "I'm a saving text", 3000);
};

// ====================================================================
// =------------------- [Notifications SubMenu] ----------------------=
Expand Down
10 changes: 5 additions & 5 deletions ScaleformUI_Csharp/LobbyMenu/MainView.cs
Expand Up @@ -43,11 +43,6 @@ public int FocusLevel
public bool TemporarilyHidden { get; set; }
public bool HideTabs { get; set; }
public bool DisplayHeader = true;
public List<InstructionalButton> InstructionalButtons = new()
{
new InstructionalButton(Control.PhoneSelect, UIMenu._selectTextLocalized),
new InstructionalButton(Control.PhoneCancel, UIMenu._backTextLocalized),
};

public MainView(string title) : this(title, "", "", "", "")
{
Expand All @@ -65,6 +60,11 @@ public MainView(string title, string subtitle, string sideTop, string sideMid, s
SideStringBottom = sideBot;
Index = 0;
TemporarilyHidden = false;
InstructionalButtons = new()
{
new InstructionalButton(Control.PhoneSelect, UIMenu._selectTextLocalized),
new InstructionalButton(Control.PhoneCancel, UIMenu._backTextLocalized),
};
_pause = ScaleformUI.PauseMenu;
}

Expand Down
1 change: 1 addition & 0 deletions ScaleformUI_Csharp/MenuHandler.cs
Expand Up @@ -102,6 +102,7 @@ public static void ProcessMouse()
/// </summary>
public static void Draw()
{
if (ScaleformUI.Warning.IsShowing || ScaleformUI.Warning.IsShowingWithButtons) return;
currentMenu?.Draw();
currentBase?.Draw();
}
Expand Down
14 changes: 6 additions & 8 deletions ScaleformUI_Csharp/PauseMenu/TabView.cs
Expand Up @@ -68,14 +68,6 @@ public int FocusLevel
public bool HideTabs { get; set; }
public bool DisplayHeader = true;

public List<InstructionalButton> InstructionalButtons = new()
{
new InstructionalButton(Control.PhoneSelect, UIMenu._selectTextLocalized),
new InstructionalButton(Control.PhoneCancel, UIMenu._backTextLocalized),
new InstructionalButton(InputGroup.INPUTGROUP_FRONTEND_BUMPERS, _browseTextLocalized),
};


internal PauseMenuScaleform _pause;
internal bool _loaded;
internal readonly static string _browseTextLocalized = Game.GetGXTEntry("HUD_INPUT1C");
Expand Down Expand Up @@ -107,6 +99,12 @@ public TabView(string title, string subtitle, string sideTop, string sideMid, st
index = 0;
FocusLevel = 0;
TemporarilyHidden = false;
InstructionalButtons = new()
{
new InstructionalButton(Control.PhoneSelect, UIMenu._selectTextLocalized),
new InstructionalButton(Control.PhoneCancel, UIMenu._backTextLocalized),
new InstructionalButton(InputGroup.INPUTGROUP_FRONTEND_BUMPERS, _browseTextLocalized),
};
_pause = ScaleformUI.PauseMenu;
}

Expand Down
2 changes: 2 additions & 0 deletions ScaleformUI_Csharp/PauseMenuBase.cs
Expand Up @@ -19,6 +19,8 @@ public virtual bool Visible
public bool CanPlayerCloseMenu = true;
private bool visible;

public List<InstructionalButton> InstructionalButtons { get; set; }

public virtual void ProcessControls()
{

Expand Down
Expand Up @@ -395,6 +395,7 @@ internal void UpdateButtons()
/// </summary>
public void Draw()
{
API.SetScriptGfxDrawBehindPausemenu(true);
_sc.Render2D();
}

Expand Down Expand Up @@ -452,7 +453,7 @@ internal void Update()
public static bool IsControlJustPressed(Control control, PadCheck keyboardOnly = PadCheck.Any) => Game.IsControlJustPressed(2, control) && (keyboardOnly == PadCheck.Keyboard ? API.IsUsingKeyboard(2) : keyboardOnly != PadCheck.Controller || !API.IsUsingKeyboard(2));

/// <summary>
/// Updates the instructional button text.
/// Updates the instructional button.
/// </summary>
public void ForceUpdate() => _changed = true;
}
Expand Down
16 changes: 13 additions & 3 deletions ScaleformUI_Csharp/Scaleforms/PopupWarning/PopupWarning.cs
Expand Up @@ -96,19 +96,29 @@ public async void ShowWarningWithButtons(string title, string subtitle, string p
_disableControls = true;
_buttonList = buttons;
if (buttons == null || buttons.Count == 0) return;
ScaleformUI.InstructionalButtons.SetInstructionalButtons(_buttonList);
ScaleformUI.InstructionalButtons.UseMouseButtons = true;
ScaleformUI.InstructionalButtons.ControlButtons.ForEach(x => x.OnControlSelected += X_OnControlSelected);
ScaleformUI.InstructionalButtons.SetInstructionalButtons(_buttonList);
ScaleformUI.InstructionalButtons.ControlButtons.ForEach(x => x.OnControlSelected += OnControlSelected);
_sc.CallFunction("SHOW_POPUP_WARNING", 1000, title, subtitle, prompt, showBackground, (int)type, errorMsg);
}

private void X_OnControlSelected(InstructionalButton control)
private void OnControlSelected(InstructionalButton control)
{
Dispose();
OnButtonPressed?.Invoke(control);
ScaleformUI.InstructionalButtons.ClearButtonList();
ScaleformUI.InstructionalButtons.UseMouseButtons = false;
OnButtonPressed = null;
if (MenuHandler.CurrentMenu != null)
{
if (MenuHandler.CurrentMenu.InstructionalButtons.Count > 0)
ScaleformUI.InstructionalButtons.SetInstructionalButtons(MenuHandler.CurrentMenu.InstructionalButtons);
}
else if (MenuHandler.currentBase != null)
{
if (MenuHandler.currentBase.InstructionalButtons.Count > 0)
ScaleformUI.InstructionalButtons.SetInstructionalButtons(MenuHandler.currentBase.InstructionalButtons);
}
}

internal void Update()
Expand Down
6 changes: 3 additions & 3 deletions ScaleformUI_Csharp/Scaleforms/ScaleformUI/ScaleformUI.cs
Expand Up @@ -61,13 +61,13 @@ public ScaleformUI()

private async Task ScaleformUIThread_Tick()
{
if (InstructionalButtons._sc != null && (InstructionalButtons.ControlButtons != null && InstructionalButtons.ControlButtons.Count != 0) || InstructionalButtons.IsSaving)
InstructionalButtons.Update();
if (MenuHandler.ableToDraw && !(API.IsWarningMessageActive() || Warning.IsShowing))
MenuHandler.ProcessMenus();
if (Game.IsPaused) return;
if (Warning._sc != null)
Warning.Update();
if (InstructionalButtons._sc != null && (InstructionalButtons.ControlButtons != null && InstructionalButtons.ControlButtons.Count != 0) || InstructionalButtons.IsSaving)
InstructionalButtons.Update();
if (Game.IsPaused) return;
if (MedMessageInstance._sc != null)
MedMessageInstance.Update();
if (BigMessageInstance._sc != null)
Expand Down
100 changes: 40 additions & 60 deletions ScaleformUI_Csharp/UIMenu.cs
Expand Up @@ -1168,46 +1168,6 @@ public UIMenu(string title, string subtitle, PointF offset, string spriteLibrary

#endregion

#region Static Methods
/// <summary>
/// Toggles the availability of the controls.
/// It does not disable the basic movement and frontend controls.
/// </summary>
/// <param name="enable"></param>
/// <param name="toggle">If we want to enable or disable the controls.</param>
[Obsolete("Use Controls.Toggle instead.", true)]
public static void DisEnableControls(bool toggle) => Controls.Toggle(toggle);

/// <summary>
/// Returns the 1080pixels-based screen resolution while mantaining current aspect ratio.
/// </summary>
[Obsolete("Use ScreenTools.ResolutionMaintainRatio instead.", true)]
public static SizeF GetScreenResolutionMaintainRatio() => ScreenTools.ResolutionMaintainRatio;

/// <summary>
/// ScreenTools.ResolutionMaintainRatio for providing backwards compatibility.
/// </summary>
/// <returns></returns>
[Obsolete("Use ScreenTools.ResolutionMaintainRatio instead.", true)]
public static SizeF GetScreenResiolutionMantainRatio() => ScreenTools.ResolutionMaintainRatio;

/// <summary>
/// Chech whether the mouse is inside the specified rectangle.
/// </summary>
/// <param name="topLeft">Start point of the rectangle at the top left.</param>
/// <param name="boxSize">size of your rectangle.</param>
/// <returns>true if the mouse is inside of the specified bounds, false otherwise.</returns>
[Obsolete("Use ScreenTools.IsMouseInBounds instead.", true)]
public static bool IsMouseInBounds(Point topLeft, Size boxSize) => ScreenTools.IsMouseInBounds(topLeft, boxSize);

/// <summary>
/// Returns the safezone bounds in pixel, relative to the 1080pixel based system.
/// </summary>
[Obsolete("Use ScreenTools.SafezoneBounds instead.", true)]
public static Point GetSafezoneBounds() => ScreenTools.SafezoneBounds;

#endregion

#region Public Methods

public async Task FadeOutMenu()
Expand Down Expand Up @@ -1247,6 +1207,27 @@ public async Task FadeInItems()
} while (isFading);
}

public void AddInstructionalButton(InstructionalButton button)
{
InstructionalButtons.Add(button);
if (Visible && !(ScaleformUI.Warning.IsShowing || ScaleformUI.Warning.IsShowingWithButtons))
ScaleformUI.InstructionalButtons.SetInstructionalButtons(InstructionalButtons);
}

public void RemoveInstructionalButton(InstructionalButton button)
{
if (InstructionalButtons.Contains(button))
InstructionalButtons.Remove(button);
if (Visible && !(ScaleformUI.Warning.IsShowing || ScaleformUI.Warning.IsShowingWithButtons))
ScaleformUI.InstructionalButtons.SetInstructionalButtons(InstructionalButtons);
}

public void RemoveInstructionalButton(int index)
{
if (index < 0 || index >= InstructionalButtons.Count)
throw new ArgumentOutOfRangeException("ScaleformUI: Cannot remove with an index less than 0 or more than the count of actual instructional buttons");
RemoveInstructionalButton(InstructionalButtons[index]);
}
/// <summary>
/// Change the menu's width. The width is calculated as DefaultWidth + WidthOffset, so a width offset of 10 would enlarge the menu by 10 pixels.
/// </summary>
Expand Down Expand Up @@ -1781,25 +1762,26 @@ public async void ProcessMouse()

public async void GoBack(bool playSound = true)
{
if (playSound)
Game.PlaySound(AUDIO_BACK, AUDIO_LIBRARY);
await FadeOutMenu();
if (BreadcrumbsHandler.CurrentDepth == 0)
if (CanPlayerCloseMenu)
{
if (CanPlayerCloseMenu)
if (playSound)
Game.PlaySound(AUDIO_BACK, AUDIO_LIBRARY);
await FadeOutMenu();
if (BreadcrumbsHandler.CurrentDepth == 0)
{
Visible = false;
BreadcrumbsHandler.Clear();
ScaleformUI.InstructionalButtons.ClearButtonList();
}
else
{
BreadcrumbsHandler.SwitchInProgress = true;
UIMenu prevMenu = BreadcrumbsHandler.PreviousMenu;
BreadcrumbsHandler.Backwards();
Visible = false;
prevMenu.Visible = true;
BreadcrumbsHandler.SwitchInProgress = false;
}
}
else
{
BreadcrumbsHandler.SwitchInProgress = true;
UIMenu prevMenu = BreadcrumbsHandler.PreviousMenu;
BreadcrumbsHandler.Backwards();
Visible = false;
prevMenu.Visible = true;
BreadcrumbsHandler.SwitchInProgress = false;
}
}

Expand Down Expand Up @@ -2197,12 +2179,10 @@ public bool Visible
else
{
canBuild = false;
FadeOutMenu();
MenuCloseEv(this);
MenuHandler.ableToDraw = false;
MenuHandler.currentMenu = null;
ScaleformUI._ui.CallFunction("CLEAR_ALL");
ScaleformUI.InstructionalButtons.ClearButtonList();
}
if (!value) return;
if (!ResetCursorOnOpen) return;
Expand Down Expand Up @@ -2606,10 +2586,10 @@ public bool MouseControlsEnabled
}
}

public bool CanPlayerCloseMenu
{
public bool CanPlayerCloseMenu
{
get => canPlayerCloseMenu;
set
set
{
canPlayerCloseMenu = value;
if (value)
Expand All @@ -2631,7 +2611,7 @@ public bool CanPlayerCloseMenu
{
ScaleformUI.InstructionalButtons.SetInstructionalButtons(InstructionalButtons);
}
}
}
}

#endregion
Expand Down
6 changes: 6 additions & 0 deletions ScaleformUI_Lua/src/base/UIMenu.lua
Expand Up @@ -1496,6 +1496,9 @@ end
function UIMenu:AddInstructionButton(button)
if type(button) == "table" then
self.InstructionalButtons[#self.InstructionalButtons + 1] = button
if self:Visible() and not ScaleformUI.Scaleforms.Warning:IsShowing() then
ScaleformUI.Scaleforms.InstructionalButtons:SetInstructionalButtons(self.InstructionalButtons)
end
end
end

Expand All @@ -1516,6 +1519,9 @@ function UIMenu:RemoveInstructionButton(button)
end
end
end
if self:Visible() and not ScaleformUI.Scaleforms.Warning:IsShowing() then
ScaleformUI.Scaleforms.InstructionalButtons:SetInstructionalButtons(self.InstructionalButtons)
end
end

---AddEnabledControl
Expand Down
14 changes: 14 additions & 0 deletions ScaleformUI_Lua/src/scaleforms/Warning/WarningHandler.lua
Expand Up @@ -24,6 +24,10 @@ function WarningInstance:IsShowing()
return self._sc ~= nil
end

function WarningInstance:IsShowingWithButtons()
return self._disableControls
end

---Loads the warning scaleform
---@return promise
function WarningInstance:Load()
Expand Down Expand Up @@ -132,8 +136,18 @@ function WarningInstance:Update()
then
self.OnButtonPressed(v)
self:Dispose()

ScaleformUI.Scaleforms.InstructionalButtons:ClearButtonList()
ScaleformUI.Scaleforms.InstructionalButtons.UseMouseButtons = false
if MenuHandler._currentMenu ~= nil then
if #MenuHandler._currentMenu.InstructionalButtons > 0 then
ScaleformUI.Scaleforms.InstructionalButtons:SetInstructionalButtons(MenuHandler._currentMenu.InstructionalButtons)
end
elseif MenuHandler._currentPauseMenu ~= nil then
if #MenuHandler._currentPauseMenu.InstructionalButtons > 0 then
ScaleformUI.Scaleforms.InstructionalButtons:SetInstructionalButtons(MenuHandler._currentPauseMenu.InstructionalButtons)
end
end
end
end
end
Expand Down

0 comments on commit 4a2db4f

Please sign in to comment.