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
127 changes: 113 additions & 14 deletions Minecraft.Client/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "..\Minecraft.World\SharedConstants.h"
#include "..\Minecraft.World\StringHelpers.h"
#include "..\Minecraft.World\ChatPacket.h"
#include "Windows64\KeyboardMouseInput.h"
#include "Common\UI\UIComponent_DebugUIConsole.h"

const wstring ChatScreen::allowedChars = SharedConstants::acceptableLetters;
vector<wstring> ChatScreen::s_chatHistory;
Expand All @@ -22,6 +24,12 @@ ChatScreen::ChatScreen()
frame = 0;
cursorIndex = 0;
s_historyIndex = -1;

if (g_KBMInput.IsKeyPressed(VK_OEM_2))
{
message.insert(cursorIndex, 1, L'/');
cursorIndex++;
}
}

void ChatScreen::init()
Expand Down Expand Up @@ -85,24 +93,27 @@ void ChatScreen::handleHistoryDown()

void ChatScreen::keyPressed(wchar_t ch, int eventKey)
{

if (eventKey == Keyboard::KEY_ESCAPE)
{
{
minecraft->setScreen(nullptr);
return;
}

if (eventKey == Keyboard::KEY_RETURN)
{
{
wstring trim = trimString(message);
if (trim.length() > 0)
{
if (!trim.empty())
{
if (!minecraft->handleClientSideCommand(trim))
{
{
MultiplayerLocalPlayer* mplp = dynamic_cast<MultiplayerLocalPlayer*>(minecraft->player.get());
if (mplp && mplp->connection)
mplp->connection->send(shared_ptr<ChatPacket>(new ChatPacket(trim)));
}

if (s_chatHistory.empty() || s_chatHistory.back() != trim)
{
{
s_chatHistory.push_back(trim);
if (s_chatHistory.size() > CHAT_HISTORY_MAX)
s_chatHistory.erase(s_chatHistory.begin());
Expand All @@ -111,33 +122,121 @@ void ChatScreen::keyPressed(wchar_t ch, int eventKey)
minecraft->setScreen(nullptr);
return;
}

if (eventKey == Keyboard::KEY_UP) { handleHistoryUp(); return; }
if (eventKey == Keyboard::KEY_DOWN) { handleHistoryDown(); return; }

if (eventKey == Keyboard::KEY_LEFT)
{
if (cursorIndex > 0)
{
if (g_KBMInput.IsKeyDown(VK_CONTROL))
{
// move left by word
while (cursorIndex > 0 && iswspace(message[cursorIndex - 1])) cursorIndex--;
while (cursorIndex > 0 && !iswspace(message[cursorIndex - 1])) cursorIndex--;
}
else if (cursorIndex > 0)
{
cursorIndex--;
}
return;
}

if (eventKey == Keyboard::KEY_RIGHT)
{
if (cursorIndex < static_cast<int>(message.length()))
{
int len = static_cast<int>(message.length());
if (g_KBMInput.IsKeyDown(VK_CONTROL))
{
// move right by word
while (cursorIndex < len && !iswspace(message[cursorIndex])) cursorIndex++;
while (cursorIndex < len && iswspace(message[cursorIndex])) cursorIndex++;
}
else if (cursorIndex < len)
{
cursorIndex++;
}
return;
}

if (eventKey == Keyboard::KEY_BACK && cursorIndex > 0)
{
message.erase(cursorIndex - 1, 1);
cursorIndex--;
{
std::wstring trim;

if (g_KBMInput.IsKeyDown(VK_CONTROL))
{
trim = L"CTRL + BACK PRESSED";

size_t start = cursorIndex;

while (start > 0 && iswspace(message[start - 1]))
start--;

while (start > 0 && !iswspace(message[start - 1]))
start--;

message.erase(start, cursorIndex - start);
cursorIndex = start;
}
else
{
trim = L"BACK PRESSED";

message.erase(cursorIndex - 1, 1);
cursorIndex--;
}

// PRINTING OUT WHEN TRIGGERED FOR DEBUGGING

wstring trim1 = trimString(trim);

//if (!minecraft->handleClientSideCommand(trim1))
//{
// MultiplayerLocalPlayer* mplp = dynamic_cast<MultiplayerLocalPlayer*>(minecraft->player.get());
// if (mplp && mplp->connection)
// mplp->connection->send(std::make_shared<ChatPacket>(trim1));
//}

return;
}

// NEEDS IMPLEMENTING (CTRL + A TO SELECT ALL)

if (g_KBMInput.IsKeyDown(VK_CONTROL) && g_KBMInput.IsKeyPressed('A'))
{
return;
}

// NEEDS IMPLEMENTING (SHIFT + LEFT ARROW TO SELECT CHARACTER)

if (g_KBMInput.IsKeyDown(VK_SHIFT) && g_KBMInput.IsKeyPressed(VK_LEFT))
{
return;
}

// NEEDS IMPLEMENTING (SHIFT + RIGHT ARROW TO SELECT CHARACTER)

if (g_KBMInput.IsKeyDown(VK_SHIFT) && g_KBMInput.IsKeyPressed(VK_RIGHT))
{
return;
}

// NEEDS IMPLEMENTING (TAB TO AUTOFILL USERNAMES e.g( et > TAB > ethxnblxd ))
// if theres multiple usernames then make a gui above the chat window and cycle through them by using tab)

if (eventKey == Keyboard::KEY_TAB)
{
return;
}

if (isAllowedChatChar(ch) && static_cast<int>(message.length()) < SharedConstants::maxChatLength)
{
{
message.insert(cursorIndex, 1, ch);
cursorIndex++;
}
}


// NEEDS IMPLEMENTING (BLUE CHARACTER SELECTION RENDERING)

void ChatScreen::render(int xm, int ym, float a)
{
fill(2, height - 14, width - 2, height - 2, 0x80000000);
Expand Down
1 change: 1 addition & 0 deletions Minecraft.Client/Common/App_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ enum EControllerActions
MINECRAFT_ACTION_INVENTORY,
MINECRAFT_ACTION_PAUSEMENU,
MINECRAFT_ACTION_DROP,
MINECRAFT_ACTION_DROPALL,
MINECRAFT_ACTION_SNEAK_TOGGLE,
MINECRAFT_ACTION_CRAFTING,
MINECRAFT_ACTION_RENDER_THIRD_PERSON,
Expand Down
98 changes: 87 additions & 11 deletions Minecraft.Client/Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "FrustumCuller.h"
#include "Camera.h"

#include "chrono"

#include "..\Minecraft.World\MobEffect.h"
#include "..\Minecraft.World\Difficulty.h"
#include "..\Minecraft.World\net.minecraft.world.level.h"
Expand Down Expand Up @@ -1509,8 +1511,40 @@ void Minecraft::run_middle()
}
}

if(g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_DROP))
localplayers[i]->ullButtonsPressed|=1LL<<MINECRAFT_ACTION_DROP;
static bool wasDown = false;
static std::chrono::steady_clock::time_point pressTime;

bool down = g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_DROP);

if (g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_DROP) && g_KBMInput.IsKeyDown(VK_CONTROL))
// TO DROP A STACK
{
localplayers[i]->ullButtonsPressed |= 1LL << MINECRAFT_ACTION_DROPALL;
}

else if (down)
// CHANGED FROM IsKeyPressed SO YOU CAN HOLD TO DROP (after 0.3 sec delay).
{
auto now = std::chrono::steady_clock::now();

if (!wasDown)
{
// first press
localplayers[i]->ullButtonsPressed |= 1LL << MINECRAFT_ACTION_DROP;
pressTime = now;
}
else
{
float held = std::chrono::duration<float>(now - pressTime).count();

if (held > 0.3f)
{
localplayers[i]->ullButtonsPressed |= 1LL << MINECRAFT_ACTION_DROP;
}
}
}

wasDown = down;

if(g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_CRAFTING) || g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_CRAFTING_ALT))
{
Expand All @@ -1524,18 +1558,27 @@ void Minecraft::run_middle()
}
}

for (int slot = 0; slot < 9; slot++)
// PREVENTS SWITCHING HOTBAR SLOTS WHEN IN MENUS

if (!ui.GetMenuDisplayed(0))
{
if (g_KBMInput.IsKeyPressed('1' + slot))
for (int slot = 0; slot < 9; slot++)
{
if (localplayers[i]->inventory)
localplayers[i]->inventory->selected = slot;
if (g_KBMInput.IsKeyPressed('1' + slot))
{
if (localplayers[i]->inventory)
localplayers[i]->inventory->selected = slot;
}
}
}

}


// Utility keys always work regardless of KBM active state
if(g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_PAUSE) && !ui.GetMenuDisplayed(i))
Minecraft* pMinecraft = Minecraft::GetInstance();

if(g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_PAUSE) && !ui.GetMenuDisplayed(i) && pMinecraft->screen == NULL)
{
localplayers[i]->ullButtonsPressed|=1LL<<MINECRAFT_ACTION_PAUSEMENU;
app.DebugPrintf("PAUSE PRESSED (keyboard) - ipad = %d\n",i);
Expand Down Expand Up @@ -2592,6 +2635,37 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
*piUse=IDS_TOOLTIPS_BLOCK;
break;

// QUICK EQUIP FOR ARMOR (TOOLTIPS ONLY)
// NEEDS LOGIC IMPLEMENTATION!

// LEATHER
case Item::helmet_leather_Id:
case Item::chestplate_leather_Id:
case Item::leggings_leather_Id:
case Item::boots_leather_Id:
// CHAIN
case Item::helmet_chain_Id:
case Item::chestplate_chain_Id:
case Item::leggings_chain_Id:
case Item::boots_chain_Id:
// IRON
case Item::helmet_iron_Id:
case Item::chestplate_iron_Id:
case Item::leggings_iron_Id:
case Item::boots_iron_Id:
// GOLD
case Item::helmet_gold_Id:
case Item::chestplate_gold_Id:
case Item::leggings_gold_Id:
case Item::boots_gold_Id:
// DIAMOND
case Item::helmet_diamond_Id:
case Item::chestplate_diamond_Id:
case Item::leggings_diamond_Id:
case Item::boots_diamond_Id:
*piUse=IDS_TOOLTIPS_EQUIP;
break;

case Item::bucket_empty_Id:
case Item::glassBottle_Id:
if (bUseItem) *piUse=IDS_TOOLTIPS_COLLECT;
Expand Down Expand Up @@ -3746,10 +3820,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
if((player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_INVENTORY)) && gameMode->isInputAllowed(MINECRAFT_ACTION_INVENTORY))
{
shared_ptr<MultiplayerLocalPlayer> player = Minecraft::GetInstance()->player;
if (!player->isRiding())
{
ui.PlayUISFX(eSFX_Press);
}
ui.PlayUISFX(eSFX_Press);

if(gameMode->isServerControlledInventory())
{
Expand Down Expand Up @@ -3805,6 +3876,11 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
player->drop();
}

if((player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_DROPALL)) && gameMode->isInputAllowed(MINECRAFT_ACTION_DROPALL))
{
player->dropall();
}

uint64_t ullButtonsPressed=player->ullButtonsPressed;

bool selected = false;
Expand Down
6 changes: 6 additions & 0 deletions Minecraft.Client/MultiPlayerLocalPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ shared_ptr<ItemEntity> MultiplayerLocalPlayer::drop()
return nullptr;
}

