-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
EPICGameGuy
committed
Jan 5, 2024
1 parent
6c80029
commit f28cb1f
Showing
9 changed files
with
208 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <array> | ||
|
||
#include "libpad.h" | ||
#include "tamtypes.h" | ||
|
||
namespace Input::Keyboard | ||
{ | ||
enum class KeyStatus : uint8_t { | ||
none = 0, | ||
pressed = 1, | ||
holding = 2, | ||
released = 3, | ||
}; | ||
|
||
void init(); | ||
void read_inputs(); | ||
u8 get_key_status(unsigned char key); | ||
KeyStatus get_key_status(unsigned char ascii_key); | ||
unsigned char convert_ascii_to_keyboard_key(unsigned char ascii_key); | ||
unsigned char convert_keyboard_key_to_ascii(unsigned char keyboard_key); | ||
|
||
// Note: convert ascii keys to keyboard keys before looking up keys in the array | ||
std::array<KeyStatus, 256>& get_all_key_statuses(); | ||
|
||
// Returns true if a key has been just pressed or is held down | ||
bool is_key_down(unsigned char key); | ||
|
||
// Returns true if a key has been just released or wasn't pressed | ||
bool is_key_up(unsigned char key); | ||
|
||
bool is_shift_down(); | ||
} // namespace Input::Keyboard |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#include "objects/text_object.hpp" | ||
#include "tick.hpp" | ||
|
||
class TextPrompt: public Tickable, public RootComponentInterface | ||
{ | ||
public: | ||
std::string prompt; | ||
std::string inputted_text; | ||
|
||
// Actual 3d text rendered | ||
TextObject text_object; | ||
|
||
virtual void tick(float deltaTime) override; | ||
virtual TransformComponent* get_root_component() override { return text_object.get_root_component(); } | ||
|
||
void set_prompt(std::string_view new_prompt); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "objects/text_prompt.hpp" | ||
|
||
#include "input/keyboard.hpp" | ||
|
||
#include <stdio.h> | ||
#include <ctype.h> | ||
|
||
void TextPrompt::tick(float deltaTime) | ||
{ | ||
using namespace Input::Keyboard; | ||
|
||
bool new_text = false; | ||
|
||
const auto& keyboard_keys = get_all_key_statuses(); | ||
for (int i = 0; i < 256; ++i) | ||
{ | ||
if (keyboard_keys[i] == KeyStatus::pressed) | ||
{ | ||
const unsigned char ascii_key = convert_keyboard_key_to_ascii(i); | ||
if (isalpha(ascii_key)) | ||
{ | ||
inputted_text += ascii_key; | ||
new_text = true; | ||
} | ||
else if (ascii_key == '.' || ascii_key == ',') | ||
{ | ||
inputted_text += ascii_key; | ||
new_text = true; | ||
} | ||
else if (i == 56 && is_shift_down()) | ||
{ | ||
inputted_text += '?'; | ||
new_text = true; | ||
} | ||
else if (i == 44) // space bar | ||
{ | ||
inputted_text += ' '; | ||
new_text = true; | ||
} | ||
else if (i == 42 && inputted_text.size() > 0) // delete key | ||
{ | ||
inputted_text.pop_back(); | ||
new_text = true; | ||
} | ||
} | ||
} | ||
|
||
if (new_text) | ||
{ | ||
text_object.set_text(prompt + "\n" + inputted_text); | ||
} | ||
} | ||
|
||
void TextPrompt::set_prompt(std::string_view new_prompt) | ||
{ | ||
prompt = new_prompt; | ||
text_object.set_text(prompt + "\n" + inputted_text); | ||
} |
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