Add chat history #100
No reviewers
Labels
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: minecraft-pi-reborn/minecraft-pi-reborn#100
Loading…
Reference in New Issue
No description provided.
Delete Branch "bigjango13/minecraft-pi-reborn:master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I got tired of retyping commands.
This adds more symbols too of course, they make up the bulk of this PR. I also made
CUSTOM_VTABLE
's_setup_##name##_vtable
not static, so stuff like this can be done without a PR.@ -4,3 +4,3 @@
struct TextInputBox {
static TextInputBox *create(const std::string &placeholder = "", const std::string &text = "");
static TextInputBox *create(const std::string &placeholder = "", const std::string &text = "", const std::vector<std::string> *history = NULL);
IMO the history code should be part of chat, not the text input widget.
I agree, however that makes input trickier and setting the text harder (unless there was
isFocused
andsetText
methods). This also has the benefit of being really easy to add history to any other text input, such as for a modded terminal.Then, why not just... add
setText
andisFocused
methods? Realistically chat is the only thing that will ever need this code. And if something else does need it, it can also just be re-implemented really easily.Right, but what about input?
What do you mean? Just add code to
keyPressed
inchat/ui.cpp
.Done 👍
@ -113,6 +119,7 @@ static Screen *create_chat_screen() {
// Init
void _init_chat_ui() {
history = {};
Most of Reborn uses this system to avoid issues with C++ initialization:
@ -2,1 +17,4 @@
property int leaf_color = 0x34;
// 64x64, Temp x humidity
static-property-array Biome *map = 0x17c970;
Just to clarify, is this
Biome[64][64]
orBiome*[64*64]
?Biome*[64*64]
, I'll update the comment to reflect this.@ -6,2 +6,4 @@
method void renderItem(Mob *mob, ItemInstance *item) = 0x4b824;
method void render(float param_1) = 0x4bfcc;
static-property ItemInHandRenderer **instance = 0x137bc0;
This seems wrong. I think this address actually refers to an
EntityRenderDispatcher
. Which then has a first property ofItemInHandRenderer
.Yup, it's
EntityRenderer::entityRenderDispatcher
.@ -78,9 +89,32 @@ CUSTOM_VTABLE(chat_screen, Screen) {
ChatScreen *self = (ChatScreen *) super;
if (key == 0x0d && self->chat->isFocused()) {
This should probably be in one big
if (self->chat->isFocused())
statement.@ -81,1 +92,3 @@
_chat_queue_message(self->chat->getText().c_str());
std::string text = self->chat->getText();
std::vector<std::string> &history = get_history();
if (history.size() == 0 || text != history.back()) {
What's the point of this check?
The
history.size() == 0
skips the next check, andtext != history.back()
prevents some duplicates from being added. So if I was using the same command or sending the same message many times it would only be in the history once, but if I said something in-between them it would save both versions, for example:This all looks good, but I have one concern.
What if I type something and then accidentally hit up/down, what happens to what I typed.
I'd suggest this system (forgive the pseudo-code):
I hope that makes sense.
Yep, will do 👍
To be clear, you want it to modify the history? So if I run
/gamemode 0
, then go back and edit it to/gamemode 1
and hit enter, the history should just be/gamemode 1
?Hmm, that could be a problem.
Maybe when
ChatScreen
is created, it copieshistory
into it's own property (history_local
?). That gets modified when you hit up/down. But when you hit enter, what you typed gets pushed to the globalhistory
(unless it is equal to what was pushed last).So
history
itself is never modified, only appended to. But if type something, then hit up/down, it won't just be thrown away.Maybe:
FWIW, Minecraft only saves the first entry, anything in history is refreshed when up/down is used. This seems a bit complex compared to something like that.
I'm basing this off GNOME Terminal (or Bash, I'm not sure who's responsible for history), which IMO, has a much superior history function to Minecraft.
Alright, will do 👍
Done.
@ -3,4 +3,6 @@
#include <string>
#include <vector>
extern "C" {
Why? This seems really useless. Considering it needs
std::vector
... which only exists on C++.Of course, but it's needed to work with the normal
HOOK
macro.Some cursedness could be done with
typeid
, but that would require changing theHOOK
macroWhat is the issue with
HOOK
and non-extern"C"
-functions?dlsym(RTLD_NEXT, #name);
assumes that the name is just "name", which isn't true for mangled names. It can intercept it fine, just not call the original.Well, that's annoying. I don't want to mess with
typeid
, so I guess this is the best solution.@ -82,0 +103,4 @@
int old_pos = self->history_pos;
self->history_pos -= 1;
if (self->history_pos < 0) self->history_pos = local_history.size() - 1;
if (old_pos != self->history_pos) {
Is this check needed? Because if
old_pos == self->history_pos
, wouldn't that just callsetText
with the current text, doing nothing?Yep, that's left over.
Hold on I'm going to sneak on last symbol in ;)
Alright, I'm ready if you are.