Skip to content

Commit

Permalink
Merge pull request #8 from CGray1234/ui-rewrite
Browse files Browse the repository at this point in the history
UI rewrite
  • Loading branch information
CGray1234 authored Dec 10, 2022
2 parents 31d48e6 + 044c248 commit f74e89e
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 74 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ add_custom_command(TARGET ${COMPILE_ID} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename stripped_lib${COMPILE_ID}.so lib${COMPILE_ID}.so
COMMENT "Rename the stripped lib to regular"
)

include(assets_include.cmake)
Binary file added assets/MiscGradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/MiscGradientSelected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/PosGradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/PosGradientSelected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/RotGradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/RotGradientSelected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions assets_include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# File from PinkCore: https://github.com/BSMGPink/PinkCore/blob/master/assets_include.cmake

# credit goes to https://github.com/Lauriethefish for this
# Directory where our arbitrary asset files are stored
set(ASSETS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/assets)
# Directory to save the object files generated by llvm-objcopy
set(ASSET_BINARIES_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/binaryAssets)
# Directory to save the prepended files to
set(PREPENDED_ASSETS_DIR ${CMAKE_CURRENT_BINARY_DIR}/prependedAssets)
set(ASSET_HEADER_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include/assets.hpp")

# Define a macro which we will use for defining the symbols to access our asset files below
set(ASSET_HEADER_DATA
"#pragma once
#include <string_view>
#include \"beatsaber-hook/shared/utils/typedefs.h\"
struct IncludedAsset {
IncludedAsset(uint8_t* start, uint8_t* end) : array(reinterpret_cast<Array<uint8_t>*>(start)) {
array->klass = nullptr;
array->monitor = nullptr;
array->bounds = nullptr;
array->max_length = end - start - 33;
*(end - 1)= '\\0';
}
operator ArrayW<uint8_t>() const {
init();
return array;
}
operator std::string_view() const {
return { reinterpret_cast<char*>(array->values), array->Length() };
}
operator std::span<uint8_t>() const {
return { array->values, array->Length() };
}
void init() const {
if(!array->klass)
array->klass = classof(Array<uint8_t>*);
}
private:
Array<uint8_t>* array;
};
#define DECLARE_FILE(name) \\
extern \"C\" uint8_t _binary_##name##_start[]; \\
extern \"C\" uint8_t _binary_##name##_end[]; \\
const IncludedAsset name { _binary_##name##_start, _binary_##name##_end};
namespace IncludedAssets {
\n")

if (EXISTS ${ASSETS_DIRECTORY})
file(MAKE_DIRECTORY ${ASSET_BINARIES_DIRECTORY})
file(MAKE_DIRECTORY ${PREPENDED_ASSETS_DIR})
file(GLOB ASSETS LIST_DIRECTORIES false ${ASSETS_DIRECTORY}/*)

# Iterate through each file in the assets directory. TODO: This could be recursive
foreach(FILE IN LISTS ASSETS)
message("-- Including asset: ${FILE}")
get_filename_component(ASSET ${FILE} NAME) # Find the asset's file name

# make a copy of the file with 32 bytes added in the build dir
add_custom_command(
OUTPUT ${PREPENDED_ASSETS_DIR}/${ASSET}
COMMAND ${CMAKE_COMMAND} -E echo_append " " > ${PREPENDED_ASSETS_DIR}/${ASSET}
COMMAND ${CMAKE_COMMAND} -E cat ${ASSETS_DIRECTORY}/${ASSET} >> ${PREPENDED_ASSETS_DIR}/${ASSET}
COMMAND ${CMAKE_COMMAND} -E echo_append " " >> ${PREPENDED_ASSETS_DIR}/${ASSET}
DEPENDS ${ASSETS_DIRECTORY}/${ASSET}
)

set(OUTPUT_FILE "${ASSET_BINARIES_DIRECTORY}/${ASSET}.o") # Save our asset in the asset binaries directory

# Use llvm-objcopy to create an object file that stores our binary asset
# The resulting file contains 3 symbols: _binary_<file_name>_start, _binary_<file_name>_size and _binary_<file_name>_end
# We only use the first two
add_custom_command(
OUTPUT ${OUTPUT_FILE}
COMMAND ${CMAKE_OBJCOPY} ${ASSET} ${OUTPUT_FILE} --input-target binary --output-target elf64-aarch64 --set-section-flags binary=strings
DEPENDS ${PREPENDED_ASSETS_DIR}/${ASSET}
WORKING_DIRECTORY ${PREPENDED_ASSETS_DIR}
)
list(APPEND BINARY_ASSET_FILES ${OUTPUT_FILE})

# Find the correct objcopy symbol name, this is always the file name with any non-alphanumeric characters replaced with _
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" FIXED_ASSET ${ASSET})
# Add to our assets header
set(ASSET_HEADER_DATA "${ASSET_HEADER_DATA}\tDECLARE_FILE(${FIXED_ASSET})\n")
endforeach()
set(ASSET_HEADER_DATA "${ASSET_HEADER_DATA}\n}\n")

# check if at least 1 asset file, otherwise ignore
list(LENGTH BINARY_ASSET_FILES COUNT)
if (${COUNT} GREATER 0)
# Generate the assets header file
file(GENERATE OUTPUT ${ASSET_HEADER_PATH} CONTENT "${ASSET_HEADER_DATA}")

# Add our assets files to the final SO
add_library(asset_files OBJECT ${BINARY_ASSET_FILES})
set_target_properties(asset_files PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${COMPILE_ID} PRIVATE asset_files ${BINARY_ASSET_FILES})
endif()
else()
message("-- Removing '${ASSET_HEADER_PATH}' as no assets have been found in '${ASSETS_DIRECTORY}'")
file(REMOVE ${ASSET_HEADER_PATH})
endif()
5 changes: 0 additions & 5 deletions include/Images/MiscSettingsIcon.hpp

This file was deleted.

5 changes: 0 additions & 5 deletions include/Images/PositionSettingsIcon.hpp

This file was deleted.

5 changes: 0 additions & 5 deletions include/Images/RotationSettingsIcon.hpp

This file was deleted.

1 change: 1 addition & 0 deletions include/UI/FlowCoordinator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "questui/shared/BeatSaberUI.hpp"
#include "questui/shared/QuestUI.hpp"
#include "ViewController.hpp"
#include "UI/GameplaySetupView.hpp"
#include "main.hpp"

DECLARE_CLASS_CODEGEN(InGameText, InGameTextFlowCoordinator, HMUI::FlowCoordinator,
Expand Down
32 changes: 26 additions & 6 deletions include/UI/GameplaySetupView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,51 @@

#include "custom-types/shared/macros.hpp"
#include "UnityEngine/MonoBehaviour.hpp"
#include "UnityEngine/UI/VerticalLayoutGroup.hpp"

#include "UnityEngine/Sprite.hpp"
#include "HMUI/ImageView.hpp"
#include "HMUI/InputFieldView.hpp"
#include "questui/shared/CustomTypes/Components/Settings/ColorSetting.hpp"
#include "questui/shared/CustomTypes/Components/Settings/IncrementSetting.hpp"
#include "UnityEngine/UI/Button.hpp"

#include "HMUI/InputFieldView.hpp"
#include "HMUI/FlowCoordinator.hpp"
#include "HMUI/ViewController.hpp"

using namespace UnityEngine;

DECLARE_CLASS_CODEGEN(InGameText, gameplaySetupView, UnityEngine::MonoBehaviour,
DECLARE_INSTANCE_FIELD(HMUI::ViewController*, viewController);
DECLARE_INSTANCE_FIELD(HMUI::FlowCoordinator*, flowCoordinator);

//Misc
DECLARE_INSTANCE_FIELD(QuestUI::ColorSetting*, QolorPicker);
DECLARE_INSTANCE_FIELD(HMUI::InputFieldView*, TextSetting);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, SizeSetting);
DECLARE_INSTANCE_FIELD(UI::Button*, MiscButton);
//Misc Layout
DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, MiscLayout);
DECLARE_INSTANCE_FIELD(HMUI::InputFieldView*, TextString);
DECLARE_INSTANCE_FIELD(QuestUI::ColorSetting*, TextColor);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, TextSize);
DECLARE_INSTANCE_FIELD(UnityEngine::UI::Button*, miscBackButton);

//Pos
DECLARE_INSTANCE_FIELD(UI::Button*, PositionButton);
// Position Layout
DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, PositionLayout);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, PosX);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, PosY);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, PosZ);
DECLARE_INSTANCE_FIELD(UnityEngine::UI::Button*, posBackButton);

//Rot
DECLARE_INSTANCE_FIELD(UI::Button*, RotationButton);
// Rotation Layout
DECLARE_INSTANCE_FIELD(UnityEngine::UI::VerticalLayoutGroup*, RotationLayout);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, RotX);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, RotY);
DECLARE_INSTANCE_FIELD(QuestUI::IncrementSetting*, RotZ);

DECLARE_INSTANCE_METHOD(void, DidActivate, bool firstActivation);
DECLARE_INSTANCE_FIELD(UnityEngine::UI::Button*, rotBackButton);


DECLARE_INSTANCE_METHOD(void, DidActivate, bool firstActivation);
);
12 changes: 12 additions & 0 deletions include/Utils/UIUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// From PinkCore: https://github.com/BSMGPink/PinkCore/blob/master/include/Utils/UIUtils.hpp

#pragma once

#include "UnityEngine/UI/Button.hpp"
#include "UnityEngine/Sprite.hpp"
#include <string>

namespace UIUtils
{
void SwapButtonSprites(UnityEngine::UI::Button* button, UnityEngine::Sprite* normal, UnityEngine::Sprite* highlighted);
}
44 changes: 44 additions & 0 deletions include/assets.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include <string_view>
#include "beatsaber-hook/shared/utils/typedefs.h"
struct IncludedAsset {
IncludedAsset(uint8_t* start, uint8_t* end) : array(reinterpret_cast<Array<uint8_t>*>(start)) {
array->klass = nullptr;
array->monitor = nullptr;
array->bounds = nullptr;
array->max_length = end - start - 33;
*(end - 1)= '\0';
}

operator ArrayW<uint8_t>() const {
init();
return array;
}
operator std::string_view() const {
return { reinterpret_cast<char*>(array->values), array->Length() };
}

operator std::span<uint8_t>() const {
return { array->values, array->Length() };
}
void init() const {
if(!array->klass)
array->klass = classof(Array<uint8_t>*);
}
private:
Array<uint8_t>* array;
};
#define DECLARE_FILE(name) \
extern "C" uint8_t _binary_##name##_start[]; \
extern "C" uint8_t _binary_##name##_end[]; \
const IncludedAsset name { _binary_##name##_start, _binary_##name##_end};
namespace IncludedAssets {

DECLARE_FILE(MiscGradient_png)
DECLARE_FILE(MiscGradientSelected_png)
DECLARE_FILE(PosGradient_png)
DECLARE_FILE(PosGradientSelected_png)
DECLARE_FILE(RotGradient_png)
DECLARE_FILE(RotGradientSelected_png)

}
Loading

0 comments on commit f74e89e

Please sign in to comment.