Implement main menu with text entry label. Update text entry mode in PGE, removed the ability to jump between saved commands and enter no longer clears or disables text entry by default.
This commit is contained in:
@@ -472,6 +472,7 @@ namespace _gfs = std::filesystem;
|
||||
#endif
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#define OLC_PLATFORM_EMSCRIPTEN
|
||||
#include <emscripten/fetch.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
@@ -951,6 +952,7 @@ namespace olc
|
||||
virtual olc::rcode SetWindowTitle(const std::string& s) = 0;
|
||||
virtual olc::rcode StartSystemEventLoop() = 0;
|
||||
virtual olc::rcode HandleSystemEvent() = 0;
|
||||
virtual olc::rcode SendRequest(std::string_view url,std::string_view data){return olc::rcode::OK;};
|
||||
static olc::PixelGameEngine* ptrPGE;
|
||||
};
|
||||
|
||||
@@ -995,6 +997,9 @@ namespace olc
|
||||
// Called when a console command is executed
|
||||
virtual bool OnConsoleCommand(const std::string& sCommand);
|
||||
|
||||
|
||||
virtual olc::rcode SendRequest(std::string_view url,std::string_view data);
|
||||
|
||||
|
||||
public: // Hardware Interfaces
|
||||
// Returns true if window is currently in focus
|
||||
@@ -1200,6 +1205,7 @@ namespace olc
|
||||
std::string TextEntryGetString() const;
|
||||
int32_t TextEntryGetCursor() const;
|
||||
bool IsTextEntryEnabled() const;
|
||||
void TextEntrySetCharLimit(const uint8_t charLimit);
|
||||
|
||||
public:
|
||||
static std::map<char,Pixel> charToColor;
|
||||
@@ -1307,6 +1313,7 @@ namespace olc
|
||||
std::vector<std::string> vDroppedFilesCache;
|
||||
olc::vi2d vDroppedFilesPoint;
|
||||
olc::vi2d vDroppedFilesPointCache;
|
||||
uint8_t nTextEntryCharLimit=std::numeric_limits<uint8_t>::max();
|
||||
|
||||
// Command Console Specific
|
||||
bool bConsoleShow = false;
|
||||
@@ -4284,13 +4291,15 @@ namespace olc
|
||||
|
||||
bool PixelGameEngine::IsTextEntryEnabled() const
|
||||
{ return bTextEntryEnable; }
|
||||
|
||||
void PixelGameEngine::TextEntrySetCharLimit(const uint8_t charLimit){
|
||||
nTextEntryCharLimit=charLimit;
|
||||
}
|
||||
|
||||
void PixelGameEngine::UpdateTextEntry()
|
||||
{
|
||||
// Check for typed characters
|
||||
for (const auto& key : vKeyboardMap)
|
||||
if (GetKey(std::get<0>(key)).bPressed)
|
||||
if (GetKey(std::get<0>(key)).bPressed&&sTextEntryString.size()<nTextEntryCharLimit)
|
||||
{
|
||||
sTextEntryString.insert(nTextEntryCursor, GetKey(olc::Key::SHIFT).bHeld ? std::get<2>(key) : std::get<1>(key));
|
||||
nTextEntryCursor++;
|
||||
@@ -4308,7 +4317,8 @@ namespace olc
|
||||
}
|
||||
if (GetKey(olc::Key::DEL).bPressed && nTextEntryCursor < sTextEntryString.size())
|
||||
sTextEntryString.erase(nTextEntryCursor, 1);
|
||||
|
||||
|
||||
/*
|
||||
if (GetKey(olc::Key::UP).bPressed)
|
||||
{
|
||||
if (!sCommandHistory.empty())
|
||||
@@ -4341,7 +4351,6 @@ namespace olc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (GetKey(olc::Key::ENTER).bPressed)
|
||||
{
|
||||
if (bConsoleShow)
|
||||
@@ -4360,7 +4369,7 @@ namespace olc
|
||||
OnTextEntryComplete(sTextEntryString);
|
||||
TextEntryEnable(false);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
// User must override these functions as required. I have not made
|
||||
@@ -4379,6 +4388,9 @@ namespace olc
|
||||
void PixelGameEngine::OnTextEntryComplete(const std::string& sText) { UNUSED(sText); }
|
||||
bool PixelGameEngine::OnConsoleCommand(const std::string& sCommand) { UNUSED(sCommand); return false; }
|
||||
|
||||
|
||||
olc::rcode PixelGameEngine::SendRequest(std::string_view url,std::string_view data){platform->SendRequest(url,data);return olc::rcode::OK;};
|
||||
|
||||
// Externalised API
|
||||
void PixelGameEngine::olc_UpdateViewport()
|
||||
{
|
||||
@@ -7188,6 +7200,27 @@ namespace olc
|
||||
ptrPGE->olc_UpdateWindowSize(width, height);
|
||||
}
|
||||
|
||||
virtual olc::rcode SendRequest(std::string_view url,std::string_view data)override{
|
||||
emscripten_fetch_attr_t attr;
|
||||
emscripten_fetch_attr_init(&attr);
|
||||
strcpy(attr.requestMethod, "GET");
|
||||
attr.attributes=EMSCRIPTEN_FETCH_LOAD_TO_MEMORY|EMSCRIPTEN_FETCH_SYNCHRONOUS;
|
||||
emscripten_fetch_t*fetch=emscripten_fetch(&attr,std::string(url).c_str()); // Blocks here until the operation is complete.
|
||||
if(fetch->status==200){
|
||||
printf("Finished downloading %llu bytes from URL %s.\n", fetch->numBytes, fetch->url);
|
||||
// The data is now available at fetch->data[0] through fetch->data[fetch->numBytes-1];
|
||||
}else{
|
||||
printf("Downloading %s failed, HTTP failure status code: %d.\n",fetch->url,fetch->status);
|
||||
}
|
||||
emscripten_fetch_close(fetch);
|
||||
|
||||
for(int i=0;i<fetch->numBytes;i++){
|
||||
std::cout<<fetch->data[i];
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
return olc::rcode::OK;
|
||||
}
|
||||
|
||||
//TY Gorbit
|
||||
static EM_BOOL focus_callback(int eventType, const EmscriptenFocusEvent* focusEvent, void* userData)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user