Skip to content

Commit

Permalink
Started work on the new asset menu!
Browse files Browse the repository at this point in the history
Now there's these cool things called folders! It's a totally new
invention, I think it'll do really well with those tiktok kids.

The way in which assets are displayed can also be adjusted now, with
both the button type and scale being variable.

This is primarily to fix #268, as the 3D previews were causing
random crashes in v0.1.x when going through the pages.

This also fixes #299, as tooltips now only show descriptions. I plan
to add a right-click option to show the full details of an asset.

This commit also contributes to #252, since tokens are now shown in
the UI as "Tiles / Tokens". The ability for tokens to be placed in
player's hands has not been implemented yet.
  • Loading branch information
drwhut committed Sep 10, 2024
1 parent 9697dd1 commit 7d66346
Show file tree
Hide file tree
Showing 12 changed files with 609 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
controller.
- Added a "Loading..." panel when the client is receiving a new state from the
host in multiplayer.
- When selecting assets, assets are now organised into folders.
- When selecting assets, the layout and scale in which assets are displayed can
now be changed.

### Changed

Expand Down Expand Up @@ -240,6 +243,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated error messages related to the multiplayer network. In some cases,
errors are now followed up with advice on how to solve the issue.
- The text of the "Hide Room Code" button has been replaced with an icon.
- In the objects menu, objects are now represented with static thumbnails
instead of rotating 3D previews, which should fix a number of crashes. (#268)
- When selecting assets, the tooltip for each asset now only displays the
description of the asset, instead of a full summary.
- When selecting assets, a scroll bar is now used instead of pages when
displaying lots of assets at once.
- The "Tokens" object type has been renamed to "Tiles / Tokens".

### Fixed

Expand Down Expand Up @@ -293,5 +303,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The import log has been removed from the main menu, as the chat window (which
displays errors and warnings generated by assets) is now shown in the main
menu.
- When selecting assets, the "Pack" and "Type" dropdowns have been removed now
that folders have been implemented.

[unreleased]: https://github.com/drwhut/tabletop-club/compare/HEAD...HEAD
10 changes: 10 additions & 0 deletions game/LICENSES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ packs. Licensing information for these assets can be viewed in-game.
URL: https://www.svgrepo.com/svg/7368/dollar-coin-in-a-hand


- Folder icon

Files:
icons/folder_icon.svg
Author: Noah Jacobus
License: CC0
Modified By: Benjamin 'drwhut' Beddows
URL: https://www.svgrepo.com/svg/535400/folder


- Godot logo

Files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[resource]
script = ExtResource( 1 )
id = "Lobby Time - Kevin MacLeod"
desc = "Welcome to the lobby of the FUTURE! Luxurious automatic ashtrays, and modern green vinyl furnishings set off the shag carpeted walls. Enjoy a Rusty Nail from our cheerful bar staff (with a complimentary cheese and fruit plate before 5pm). We feature prime rib dinners every day that ends in a \\\"y\\\"! Remember to tip the bellhops at least 5 cents per bag. Enjoy your stay! This was written 2 years before it was published, because I didn't have a good enough upright bass sample to make it go."
desc = "Welcome to the lobby of the FUTURE! Luxurious automatic ashtrays, and modern green vinyl furnishings set off the shag carpeted walls. Enjoy a Rusty Nail from our cheerful bar staff (with a complimentary cheese and fruit plate before 5pm). We feature prime rib dinners every day that ends in a \"y\"! Remember to tip the bellhops at least 5 cents per bag. Enjoy your stay! This was written 2 years before it was published, because I didn't have a good enough upright bass sample to make it go."
pack = "TabletopClub"
type = "music"
author = "Kevin MacLeod"
Expand Down
9 changes: 9 additions & 0 deletions game/fonts/res/asset_menu_font.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_resource type="DynamicFont" load_steps=3 format=2]

[ext_resource path="res://fonts/data/PTSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://fonts/data/Cabin-Regular.ttf" type="DynamicFontData" id=2]

[resource]
use_filter = true
font_data = ExtResource( 2 )
fallback/0 = ExtResource( 1 )
10 changes: 10 additions & 0 deletions game/fonts/res/asset_menu_font_major.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[gd_resource type="DynamicFont" load_steps=3 format=2]

[ext_resource path="res://fonts/data/PTSans-Regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://fonts/data/Cabin-Regular.ttf" type="DynamicFontData" id=2]

