Cleanup of some code
This commit is contained in:
		
							
								
								
									
										5
									
								
								assets/games/liminal/prefabs/Button.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								assets/games/liminal/prefabs/Button.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					<prefab name="Button" type="">
 | 
				
			||||||
 | 
					  <asset type="truetype" name="font_main" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <UISimpleLabel ref="label" font="font_main" size="32" /> 
 | 
				
			||||||
 | 
					</prefab>
 | 
				
			||||||
@@ -4,6 +4,7 @@
 | 
				
			|||||||
# https://opensource.org/licenses/MIT
 | 
					# https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tool_prefab(${CMAKE_CURRENT_LIST_DIR}/AvePrefab.xml)
 | 
					tool_prefab(${CMAKE_CURRENT_LIST_DIR}/AvePrefab.xml)
 | 
				
			||||||
 | 
					tool_prefab(${CMAKE_CURRENT_LIST_DIR}/Button.xml)
 | 
				
			||||||
tool_prefab(${CMAKE_CURRENT_LIST_DIR}/EthPrefab.xml)
 | 
					tool_prefab(${CMAKE_CURRENT_LIST_DIR}/EthPrefab.xml)
 | 
				
			||||||
tool_prefab(${CMAKE_CURRENT_LIST_DIR}/CraigPrefab.xml)
 | 
					tool_prefab(${CMAKE_CURRENT_LIST_DIR}/CraigPrefab.xml)
 | 
				
			||||||
