-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from OpenVicProject/tooltip
Tooltips
- Loading branch information
Showing
45 changed files
with
1,952 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include "GUIButton.hpp" | ||
|
||
#include <array> | ||
|
||
#include <godot_cpp/variant/utility_functions.hpp> | ||
|
||
#include "openvic-extension/singletons/AssetManager.hpp" | ||
#include "openvic-extension/utility/Utilities.hpp" | ||
|
||
using namespace godot; | ||
using namespace OpenVic; | ||
|
||
GUI_TOOLTIP_IMPLEMENTATIONS(GUIButton) | ||
|
||
void GUIButton::_bind_methods() { | ||
GUI_TOOLTIP_BIND_METHODS(GUIButton) | ||
} | ||
|
||
void GUIButton::_notification(int what) { | ||
_tooltip_notification(what); | ||
} | ||
|
||
GUIButton::GUIButton() : tooltip_active { false } {} | ||
|
||
Error GUIButton::set_gfx_button_state_having_texture(Ref<GFXButtonStateHavingTexture> const& texture) { | ||
ERR_FAIL_NULL_V(texture, FAILED); | ||
|
||
Error err = OK; | ||
|
||
set_custom_minimum_size(texture->get_size()); | ||
|
||
{ | ||
Ref<StyleBoxTexture> stylebox = AssetManager::make_stylebox_texture(texture); | ||
|
||
if (stylebox.is_valid()) { | ||
static const StringName normal_theme = "normal"; | ||
|
||
add_theme_stylebox_override(normal_theme, stylebox); | ||
} else { | ||
UtilityFunctions::push_error("Failed to make StyleBoxTexture for GUIButton ", get_name()); | ||
|
||
err = FAILED; | ||
} | ||
} | ||
|
||
using enum GFXButtonStateTexture::ButtonState; | ||
|
||
for (GFXButtonStateTexture::ButtonState button_state : { HOVER, PRESSED, DISABLED }) { | ||
Ref<GFXButtonStateTexture> button_state_texture = texture->get_button_state_texture(button_state); | ||
|
||
if (button_state_texture.is_valid()) { | ||
Ref<StyleBoxTexture> stylebox = AssetManager::make_stylebox_texture(button_state_texture); | ||
|
||
if (stylebox.is_valid()) { | ||
add_theme_stylebox_override(button_state_texture->get_button_state_name(), stylebox); | ||
} else { | ||
UtilityFunctions::push_error( | ||
"Failed to make ", GFXButtonStateTexture::button_state_to_name(button_state), | ||
" StyleBoxTexture for GUIButton ", get_name() | ||
); | ||
|
||
err = FAILED; | ||
} | ||
} else { | ||
UtilityFunctions::push_error( | ||
"Failed to make ", GFXButtonStateTexture::button_state_to_name(button_state), | ||
" GFXButtonStateTexture for GUIButton ", get_name() | ||
); | ||
|
||
err = FAILED; | ||
} | ||
} | ||
|
||
return err; | ||
} | ||
|
||
Error GUIButton::set_gfx_font(GFX::Font const* gfx_font) { | ||
ERR_FAIL_NULL_V(gfx_font, FAILED); | ||
|
||
AssetManager* asset_manager = AssetManager::get_singleton(); | ||
ERR_FAIL_NULL_V(asset_manager, FAILED); | ||
|
||
Error err = OK; | ||
|
||
const StringName font_file = Utilities::std_to_godot_string(gfx_font->get_fontname()); | ||
const Ref<Font> font = asset_manager->get_font(font_file); | ||
|
||
if (font.is_valid()) { | ||
static const StringName font_theme = "font"; | ||
|
||
add_theme_font_override(font_theme, font); | ||
} else { | ||
UtilityFunctions::push_error("Failed to load font \"", font_file, "\" for GUIButton ", get_name()); | ||
|
||
err = FAILED; | ||
} | ||
|
||
static const std::array<StringName, 5> button_font_themes { | ||
"font_color", "font_hover_color", "font_hover_pressed_color", "font_pressed_color", "font_disabled_color" | ||
}; | ||
|
||
const Color colour = Utilities::to_godot_color(gfx_font->get_colour()); | ||
|
||
for (StringName const& theme_name : button_font_themes) { | ||
add_theme_color_override(theme_name, colour); | ||
} | ||
|
||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include <godot_cpp/classes/button.hpp> | ||
|
||
#include <openvic-simulation/interface/GFXSprite.hpp> | ||
|
||
#include "openvic-extension/classes/GFXButtonStateTexture.hpp" | ||
#include "openvic-extension/classes/GUIHasTooltip.hpp" | ||
|
||
namespace OpenVic { | ||
class GUIButton : public godot::Button { | ||
GDCLASS(GUIButton, godot::Button) | ||
|
||
GUI_TOOLTIP_DEFINITIONS | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
void _notification(int what); | ||
|
||
godot::Error set_gfx_button_state_having_texture(godot::Ref<GFXButtonStateHavingTexture> const& texture); | ||
|
||
public: | ||
GUIButton(); | ||
|
||
godot::Error set_gfx_font(GFX::Font const* gfx_font); | ||
}; | ||
} |
Oops, something went wrong.