C ++游戏修改 - 切换菜单选项

时间:2018-02-04 21:15:06

标签: c++

我正在为GTAV进行游戏修改。我试图在菜单本身中实现切换选项。到目前为止我有这个:

char* PlayerOptions[8] = {
    "Invisible",
    "Godmode",
    "No Ragdoll",
    "Super Jump",
    "Fast Run",
    "No Police",
    "Character Options >",
    "Cash Options >"
};

// ...

for (int i = 0; i < MenuSizes[selectedMenu]; i++) {
    if (i == selectedIndex) {
        // draw hovered option to screen
        DRAW_TEXT(PlayerOptions[i], 0.050, 0.150 + (0.1 * ((double)i / 3)), 0.35, 0.35, 0, false, false, false, false, selected_text_R, selected_text_G, selected_text_B, 255);
        DRAW_TEXT("OFF", 0.175, 0.150 + (0.1 * ((double)i / 3)), 0.25, 0.25, 0, false, false, false, false, 255, 255, 255, 255);
    } else {
        // draw non-hovered option to screen
        DRAW_TEXT(PlayerOptions[i], 0.050, 0.150 + (0.1 * ((double)i / 3)), 0.35, 0.35, 0, false, false, false, false, 255, 255, 255, 255);
        DRAW_TEXT("OFF", 0.175, 0.150 + (0.1 * ((double)i / 3)), 0.25, 0.25, 0, false, false, false, false, 255, 255, 255, 255);
    }
}

我正在寻找启用/禁用选项的方法,并在启用时将其显示在屏幕上。我考虑过这样的事情:

char* PlayerOptions[8] = {
                         // name, isEnabled, isSubmenu
    char* Invisible[3] = {"Invisible", false, false},
    char* Godmode[3] = {"Godmode", false, false},
    char* Ragdoll[3] = {"No Ragdoll", false, false},
    char* SuperJump[3] = {"Super Jump", false, false},
    char* FastRun[3] = {"Fast Run", false, false},
    char* NoPolice[3] = {"No Police", false, false},
    char* CharacterOptions[3] = {"Character Options", false, true},
    char* CashOptions[3] = {"Cash Options", false, true},
};

这样的事情是可能的,我将如何访问这些/更改这些值,例如当我使用菜单项时,如何将该项目的isEnabled更改为true

或者,如果有人对此有更好的建议,请建议他们!我正在拼命寻找答案,我已经找了好几天了!非常感谢!

修改

根据给定的评论,这就是我现在所拥有的:

struct PlayerOptions {
    char* name;
    int isEnabled;
    int isSubmenu;
};

1 个答案:

答案 0 :(得分:1)

您已使用C ++标记了该问题,但很明显您使用的是C语法,因此我将提供两个答案:一个使用C语法,另一个使用C ++

用C:

#include <stdio.h>

#define false 0
#define true 1

typedef struct
{
   char* name;
   short isEnabled;
   short isSubMenu;
} PlayerOption;

PlayerOption playerOptions[] = {
   { "Invisible",         false, false },
   { "Godmode",           false, false },
   { "No Ragdoll",        false, false },
   { "Super Jump",        false, false },
   { "Fast Run",          false, false },
   { "No Police",         false, false },
   { "Character Options", false, true  },
   { "Cash Options",      false, true  }
};

/* you could just use const int numPlayerOptions = 8 here instead... */
/* the advantage of this is that you don't need to change this line  */
/* when you change the array                                         */
const int numPlayerOptions = sizeof(playerOptions) / sizeof(PlayerOption);

int main()
{
   int i;

   /* update enabled value */
   playerOptions[3].isEnabled = true;

   /* print the array */
   for(i=0;i<numPlayerOptions;i++)
       printf("%s %s %s\n",
           playerOptions[i].name,
           playerOptions[i].isEnabled?"true":"false",
           playerOptions[i].isSubMenu?"true":"false"
       );

   return 0;
}

使用C ++:

#include <iostream>
#include <string>
#include <vector>

struct PlayerOption
{
   std::string name;
   bool isEnabled;
   bool isSubMenu;
};

std::vector<PlayerOption> playerOptions
{
   { "Invisible",         false, false },
   { "Godmode",           false, false },
   { "No Ragdoll",        false, false },
   { "Super Jump",        false, false },
   { "Fast Run",          false, false },
   { "No Police",         false, false },
   { "Character Options", false, true  },
   { "Cash Options",      false, true  }
};

int main()
{
   // update enabled value
   playerOptions[3].isEnabled = true;

   // print the vector
   for(PlayerOption option : playerOptions)
       std::cout << std::boolalpha
          << " " << option.name
          << " " << option.isEnabled
          << " " << option.isSubMenu
          << " " << std::endl;

   return 0;
}