mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-02 23:07:36 +02:00
Added callbacks for preset dropdowns
This commit is contained in:
parent
653304b004
commit
861c53059e
@ -26,18 +26,35 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
|
|||||||
{
|
{
|
||||||
recActions = 0;
|
recActions = 0;
|
||||||
|
|
||||||
addCallback("setTimerPreset", [&](int index){
|
auto setTimerPresetCallback = [this](int index){
|
||||||
if(!variables["timerPresets"].isNull())
|
if(!variables["timerPresets"].isNull())
|
||||||
{
|
{
|
||||||
auto tpreset = variables["timerPresets"].Vector().at(index).Vector();
|
auto tpreset = variables["timerPresets"].Vector().at(index).Vector();
|
||||||
TurnTimerInfo tinfo;
|
TurnTimerInfo tinfo = SEL->getStartInfo()->turnTimerInfo;
|
||||||
tinfo.baseTimer = tpreset.at(0).Integer() * 1000;
|
tinfo.baseTimer = tpreset.at(0).Integer() * 1000;
|
||||||
tinfo.turnTimer = tpreset.at(1).Integer() * 1000;
|
tinfo.turnTimer = tpreset.at(1).Integer() * 1000;
|
||||||
tinfo.battleTimer = tpreset.at(2).Integer() * 1000;
|
tinfo.battleTimer = tpreset.at(2).Integer() * 1000;
|
||||||
tinfo.unitTimer = tpreset.at(3).Integer() * 1000;
|
tinfo.unitTimer = tpreset.at(3).Integer() * 1000;
|
||||||
|
tinfo.accumulatingTurnTimer = tpreset.at(4).Bool();
|
||||||
|
tinfo.accumulatingUnitTimer = tpreset.at(5).Bool();
|
||||||
CSH->setTurnTimerInfo(tinfo);
|
CSH->setTurnTimerInfo(tinfo);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
auto setSimturnsPresetCallback = [this](int index){
|
||||||
|
if(!variables["simturnsPresets"].isNull())
|
||||||
|
{
|
||||||
|
auto tpreset = variables["simturnsPresets"].Vector().at(index).Vector();
|
||||||
|
SimturnsInfo tinfo = SEL->getStartInfo()->simturnsInfo;
|
||||||
|
tinfo.optionalTurns = tpreset.at(0).Integer();
|
||||||
|
tinfo.requiredTurns = tpreset.at(1).Integer();
|
||||||
|
tinfo.allowHumanWithAI = tpreset.at(2).Bool();
|
||||||
|
CSH->setSimturnsInfo(tinfo);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
addCallback("setTimerPreset", setTimerPresetCallback);
|
||||||
|
addCallback("setSimturnPreset", setSimturnsPresetCallback);
|
||||||
|
|
||||||
addCallback("setSimturnDurationMin", [&](int index){
|
addCallback("setSimturnDurationMin", [&](int index){
|
||||||
SimturnsInfo info = SEL->getStartInfo()->simturnsInfo;
|
SimturnsInfo info = SEL->getStartInfo()->simturnsInfo;
|
||||||
@ -59,6 +76,18 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
|
|||||||
CSH->setSimturnsInfo(info);
|
CSH->setSimturnsInfo(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addCallback("setTurnTimerAccumulate", [&](int index){
|
||||||
|
TurnTimerInfo info = SEL->getStartInfo()->turnTimerInfo;
|
||||||
|
info.accumulatingTurnTimer = index;
|
||||||
|
CSH->setTurnTimerInfo(info);
|
||||||
|
});
|
||||||
|
|
||||||
|
addCallback("setUnitTimerAccumulate", [&](int index){
|
||||||
|
TurnTimerInfo info = SEL->getStartInfo()->turnTimerInfo;
|
||||||
|
info.accumulatingUnitTimer = index;
|
||||||
|
CSH->setTurnTimerInfo(info);
|
||||||
|
});
|
||||||
|
|
||||||
//helper function to parse string containing time to integer reflecting time in seconds
|
//helper function to parse string containing time to integer reflecting time in seconds
|
||||||
//assumed that input string can be modified by user, function shall support user's intention
|
//assumed that input string can be modified by user, function shall support user's intention
|
||||||
// normal: 2:00, 12:30
|
// normal: 2:00, 12:30
|
||||||
@ -194,6 +223,34 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
|
|||||||
|
|
||||||
w->setItem(0);
|
w->setItem(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(auto w = widget<ComboBox>("simturnsPresetSelector"))
|
||||||
|
{
|
||||||
|
w->onConstructItems = [this](std::vector<const void *> & curItems)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < variables["simturnsPresets"].Vector().size(); ++i)
|
||||||
|
curItems.push_back((void*)i);
|
||||||
|
};
|
||||||
|
|
||||||
|
w->onSetItem = [setSimturnsPresetCallback](const void * item){
|
||||||
|
size_t itemIndex = (size_t)item;
|
||||||
|
setSimturnsPresetCallback(itemIndex);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(auto w = widget<ComboBox>("timerPresetSelector"))
|
||||||
|
{
|
||||||
|
w->onConstructItems = [this](std::vector<const void *> & curItems)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < variables["timerPresets"].Vector().size(); ++i)
|
||||||
|
curItems.push_back((void*)i);
|
||||||
|
};
|
||||||
|
|
||||||
|
w->onSetItem = [setTimerPresetCallback](const void * item){
|
||||||
|
size_t itemIndex = (size_t)item;
|
||||||
|
setTimerPresetCallback(itemIndex);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionsTabBase::recreate()
|
void OptionsTabBase::recreate()
|
||||||
@ -246,6 +303,12 @@ void OptionsTabBase::recreate()
|
|||||||
if(auto buttonSimturnsAI = widget<CToggleButton>("buttonSimturnsAI"))
|
if(auto buttonSimturnsAI = widget<CToggleButton>("buttonSimturnsAI"))
|
||||||
buttonSimturnsAI->setSelectedSilent(SEL->getStartInfo()->simturnsInfo.allowHumanWithAI);
|
buttonSimturnsAI->setSelectedSilent(SEL->getStartInfo()->simturnsInfo.allowHumanWithAI);
|
||||||
|
|
||||||
|
if(auto buttonTurnTimerAccumulate = widget<CToggleButton>("buttonTurnTimerAccumulate"))
|
||||||
|
buttonTurnTimerAccumulate->setSelectedSilent(SEL->getStartInfo()->turnTimerInfo.accumulatingTurnTimer);
|
||||||
|
|
||||||
|
if(auto buttonUnitTimerAccumulate = widget<CToggleButton>("buttonUnitTimerAccumulate"))
|
||||||
|
buttonUnitTimerAccumulate->setSelectedSilent(SEL->getStartInfo()->turnTimerInfo.accumulatingUnitTimer);
|
||||||
|
|
||||||
const auto & turnTimerRemote = SEL->getStartInfo()->turnTimerInfo;
|
const auto & turnTimerRemote = SEL->getStartInfo()->turnTimerInfo;
|
||||||
|
|
||||||
//classic timer
|
//classic timer
|
||||||
|
@ -33,9 +33,9 @@ ComboBox::DropDown::Item::Item(const JsonNode & config, ComboBox::DropDown & _dr
|
|||||||
|
|
||||||
void ComboBox::DropDown::Item::updateItem(int idx, const void * _item)
|
void ComboBox::DropDown::Item::updateItem(int idx, const void * _item)
|
||||||
{
|
{
|
||||||
|
item = _item;
|
||||||
if(auto w = widget<CLabel>("labelName"))
|
if(auto w = widget<CLabel>("labelName"))
|
||||||
{
|
{
|
||||||
item = _item;
|
|
||||||
if(dropDown.comboBox.getItemText)
|
if(dropDown.comboBox.getItemText)
|
||||||
w->setText(dropDown.comboBox.getItemText(idx, item));
|
w->setText(dropDown.comboBox.getItemText(idx, item));
|
||||||
}
|
}
|
||||||
@ -130,20 +130,21 @@ void ComboBox::DropDown::clickPressed(const Point & cursorPosition)
|
|||||||
|
|
||||||
void ComboBox::DropDown::updateListItems()
|
void ComboBox::DropDown::updateListItems()
|
||||||
{
|
{
|
||||||
|
int elemIdx = 0;
|
||||||
|
|
||||||
if(auto w = widget<CSlider>("slider"))
|
if(auto w = widget<CSlider>("slider"))
|
||||||
|
elemIdx = w->getValue();
|
||||||
|
|
||||||
|
for(auto item : items)
|
||||||
{
|
{
|
||||||
int elemIdx = w->getValue();
|
if(elemIdx < curItems.size())
|
||||||
for(auto item : items)
|
|
||||||
{
|
{
|
||||||
if(elemIdx < curItems.size())
|
item->updateItem(elemIdx, curItems[elemIdx]);
|
||||||
{
|
elemIdx++;
|
||||||
item->updateItem(elemIdx, curItems[elemIdx]);
|
}
|
||||||
elemIdx++;
|
else
|
||||||
}
|
{
|
||||||
else
|
item->updateItem(elemIdx);
|
||||||
{
|
|
||||||
item->updateItem(elemIdx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +168,9 @@ ComboBox::ComboBox(Point position, const AnimationPath & defName, const std::pai
|
|||||||
|
|
||||||
void ComboBox::setItem(const void * item)
|
void ComboBox::setItem(const void * item)
|
||||||
{
|
{
|
||||||
if(auto w = std::dynamic_pointer_cast<CLabel>(overlay); getItemText)
|
auto w = std::dynamic_pointer_cast<CLabel>(overlay);
|
||||||
|
|
||||||
|
if( w && getItemText)
|
||||||
addTextOverlay(getItemText(0, item), w->font, w->color);
|
addTextOverlay(getItemText(0, item), w->font, w->color);
|
||||||
|
|
||||||
if(onSetItem)
|
if(onSetItem)
|
||||||
|
@ -37,12 +37,13 @@ class ComboBox : public CButton
|
|||||||
bool receiveEvent(const Point & position, int eventType) const override;
|
bool receiveEvent(const Point & position, int eventType) const override;
|
||||||
void clickPressed(const Point & cursorPosition) override;
|
void clickPressed(const Point & cursorPosition) override;
|
||||||
void setItem(const void *);
|
void setItem(const void *);
|
||||||
|
|
||||||
|
void updateListItems();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DropDown::Item> buildItem(const JsonNode & config);
|
std::shared_ptr<DropDown::Item> buildItem(const JsonNode & config);
|
||||||
|
|
||||||
void sliderMove(int slidPos);
|
void sliderMove(int slidPos);
|
||||||
void updateListItems();
|
|
||||||
|
|
||||||
ComboBox & comboBox;
|
ComboBox & comboBox;
|
||||||
std::vector<std::shared_ptr<Item>> items;
|
std::vector<std::shared_ptr<Item>> items;
|
||||||
@ -66,4 +67,6 @@ public:
|
|||||||
std::function<std::string(int, const void *)> getItemText;
|
std::function<std::string(int, const void *)> getItemText;
|
||||||
|
|
||||||
void setItem(int id);
|
void setItem(int id);
|
||||||
|
|
||||||
|
void updateListItems();
|
||||||
};
|
};
|
||||||
|
@ -113,17 +113,17 @@
|
|||||||
{
|
{
|
||||||
"timerPresets" :
|
"timerPresets" :
|
||||||
[
|
[
|
||||||
[0, 60, 0, 0],
|
[0, 60, 0, 0, false, false],
|
||||||
[0, 120, 0, 0],
|
[0, 120, 0, 0, false, false],
|
||||||
[0, 240, 0, 0],
|
[0, 240, 0, 0, false, false],
|
||||||
[0, 360, 0, 0],
|
[0, 360, 0, 0, false, false],
|
||||||
[0, 480, 0, 0],
|
[0, 480, 0, 0, false, false],
|
||||||
[0, 600, 0, 0],
|
[0, 600, 0, 0, false, false],
|
||||||
[0, 900, 0, 0],
|
[0, 900, 0, 0, false, false],
|
||||||
[0, 1200, 0, 0],
|
[0, 1200, 0, 0, false, false],
|
||||||
[0, 1500, 0, 0],
|
[0, 1500, 0, 0, false, false],
|
||||||
[0, 1800, 0, 0],
|
[0, 1800, 0, 0, false, false],
|
||||||
[0, 0, 0, 0],
|
[0, 0, 0, 0, false, false],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,17 +92,30 @@
|
|||||||
{
|
{
|
||||||
"timerPresets" :
|
"timerPresets" :
|
||||||
[
|
[
|
||||||
[0, 60, 0, 0],
|
[ 0, 0, 0, 0, false, false],
|
||||||
[0, 120, 0, 0],
|
[ 0, 60, 0, 0, false, false],
|
||||||
[0, 240, 0, 0],
|
[ 0, 120, 0, 0, false, false],
|
||||||
[0, 360, 0, 0],
|
[ 0, 300, 0, 0, false, false],
|
||||||
[0, 480, 0, 0],
|
[ 0, 600, 0, 0, false, false],
|
||||||
[0, 600, 0, 0],
|
[ 0, 1200, 0, 0, false, false],
|
||||||
[0, 900, 0, 0],
|
[ 0, 1800, 0, 0, false, false],
|
||||||
[0, 1200, 0, 0],
|
[ 960, 480, 120, 0, true, false],
|
||||||
[0, 1500, 0, 0],
|
[ 960, 480, 75, 0, true, false],
|
||||||
[0, 1800, 0, 0],
|
[ 480, 240, 60, 0, true, false],
|
||||||
[0, 0, 0, 0],
|
[ 120, 90, 60, 0, true, false],
|
||||||
|
[ 120, 60, 15, 0, true, false],
|
||||||
|
[ 60, 60, 0, 0, true, false]
|
||||||
|
],
|
||||||
|
"simturnsPresets" :
|
||||||
|
[
|
||||||
|
[ 0, 0, false],
|
||||||
|
[ 999, 0, false],
|
||||||
|
[ 7, 0, false],
|
||||||
|
[ 14, 0, false],
|
||||||
|
[ 28, 0, false],
|
||||||
|
[ 7, 7, false],
|
||||||
|
[ 14, 14, false],
|
||||||
|
[ 28, 28, false]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,13 +173,15 @@
|
|||||||
"name": "buttonTurnTimerAccumulate",
|
"name": "buttonTurnTimerAccumulate",
|
||||||
"position": {"x": 160, "y": 195},
|
"position": {"x": 160, "y": 195},
|
||||||
"type": "toggleButton",
|
"type": "toggleButton",
|
||||||
"image": "lobby/checkbox"
|
"image": "lobby/checkbox",
|
||||||
|
"callback" : "setSimturnAI"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "buttonUnitTimerAccumulate",
|
"name": "buttonUnitTimerAccumulate",
|
||||||
"position": {"x": 160, "y": 327},
|
"position": {"x": 160, "y": 327},
|
||||||
"type": "toggleButton",
|
"type": "toggleButton",
|
||||||
"image": "lobby/checkbox"
|
"image": "lobby/checkbox",
|
||||||
|
"callback" : "setSimturnAI"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -297,7 +299,6 @@
|
|||||||
"position": {"x": 278, "y": 478}
|
"position": {"x": 278, "y": 478}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type" : "label",
|
|
||||||
"text": "vcmi.optionsTab.simturnsMin.help",
|
"text": "vcmi.optionsTab.simturnsMin.help",
|
||||||
"type": "multiLineLabel",
|
"type": "multiLineLabel",
|
||||||
"font": "tiny",
|
"font": "tiny",
|
||||||
@ -306,7 +307,6 @@
|
|||||||
"rect": {"x": 70, "y": 430, "w": 300, "h": 40}
|
"rect": {"x": 70, "y": 430, "w": 300, "h": 40}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type" : "label",
|
|
||||||
"text": "vcmi.optionsTab.simturnsMax.help",
|
"text": "vcmi.optionsTab.simturnsMax.help",
|
||||||
"type": "multiLineLabel",
|
"type": "multiLineLabel",
|
||||||
"font": "tiny",
|
"font": "tiny",
|
||||||
@ -318,7 +318,8 @@
|
|||||||
"name": "buttonSimturnsAI",
|
"name": "buttonSimturnsAI",
|
||||||
"position": {"x": 70, "y": 535},
|
"position": {"x": 70, "y": 535},
|
||||||
"type": "toggleButton",
|
"type": "toggleButton",
|
||||||
"image": "lobby/checkbox"
|
"image": "lobby/checkbox",
|
||||||
|
"callback" : "setSimturnAI"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "labelSimturnsAI",
|
"name": "labelSimturnsAI",
|
||||||
@ -329,5 +330,36 @@
|
|||||||
"text": "vcmi.optionsTab.simturnsAI.hover",
|
"text": "vcmi.optionsTab.simturnsAI.hover",
|
||||||
"position": {"x": 110, "y": 540}
|
"position": {"x": 110, "y": 540}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
|
||||||
|
"variables":
|
||||||
|
{
|
||||||
|
"timerPresets" :
|
||||||
|
[
|
||||||
|
[ 0, 0, 0, 0, false, false],
|
||||||
|
[ 0, 60, 0, 0, false, false],
|
||||||
|
[ 0, 120, 0, 0, false, false],
|
||||||
|
[ 0, 300, 0, 0, false, false],
|
||||||
|
[ 0, 600, 0, 0, false, false],
|
||||||
|
[ 0, 1200, 0, 0, false, false],
|
||||||
|
[ 0, 1800, 0, 0, false, false],
|
||||||
|
[ 960, 480, 120, 0, true, false],
|
||||||
|
[ 960, 480, 75, 0, true, false],
|
||||||
|
[ 480, 240, 60, 0, true, false],
|
||||||
|
[ 120, 90, 60, 0, true, false],
|
||||||
|
[ 120, 60, 15, 0, true, false],
|
||||||
|
[ 60, 60, 0, 0, true, false]
|
||||||
|
],
|
||||||
|
"simturnsPresets" :
|
||||||
|
[
|
||||||
|
[ 0, 0, false],
|
||||||
|
[ 999, 0, false],
|
||||||
|
[ 7, 0, false],
|
||||||
|
[ 14, 0, false],
|
||||||
|
[ 28, 0, false],
|
||||||
|
[ 7, 7, false],
|
||||||
|
[ 14, 14, false],
|
||||||
|
[ 28, 28, false]
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ void TurnTimerHandler::onPlayerGetTurn(PlayerColor player)
|
|||||||
{
|
{
|
||||||
endTurnAllowed[player] = true;
|
endTurnAllowed[player] = true;
|
||||||
auto & timer = timers[player];
|
auto & timer = timers[player];
|
||||||
if(si->turnTimerInfo.accumulatingTurnTimer > 0)
|
if(si->turnTimerInfo.accumulatingTurnTimer)
|
||||||
timer.baseTimer += timer.turnTimer;
|
timer.baseTimer += timer.turnTimer;
|
||||||
timer.turnTimer = si->turnTimerInfo.turnTimer;
|
timer.turnTimer = si->turnTimerInfo.turnTimer;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user