Skip to content

Commit

Permalink
mainly scene restructurdicting Next level visual fix (#6)
Browse files Browse the repository at this point in the history
* menu scene tree refactor game page

* menu scene tree refactor about page

* menu scene tree refactor settings page

* fix scroll to bug report

* Fixing stuff the merge broke

* Fix title font and added margin container to main_theme.tres

* fix about page crashing on reload

* game_card scene tree refactor

* game_card_add_yours scene tree refactor

* fix assert fail

* fix themes and theme overwrites

* fix merge

* rename About.gd to about.gd

* fix about page empty bottom part

* Fixed most colors/margins

* fix visuals

* Disable bbcode for no reason

* fix theme even more

* Fixed more margins/color issues

* add much needed about.gd docu & make it respond to line spacing

* fix visuals again

* refactor about.gd thanks to Numenters tip

* Fixed play time game card position

* fix more visuals

Co-authored-by: RedstoneMedia <34373974+RedstoneMedia@users.noreply.github.com>
  • Loading branch information
ASecondGuy and RedstoneMedia authored Jul 2, 2022
1 parent 331cc7d commit 8e271ad
Show file tree
Hide file tree
Showing 12 changed files with 527 additions and 784 deletions.
110 changes: 110 additions & 0 deletions game/app/scenes/about.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
tool
extends ScrollContainer
# This script translates a simplified syntax into bbcode for the RichTextLabel to display.
# It can also calculate the position of specific lines. This is used by menu to smooth scroll.
# How to edit the about page:
# -Edit the text property of this About node.
# -Everything will be translated using tr()
# (every key will be substituted anything else stays the same)
# -titles can be added by using the title_key at the start of the line.
# (this is a shorthand for using [font="res://.../titlefont.tres")
# -Any [url] tag will be treated like a link. If you add one color it the same as the others.
# (specific color is subject to change)

export(String) var title_key := "# "
# This is the About text. To add a Title use the title key
export(String, MULTILINE) var text := "" setget set_text
export(Font) var title_font: Font

onready var _label := $MC/RichTextLabel


# this is needed to ract to any language changes that might need retranslating
func _notification(what):
if what == NOTIFICATION_TRANSLATION_CHANGED:
_write_def()


func _ready():
_write_to_label()


func set_text(val: String):
text = val
# updating this is only needed in editor
# In-game it is updated by other sources
if Engine.editor_hint:
_write_def()


func _write_to_label():
# Fails in Editor when you edit the script.
if !is_instance_valid(_label):
return
# this part might need a refactor
_label.clear()
for line in text.split("\n"):
# this loop treats every line in sequence
var is_title: bool = line.begins_with(title_key)
line = line.trim_prefix(title_key)
if is_title:
_label.push_font(title_font)

# first refers to the first part of the line
var first := true
for key in line.split(" "):
# each part of this might be a translation key, one or more bb tags,
# one or more closing tags, or just text
if key.match("[/*]"):
# RichTextLabel requires pop() when closing tag from previus append_bbcode()
for _i in range(key.count("[")):
_label.pop()
else:
# append the translation of whatever key is
# anything not a key will be returned unchanged
# tr("[color=blue]") = "[color=blue]"
if first:
# the first part of the line shouldn't have a seperating " " infront of it
_label.append_bbcode(tr(key))
else:
_label.append_bbcode(" " + tr(key))
first = false
# close the [font] tag for the title font
if is_title:
_label.pop()
_label.newline()


# determines how far down to scroll until the line is found
# !this is searched in the untranslated text
func get_line_absolute_height(line: String):
var pos: float = 0
var lines: Array = text.split("\n")
var font_height: int = _label.get_font("normal_font").get_height()
var line_spacing: float = _label.get_constant("line_separation")

var line_location := text.find(line)
# count won't work if location is 0. If it is the height is also 0
if line_location == 0:
return 0
# go over every line and add its height
for i in text.count("\n", 0, line_location):
# i is the line to add the size of
if lines[i].begins_with(title_key):
pos += title_font.get_height()
else:
pos += font_height
pos += line_spacing
return pos


# helper to call _write_to_label deferred
# (_write_to_label will be called at the end of the frame after everything else)
func _write_def():
call_deferred("_write_to_label")


# This is called when the user clicks on a [url] tag in the label.
# Utils.open_url() actually supports more than just urls
func _on_RichTextLabel_meta_clicked(meta):
Utils.open_url(meta)
49 changes: 24 additions & 25 deletions game/app/scenes/game_card.gd
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
extends ColorRect
extends PanelContainer

var _game_config: ConfigFile = null
var _playtime: float = 0
var _last_played = -1

onready var _label_title := $MC/VC/HC/VC/MC/LabelTitle
onready var _label_description := $MC/VC/SC/MC/LabelDescription
onready var _texture_icon_rect := $MC/VC/HC/TextureRectIcon
onready var _label_playtime := $MC/VC/HC/VC/HC/LabelPlaytimeNumber
onready var _label_playtime_unit := $MC/VC/HC/VC/HC/LabelPlaytimeUnit
onready var _label_title := $Card/TitleSection/VC/LabelTitle
onready var _label_description := $Card/Description
onready var _texture_icon_rect := $Card/TitleSection/icon
onready var _label_playtime := $Card/TitleSection/VC/HC/LabelPlaytimeNumber
onready var _label_playtime_unit := $Card/TitleSection/VC/HC/LabelPlaytimeUnit

onready var _popup_label_title := $PopupDialogInfo/VC/PC/MC/HC/MC/VC/MC/LabelTitle
onready var _popup_label_description := $PopupDialogInfo/VC/PC2/MC/HC/SC/MC/VC/LabelDescription
onready var _popup_icon_rect := $PopupDialogInfo/VC/PC/MC/HC/TextureRectIcon
onready var _popup_label_author := $PopupDialogInfo/VC/PC2/MC/HC/VC/LabelAuthor
onready var _popup_label_version := $PopupDialogInfo/VC/PC2/MC/HC/VC/LabelVersion
onready var _popup_label_playtime := $PopupDialogInfo/VC/PC/MC/HC/MC/VC/HC/LabelPlaytimeNumber
onready var _popup_label_playtime_unit := $PopupDialogInfo/VC/PC/MC/HC/MC/VC/HC/LabelPlaytimeUnit
onready var _popup_label_playtime_2 := $PopupDialogInfo/VC/PC/MC/HC/MC/VC/HC/LabelPlaytimeNumber2
onready var _popup_label_playtime_unit_2 := $PopupDialogInfo/VC/PC/MC/HC/MC/VC/HC/LabelPlaytimeUnit2
onready var _popup_label_highscore := $PopupDialogInfo/VC/PC/MC/HC/VC/LabelHighscore
onready var _popup_label_title := $PopupDialogInfo/VC/TitleSection/HC/Title/LabelTitle
onready var _popup_label_description := $PopupDialogInfo/VC/InfoSection/HC/Description
onready var _popup_icon_rect := $PopupDialogInfo/VC/TitleSection/HC/TextureRectIcon
onready var _popup_label_author := $PopupDialogInfo/VC/InfoSection/HC/VC/LabelAuthor
onready var _popup_label_version := $PopupDialogInfo/VC/InfoSection/HC/VC/LabelVersion
onready var _popup_playtime := $PopupDialogInfo/VC/TitleSection/HC/Title/HC/LabelPlaytimeNumber
onready var _popup_playtime_2 := $PopupDialogInfo/VC/TitleSection/HC/Title/HC/LabelPlaytimeNumber2
onready var _popup_playtime_unit := $PopupDialogInfo/VC/TitleSection/HC/Title/HC/LabelPlaytimeUnit
onready var _popup_playtime_unit_2 := $PopupDialogInfo/VC/TitleSection/HC/Title/HC/LabelPlaytimeUnit2
onready var _popup_label_highscore := $PopupDialogInfo/VC/TitleSection/HC/HighScore/LabelHighscore


func setup(game_config: ConfigFile):
Expand All @@ -36,18 +36,17 @@ func setup(game_config: ConfigFile):
var playtime_unit = playtime_dict["unit"]

if playtime_dict.has("another_number"):
_popup_label_playtime_2.visible = true
_popup_label_playtime_2.text = playtime_dict["another_number"]
_popup_playtime_2.visible = true
_popup_playtime_2.text = playtime_dict["another_number"]
if playtime_dict.has("another_unit"):
_popup_label_playtime_unit_2.visible = true
_popup_label_playtime_unit_2.text = playtime_dict["another_unit"]
_popup_playtime_unit_2.visible = true
_popup_playtime_unit_2.text = playtime_dict["another_unit"]

var highscore_dict = GameManager.get_highscore(game_id)
if highscore_dict.has("score"):
_popup_label_highscore.text = str(highscore_dict["score"])
else:
$PopupDialogInfo/VC/PC/MC/HC/VC/Label.visible = false
$PopupDialogInfo/VC/PC/MC/HC/VC/LabelHighscore.visible = false
$PopupDialogInfo/VC/TitleSection/HC/HighScore.visible = false

_label_title.text = game_name
_label_description.text = game_description
Expand All @@ -58,8 +57,8 @@ func setup(game_config: ConfigFile):
_popup_label_description.text = game_description
_popup_label_author.text = game_config.get_value("game", "creator")
_popup_label_version.text = game_config.get_value("game", "version")
_popup_label_playtime.text = playtime_number
_popup_label_playtime_unit.text = playtime_unit
_popup_playtime.text = playtime_number
_popup_playtime_unit.text = playtime_unit

var icon_file_name = game_config.get_value("game", "icon")
var icon_path = GameManager.make_game_file_path(game_id, icon_file_name)
Expand Down Expand Up @@ -113,7 +112,7 @@ func _format_playtime(playtime: float) -> Dictionary:


func _on_ButtonInfo_pressed():
$PopupDialogInfo.popup_centered()
$PopupDialogInfo.popup_centered($PopupDialogInfo/VC.rect_size)


func _on_ButtonPlay_pressed():
Expand Down
Loading

0 comments on commit 8e271ad

Please sign in to comment.