Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/DialogueEditor/components/Dropdown/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
local root = script.Parent.Parent.Parent;
local React = require(root.roblox_packages.react);
local useStudioColors = require(root.DialogueEditor.hooks.useStudioColors);
local VirtualService = require(root.VirtualService);

export type DropdownProps = {
text: string;
Expand All @@ -25,6 +26,26 @@ local function Dropdown(props: DropdownProps)
local isOpen = props.isOpen;
local setIsOpen = props.setIsOpen;
local layoutOrder = props.layoutOrder or 0;
local toggleButtonRef = React.useRef(nil);

React.useEffect(function()

local toggleButton = toggleButtonRef.current;
assert(toggleButton, "Toggle button reference is nil.");

local connection = VirtualService.events.GuiButton.Activated:getSignal(toggleButton):Connect(function()

setIsOpen(not isOpen);

end);

return function()

connection:Disconnect();

end;

end, {isOpen :: unknown, setIsOpen});

return React.createElement("Frame", {
BackgroundTransparency = 1;
Expand All @@ -43,9 +64,10 @@ local function Dropdown(props: DropdownProps)
Size = UDim2.fromScale(1, 1);
BackgroundColor3 = if props.isDisabled then Color3.new(0.501961, 0.501961, 0.501961) else colors.input;
BackgroundTransparency = if props.isDisabled then 0.75 else 0;
[React.Event.Activated] = if props.isDisabled then nil else function()
ref = toggleButtonRef;
[React.Event.Activated] = if props.isDisabled then nil else function(self)

setIsOpen(not isOpen);
VirtualService.events.GuiButton.Activated:fireEvent(self);

end;
Text = "";
Expand Down Expand Up @@ -121,15 +143,15 @@ local function Dropdown(props: DropdownProps)
AutomaticCanvasSize = Enum.AutomaticSize.Y;
AutomaticSize = Enum.AutomaticSize.Y;
CanvasSize = UDim2.fromScale(1, 1);
[React.Event.InputEnded] = function(self, input)
-- [React.Event.InputEnded] = function(self, input)

if input == Enum.UserInputType.MouseButton1 then
-- if input == Enum.UserInputType.MouseButton1 then

setIsOpen(not isOpen);
-- setIsOpen(not isOpen);

end;
-- end;

end;
-- end;
}, {
UIListLayout = React.createElement("UIListLayout", {
SortOrder = Enum.SortOrder.LayoutOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,26 @@ return {

end;

local function createDialogueScript(name: string, type: "Conversation" | "Dialogue")
local function createDialogueScript(name: string, type: "Conversation" | "Message" | "Redirect")

local dialogueScript = Instance.new("ModuleScript");

if type == "Conversation" then

dialogueScript:AddTag("DialogueMakerConversationScript");

elseif type == "Dialogue" then

dialogueScript:AddTag("DialogueMakerDialogueScript");
dialogueScript:SetAttribute("DialogueType", "Message");

else

error("Invalid dialogue script type: " .. tostring(type));
dialogueScript:AddTag("DialogueMakerDialogueScript");
dialogueScript:SetAttribute("DialogueType", type);

end;

return dialogueScript;

end;

local function render(type: "Conversation" | "Dialogue"): ModuleScript
local function render(type: "Conversation" | "Message" | "Redirect"): ModuleScript

assert(reactRoot, "React root should be initialized before running tests.");

Expand Down Expand Up @@ -164,7 +160,7 @@ return {

expect(function()

render("Dialogue");
render("Message");

assert(screenGui, "ScreenGui should be initialized before running tests.");
local dialogueOptions = screenGui:FindFirstChildOfClass("Frame");
Expand All @@ -179,6 +175,33 @@ return {
end).toFinishBeforeSeconds(1);

end);

it(`hides non-initialization actions for "Redirect"-type dialogue scripts`, function()

expect(function()

render("Redirect");

assert(screenGui, "ScreenGui should be initialized before running tests.");
local dialogueOptions = screenGui:FindFirstChildOfClass("Frame");
assert(dialogueOptions, "DialogueOptions should be rendered.");

local actionsDropdown = dialogueOptions:FindFirstChild("ActionsDropdown");
assert(actionsDropdown, "Actions dropdown should be present in the DialogueOptions.");

local toggleButton = actionsDropdown:FindFirstChild("ToggleButton");
assert(toggleButton and toggleButton:IsA("TextButton"), "Toggle button should be present in the ActionsDropdown.");

VirtualService.events.GuiButton.Activated:fireEvent(toggleButton);

local optionsFrame = actionsDropdown:WaitForChild("OptionsFrame");
expect(optionsFrame:FindFirstChild("InitializationButton")).toNotBe(nil);
expect(optionsFrame:FindFirstChild("CompletionButton")).toBe(nil);
expect(optionsFrame:FindFirstChild("CleanupButton")).toBe(nil);

end).toFinishBeforeSeconds(1);

end);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ local function DialogueOptions(properties: DialogueOptionsProperties)
end;

local option = React.createElement(DropdownOption, {
key = actionType :: string;
key = `{actionType}Button`;
text = actionType :: string;
layoutOrder = index;
onClick = function()
Expand Down