-
Notifications
You must be signed in to change notification settings - Fork 7
Fixed array tooltips, removed \n from lang #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JackOfNoneTrades
wants to merge
4
commits into
Carbon-Config-Project:1.7.10
Choose a base branch
from
JackOfNoneTrades:1.7.10
base: 1.7.10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6e33855
Fixed array tooltips, removed \n from lang
16f98c8
Added multiline support to yes/no and MultiChoiceScreen GUIs
1445c46
color format range checks, also checks whether a style exists
7237460
Adapted some font renderer code to make FormattingUtil and its usages…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
62 changes: 62 additions & 0 deletions
62
src/main/java/carbonconfiglib/gui/screen/FormattingUtil.java
This file contains hidden or 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,62 @@ | ||
| package carbonconfiglib.gui.screen; | ||
|
|
||
| import net.minecraft.client.gui.FontRenderer; | ||
| import net.minecraft.util.IChatComponent; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class FormattingUtil { | ||
| private static boolean isFormatColor(char c) { | ||
| return c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F'; | ||
| } | ||
|
|
||
| private static boolean isFormatSpecialNoReset(char c) { | ||
| return c >= 'k' && c <= 'o' || c >= 'K' && c <= 'O'; | ||
| } | ||
|
|
||
| private static String getFormatFromString(String s) { | ||
| String s1 = ""; | ||
| int i = -1; | ||
| int j = s.length(); | ||
|
|
||
| while ((i = s.indexOf(167, i + 1)) != -1) | ||
| { | ||
| if (i < j - 1) | ||
| { | ||
| char c0 = s.charAt(i + 1); | ||
|
|
||
| if (isFormatColor(c0)) | ||
| { | ||
| s1 = "\u00a7" + c0; | ||
| } | ||
| else if (isFormatSpecialNoReset(c0)) | ||
| { | ||
| s1 = s1 + "\u00a7" + c0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return s1; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static String[] listFormattedStringToWidthRespectingNewlines(FontRenderer fontRenderer, String s, int width) { | ||
| List<String> result = new ArrayList<>(); | ||
| String[] lines = s.split("\\\\n"); | ||
| String formatting = getFormatFromString(s); | ||
| for (String line : lines) { | ||
| if (width > 0) { | ||
| result.addAll(fontRenderer.listFormattedStringToWidth(formatting + line, width)); | ||
| } else { | ||
| result.add(formatting + line); | ||
| } | ||
| } | ||
| return result.toArray(new String[0]); | ||
| } | ||
|
|
||
| public static String[] listFormattedStringToWidthRespectingNewlines(FontRenderer fontRenderer, String s) { | ||
| return listFormattedStringToWidthRespectingNewlines(fontRenderer, s, -1); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/carbonconfiglib/gui/screen/GuiMultiLineYesNo.java
This file contains hidden or 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,35 @@ | ||
| package carbonconfiglib.gui.screen; | ||
|
|
||
| import cpw.mods.fml.relauncher.Side; | ||
| import cpw.mods.fml.relauncher.SideOnly; | ||
| import net.minecraft.client.gui.GuiYesNo; | ||
| import net.minecraft.client.gui.GuiYesNoCallback; | ||
|
|
||
| @SideOnly(Side.CLIENT) | ||
| public class GuiMultiLineYesNo extends GuiYesNo { | ||
|
|
||
| private final String message; | ||
|
|
||
| public GuiMultiLineYesNo(GuiYesNoCallback callback, String title, String message, int id) { | ||
| super(callback, title, "", id); | ||
| this.message = message; | ||
| } | ||
|
|
||
| public GuiMultiLineYesNo(GuiYesNoCallback parent, String title, String message, String confirm, String cancel, int id) { | ||
| super(parent, title, "", confirm, cancel, id); | ||
| this.message = message; | ||
| } | ||
|
|
||
| @Override | ||
| public void drawScreen(int mouseX, int mouseY, float partialTicks) { | ||
| super.drawScreen(mouseX, mouseY, partialTicks); | ||
|
|
||
| int lineHeight = this.fontRendererObj.FONT_HEIGHT + 2; | ||
| int startY = 90; | ||
| String[] messages = FormattingUtil.listFormattedStringToWidthRespectingNewlines(this.fontRendererObj, message, this.width - 50); | ||
|
|
||
| for (int i = 0; i < messages.length; ++i) { | ||
| this.drawCenteredString(this.fontRendererObj, messages[i], this.width / 2, startY + (i * lineHeight), 16777215); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw that line into the init function, font renderer and width are accessible once the init is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, width is 0