Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions patches/minecraft/net/minecraft/client/gui/GuiChat.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
--- before/net/minecraft/client/gui/GuiChat.java
+++ after/net/minecraft/client/gui/GuiChat.java
@@ -26,6 +26,8 @@
private TabCompleter tabCompleter;
protected GuiTextField inputField;
private String defaultInputFieldText = "";
+ private com.cleanroommc.client.chat.suggestion.SuggestionList suggestionList;
+ private com.cleanroommc.client.chat.suggestion.SuggestionUpdater suggestionUpdater;

public GuiChat()
{
@@ -48,6 +50,13 @@
this.inputField.setText(this.defaultInputFieldText);
this.inputField.setCanLoseFocus(false);
this.tabCompleter = new GuiChat.ChatTabCompleter(this.inputField);
+ this.suggestionList = new com.cleanroommc.client.chat.suggestion.SuggestionList(this.inputField);
+ this.suggestionUpdater = new com.cleanroommc.client.chat.suggestion.SuggestionUpdater(this.suggestionList, this.tabCompleter, this.inputField);
+ this.inputField.setGuiResponder(this.suggestionUpdater);
+ if (this.defaultInputFieldText != null)
+ {
+ this.suggestionUpdater.setEntryValue(0, this.defaultInputFieldText);
+ }
}

@Override
@@ -70,6 +79,15 @@

if (keyCode == 15)
{
+ if (this.suggestionList.isVisible())
+ {
+ String selected = this.suggestionList.getSelected();
+ if (selected == null) {
+ selected = this.suggestionList.getFirst();
+ }
+ this.suggestionList.applySuggestion(this.inputField, selected);
+ return;
+ }
this.tabCompleter.complete();
}
else
@@ -79,10 +97,20 @@

if (keyCode == 1)
{
+ if (this.suggestionList.isVisible())
+ {
+ this.suggestionList.hide();
+ }
this.mc.displayGuiScreen(null);
}
else if (keyCode == 28 || keyCode == 156)
{
+ String selected = this.suggestionList.getSelected();
+ if (selected != null)
+ {
+ this.suggestionList.applySuggestion(this.inputField, selected);
+ return;
+ }
String s = this.inputField.getText().trim();

if (!s.isEmpty())
@@ -94,10 +122,20 @@
}
else if (keyCode == 200)
{
+ if (this.suggestionList.isVisible())
+ {
+ this.suggestionList.selectPrev();
+ return;
+ }
this.getSentHistory(-1);
}
else if (keyCode == 208)
{
+ if (this.suggestionList.isVisible())
+ {
+ this.suggestionList.selectNext();
+ return;
+ }
this.getSentHistory(1);
}
else if (keyCode == 201)
@@ -111,6 +149,8 @@
else
{
this.inputField.textboxKeyTyped(typedChar, keyCode);
+ // Cleanroom: cursor-move keys change the cursor without firing the GuiResponder - refresh here
+ this.suggestionUpdater.refresh();
}
}

@@ -132,6 +172,13 @@
i = -1;
}

+ int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth;
+ int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
+ if (this.suggestionList.isMouseOver(this.inputField.x, this.inputField.y, this.inputField.width, mouseX, mouseY))
+ {
+ this.suggestionList.scroll(i);
+ return;
+ }
if (!isShiftKeyDown())
{
i *= 7;
@@ -146,6 +193,12 @@
{
if (mouseButton == 0)
{
+ String clicked = this.suggestionList.mouseClicked(this.inputField.x, this.inputField.y, this.inputField.width, mouseX, mouseY);
+ if (clicked != null)
+ {
+ this.suggestionList.applySuggestion(this.inputField, clicked);
+ return;
+ }
ITextComponent itextcomponent = this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());

if (itextcomponent != null && this.handleComponentClick(itextcomponent))
@@ -155,6 +208,8 @@
}

this.inputField.mouseClicked(mouseX, mouseY, mouseButton);
+ // Cleanroom: click repositions the cursor without firing the GuiResponder - refresh to follow it
+ this.suggestionUpdater.refresh();
super.mouseClicked(mouseX, mouseY, mouseButton);
}

@@ -201,7 +256,9 @@
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
drawRect(2, this.height - 14, this.width - 2, this.height - 2, Integer.MIN_VALUE);
+ this.suggestionList.drawGhostText(this.inputField, this.fontRenderer);
this.inputField.drawTextBox();
+ this.suggestionList.drawCommandColor(this.inputField, this.fontRenderer);
ITextComponent itextcomponent = this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());

if (itextcomponent != null && itextcomponent.getStyle().getHoverEvent() != null)
@@ -209,6 +266,7 @@
this.handleComponentHover(itextcomponent, mouseX, mouseY);
}

+ this.suggestionList.render(this.inputField.x, this.inputField.y, this.inputField.width, mouseX, mouseY);
super.drawScreen(mouseX, mouseY, partialTicks);
}

@@ -222,6 +280,7 @@
public void setCompletions(String... newCompletions)
{
this.tabCompleter.setCompletions(newCompletions);
+ this.suggestionList.updateSuggestions(newCompletions);
}

@SideOnly(Side.CLIENT)
@@ -232,29 +291,6 @@
public ChatTabCompleter(GuiTextField p_i46749_1_)
{
super(p_i46749_1_, false);
- }
-
- @Override
- public void complete()
- {
- super.complete();
-
- if (this.completions.size() > 1)
- {
- StringBuilder stringbuilder = new StringBuilder();
-
- for (String s : this.completions)
- {
- if (stringbuilder.length() > 0)
- {
- stringbuilder.append(", ");
- }
-
- stringbuilder.append(s);
- }
-
- this.client.ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new TextComponentString(stringbuilder.toString()), 1);
- }
}

@Nullable
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import net.minecraft.client.Minecraft;
@@ -631,6 +632,7 @@
@@ -603,6 +604,11 @@
return this.cursorPosition;
}

+ public int getLineScrollOffset()
+ {
+ return this.lineScrollOffset;
+ }
+
public boolean getEnableBackgroundDrawing()
{
return this.enableBackgroundDrawing;
@@ -631,6 +637,7 @@
}

this.isFocused = isFocusedIn;
Expand Down
Loading