-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bugs, optimized the code and moved the settings
- Loading branch information
1 parent
b71faad
commit 25e508e
Showing
21 changed files
with
388 additions
and
283 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
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,99 @@ | ||
#include "CodeBlock.hpp" | ||
#include <vector> | ||
|
||
std::vector<std::pair<char, SEL_MenuHandler>> CodeBlock::dataTypes({ | ||
{ 'B', menu_selector(CodeBlock::onBody) }, | ||
{ 'Q', menu_selector(CodeBlock::onQuery) }, | ||
{ 'H', menu_selector(CodeBlock::onHeaders) }, | ||
{ 'R', menu_selector(CodeBlock::onResponse) } | ||
}); | ||
|
||
size_t CodeBlock::buttonCount = CodeBlock::dataTypes.size(); | ||
|
||
char CodeBlock::currentDataType = CodeBlock::dataTypes.at(0).first; | ||
|
||
CodeBlock* CodeBlock::create(const CCSize& size, const CCSize& buttonBarSize) { | ||
CodeBlock* instance = new CodeBlock(); | ||
|
||
if (instance && instance->init(size, buttonBarSize)) { | ||
instance->autorelease(); | ||
|
||
return instance; | ||
} else { | ||
CC_SAFE_DELETE(instance); | ||
|
||
return nullptr; | ||
} | ||
} | ||
|
||
bool CodeBlock::init(const CCSize& size, const CCSize& buttonBarSize) { | ||
const size_t buttonCount = CodeBlock::dataTypes.size(); | ||
std::vector<CCMenuItemSpriteExtra*> buttons; | ||
|
||
if (!JSONCodeBlock::init({ HttpInfo::UNKNOWN_CONTENT, "" }, size)) { | ||
return false; | ||
} | ||
|
||
for (size_t i = 0; i < buttonCount; i++) { | ||
const auto& [key, selector] = CodeBlock::dataTypes.at(i); | ||
std::string keyStr(1, key); | ||
CCLabelBMFont* label = CCLabelBMFont::create(keyStr.c_str(), "consola.fnt"_spr); | ||
|
||
buttons.push_back(CCMenuItemSpriteExtra::create(label, this, selector)); | ||
label->setScale(0.8f); | ||
label->setAnchorPoint(CENTER); | ||
label->setColor(ThemeStyle::getTheme().line); | ||
label->setPosition(ccp(buttonBarSize.width / buttonCount, buttonBarSize.height) / 2); | ||
m_labels.insert({ key, label }); | ||
|
||
cocos::getChild<CCSprite>(label, 0)->setPositionY(buttonBarSize.height / 2); | ||
} | ||
|
||
ButtonBar* buttonBar = ButtonBar::create("square02_001.png", 0.2f, buttonBarSize, buttons); | ||
|
||
buttonBar->setPosition({ size.width - PADDING * 1.5f, size.height - PADDING }); | ||
buttonBar->setAnchorPoint(TOP_RIGHT); | ||
this->addChild(buttonBar); | ||
|
||
return true; | ||
} | ||
|
||
void CodeBlock::onBody(CCObject* sender) { | ||
this->setCode(m_request->formatBody()); | ||
this->updateDataTypeColor('B'); | ||
} | ||
|
||
void CodeBlock::onQuery(CCObject* sender) { | ||
this->setCode({ HttpInfo::JSON, m_request->formatQuery() }); | ||
this->updateDataTypeColor('Q'); | ||
} | ||
|
||
void CodeBlock::onHeaders(CCObject* sender) { | ||
this->setCode({ HttpInfo::JSON, m_request->formatHeaders() }); | ||
this->updateDataTypeColor('H'); | ||
} | ||
|
||
void CodeBlock::onResponse(CCObject* sender) { | ||
this->setCode(m_request->formatResponse()); | ||
this->updateDataTypeColor('R'); | ||
} | ||
|
||
void CodeBlock::updateDataTypeColor(char type) { | ||
const ThemeStyle& theme = ThemeStyle::getTheme(); | ||
currentDataType = type; | ||
|
||
for (const auto& [key, _] : CodeBlock::dataTypes) { | ||
m_labels.at(key)->setColor(key == type ? theme.text : theme.line); | ||
} | ||
} | ||
|
||
void CodeBlock::updateRequest(HttpInfo* request) { | ||
m_request = request; | ||
|
||
switch (currentDataType) { | ||
case 'B': this->onBody(nullptr); break; | ||
case 'Q': this->onQuery(nullptr); break; | ||
case 'H': this->onHeaders(nullptr); break; | ||
case 'R': this->onResponse(nullptr); break; | ||
} | ||
} |
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,28 @@ | ||
#pragma once | ||
|
||
#include "ButtonBar.hpp" | ||
#include "../include.hpp" | ||
#include "../objects/HttpInfo.hpp" | ||
#include "lists/JSONCodeBlock.hpp" | ||
#include "../objects/ThemeStyle.hpp" | ||
|
||
struct CodeBlock : public JSONCodeBlock { | ||
static size_t buttonCount; | ||
|
||
static CodeBlock* create(const CCSize& size, const CCSize& buttonBarSize); | ||
|
||
void updateRequest(HttpInfo* request); | ||
private: | ||
static std::vector<std::pair<char, SEL_MenuHandler>> dataTypes; | ||
static char currentDataType; | ||
|
||
std::unordered_map<char, CCLabelBMFont*> m_labels; | ||
HttpInfo* m_request; | ||
|
||
bool init(const CCSize& size, const CCSize& buttonBarSize); | ||
void onBody(CCObject* sender); | ||
void onQuery(CCObject* sender); | ||
void onHeaders(CCObject* sender); | ||
void onResponse(CCObject* sender); | ||
void updateDataTypeColor(char type); | ||
}; |
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,40 @@ | ||
#include "InfoArea.hpp" | ||
|
||
InfoArea* InfoArea::create(const CCSize& size) { | ||
InfoArea* instance = new InfoArea(); | ||
|
||
if (instance && instance->init(size)) { | ||
instance->autorelease(); | ||
|
||
return instance; | ||
} else { | ||
CC_SAFE_DELETE(instance); | ||
|
||
return nullptr; | ||
} | ||
} | ||
|
||
bool InfoArea::init(const CCSize& size) { | ||
SimpleTextArea* infoText = SimpleTextArea::create("", "chatFont.fnt", 0.5f, size.width - PADDING * 4); | ||
CCScale9Sprite* infoBg = CCScale9Sprite::create("square02b_001.png"); | ||
|
||
if (!BorderFix::init(infoBg, LIGHTER_BROWN_4B, size)) { | ||
return false; | ||
} | ||
|
||
this->setPadding(PADDING); | ||
infoBg->addChild(infoText); | ||
infoBg->setColor(LIGHT_BROWN_3B); | ||
infoText->setID("info_text"_spr); | ||
infoText->setAnchorPoint(CENTER_LEFT); | ||
infoText->setPosition({ PADDING, infoBg->getContentHeight() / 2 }); | ||
infoText->setMaxLines(5); | ||
infoText->setLinePadding(2); | ||
infoText->setWrappingMode(CUTOFF_WRAP); | ||
|
||
return true; | ||
} | ||
|
||
void InfoArea::updateRequest(HttpInfo* request) { | ||
as<SimpleTextArea*>(this->getNode()->getChildByID("info_text"_spr))->setText(request->generateBasicInfo()); | ||
} |
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,12 @@ | ||
#pragma once | ||
|
||
#include "BorderFix.hpp" | ||
#include "../include.hpp" | ||
#include "../objects/HttpInfo.hpp" | ||
|
||
struct InfoArea : public BorderFix { | ||
static InfoArea* create(const CCSize& size); | ||
void updateRequest(HttpInfo* request); | ||
private: | ||
bool init(const CCSize& size); | ||
}; |
Oops, something went wrong.