Skip to content

Commit

Permalink
・[fix] 初回起動時にレース場のチェックがすべて外れているのを修正
Browse files Browse the repository at this point in the history
・[fix] "プレビューウィンドウの更新をトレーニング画面で止める"が機能していなかったのを修正
・[fix] 起動時にイベント名の検索が機能していなかったのを修正
・[fix] 特定のイベント名の選択肢が出てこなかったのを修正
  • Loading branch information
amate committed Apr 18, 2021
1 parent f969fc3 commit e731a09
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 15 deletions.
18 changes: 11 additions & 7 deletions UmaCruise/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,22 @@ LRESULT CMainDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&)
m_previewWindow.ShowWindow(SW_NORMAL);
}
}

// Race
m_showRaceAfterCurrentDate = jsonSetting["MainDlg"].value<bool>("ShowRaceAfterCurrentDate", m_showRaceAfterCurrentDate);
const int32_t state = jsonSetting["MainDlg"].value<int32_t>("RaceMatchState", -1);
_SetRaceMatchState(state);
_UpdateRaceList(L"");
} else {
_SetRaceMatchState(-1);
}
_UpdateRaceList(L"");

DoDataExchange(DDX_LOAD);

} catch (std::exception& e)
{
ATLTRACE(L"%s\n", (LPCWSTR)(CA2W(e.what())));
ERROR_LOG << L"LoadConfig failed: " << (LPCWSTR)(CA2W(e.what()));
ATLASSERT(FALSE);
}
ChangeWindowTitle(L"init suscess!");