tool_prefab(${CMAKE_CURRENT_LIST_DIR}/RoninPrefab.xml)
 | 
					tool_prefab(${CMAKE_CURRENT_LIST_DIR}/RoninPrefab.xml)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
 | 
				
			|||||||
  PRIVATE
 | 
					  PRIVATE
 | 
				
			||||||
    UILabel.cpp
 | 
					    UILabel.cpp
 | 
				
			||||||
    UIRichTextLabel.cpp
 | 
					    UIRichTextLabel.cpp
 | 
				
			||||||
 | 
					    UISimpleLabel.cpp
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
							
								
								
									
										49
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
				
			|||||||
 | 
					// Copyright (c) 2023 Dominic Masters
 | 
				
			||||||
 | 
					// 
 | 
				
			||||||
 | 
					// This software is released under the MIT License.
 | 
				
			||||||
 | 
					// https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "UISimpleLabel.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace Dawn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					UISimpleLabel::UISimpleLabel(SceneItem *i) :
 | 
				
			||||||
 | 
					  UILabel(i),
 | 
				
			||||||
 | 
					  text("Hello World"),
 | 
				
			||||||
 | 
					  font(nullptr),
 | 
				
			||||||
 | 
					  size(12),
 | 
				
			||||||
 | 
					  style(0),
 | 
				
			||||||
 | 
					  decorations(0),
 | 
				
			||||||
 | 
					  color(COLOR_WHITE)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void UISimpleLabel::onStart() {
 | 
				
			||||||
 | 
					  UILabel::onStart();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  useEffect([&] {
 | 
				
			||||||
 | 
					    if(this->font == nullptr) {
 | 
				
			||||||
 | 
					      this->rebufferQuads({ });
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct UILabelText text;
 | 
				
			||||||
 | 
					    struct UILabelStyle style;
 | 
				
			||||||
 | 
					    style.font = this->font;
 | 
				
			||||||
 | 
					    style.size = this->size;
 | 
				
			||||||
 | 
					    style.style = this->style;
 | 
				
			||||||
 | 
					    style.decorations = this->decorations;
 | 
				
			||||||
 | 
					    style.color = this->color;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    text.style = style;
 | 
				
			||||||
 | 
					    text.text = this->text;
 | 
				
			||||||
 | 
					    this->rebufferQuads({ text });
 | 
				
			||||||
 | 
					  }, {
 | 
				
			||||||
 | 
					    &this->text,
 | 
				
			||||||
 | 
					    &this->font, 
 | 
				
			||||||
 | 
					    &this->size, 
 | 
				
			||||||
 | 
					    &this->style,
 | 
				
			||||||
 | 
					    &this->decorations,
 | 
				
			||||||
 | 
					    &this->color
 | 
				
			||||||
 | 
					  })();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										29
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					// Copyright (c) 2023 Dominic Masters
 | 
				
			||||||
 | 
					// 
 | 
				
			||||||
 | 
					// This software is released under the MIT License.
 | 
				
			||||||
 | 
					// https://opensource.org/licenses/MIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					#include "UILabel.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Dawn {
 | 
				
			||||||
 | 
					  class UISimpleLabel : public UILabel {
 | 
				
			||||||
 | 
					    public:
 | 
				
			||||||
 | 
					      // @optional
 | 
				
			||||||
 | 
					      StateProperty<std::string> text;
 | 
				
			||||||
 | 
					      // @optional
 | 
				
			||||||
 | 
					      StateProperty<TrueTypeAsset*> font;
 | 
				
			||||||
 | 
					      // @optional
 | 
				
			||||||
 | 
					      StateProperty<uint32_t> size;
 | 
				
			||||||
 | 
					      // @optional
 | 
				
			||||||
 | 
					      StateProperty<flag_t> style;
 | 
				
			||||||
 | 
					      // @optional
 | 
				
			||||||
 | 
					      StateProperty<flag_t> decorations;
 | 
				
			||||||
 | 
					      // @optional
 | 
				
			||||||
 | 
					      StateProperty<struct Color> color;
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      UISimpleLabel(SceneItem *item);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      void onStart() override;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -142,7 +142,7 @@ namespace Dawn {
 | 
				
			|||||||
      parser = vec3Parser;
 | 
					      parser = vec3Parser;
 | 
				
			||||||
    } else if(type.find("vec4") != std::string::npos) {
 | 
					    } else if(type.find("vec4") != std::string::npos) {
 | 
				
			||||||
      parser = vec4Parser;
 | 
					      parser = vec4Parser;
 | 
				
			||||||
    } else if(type == "int32_t" || type == "int") {
 | 
					    } else if(type == "int32_t" || type == "int" || type == "uint32_t" || type == "uint") {
 | 
				
			||||||
      parser = intParser;
 | 
					      parser = intParser;
 | 
				
			||||||
    } else if(type == "bool_t") {
 | 
					    } else if(type == "bool_t") {
 | 
				
			||||||
      parser = boolParser;
 | 
					      parser = boolParser;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,7 @@ include(util/generator/CMakeLists.txt)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Tools
 | 
					# Tools
 | 
				
			||||||
add_subdirectory(prefabtool)
 | 
					add_subdirectory(prefabtool)
 | 
				
			||||||
 | 
					add_subdirectory(propertytool)
 | 
				
			||||||
add_subdirectory(scenetool)
 | 
					add_subdirectory(scenetool)
 | 
				
			||||||
add_subdirectory(texturetool)
 | 
					add_subdirectory(texturetool)
 | 
				
			||||||
add_subdirectory(truetypetool)
 | 
					add_subdirectory(truetypetool)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -226,6 +226,39 @@ void File::setPosition(size_t n) {
 | 
				
			|||||||
  fseek(this->file, n, SEEK_CUR);
 | 
					  fseek(this->file, n, SEEK_CUR);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::string File::getFileName(bool_t withExt) {
 | 
				
			||||||
 | 
					  // Remove all but last slash
 | 
				
			||||||
 | 
					  std::string basename;
 | 
				
			||||||
 | 
					  size_t lastSlash = this->filename.find_last_of('/');
 | 
				
			||||||
 | 
					  if(lastSlash == std::string::npos) {
 | 
				
			||||||
 | 
					    basename = this->filename;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    basename = this->filename.substr(lastSlash + 1);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Do we need to remove ext?
 | 
				
			||||||
 | 
					  if(withExt) return basename;
 | 
				
			||||||
 | 
					  size_t lastDot = basename.find_last_of('.');
 | 
				
			||||||
 | 
					  if(lastDot == std::string::npos) return basename;
 | 
				
			||||||
 | 
					  return basename.substr(0, lastDot);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					std::string File::getExtension() {
 | 
				
			||||||
 | 
					  // Remove all but last slash
 | 
				
			||||||
 | 
					  std::string basename;
 | 
				
			||||||
 | 
					  size_t lastSlash = this->filename.find_last_of('/');
 | 
				
			||||||
 | 
					  if(lastSlash == std::string::npos) {
 | 
				
			||||||
 | 
					    basename = this->filename;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    basename = this->filename.substr(lastSlash + 1);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  size_t lastDot = basename.find_last_of('.');
 | 
				
			||||||
 | 
					  if(lastDot == std::string::npos) return "";
 | 
				
			||||||
 | 
					  return basename.substr(lastDot + 1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
File::~File() {
 | 
					File::~File() {
 | 
				
			||||||
  if(this->file != nullptr) this->close();
 | 
					  if(this->file != nullptr) this->close();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -160,6 +160,21 @@ namespace Dawn {
 | 
				
			|||||||
       */
 | 
					       */
 | 
				
			||||||
      void setPosition(size_t pos);
 | 
					      void setPosition(size_t pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /**
 | 
				
			||||||
 | 
					       * Get the file name of this file, optionally with the extension.
 | 
				
			||||||
 | 
					       * 
 | 
				
			||||||
 | 
					       * @param withExtension If true, the extension will be included.
 | 
				
			||||||
 | 
					       * @return The file name.
 | 
				
			||||||
 | 
					       */
 | 
				
			||||||
 | 
					      std::string getFileName(bool_t withExtension = true);
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
 | 
					      /**
 | 
				
			||||||
 | 
					       * Returns the extension of this file.
 | 
				
			||||||
 | 
					       * 
 | 
				
			||||||
 | 
					       * @return The extension of this file.
 | 
				
			||||||
 | 
					       */
 | 
				
			||||||
 | 
					      std::string getExtension();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Destruct the File manager.
 | 
					       * Destruct the File manager.
 | 
				
			||||||
       */
 | 
					       */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,8 +34,8 @@ void SceneAssetGenerator::generate(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    case SCENE_ASSET_TYPE_TRUETYPE_FONT:
 | 
					    case SCENE_ASSET_TYPE_TRUETYPE_FONT:
 | 
				
			||||||
      assetType = "TrueTypeAsset";
 | 
					      assetType = "TrueTypeAsset";
 | 
				
			||||||
      assetMap[asset->fileName] = "&" + asset->usageName + "->font";
 | 
					      assetMap[asset->fileName] = asset->usageName;
 | 
				
			||||||
      assetMap[asset->usageName] = "&" + asset->usageName + "->font";
 | 
					      assetMap[asset->usageName] = asset->usageName;
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ set(
 | 
				
			|||||||
    ${D}/SceneCodeParser.cpp
 | 
					    ${D}/SceneCodeParser.cpp
 | 
				
			||||||
    ${D}/SceneItemComponentParser.cpp
 | 
					    ${D}/SceneItemComponentParser.cpp
 | 
				
			||||||
    ${D}/SceneItemComponentRegistry.cpp
 | 
					    ${D}/SceneItemComponentRegistry.cpp
 | 
				
			||||||
 | 
					    ${D}/ScenePropertyParser.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  CACHE INTERNAL
 | 
					  CACHE INTERNAL
 | 
				
			||||||
    ${DAWN_CACHE_TARGET}
 | 
					    ${DAWN_CACHE_TARGET}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user