shared_ptr<ItemEntity> MultiplayerLocalPlayer::dropall()
{
connection->send(std::make_shared<PlayerActionPacket>(PlayerActionPacket::DROP_ALL_ITEMS, 0, 0, 0, 0));
return nullptr;
}

void MultiplayerLocalPlayer::reallyDrop(shared_ptr<ItemEntity> itemEntity)
{
}
Expand Down
3 changes: 3 additions & 0 deletions Minecraft.Client/MultiPlayerLocalPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class MultiplayerLocalPlayer : public LocalPlayer

using Player::drop;
virtual shared_ptr<ItemEntity> drop();

using Player::dropall;
virtual shared_ptr<ItemEntity> dropall();
protected:
virtual void reallyDrop(shared_ptr<ItemEntity> itemEntity);
public:
Expand Down
1 change: 1 addition & 0 deletions Minecraft.Client/Windows64/KeyboardMouseInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class KeyboardMouseInput
static const int KEY_CRAFTING = 'C';
static const int KEY_CRAFTING_ALT = 'R';
static const int KEY_CHAT = 'T';
static const int KEY_SLASHCOMMANDCHAT = VK_OEM_2;
static const int KEY_CONFIRM = VK_RETURN;
static const int KEY_CANCEL = VK_ESCAPE;
static const int KEY_PAUSE = VK_ESCAPE;
Expand Down
10 changes: 9 additions & 1 deletion Minecraft.Client/Windows64/Windows64_Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
}

// TAB opens game info menu. - Vvis :3 - Updated by detectiveren
if (g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_HOST_SETTINGS) && !ui.GetMenuDisplayed(0))
if (g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_HOST_SETTINGS) && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL)
{
if (Minecraft* pMinecraft = Minecraft::GetInstance())
{
Expand All @@ -1821,6 +1821,14 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
SetFocus(g_hWnd);
}

else if (g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_SLASHCOMMANDCHAT) && app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL)
// Needs to set the message with "/" when pressed.
{
g_KBMInput.ClearCharBuffer();
pMinecraft->setScreen(new ChatScreen());
SetFocus(g_hWnd);
}

#if 0
// has the game defined profile data been changed (by a profile load)
if(app.uiGameDefinedDataChangedBitmask!=0)
Expand Down
Loading
Loading