Skip to content

Commit

Permalink
Merge pull request #5686 from MjnMixael/lua_add_scrollback
Browse files Browse the repository at this point in the history
Lua add scrollback
  • Loading branch information
TRBlount authored Oct 18, 2023
2 parents b3295e5 + b8728ed commit a9f5a11
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/hud/hudmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#define MAX_HUD_LINE_LEN 256 // maximum number of characters for a HUD message

// If these are changed, the lua 'addMessageToScrollback' method in mission.cpp should be updated.
#define HUD_SOURCE_COMPUTER 0
#define HUD_SOURCE_TRAINING 1
#define HUD_SOURCE_HIDDEN 2
Expand Down
69 changes: 69 additions & 0 deletions code/scripting/api/libs/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,75 @@ ADE_FUNC(sendPlainMessage,
return ADE_RETURN_TRUE;
}

ADE_FUNC(addMessageToScrollback,
l_Mission,
"string message, [team|enumeration source=HUD_SOURCE_COMPUTER]",
"Adds a string to the message log scrollback without sending it as a message first. Source should be either the team handle "
"or one of the SCROLLBACK_SOURCE enumerations.",
"boolean",
"true if successful, false otherwise")
{
const char* message = nullptr;
int team = -1;
enum_h* esp = nullptr;

int source = HUD_SOURCE_COMPUTER;
if (luacpp::convert::ade_odata_is_userdata_type(L, 2, l_Team)) {
if (!ade_get_args(L, "s|o", &message, l_Team.Get(&team))) {
return ADE_RETURN_FALSE;
} else {
source = HUD_team_get_source(team);
if (source < HUD_SOURCE_TEAM_OFFSET) {
LuaError(L, "Got team index %i. Team source may be invalid!", source);
return ADE_RETURN_FALSE;
}
}
} else {
if (!ade_get_args(L, "s|o", &message, l_Enum.GetPtr(&esp))) {
return ADE_RETURN_FALSE;
} else {
if (esp != nullptr) {
switch (esp->index) {
case LE_SCROLLBACK_SOURCE_COMPUTER:
source = HUD_SOURCE_COMPUTER;
break;
case LE_SCROLLBACK_SOURCE_TRAINING:
source = HUD_SOURCE_TRAINING;
break;
case LE_SCROLLBACK_SOURCE_HIDDEN:
source = HUD_SOURCE_HIDDEN;
break;
case LE_SCROLLBACK_SOURCE_IMPORTANT:
source = HUD_SOURCE_IMPORTANT;
break;
case LE_SCROLLBACK_SOURCE_FAILED:
source = HUD_SOURCE_FAILED;
break;
case LE_SCROLLBACK_SOURCE_SATISFIED:
source = HUD_SOURCE_SATISFIED;
break;
case LE_SCROLLBACK_SOURCE_COMMAND:
source = HUD_SOURCE_TERRAN_CMD;
break;
case LE_SCROLLBACK_SOURCE_NETPLAYER:
source = HUD_SOURCE_NETPLAYER;
break;
default:
LuaError(L, "Invalid enumeration used! Must be one of SCROLLBACK_SOURCE_*.");
return ADE_RETURN_FALSE;
}
}
}
}

if (message == nullptr)
return ADE_RETURN_FALSE;

HUD_add_to_scrollback(message, source);

return ADE_RETURN_TRUE;
}

ADE_FUNC(createShip,
l_Mission,
"[string Name, shipclass Class /* First ship class by default */, orientation Orientation=null, vector Position /* "
Expand Down
8 changes: 8 additions & 0 deletions code/scripting/api/objs/enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ const lua_enum_def_list Enumerations[] = {
{"HOTKEY_LINE_WING", LE_HOTKEY_LINE_WING, true},
{"HOTKEY_LINE_SHIP", LE_HOTKEY_LINE_SHIP, true},
{"HOTKEY_LINE_SUBSHIP", LE_HOTKEY_LINE_SUBSHIP, true},
{"SCROLLBACK_SOURCE_COMPUTER", LE_SCROLLBACK_SOURCE_COMPUTER, true},
{"SCROLLBACK_SOURCE_TRAINING", LE_SCROLLBACK_SOURCE_TRAINING, true},
{"SCROLLBACK_SOURCE_HIDDEN", LE_SCROLLBACK_SOURCE_HIDDEN, true},
{"SCROLLBACK_SOURCE_IMPORTANT", LE_SCROLLBACK_SOURCE_IMPORTANT, true},
{"SCROLLBACK_SOURCE_FAILED", LE_SCROLLBACK_SOURCE_FAILED, true},
{"SCROLLBACK_SOURCE_SATISFIED", LE_SCROLLBACK_SOURCE_SATISFIED, true},
{"SCROLLBACK_SOURCE_COMMAND", LE_SCROLLBACK_SOURCE_COMMAND, true},
{"SCROLLBACK_SOURCE_NETPLAYER", LE_SCROLLBACK_SOURCE_NETPLAYER, true},
};

const size_t Num_enumerations = sizeof(Enumerations) / sizeof(lua_enum_def_list);
Expand Down
8 changes: 8 additions & 0 deletions code/scripting/api/objs/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ enum lua_enum : int32_t {
LE_HOTKEY_LINE_WING,
LE_HOTKEY_LINE_SHIP,
LE_HOTKEY_LINE_SUBSHIP,
LE_SCROLLBACK_SOURCE_COMPUTER,
LE_SCROLLBACK_SOURCE_TRAINING,
LE_SCROLLBACK_SOURCE_HIDDEN,
LE_SCROLLBACK_SOURCE_IMPORTANT,
LE_SCROLLBACK_SOURCE_FAILED,
LE_SCROLLBACK_SOURCE_SATISFIED,
LE_SCROLLBACK_SOURCE_COMMAND,
LE_SCROLLBACK_SOURCE_NETPLAYER,
ENUM_NEXT_INDEX,
ENUM_COMBINATION,
ENUM_INVALID
Expand Down

0 comments on commit a9f5a11

Please sign in to comment.