[resource]
size = 20
use_filter = true
font_data = ExtResource( 2 )
fallback/0 = ExtResource( 1 )
4 changes: 4 additions & 0 deletions game/icons/folder_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions game/icons/folder_icon.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/folder_icon.svg-427f1e04848ab8ef3a4529875e530b78.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icons/folder_icon.svg"
dest_files=[ "res://.import/folder_icon.svg-427f1e04848ab8ef3a4529875e530b78.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=0.125
12 changes: 12 additions & 0 deletions game/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://assets/objects/advanced_rigid_body.gd"
}, {
"base": "Control",
"class": "AssetButton",
"language": "GDScript",
"path": "res://ui/asset_menu/asset_button.gd"
}, {
"base": "Reference",
"class": "AssetCatalog",
"language": "GDScript",
Expand Down Expand Up @@ -104,6 +109,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://assets/entry/entry_template_text.gd"
}, {
"base": "GridContainer",
"class": "AssetGrid",
"language": "GDScript",
"path": "res://ui/asset_menu/asset_grid.gd"
}, {
"base": "Reference",
"class": "AssetNode",
"language": "GDScript",
Expand Down Expand Up @@ -528,6 +538,7 @@ _global_script_class_icons={
"ActualTextFile": "",
"AdvancedConfigFile": "",
"AdvancedRigidBody3D": "",
"AssetButton": "",
"AssetCatalog": "",
"AssetCatalogInteractive": "",
"AssetEntry": "",
Expand All @@ -544,6 +555,7 @@ _global_script_class_icons={
"AssetEntryTemplate": "",
"AssetEntryTemplateImage": "",
"AssetEntryTemplateText": "",
"AssetGrid": "",
"AssetNode": "",
"AssetPack": "",
"AssetPackCatalog": "",
Expand Down
200 changes: 200 additions & 0 deletions game/ui/asset_menu/asset_button.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# tabletop-club
# Copyright (c) 2020-2024 Benjamin 'drwhut' Beddows.
# Copyright (c) 2021-2024 Tabletop Club contributors (see game/CREDITS.tres).
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

class_name AssetButton
extends Control

## A button with multiple appearances that represents an asset in the AssetDB.


## Fired when the button is pressed.
signal pressed()


## The ways in which the button can appear.
enum ButtonType {
VERTICAL,
HORIZONTAL,
}


## The size of the detail icons in the top-right corner.
const DETAIL_ICON_SIZE := Vector2(20.0, 20.0)

## The margin given to the detail icons relative to the edge of the button.
const DETAIL_ICON_MARGIN := 2.0


## Sets what the button looks like.
export(ButtonType) var appearance: int setget set_appearance, get_appearance

## Sets the text that the button displays.
## TODO: Do we want the text to be able to scroll? Or do we rely on being able
## to show the entire text?
export(String) var text: String setget set_text, get_text

## Sets the icon that the button displays.
export(Texture) var texture: Texture setget set_texture, get_texture

## Set the hint that is displayed when the button is hovered over.
export(String) var hint: String setget set_hint, get_hint

## Set the font used to render the button text.
export(Font) var font_override: Font setget set_font_override, get_font_override

## Set if the button represents a folder.
export(bool) var folder: bool setget set_folder, is_folder

## Set if the button represents a stack.
export(bool) var stack: bool setget set_stack, is_stack


# The button that is used when in vertical mode.
var _button_vertical: VerticalButton = null

# The button that is used when in horizontal mode.
var _button_horizontal: Button = null

# The icon that shows the button represents a folder.
var _folder_icon: TextureRect = null

# The icon that shows the button represents a stack.
var _stack_icon: TextureRect = null


func _init():
_button_vertical = VerticalButton.new()
_button_vertical.anchor_right = 1
_button_vertical.anchor_bottom = 1
_button_vertical.connect("pressed", self, "_on_button_pressed")
add_child(_button_vertical)

_button_horizontal = Button.new()
_button_horizontal.clip_text = true
_button_horizontal.expand_icon = true
_button_horizontal.anchor_right = 1
_button_horizontal.anchor_bottom = 1
_button_horizontal.visible = false
_button_horizontal.connect("pressed", self, "_on_button_pressed")
add_child(_button_horizontal)

var icon_container := HBoxContainer.new()
icon_container.anchor_left = 1
icon_container.anchor_right = 1
icon_container.margin_top = DETAIL_ICON_MARGIN
icon_container.margin_right = -DETAIL_ICON_MARGIN
icon_container.grow_horizontal = Control.GROW_DIRECTION_BEGIN
icon_container.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(icon_container)

_folder_icon = TextureRect.new()
_folder_icon.texture = preload("res://icons/folder_icon.svg")
_folder_icon.expand = true
_folder_icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
_folder_icon.rect_min_size = DETAIL_ICON_SIZE
_folder_icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
_folder_icon.visible = false
icon_container.add_child(_folder_icon)

_stack_icon = TextureRect.new()
_stack_icon.texture = preload("res://icons/stack_icon.svg")
_stack_icon.expand = true
_stack_icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_COVERED
_stack_icon.rect_min_size = DETAIL_ICON_SIZE
_stack_icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
_stack_icon.visible = false
icon_container.add_child(_stack_icon)


func get_appearance() -> int:
if _button_vertical.visible:
return ButtonType.VERTICAL
elif _button_horizontal.visible:
return ButtonType.HORIZONTAL

return 0


func get_text() -> String:
# Any of the buttons should work fine here.
return _button_horizontal.text


func get_texture() -> Texture:
return _button_horizontal.texture


func get_hint() -> String:
return _button_horizontal.hint_tooltip


func get_font_override() -> Font:
return _button_horizontal.get_font("font")


func is_folder() -> bool:
return _folder_icon.visible


func is_stack() -> bool:
return _stack_icon.visible


func set_appearance(new_value: int) -> void:
if new_value < ButtonType.VERTICAL or new_value > ButtonType.HORIZONTAL:
push_error("Invalid value '%d' for asset button appearance" % new_value)
return

_button_vertical.visible = (new_value == ButtonType.VERTICAL)
_button_horizontal.visible = (new_value == ButtonType.HORIZONTAL)


func set_text(new_value: String) -> void:
_button_vertical.vertical_text = new_value
_button_horizontal.text = new_value


func set_texture(new_value: Texture) -> void:
_button_vertical.texture = new_value
_button_horizontal.icon = new_value


func set_hint(new_value: String) -> void:
_button_vertical.hint_tooltip = new_value
_button_horizontal.hint_tooltip = new_value


func set_font_override(new_value: Font) -> void:
_button_vertical.font_override = new_value
_button_horizontal.add_font_override("font", new_value)


func set_folder(new_value: bool) -> void:
_folder_icon.visible = new_value


func set_stack(new_value: bool) -> void:
_stack_icon.visible = new_value


func _on_button_pressed():
emit_signal("pressed")
Loading

0 comments on commit 7d66346

Please sign in to comment.