Skip to content

Commit

Permalink
[Fix] font command not resetting font on the next line & mugshots bei…
Browse files Browse the repository at this point in the history
…ng unnecessarily reset when not used & Fixed text next line availability inconsistencies
  • Loading branch information
RhenaudTheLukark committed Mar 22, 2024
1 parent f8e2abd commit 5dcc775
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Assets/Scripts/Battle/UIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ private void UpdateMonsterDialogue() {
continue;
}

if ((!monsterDialogues[i].AllLinesComplete() || monsterDialogues[i].LineCount() == 0) && !monsterDialogues[i].CanAutoSkipThis() && (monsterDialogues[i].AllLinesComplete() || !monsterDialogues[i].LineComplete())) {
if (!monsterDialogues[i].AllLinesComplete() && (!monsterDialogues[i].CanSkipToNextLine() || !monsterDialogues[i].LineComplete())) {
allGood = false;
continue;
}
Expand Down Expand Up @@ -1394,15 +1394,15 @@ private void Update() {
mainTextManager.SetPause(false);

if (state == "DIALOGRESULT")
if (mainTextManager.CanAutoSkipAll() || mainTextManager.CanAutoSkip() || (mainTextManager.CanAutoSkipThis() && mainTextManager.LineComplete()))
if (mainTextManager.CanAutoSkipAny(true))
if (mainTextManager.HasNext())
mainTextManager.NextLineText();
else
SwitchState(stateAfterDialogs);

if (state == "ENEMYDIALOGUE") {
if (monsterDialogues.Where(mgr => mgr != null && mgr.isactive).All(mgr => mgr.CanAutoSkipThis())) DoNextMonsterDialogue();
else UpdateMonsterDialogue();
if (monsterDialogues.Where(mgr => mgr != null && mgr.isactive).All(mgr => mgr.CanSkipToNextLine())) DoNextMonsterDialogue();
else UpdateMonsterDialogue();
}

if (state == "DEFENDING") {
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Lua/CLRBindings/LuaTextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected override void Update() {
break;
}
}
if (CanAutoSkipAny() && (!UIController.instance || !UIController.instance.monsterDialogues.Contains(this)))
if (CanAutoSkipAny(true) && (!UIController.instance || !UIController.instance.monsterDialogues.Contains(this)))
NextLine();
if (GlobalControls.input.Cancel == ButtonState.PRESSED && CanSkip() && !LineComplete() && (!UIController.instance || this != UIController.instance.mainTextManager || !UIController.instance.stateSwitched))
DoSkipFromPlayer();
Expand Down
32 changes: 17 additions & 15 deletions Assets/Scripts/Overworld/PlayerOverworld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,22 @@ private void OnDisable() {
private void FinishFade() { PlayerNoMove = false; } // Scene loaded

private void NextText() {
if (!textmgr.AllLinesComplete() && (textmgr.CanAutoSkipAll() || textmgr.LineComplete()))
textmgr.NextLineText();
else if ((textmgr.AllLinesComplete() || textmgr.CanAutoSkipAll()) && textmgr.LineCount() != 0) {
EventManager.instance.passPressOnce = true;
textmgr.transform.parent.parent.SetAsFirstSibling();
textmgr.SetTextQueue(null);
textmgr.HideTextObject();
textmgr.SetHorizontalSpacing(textmgr.font.CharSpacing);
textmgr.SetVerticalSpacing();
textmgr.SetTextFrameAlpha(0);
if (EventManager.instance.script != null)
EventManager.instance.script.Call("CYFEventNextCommand");
else
PlayerNoMove = false; //End text no event
if (textmgr.CanAutoSkipAny(true) || textmgr.LineComplete()) {
if (!textmgr.AllLinesComplete())
textmgr.NextLineText();
else if (textmgr.LineCount() != 0) {
EventManager.instance.passPressOnce = true;
textmgr.transform.parent.parent.SetAsFirstSibling();
textmgr.SetTextQueue(null);
textmgr.HideTextObject();
textmgr.SetHorizontalSpacing(textmgr.font.CharSpacing);
textmgr.SetVerticalSpacing();
textmgr.SetTextFrameAlpha(0);
if (EventManager.instance.script != null)
EventManager.instance.script.Call("CYFEventNextCommand");
else
PlayerNoMove = false; //End text no event
}
}
}

Expand All @@ -220,7 +222,7 @@ private IEnumerator TextCoroutine() {
if (!GameObject.Find("textframe_border_outer")) continue;
if (GameObject.Find("textframe_border_outer").GetComponent<Image>().color.a == 0) continue;
try {
if (textmgr.CanAutoSkipAll())
if (textmgr.CanAutoSkipAny(true))
NextText();
if (GlobalControls.input.Cancel == ButtonState.PRESSED && !textmgr.LineComplete() && textmgr.CanSkip()) {
if (EventManager.instance.script != null && EventManager.instance.script.GetVar("playerskipdocommand").Boolean)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Overworld/ShopScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,9 @@ private void TextInputManager() {
tmBigTalk.DoSkipFromPlayer();
else
tmBigTalk.SkipLine();
} else if ((GlobalControls.input.Confirm == ButtonState.PRESSED || tmBigTalk.CanAutoSkipAll()) && tmBigTalk.LineComplete() && !tmBigTalk.AllLinesComplete())
} else if ((GlobalControls.input.Confirm == ButtonState.PRESSED || tmBigTalk.CanAutoSkipAny(true)) && tmBigTalk.LineComplete() && !tmBigTalk.AllLinesComplete())
tmBigTalk.NextLineText();
else if ((GlobalControls.input.Confirm == ButtonState.PRESSED || tmBigTalk.CanAutoSkipAll()) && tmBigTalk.AllLinesComplete()) {
else if ((GlobalControls.input.Confirm == ButtonState.PRESSED || tmBigTalk.CanAutoSkipAny(true)) && tmBigTalk.AllLinesComplete()) {
switch (currentState) {
case State.TALKINPROGRESS:
ChangeState(State.TALK);
Expand Down
37 changes: 21 additions & 16 deletions Assets/Scripts/Text/TextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public LetterData(int index, Image image, Sprite sprite, Vector2 position, bool

private bool paused;
private bool muted;
private bool autoSkipThis;
private bool skippableToNextLine;
private bool autoSkipAll;
private bool autoSkip;
private bool skipFromPlayer;
Expand Down Expand Up @@ -142,17 +142,19 @@ public TextManager() {

[MoonSharpHidden] public void SetCaller(ScriptWrapper s) { caller = s; }

public void SetFont(UnderFont font) {
public void SetFont(UnderFont font, bool inline = false) {
this.font = font;
defaultFont = font;
defaultVoice = font.SoundName;

if (defaultFont == null)
if (!inline || defaultFont == null) {
defaultFont = font;
defaultVoice = font.SoundName;
fontDefaultColor = font.DefaultColor;
}

vSpacing = 0;
hSpacing = font.CharSpacing;
fontDefaultColor = defaultColor = font.DefaultColor;

defaultColor = font.DefaultColor;
if (this as LuaTextManager) {
if ((this as LuaTextManager).textColorSet) defaultColor = ((LuaTextManager) this)._color;
if ((this as LuaTextManager).textAlphaSet) defaultColor.a = ((LuaTextManager) this).alpha;
Expand Down Expand Up @@ -228,11 +230,14 @@ public bool GetAutoLineBreak() {
}

[MoonSharpHidden] public void SetTextQueue(TextMessage[] newTextQueue) {
if (newTextQueue == null)
newTextQueue = new TextMessage[] { };

if (UnitaleUtil.IsOverworld && (gameObject.name == "TextManager OW"))
PlayerOverworld.AutoSetUIPos();

ResetFont();
if (mugshot != null) {
if (mugshotList != null) {
bool oldLineHasMugshot = lineHasMugshot;
SetMugshot(DynValue.NewNil());
SetMugshotShift(oldLineHasMugshot);
Expand Down Expand Up @@ -270,9 +275,9 @@ [MoonSharpHidden] public void AddToTextQueue(TextMessage[] textQueueToAdd) {

[MoonSharpHidden] public bool CanSkip() { return currentSkippable; }
[MoonSharpHidden] public bool CanAutoSkip() { return autoSkip; }
[MoonSharpHidden] public bool CanAutoSkipThis() { return autoSkipThis; }
[MoonSharpHidden] public bool CanSkipToNextLine() { return skippableToNextLine; }
[MoonSharpHidden] public bool CanAutoSkipAll() { return autoSkipAll; }
[MoonSharpHidden] public bool CanAutoSkipAny() { return CanAutoSkip() || CanAutoSkipThis() || CanAutoSkipAll(); }
[MoonSharpHidden] public bool CanAutoSkipAny(bool onlySkippableIfConfirm = false) { return CanAutoSkip() || (CanSkipToNextLine() && (!onlySkippableIfConfirm || GlobalControls.input.Confirm == ButtonState.PRESSED)) || CanAutoSkipAll(); }

public int LineCount() {
return textQueue == null ? 0 : textQueue.Length;
Expand Down Expand Up @@ -359,7 +364,7 @@ protected void ShowLine(int line) {
commandColorSet = false;
commandAlphaSet = false;
currentSkippable = true;
autoSkipThis = false;
skippableToNextLine = false;
autoSkip = false;
autoSkipAll = false;
instantCommand = false;
Expand Down Expand Up @@ -823,7 +828,7 @@ private bool CheckCommand() {
}

protected virtual void Update() {
if (mugshot != null && mugshotList != null)
if (mugshotList != null)
if (UnitaleUtil.IsOverworld && mugshot.alpha != 0 && mugshotList.Length > 1) {
if (!mugshot.animcomplete && (letterTimer < 0 || LineComplete())) {
mugshot.StopAnimation();
Expand Down Expand Up @@ -998,7 +1003,7 @@ private void PreCreateControlCommand(string command, bool movementCommand = fals
UnitaleUtil.DisplayLuaError("", "[font:x] usage - The font \"" + cmds[1] + "\" doesn't exist.\nYou should check if you made a typo, or if the font really is in your mod.", true);
break;
}
SetFont(uf);
SetFont(uf, true);
if (GetType() == typeof(LuaTextManager) && ((LuaTextManager)this).bubble)
((LuaTextManager) this).UpdateBubble();
break;
Expand Down Expand Up @@ -1061,10 +1066,10 @@ private void InUpdateControlCommand(DynValue command, int index = 0) {
catch { Debug.LogError("[waitall:x] usage - You used the value \"" + cmds[1] + "\" to set the text's waiting time between letters, but it's not a valid integer value."); }
break;

case "novoice": commandVoice = "none"; break;
case "next": autoSkip = true; break;
case "finished": autoSkipThis = true; break;
case "nextthisnow": autoSkipAll = true; break;
case "novoice": commandVoice = "none"; break;
case "next": autoSkip = true; break;
case "finished": skippableToNextLine = true; break;
case "nextthisnow": autoSkipAll = true; break;
case "speed":
try {
//you can only set text speed to a number >= 0
Expand Down

0 comments on commit 5dcc775

Please sign in to comment.