generated from LabyMod/addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement staff note management and tag history ingame
- Loading branch information
Showing
25 changed files
with
1,119 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
78 changes: 78 additions & 0 deletions
78
core/src/main/java/com/rappytv/globaltags/activities/CreateNoteActivity.java
This file contains 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,78 @@ | ||
package com.rappytv.globaltags.activities; | ||
|
||
import com.rappytv.globaltags.GlobalTagAddon; | ||
import com.rappytv.globaltags.api.GlobalTagAPI; | ||
import com.rappytv.globaltags.api.Util; | ||
import java.util.UUID; | ||
import net.labymod.api.Laby; | ||
import net.labymod.api.client.component.Component; | ||
import net.labymod.api.client.component.format.NamedTextColor; | ||
import net.labymod.api.client.gui.icon.Icon; | ||
import net.labymod.api.client.gui.screen.Parent; | ||
import net.labymod.api.client.gui.screen.ScreenInstance; | ||
import net.labymod.api.client.gui.screen.activity.AutoActivity; | ||
import net.labymod.api.client.gui.screen.activity.Link; | ||
import net.labymod.api.client.gui.screen.activity.types.SimpleActivity; | ||
import net.labymod.api.client.gui.screen.widget.Widget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.ComponentWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.input.TextFieldWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.FlexibleContentWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.VerticalListWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.renderer.IconWidget; | ||
|
||
@Link("input.lss") | ||
@AutoActivity | ||
public class CreateNoteActivity extends SimpleActivity { | ||
|
||
private final GlobalTagAPI api; | ||
private final UUID uuid; | ||
private final String username; | ||
|
||
public CreateNoteActivity(GlobalTagAPI api, UUID uuid, String username) { | ||
this.api = api; | ||
this.uuid = uuid; | ||
this.username = username; | ||
} | ||
|
||
@Override | ||
public void initialize(Parent parent) { | ||
super.initialize(parent); | ||
FlexibleContentWidget windowWidget = new FlexibleContentWidget().addId("window"); | ||
HorizontalListWidget profileWrapper = new HorizontalListWidget().addId("header"); | ||
IconWidget headWidget = new IconWidget(Icon.head(this.uuid)).addId("head"); | ||
ComponentWidget titleWidget = ComponentWidget.i18n("globaltags.context.staff_notes.create.title", this.username).addId("username"); | ||
VerticalListWidget<Widget> content = new VerticalListWidget<>().addId("content"); | ||
ComponentWidget labelWidget = ComponentWidget.i18n("globaltags.context.staff_notes.create.label").addId("label"); | ||
TextFieldWidget inputWidget = new TextFieldWidget() | ||
.placeholder(Component.translatable("globaltags.context.staff_notes.create.placeholder", NamedTextColor.DARK_GRAY)) | ||
.addId("input"); | ||
ButtonWidget sendButton = new ButtonWidget() | ||
.updateComponent(Component.translatable("globaltags.context.staff_notes.create.send", NamedTextColor.AQUA)) | ||
.addId("send-button"); | ||
sendButton.setEnabled(false); | ||
sendButton.setActionListener(() -> api.getApiHandler().createNote(uuid, inputWidget.getText(), (response) -> { | ||
Laby.references().chatExecutor().displayClientMessage( | ||
Component.empty() | ||
.append(GlobalTagAddon.prefix) | ||
.append(Util.getResponseComponent(response)) | ||
); | ||
Laby.labyAPI().minecraft().executeOnRenderThread(() -> | ||
Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null) | ||
); | ||
})); | ||
inputWidget.updateListener((text) -> sendButton.setEnabled(!text.isBlank())); | ||
|
||
profileWrapper.addEntry(headWidget); | ||
profileWrapper.addEntry(titleWidget); | ||
|
||
content.addChild(labelWidget); | ||
content.addChild(inputWidget); | ||
content.addChild(sendButton); | ||
|
||
windowWidget.addContent(profileWrapper); | ||
windowWidget.addContent(content); | ||
this.document.addChild(windowWidget); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
core/src/main/java/com/rappytv/globaltags/activities/StaffNotesActivity.java
This file contains 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,79 @@ | ||
package com.rappytv.globaltags.activities; | ||
|
||
import com.rappytv.globaltags.GlobalTagAddon; | ||
import com.rappytv.globaltags.activities.widgets.StaffNoteWidget; | ||
import com.rappytv.globaltags.api.GlobalTagAPI; | ||
import com.rappytv.globaltags.wrapper.model.PlayerNote; | ||
import net.labymod.api.Laby; | ||
import net.labymod.api.client.component.Component; | ||
import net.labymod.api.client.component.TextComponent; | ||
import net.labymod.api.client.component.format.NamedTextColor; | ||
import net.labymod.api.client.gui.icon.Icon; | ||
import net.labymod.api.client.gui.screen.Parent; | ||
import net.labymod.api.client.gui.screen.ScreenInstance; | ||
import net.labymod.api.client.gui.screen.activity.AutoActivity; | ||
import net.labymod.api.client.gui.screen.activity.Link; | ||
import net.labymod.api.client.gui.screen.activity.types.SimpleActivity; | ||
import net.labymod.api.client.gui.screen.widget.widgets.ComponentWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.FlexibleContentWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.ScrollWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.VerticalListWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.renderer.IconWidget; | ||
import java.util.UUID; | ||
|
||
@Link("list.lss") | ||
@AutoActivity | ||
public class StaffNotesActivity extends SimpleActivity { | ||
|
||
private final GlobalTagAPI api; | ||
private final UUID uuid; | ||
private final String username; | ||
|
||
public StaffNotesActivity(GlobalTagAPI api, UUID uuid, String username) { | ||
this.api = api; | ||
this.uuid = uuid; | ||
this.username = username; | ||
} | ||
|
||
@Override | ||
public void initialize(Parent parent) { | ||
super.initialize(parent); | ||
api.getApiHandler().getNotes(uuid, (response) -> Laby.labyAPI().minecraft().executeOnRenderThread(() -> { | ||
if(document.getChild("window") != null) return; | ||
if(!response.successful()) { | ||
Laby.references().chatExecutor().displayClientMessage( | ||
TextComponent.builder() | ||
.append(GlobalTagAddon.prefix) | ||
.append(Component.text(response.error(), NamedTextColor.RED)) | ||
.build() | ||
); | ||
Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); | ||
return; | ||
} | ||
FlexibleContentWidget windowWidget = new FlexibleContentWidget().addId("window"); | ||
HorizontalListWidget profileWrapper = new HorizontalListWidget().addId("header"); | ||
ButtonWidget createButton = ButtonWidget | ||
.text("+", () -> Laby.labyAPI().minecraft().minecraftWindow().displayScreen( | ||
new CreateNoteActivity(api, uuid, username) | ||
)) | ||
.addId("create-button"); | ||
createButton.setHoverComponent(Component.translatable("globaltags.context.staff_notes.hover.create")); | ||
IconWidget headWidget = new IconWidget(Icon.head(this.uuid)).addId("head"); | ||
ComponentWidget titleWidget = ComponentWidget.i18n("globaltags.context.staff_notes.title", this.username).addId("username"); | ||
VerticalListWidget<StaffNoteWidget> notes = new VerticalListWidget<>().addId("item-list"); | ||
for (PlayerNote note : response.data()) { | ||
notes.addChild(new StaffNoteWidget(uuid, api, note)); | ||
} | ||
|
||
profileWrapper.addEntryInitialized(headWidget); | ||
profileWrapper.addEntryInitialized(titleWidget); | ||
profileWrapper.addEntryInitialized(createButton); | ||
|
||
windowWidget.addContentInitialized(profileWrapper); | ||
windowWidget.addContentInitialized(new ScrollWidget(notes)); | ||
this.document.addChildInitialized(windowWidget); | ||
})); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
core/src/main/java/com/rappytv/globaltags/activities/TagHistoryActivity.java
This file contains 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,72 @@ | ||
package com.rappytv.globaltags.activities; | ||
|
||
import com.rappytv.globaltags.GlobalTagAddon; | ||
import com.rappytv.globaltags.activities.widgets.TagHistoryEntryWidget; | ||
import com.rappytv.globaltags.api.GlobalTagAPI; | ||
import net.labymod.api.Laby; | ||
import net.labymod.api.client.component.Component; | ||
import net.labymod.api.client.component.TextComponent; | ||
import net.labymod.api.client.component.format.NamedTextColor; | ||
import net.labymod.api.client.gui.icon.Icon; | ||
import net.labymod.api.client.gui.screen.Parent; | ||
import net.labymod.api.client.gui.screen.ScreenInstance; | ||
import net.labymod.api.client.gui.screen.activity.AutoActivity; | ||
import net.labymod.api.client.gui.screen.activity.Link; | ||
import net.labymod.api.client.gui.screen.activity.types.SimpleActivity; | ||
import net.labymod.api.client.gui.screen.widget.widgets.ComponentWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.FlexibleContentWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.ScrollWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.HorizontalListWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.layout.list.VerticalListWidget; | ||
import net.labymod.api.client.gui.screen.widget.widgets.renderer.IconWidget; | ||
|
||
import java.util.UUID; | ||
|
||
@Link("list.lss") | ||
@AutoActivity | ||
public class TagHistoryActivity extends SimpleActivity { | ||
|
||
private final GlobalTagAPI api; | ||
private final UUID uuid; | ||
private final String username; | ||
|
||
public TagHistoryActivity(GlobalTagAPI api, UUID uuid, String username) { | ||
this.api = api; | ||
this.uuid = uuid; | ||
this.username = username; | ||
} | ||
|
||
@Override | ||
public void initialize(Parent parent) { | ||
super.initialize(parent); | ||
api.getApiHandler().getTagHistory(uuid, (response) -> Laby.labyAPI().minecraft().executeOnRenderThread(() -> { | ||
if(document.getChild("window") != null) return; | ||
System.out.println(response.data()); | ||
if(!response.successful()) { | ||
Laby.references().chatExecutor().displayClientMessage( | ||
TextComponent.builder() | ||
.append(GlobalTagAddon.prefix) | ||
.append(Component.text(response.error(), NamedTextColor.RED)) | ||
.build() | ||
); | ||
Laby.labyAPI().minecraft().minecraftWindow().displayScreen((ScreenInstance) null); | ||
return; | ||
} | ||
FlexibleContentWidget windowWidget = new FlexibleContentWidget().addId("window"); | ||
HorizontalListWidget profileWrapper = new HorizontalListWidget().addId("header"); | ||
IconWidget headWidget = new IconWidget(Icon.head(this.uuid)).addId("head"); | ||
ComponentWidget titleWidget = ComponentWidget.i18n("globaltags.context.tag_history.title", this.username).addId("username"); | ||
VerticalListWidget<TagHistoryEntryWidget> notes = new VerticalListWidget<>().addId("item-list"); | ||
for(int i = 0; i < response.data().size(); i++) { | ||
notes.addChild(new TagHistoryEntryWidget(i + 1, api, response.data().get(i))); | ||
} | ||
|
||
profileWrapper.addEntryInitialized(headWidget); | ||
profileWrapper.addEntryInitialized(titleWidget); | ||
|
||
windowWidget.addContentInitialized(profileWrapper); | ||
windowWidget.addContentInitialized(new ScrollWidget(notes)); | ||
this.document.addChildInitialized(windowWidget); | ||
})); | ||
} | ||
} |
Oops, something went wrong.