Commit 90d446de authored by edo9300's avatar edo9300

Merge remote-tracking branch 'refs/remotes/origin/advanced-rules--tset'

parents 3e07dd40 642fb39a
This diff is collapsed.
......@@ -8,6 +8,7 @@
#include "duelclient.h"
#include "netserver.h"
#include "single_mode.h"
#include "../ocgcore/duel.h"
#include <sstream>
#include "utils.h"
......@@ -162,12 +163,22 @@ bool Game::Initialize() {
for(int i = 0; i < 14; ++i)
chkRules[i] = env->addCheckBox(false, recti(10 + (i % 2) * 150, 10 + (i / 2) * 20, 200 + (i % 2) * 120, 30 + (i / 2) * 20), wRules, 353+i, dataManager.GetSysString(1132 + i));
env->addStaticText(dataManager.GetSysString(1236), rect<s32>(20, 180, 220, 200), false, false, wCreateHost);
cbDuelRule = env->addComboBox(rect<s32>(140, 175, 300, 200), wCreateHost);
cbDuelRule = env->addComboBox(rect<s32>(140, 175, 300, 200), wCreateHost, COMBOBOX_DUEL_RULE);
cbDuelRule->addItem(dataManager.GetSysString(1260));
cbDuelRule->addItem(dataManager.GetSysString(1261));
cbDuelRule->addItem(dataManager.GetSysString(1262));
cbDuelRule->addItem(dataManager.GetSysString(1263));
cbDuelRule->setSelected(DEFAULT_DUEL_RULE - 1);
btnCustomRule = env->addButton(rect<s32>(305, 175, 370, 200), wCreateHost, BUTTON_CUSTOM_RULE, dataManager.GetSysString(1626));
wCustomRules = env->addWindow(rect<s32>(700, 100, 910, 280), false, dataManager.strBuffer);
wCustomRules->getCloseButton()->setVisible(false);
wCustomRules->setDrawTitlebar(false);
wCustomRules->setDraggable(true);
wCustomRules->setVisible(false);
for(int i = 0; i < 5; ++i)
chkCustomRules[i] = env->addCheckBox(false, recti(10, 10 + i * 20, 200, 30 + i * 20), wCustomRules, 353 + i, dataManager.GetSysString(1265 + i));
btnCustomRulesOK = env->addButton(rect<s32>(55, 130, 155, 155), wCustomRules, BUTTON_CUSTOM_RULE_OK, dataManager.GetSysString(1211));
duel_param = MASTER_RULE_4;
chkNoCheckDeck = env->addCheckBox(false, rect<s32>(20, 210, 170, 230), wCreateHost, -1, dataManager.GetSysString(1229));
chkNoShuffleDeck = env->addCheckBox(false, rect<s32>(180, 210, 360, 230), wCreateHost, -1, dataManager.GetSysString(1230));
env->addStaticText(dataManager.GetSysString(1231), rect<s32>(20, 240, 320, 260), false, false, wCreateHost);
......@@ -194,7 +205,7 @@ bool Game::Initialize() {
wHostPrepare2 = env->addWindow(rect<s32>(750, 120, 950, 440), false, dataManager.GetSysString(1625));
wHostPrepare2->getCloseButton()->setVisible(false);
wHostPrepare2->setVisible(false);
stHostPrepRule2 = env->addStaticText(L"", rect<s32>(10, 30, 460, 230), false, true, wHostPrepare2);
stHostPrepRule2 = env->addStaticText(L"", rect<s32>(10, 30, 460, 350), false, true, wHostPrepare2);
wHostPrepare = env->addWindow(rect<s32>(270, 120, 750, 440), false, dataManager.GetSysString(1250));
wHostPrepare->getCloseButton()->setVisible(false);
wHostPrepare->setVisible(false);
......@@ -1400,6 +1411,80 @@ int Game::LocalPlayer(int player) {
const wchar_t* Game::LocalName(int local_player) {
return local_player == 0 ? dInfo.hostname : dInfo.clientname;
}
void Game::UpdateDuelParam() {
uint32 flag = 0, filter = 0x100;
for (int i = 0; i < 5; ++i, filter <<= 1)
if (chkCustomRules[i]->isChecked()) {
flag |= filter;
}
cbDuelRule->clear();
cbDuelRule->addItem(dataManager.GetSysString(1260));
cbDuelRule->addItem(dataManager.GetSysString(1261));
cbDuelRule->addItem(dataManager.GetSysString(1262));
cbDuelRule->addItem(dataManager.GetSysString(1263));
switch (flag) {
case MASTER_RULE_1: {
cbDuelRule->setSelected(0);
break;
}
case MASTER_RULE_2: {
cbDuelRule->setSelected(1);
break;
}
case MASTER_RULE_3: {
cbDuelRule->setSelected(2);
break;
}
case MASTER_RULE_4: {
cbDuelRule->setSelected(3);
break;
}
default: {
cbDuelRule->addItem(dataManager.GetSysString(1264));
cbDuelRule->setSelected(4);
break;
}
}
duel_param = flag;
}
int Game::GetMasterRule(uint32 param, int* truerule) {
switch(param) {
case MASTER_RULE_1: {
if (truerule)
*truerule = 1;
return 1;
break;
}
case MASTER_RULE_2: {
if (truerule)
*truerule = 2;
return 2;
break;
}
case MASTER_RULE_3: {
if (truerule)
*truerule = 3;
return 3;
break;
}
case MASTER_RULE_4: {
if (truerule)
*truerule = 4;
return 4;
break;
}
default: {
if (truerule)
*truerule = 5;
if(param & DUEL_EMZONE)
return 4;
else if (param & DUEL_PZONE)
return 3;
else
return 2;
}
}
}
void Game::OnResize()
{
wMainMenu->setRelativePosition(ResizeWin(370, 200, 650, 415));
......@@ -1454,6 +1539,7 @@ void Game::OnResize()
wHostPrepare->setRelativePosition(ResizeWin(270, 120, 750, 440));
wHostPrepare2->setRelativePosition(ResizeWin(750, 120, 950, 440));
wRules->setRelativePosition(ResizeWin(630, 100, 1000, 310));
wCustomRules->setRelativePosition(ResizeWin(700, 100, 910, 280));
wReplay->setRelativePosition(ResizeWin(220, 100, 800, 520));
wSinglePlay->setRelativePosition(ResizeWin(220, 100, 800, 520));
......
......@@ -127,6 +127,8 @@ public:
int LocalPlayer(int player);
const wchar_t* LocalName(int local_player);
void UpdateDuelParam();
int GetMasterRule(uint32 param, int* truerule = 0);
bool HasFocus(EGUI_ELEMENT_TYPE type) const {
irr::gui::IGUIElement* focus = env->getFocus();
......@@ -185,6 +187,7 @@ public:
bool is_building;
bool is_siding;
uint32 duel_param;
irr::core::dimension2d<irr::u32> window_size;
......@@ -268,6 +271,10 @@ public:
irr::gui::IGUICheckBox* chkRules[14];
irr::gui::IGUIButton* btnRulesOK;
irr::gui::IGUIComboBox* cbDuelRule;
irr::gui::IGUIButton* btnCustomRule;
irr::gui::IGUICheckBox* chkCustomRules[5];
irr::gui::IGUIWindow* wCustomRules;
irr::gui::IGUIButton* btnCustomRulesOK;
irr::gui::IGUICheckBox* chkNoCheckDeck;
irr::gui::IGUICheckBox* chkNoShuffleDeck;
irr::gui::IGUIButton* btnHostConfirm;
......@@ -507,6 +514,7 @@ extern Game* mainGame;
#define BUTTON_LAN_REFRESH 116
#define BUTTON_RULE_CARDS 117
#define BUTTON_RULE_OK 118
#define BUTTON_CUSTOM_RULE 119
#define BUTTON_HP_DUELIST 120
#define BUTTON_HP_OBSERVER 121
#define BUTTON_HP_START 122
......@@ -515,6 +523,8 @@ extern Game* mainGame;
#define CHECKBOX_HP_READY 125
#define BUTTON_HP_READY 126
#define BUTTON_HP_NOTREADY 127
#define COMBOBOX_DUEL_RULE 128
#define BUTTON_CUSTOM_RULE_OK 129
#define LISTBOX_REPLAY_LIST 130
#define BUTTON_LOAD_REPLAY 131
#define BUTTON_CANCEL_REPLAY 132
......
......@@ -6,6 +6,7 @@
#include "replay_mode.h"
#include "single_mode.h"
#include "image_manager.h"
#include "../ocgcore/duel.h"
#include "game.h"
#include "utils.h"
......@@ -31,6 +32,10 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
case irr::EET_GUI_EVENT: {
irr::gui::IGUIElement* caller = event.GUIEvent.Caller;
s32 id = caller->getID();
if(mainGame->wRules->isVisible() && (id != BUTTON_RULE_OK && (id <CHECK_SEALED_DUEL || id>CHECK_DECK_MASTER_DUEL)))
break;
if(mainGame->wCustomRules->isVisible() && id != BUTTON_CUSTOM_RULE_OK)
break;
switch(event.GUIEvent.EventType) {
case irr::gui::EGET_ELEMENT_HOVERED: {
// Set cursor to an I-Beam if hovering over an edit box
......@@ -120,17 +125,46 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_RULE_CARDS: {
if(mainGame->wRules->isVisible()){
mainGame->HideElement(mainGame->wRules);
}else {
mainGame->PopupElement(mainGame->wRules);
}
mainGame->PopupElement(mainGame->wRules);
break;
}
case BUTTON_RULE_OK: {
case BUTTON_RULE_OK: {
mainGame->HideElement(mainGame->wRules);
break;
}
case BUTTON_CUSTOM_RULE: {
switch (mainGame->cbDuelRule->getSelected()) {
case 0: {
mainGame->duel_param = MASTER_RULE_1;
break;
}
case 1: {
mainGame->duel_param = MASTER_RULE_2;
break;
}
case 2: {
mainGame->duel_param = MASTER_RULE_3;
break;
}
case 3: {
mainGame->duel_param = MASTER_RULE_4;
break;
}
}
uint32 filter = 0x100;
for (int i = 0; i < 5; ++i, filter <<= 1)
if (mainGame->duel_param & filter)
mainGame->chkCustomRules[i]->setChecked(true);
else
mainGame->chkCustomRules[i]->setChecked(false);
mainGame->PopupElement(mainGame->wCustomRules);
break;
}
case BUTTON_CUSTOM_RULE_OK: {
mainGame->UpdateDuelParam();
mainGame->HideElement(mainGame->wCustomRules);
break;
}
case BUTTON_HOST_CONFIRM: {
BufferIO::CopyWStr(mainGame->ebServerName->getText(), mainGame->gameConf.gamename, 20);
if(!NetServer::StartServer(mainGame->gameConf.serverport))
......@@ -139,7 +173,6 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
NetServer::StopServer();
break;
}
mainGame->HideElement(mainGame->wRules);
mainGame->btnHostConfirm->setEnabled(false);
mainGame->btnHostCancel->setEnabled(false);
break;
......@@ -148,7 +181,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true);
mainGame->HideElement(mainGame->wRules);
if(mainGame->wRules->isVisible())
mainGame->HideElement(mainGame->wRules);
mainGame->HideElement(mainGame->wCreateHost);
mainGame->ShowElement(mainGame->wLanWindow);
break;
......@@ -202,7 +236,8 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true);
mainGame->HideElement(mainGame->wHostPrepare);
mainGame->HideElement(mainGame->wHostPrepare2);
if(mainGame->wHostPrepare2->isVisible())
mainGame->HideElement(mainGame->wHostPrepare2);
mainGame->ShowElement(mainGame->wLanWindow);
mainGame->wChat->setVisible(false);
if(exit_on_return)
......@@ -495,6 +530,40 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
break;
}
case irr::gui::EGET_COMBO_BOX_CHANGED: {
switch (id) {
case COMBOBOX_DUEL_RULE: {
switch (mainGame->cbDuelRule->getSelected()) {
case 0:{
mainGame->cbDuelRule->removeItem(4);
mainGame->duel_param = MASTER_RULE_1;
break;
}
case 1: {
mainGame->cbDuelRule->removeItem(4);
mainGame->duel_param = MASTER_RULE_2;
break;
}
case 2: {
mainGame->cbDuelRule->removeItem(4);
mainGame->duel_param = MASTER_RULE_3;
break;
}
case 3: {
mainGame->cbDuelRule->removeItem(4);
mainGame->duel_param = MASTER_RULE_4;
break;
}
}
uint32 filter = 0x100;
for (int i = 0; i < 5; ++i, filter <<= 1)
if (mainGame->duel_param & filter)
mainGame->chkCustomRules[i]->setChecked(true);
else
mainGame->chkCustomRules[i]->setChecked(false);
}
}
}
default: break;
}
break;
......
......@@ -22,20 +22,22 @@ struct HostInfo {
unsigned char start_hand;
unsigned char draw_count;
unsigned short time_limit;
int destiny_draw;
int sealed;
int booster;
int speed;
int concentration;
int boss;
int city;
int kingdom;
int dimension;
int turbo1;
int turbo2;
int doubled;
int command;
int master;
unsigned char check;
unsigned int duel_flag;
bool destiny_draw;
bool sealed;
bool booster;
bool speed;
bool concentration;
bool boss;
bool city;
bool kingdom;
bool dimension;
bool turbo1;
bool turbo2;
bool doubled;
bool command;
bool master;
int rule_count;
};
struct HostPacket {
......
......@@ -80,8 +80,37 @@ int ReplayMode::ReplayThread(void* param) {
int start_hand = cur_replay.ReadInt32();
int draw_count = cur_replay.ReadInt32();
int opt = cur_replay.ReadInt32();
int duel_rule = opt >> 16;
mainGame->dInfo.duel_rule = duel_rule;
int rule = opt >> 16; //backwards compatibility with master rule replays
if(rule)
switch (rule) {
case 1: {
opt |= MASTER_RULE_1;
break;
}
case 2: {
opt |= MASTER_RULE_2;
break;
}
case 3: {
opt |= MASTER_RULE_3;
break;
}
case 4: {
opt |= MASTER_RULE_4;
break;
}
}
//pre mr4 replay compatibility
if(opt & DUEL_OBSOLETE_RULING) {
opt &= ~DUEL_OBSOLETE_RULING;
opt |= MASTER_RULE_1;
} else if (!(opt & 0xff80))
opt |= MASTER_RULE_3;
mainGame->dInfo.duel_rule = 2;
if(opt & DUEL_EMZONE)
mainGame->dInfo.duel_rule = 4;
else if(opt & DUEL_PZONE)
mainGame->dInfo.duel_rule = 3;
mainGame->dInfo.speed = (opt & SPEED_DUEL) ? 1 : 0;
set_player_info(pduel, 0, start_lp, start_hand, draw_count);
set_player_info(pduel, 1, start_lp, start_hand, draw_count);
......
......@@ -413,7 +413,7 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
pduel = create_duel(rnd.rand());
set_player_info(pduel, 0, host_info.start_lp, host_info.start_hand, host_info.draw_count);
set_player_info(pduel, 1, host_info.start_lp, host_info.start_hand, host_info.draw_count);
int opt = (int)host_info.duel_rule << 16;
int opt = host_info.duel_flag;
if(host_info.no_shuffle_deck)
opt |= DUEL_PSEUDO_SHUFFLE;
if(host_info.speed)
......
......@@ -382,7 +382,7 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
pduel = create_duel(rnd.rand());
set_player_info(pduel, 0, host_info.start_lp, host_info.start_hand, host_info.draw_count);
set_player_info(pduel, 1, host_info.start_lp, host_info.start_hand, host_info.draw_count);
int opt = (int)host_info.duel_rule << 16;
int opt = host_info.duel_flag;
if(host_info.no_shuffle_deck)
opt |= DUEL_PSEUDO_SHUFFLE;
if(host_info.speed)
......
......@@ -302,6 +302,12 @@
!system 1261 Master Rule 2
!system 1262 Master Rule 3
!system 1263 Master Rule 4
!system 1264 Custom Rule
!system 1265 Obsolete Ignition
!system 1266 1st Turn Draw
!system 1267 1 Field
!system 1268 Pendulum Zones
!system 1269 Extra Monster Zones
!system 1270 Card info
!system 1271 Log
!system 1272 Clear Log
......@@ -426,6 +432,7 @@
!system 1623 Coin landed on:
!system 1624 Die landed on:
!system 1625 Extra Rules
!system 1626 Custom
!system 1999 Show anime cards
!system 2046 Enable sound effects
!system 2047 Enable music
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment