Skip to content

Commit

Permalink
Use variant instead of any
Browse files Browse the repository at this point in the history
  • Loading branch information
ikt32 committed Dec 10, 2017
1 parent 00da3f4 commit a61461d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 32 deletions.
12 changes: 0 additions & 12 deletions InstructionalButton.cpp

This file was deleted.

5 changes: 3 additions & 2 deletions InstructionalButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
class InstructionalButton
{
public:
InstructionalButton();
~InstructionalButton();
InstructionalButton() { }

~InstructionalButton() { }
};

1 change: 0 additions & 1 deletion Scaleform.cpp

This file was deleted.

30 changes: 15 additions & 15 deletions Scaleform.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>
#include "inc/natives.h"
#include <vector>
#include <any>
#include <variant>

class ScaleformArgumentTXD {
public:
Expand All @@ -19,6 +19,7 @@ class ScaleformArgumentTXD {

class Scaleform
{
using ScaleArg = std::variant<std::string, int, float, double, bool, ScaleformArgumentTXD>;
public:
Scaleform(std::string scaleformID) {
m_handle = GRAPHICS::REQUEST_SCALEFORM_MOVIE((char *)scaleformID.c_str());
Expand All @@ -41,32 +42,31 @@ class Scaleform
return GRAPHICS::HAS_SCALEFORM_MOVIE_LOADED(m_handle);
}

void CallFunction(std::string function, std::vector<std::any> args = std::vector<std::any>{}) {
void CallFunction(std::string function, std::vector<ScaleArg> args = {}) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION(m_handle, (char *)function.c_str());
for (auto arg : args) {
if (!arg.has_value()) continue;
if (arg.type() == typeid(std::string)) {
if (std::holds_alternative<std::string>(arg)) {
GRAPHICS::BEGIN_TEXT_COMMAND_SCALEFORM_STRING("STRING");
UI::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME((char *)std::any_cast<std::string>(arg).c_str());
UI::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME((char *)std::get<std::string>(arg).c_str());
GRAPHICS::END_TEXT_COMMAND_SCALEFORM_STRING();
}
else if (arg.type() == typeid(int)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT(std::any_cast<int>(arg));
else if (std::holds_alternative<int>(arg)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT(std::get<int>(arg));
}
else if (arg.type() == typeid(float)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_FLOAT(std::any_cast<float>(arg));
else if (std::holds_alternative<float>(arg)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_FLOAT(std::get<float>(arg));

}
else if (arg.type() == typeid(double)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_FLOAT((float)std::any_cast<double>(arg));
else if (std::holds_alternative<double>(arg)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_FLOAT((float)std::get<double>(arg));

}
else if (arg.type() == typeid(bool)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_BOOL(std::any_cast<bool>(arg));
else if (std::holds_alternative<bool>(arg)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_BOOL(std::get<bool>(arg));

}
else if (arg.type() == typeid(ScaleformArgumentTXD)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_STRING((char *)std::any_cast<ScaleformArgumentTXD>(arg).Txd().c_str());
else if (std::holds_alternative<ScaleformArgumentTXD>(arg)) {
GRAPHICS::_PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_STRING((char *)std::get<ScaleformArgumentTXD>(arg).Txd().c_str());
}
else {

Expand Down
6 changes: 4 additions & 2 deletions menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ void Menu::EndMenu() {
instructionalButtonsScaleform.CallFunction("CREATE_CONTAINER");
instructionalButtonsScaleform.CallFunction("SET_DATA_SLOT", { 0, std::string(CONTROLS::GET_CONTROL_INSTRUCTIONAL_BUTTON(2, ControlPhoneSelect, 0)), std::string(UI::_GET_LABEL_TEXT("HUD_INPUT2")) });
instructionalButtonsScaleform.CallFunction("SET_DATA_SLOT", { 1, std::string(CONTROLS::GET_CONTROL_INSTRUCTIONAL_BUTTON(2, ControlPhoneCancel, 0)), std::string(UI::_GET_LABEL_TEXT("HUD_INPUT3")) });

instructionalButtonsScaleform.CallFunction("SET_DATA_SLOT", { 2, std::string(CONTROLS::GET_CONTROL_INSTRUCTIONAL_BUTTON(2, ControlPhoneUp, 0)), std::string("Up") });
instructionalButtonsScaleform.CallFunction("SET_DATA_SLOT", { 3, std::string(CONTROLS::GET_CONTROL_INSTRUCTIONAL_BUTTON(2, ControlPhoneDown, 0)), std::string("Down") });

//int count = 2;
//for (auto button : instructionalButtons) {
// if (button.ItemBind == null || MenuItems[CurrentSelection] == button.ItemBind) {
Expand All @@ -607,7 +609,7 @@ void Menu::EndMenu() {
// }
//}

instructionalButtonsScaleform.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", std::vector<std::any>{ -1 });
instructionalButtonsScaleform.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", { -1 });
instructionalButtonsScaleform.Render2D();

disableKeys();
Expand Down

0 comments on commit a61461d

Please sign in to comment.