OriginalsSubfolderComponent.cpp (8622B)
1 /*---------------------------------------------------------------------------------------- 2 3 Copyright (c) 2023 AUDIOKINETIC Inc. 4 5 This file is licensed to use under the license available at: 6 https://github.com/audiokinetic/ReaWwise/blob/main/License.txt (the "License"). 7 You may not use this file except in compliance with the License. 8 9 Unless required by applicable law or agreed to in writing, software distributed 10 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 specific language governing permissions and limitations under the License. 13 14 ----------------------------------------------------------------------------------------*/ 15 16 #include "OriginalsSubfolderComponent.h" 17 18 #include "BinaryData.h" 19 #include "Persistance/ApplicationState.h" 20 21 namespace AK::WwiseTransfer 22 { 23 namespace WwiseOriginalsComponentConstants 24 { 25 constexpr int margin = 10; 26 constexpr int spacing = 4; 27 constexpr int editorBoxHeight = 26; 28 constexpr int labelWidth = 122; 29 constexpr int wildcardsButtonWidth = 80; 30 constexpr int smallButtonWidth = 26; 31 } // namespace WwiseOriginalsComponentConstants 32 33 OriginalsSubfolderComponent::OriginalsSubfolderComponent(juce::ValueTree appState, const juce::String& applicationName, ApplicationProperties& applicationProperties, WaapiClientWatcher& waapiCW) 34 : applicationState(appState) 35 , projectPath(applicationState, IDs::projectPath, nullptr) 36 , originalsSubfolder(applicationState, IDs::originalsSubfolder, nullptr) 37 , fileBrowserButton("FileBrowserButton", juce::Drawable::createFromImageData(BinaryData::General_FolderWithTriangle_Normal_svg, BinaryData::General_FolderWithTriangle_Normal_svgSize)) 38 , aboutButton("AboutButton", juce::Drawable::createFromImageData(BinaryData::Dialog_Help_Active_png, BinaryData::Dialog_Help_Active_pngSize)) 39 , crossMachineTransferSettingsButton("crossMachineTransferSettingsButton", juce::Drawable::createFromImageData(BinaryData::Dialog_Settings_Active_png, BinaryData::Dialog_Settings_Active_pngSize)) 40 , originalsFolder(applicationState, IDs::originalsFolder, nullptr) 41 , languageSubfolder(applicationState, IDs::languageSubfolder, nullptr) 42 , aboutComponent(applicationName) 43 , crossMachineTransferSettingsComponent(applicationName, applicationProperties, waapiCW) 44 { 45 projectPathLabel.setText("Project Path", juce::dontSendNotification); 46 projectPathLabel.setBorderSize(juce::BorderSize(0)); 47 projectPathLabel.setMinimumHorizontalScale(1.0f); 48 projectPathLabel.setJustificationType(juce::Justification::right); 49 50 originalsSubfolderLabel.setText("Originals Subfolder", juce::dontSendNotification); 51 originalsSubfolderLabel.setBorderSize(juce::BorderSize(0)); 52 originalsSubfolderLabel.setMinimumHorizontalScale(1.0f); 53 originalsSubfolderLabel.setJustificationType(juce::Justification::right); 54 55 projectPathEditor.setFont(CustomLookAndFeelConstants::smallFontSize); 56 projectPathEditor.getValueToTruncate().referTo(projectPath.getPropertyAsValue()); 57 projectPathEditor.setReadOnly(true); 58 projectPathEditor.setMouseClickGrabsKeyboardFocus(false); 59 60 projectPathEditor.setMouseCursor(juce::MouseCursor::NormalCursor); 61 62 originalsSubfolderEditor.setFont(CustomLookAndFeelConstants::smallFontSize); 63 originalsSubfolderEditor.getTextValue().referTo(originalsSubfolder.getPropertyAsValue()); 64 originalsSubfolderEditor.getValidationValue().referTo(applicationState.getPropertyAsValue(IDs::originalsSubfolderValid, nullptr)); 65 originalsSubfolderEditor.getErrorMessageValue().referTo(applicationState.getPropertyAsValue(IDs::originalsSubfolderErrorMessage, nullptr)); 66 67 aboutButton.setTooltip("About ReaWwise"); 68 aboutButton.onClick = [this] 69 { 70 showAboutWindow(); 71 }; 72 73 crossMachineTransferSettingsButton.setTooltip("Cross Machine Transfer Settings"); 74 crossMachineTransferSettingsButton.onClick = [this] 75 { 76 showCrossMachineTransferSettingsWindow(); 77 }; 78 79 fileBrowserButton.onClick = [this] 80 { 81 selectOriginalsSubfoler(); 82 }; 83 84 wildcardSelector.onItemSelected = [this](const juce::String& wildcard) 85 { 86 onWildcardSelected(wildcard); 87 }; 88 89 addAndMakeVisible(projectPathLabel); 90 addAndMakeVisible(projectPathEditor); 91 addAndMakeVisible(originalsSubfolderLabel); 92 addAndMakeVisible(originalsSubfolderEditor); 93 addAndMakeVisible(fileBrowserButton); 94 addAndMakeVisible(wildcardSelector); 95 addAndMakeVisible(aboutButton); 96 addAndMakeVisible(crossMachineTransferSettingsButton); 97 98 refreshComponent(); 99 100 applicationState.addListener(this); 101 } 102 103 OriginalsSubfolderComponent::~OriginalsSubfolderComponent() 104 { 105 applicationState.removeListener(this); 106 } 107 108 void OriginalsSubfolderComponent::resized() 109 { 110 using namespace WwiseOriginalsComponentConstants; 111 112 auto area = getLocalBounds(); 113 114 auto projectPathSection = area.removeFromTop(editorBoxHeight); 115 { 116 projectPathLabel.setBounds(projectPathSection.removeFromLeft(labelWidth)); 117 projectPathSection.removeFromLeft(margin); 118 119 aboutButton.setBounds(projectPathSection.removeFromRight(smallButtonWidth)); 120 projectPathSection.removeFromRight(spacing); 121 122 crossMachineTransferSettingsButton.setBounds(projectPathSection.removeFromRight(smallButtonWidth)); 123 projectPathSection.removeFromRight(spacing); 124 125 projectPathEditor.setBounds(projectPathSection); 126 } 127 128 area.removeFromTop(margin); 129 130 auto originalsSubfolderSection = area.removeFromTop(editorBoxHeight); 131 { 132 originalsSubfolderLabel.setBounds(originalsSubfolderSection.removeFromLeft(labelWidth)); 133 134 wildcardSelector.setBounds(originalsSubfolderSection.removeFromRight(wildcardsButtonWidth)); 135 originalsSubfolderSection.removeFromRight(spacing); 136 137 fileBrowserButton.setBounds(originalsSubfolderSection.removeFromRight(smallButtonWidth)); 138 originalsSubfolderSection.removeFromRight(spacing); 139 140 originalsSubfolderSection.removeFromLeft(margin); 141 originalsSubfolderEditor.setBounds(originalsSubfolderSection); 142 } 143 } 144 145 void OriginalsSubfolderComponent::refreshComponent() 146 { 147 auto projectPathEmpty = projectPath.get().isEmpty(); 148 auto originalsFolderEmpty = originalsFolder.get().isEmpty(); 149 150 projectPathLabel.setEnabled(!projectPathEmpty); 151 projectPathEditor.setAlpha(!projectPathEmpty ? 1 : 0.5f); 152 153 fileBrowserButton.setEnabled(!projectPathEmpty && !originalsFolderEmpty); 154 fileBrowserButton.setTooltip(originalsFolderEmpty ? "File browser is only available when connected to Wwise 2022+" : "Browse"); 155 } 156 157 void OriginalsSubfolderComponent::selectOriginalsSubfoler() 158 { 159 fileChooser = std::make_unique<juce::FileChooser>("Please select a subfolder relative to the Wwise originals folder...", juce::File(originalsFolder + languageSubfolder), "*"); 160 161 auto folderChooserFlags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories; 162 163 fileChooser->launchAsync(folderChooserFlags, [this](const juce::FileChooser& chooser) 164 { 165 juce::File relativeFolder(chooser.getResult()); 166 167 originalsSubfolder = relativeFolder.getRelativePathFrom(juce::File(originalsFolder + languageSubfolder)); 168 }); 169 } 170 171 void OriginalsSubfolderComponent::onWildcardSelected(const juce::String& wildcard) 172 { 173 originalsSubfolder = originalsSubfolderEditor.getText() + wildcard; 174 } 175 176 void OriginalsSubfolderComponent::valueTreePropertyChanged(juce::ValueTree& treeWhosePropertyHasChanged, const juce::Identifier& property) 177 { 178 auto treeType = treeWhosePropertyHasChanged.getType(); 179 180 if(treeType == IDs::application && property == IDs::projectPath || treeType == IDs::application && property == IDs::originalsFolder) 181 { 182 triggerAsyncUpdate(); 183 } 184 } 185 186 void OriginalsSubfolderComponent::handleAsyncUpdate() 187 { 188 refreshComponent(); 189 } 190 void OriginalsSubfolderComponent::showAboutWindow() 191 { 192 juce::DialogWindow::LaunchOptions options; 193 options.dialogTitle = "About ReaWwise"; 194 options.useNativeTitleBar = true; 195 options.resizable = false; 196 options.componentToCentreAround = this->getParentComponent()->getParentComponent(); 197 options.content = juce::OptionalScopedPointer<juce::Component>(&aboutComponent, false); 198 199 options.launchAsync(); 200 } 201 void OriginalsSubfolderComponent::showCrossMachineTransferSettingsWindow() 202 { 203 juce::DialogWindow::LaunchOptions options; 204 options.dialogTitle = "Waapi Network Transfer Settings"; 205 options.useNativeTitleBar = true; 206 options.resizable = false; 207 options.componentToCentreAround = this->getParentComponent()->getParentComponent(); 208 options.content = juce::OptionalScopedPointer<juce::Component>(&crossMachineTransferSettingsComponent, false); 209 210 options.launchAsync(); 211 } 212 } // namespace AK::WwiseTransfer