Expand Down Expand Up @@ -430,11 +434,8 @@ void CMainDlg::OnStart(UINT uNotifyCode, int nID, CWindow wndCtl)
bool success = m_umaTextRecoginzer.TextRecognizer(ssImage.get());
if (success) {
bool updateImage = true;
if (m_config.stopUpdatePreviewOnTraining) {
const std::wstring& currentMenu = m_umaTextRecoginzer.GetCurrentMenu();
if (currentMenu != L"育成" && currentMenu != L"トレーニング") {
updateImage = false;
}
if (m_config.stopUpdatePreviewOnTraining && !m_umaTextRecoginzer.IsTrainingMenu()) {
updateImage = false;
}
if (updateImage) {
m_previewWindow.UpdateImage(ssImage.release());
Expand Down Expand Up @@ -518,6 +519,9 @@ void CMainDlg::OnStart(UINT uNotifyCode, int nID, CWindow wndCtl)
void CMainDlg::OnEventNameChanged(UINT uNotifyCode, int nID, CWindow wndCtl)
{
DoDataExchange(DDX_SAVE, IDC_EDIT_EVENTNAME);
if (m_eventName.IsEmpty()) {
return;
}
std::vector<std::wstring> eventNames;
eventNames.emplace_back((LPCWSTR)m_eventName);
auto optUmaEvent = m_umaEventLibrary.AmbiguousSearchEvent(eventNames);
Expand Down
3 changes: 3 additions & 0 deletions UmaCruise/UmaCruise.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@
<TypeLibraryName>$(IntDir)/UmaCruise.tlb</TypeLibraryName>
<DllDataFileName />
</Midl>
<PostBuildEvent>
<Command>copy "$(targetPath)" "$(SolutionDir)#Release\UmaUmaCruise\UmaUmaCruise.exe"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="AboutDlg.cpp" />
Expand Down
8 changes: 8 additions & 0 deletions UmaCruise/UmaEventLibrary.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "UmaEventLibrary.h"

#include <regex>
#include <boost\algorithm\string\trim.hpp>
#include <boost\algorithm\string\replace.hpp>
#include <boost\filesystem.hpp>
Expand Down Expand Up @@ -55,6 +56,12 @@ boost::optional<std::wstring> retrieve(
return retrieve(dbr, ambiguousEventNames, measure, threshold, kMinThreshold);
}

void EventNameNormalize(std::wstring& eventName)
{
std::wregex rx(L"(進行度[^\\)]+)");
eventName = std::regex_replace(eventName, rx, L"");
}

// ==============================================================

bool UmaEventLibrary::LoadUmaMusumeLibrary()
Expand All @@ -66,6 +73,7 @@ bool UmaEventLibrary::LoadUmaMusumeLibrary()
for (const json& jsonEvent : jsonEventList) {
auto eventElm = *jsonEvent.items().begin();
std::wstring eventName = UTF16fromUTF8(eventElm.key());
EventNameNormalize(eventName);

charaEvent.umaEventList.emplace_back();
UmaEvent& umaEvent = charaEvent.umaEventList.back();
Expand Down
29 changes: 26 additions & 3 deletions UmaCruise/UmaTextRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,18 @@ bool UmaTextRecognizer::TextRecognizer(Gdiplus::Bitmap* image)

cv::Mat thresImage;
cv::threshold(grayImage, thresImage, 0.0, 255.0, cv::THRESH_OTSU);

#if 0
// 4倍
cv::Mat resizedImage;
constexpr double scale = 4.0;
cv::resize(cutImage2, resizedImage, cv::Size(), scale, scale, cv::INTER_CUBIC);

cv::Mat grayImage2;
cv::cvtColor(resizedImage, grayImage2, cv::COLOR_RGB2GRAY);

cv::Mat thresImage2;
cv::threshold(grayImage2, thresImage2, 0.0, 255.0, cv::THRESH_OTSU);
#endif
auto funcPushBackImageText = [this](cv::Mat& image) {
std::wstring text = TextFromImage(image);

Expand All @@ -299,6 +310,8 @@ bool UmaTextRecognizer::TextRecognizer(Gdiplus::Bitmap* image)
funcPushBackImageText(grayImage);
funcPushBackImageText(invertedImage);
funcPushBackImageText(thresImage);
//funcPushBackImageText(resizedImage);
//funcPushBackImageText(thresImage2);
}
{ // 現在の日付
CRect rcTurnBounds = _AdjustBounds(srcImage, m_testBounds[kCurrentTurnBounds]);
Expand Down Expand Up @@ -328,12 +341,22 @@ bool UmaTextRecognizer::TextRecognizer(Gdiplus::Bitmap* image)

//INFO_LOG << L"CurrentTurn, cut: " << cutImageText << L" thres: " << thresImageText;
}
{ // 現在メニュー[育成/トレーニング]
{ // 現在メニュー[トレーニング]
m_bTrainingMenu = false;

CRect rcCurrentMenuBounds = _AdjustBounds(srcImage, m_testBounds[kCurrentMenuBounds]);
cv::Mat cutImage(srcImage, cvRectFromCRect(rcCurrentMenuBounds));

std::wstring cutImageText = TextFromImage(cutImage);
m_currentMenu = cutImageText;
if (cutImageText == L"トレーニング") {
CRect rcBackButtonBounds = _AdjustBounds(srcImage, m_testBounds[kBackButtonBounds]);
cv::Mat cutImage2(srcImage, cvRectFromCRect(rcBackButtonBounds));

std::wstring cutImage2Text = TextFromImage(cutImage2);
if (cutImage2Text == L"戻る") {
m_bTrainingMenu = true;
}
}
}

return true;
Expand Down
10 changes: 5 additions & 5 deletions UmaCruise/UmaTextRecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class UmaTextRecognizer
const std::vector<std::wstring>& GetEventName() const {
return m_eventName;
}
const std::wstring& GetCurrentMenu() const {
return m_currentMenu;
bool IsTrainingMenu() const {
return m_bTrainingMenu;
}

private:
Expand All @@ -44,10 +44,10 @@ class UmaTextRecognizer
CSize m_baseClientSize;

enum TestBounds {
kUmaMusumeSubNameBounds, kUmaMusumeNameBounds, kCurrentTurnBounds, kEventCategoryBounds, kEventNameBounds, kEventNameIconBounds, kCurrentMenuBounds, kMaxCount
kUmaMusumeSubNameBounds, kUmaMusumeNameBounds, kCurrentTurnBounds, kEventCategoryBounds, kEventNameBounds, kEventNameIconBounds, kCurrentMenuBounds, kBackButtonBounds, kMaxCount
};
static constexpr LPCWSTR kTestBoundsName[kMaxCount] = {
L"UmaMusumeSubNameBounds", L"UmaMusumeNameBounds", L"CurrentTurnBounds", L"EventCategoryBounds", L"EventNameBounds", L"EventNameIconBounds", L"CurrentMenuBounds",
L"UmaMusumeSubNameBounds", L"UmaMusumeNameBounds", L"CurrentTurnBounds", L"EventCategoryBounds", L"EventNameBounds", L"EventNameIconBounds", L"CurrentMenuBounds", L"BackButtonBounds",
};
std::array<CRect, kMaxCount> m_testBounds;
int m_kCurrentTurnThreshold = 111;
Expand All @@ -56,6 +56,6 @@ class UmaTextRecognizer
std::vector<std::wstring> m_umaMusumeName;
std::vector<std::wstring> m_currentTurn;
std::vector<std::wstring> m_eventName;
std::wstring m_currentMenu;
bool m_bTrainingMenu = false;
};

6 changes: 6 additions & 0 deletions UmaLibrary/Common.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
},
"EventNameIconBounds": {
"x": 96, "y": 197, "width": 30, "height": 30
},
"CurrentMenuBounds" : {
"x": 19, "y": 2, "width": 114, "height": 31
},
"BackButtonBounds" : {
"x": 43, "y": 993, "width": 58, "height": 32
}
},

Expand Down

0 comments on commit e731a09

Please sign in to comment.