Skip to content

Commit

Permalink
Merge branch 'main' into feat-read-assets-from-client-11+
Browse files Browse the repository at this point in the history
  • Loading branch information
majestyotbr authored Aug 16, 2024
2 parents 6bf8fb7 + 7b137f7 commit c208cff
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 81 deletions.
132 changes: 102 additions & 30 deletions source/browse_tile_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ EVT_BUTTON(wxID_FIND, BrowseTileWindow::OnClickSelectRaw)
EVT_BUTTON(wxID_ABOUT, BrowseTileWindow::OnClickProperties)
EVT_BUTTON(wxID_OK, BrowseTileWindow::OnClickOK)
EVT_BUTTON(wxID_CANCEL, BrowseTileWindow::OnClickCancel)
EVT_BUTTON(wxID_UP, BrowseTileWindow::OnButtonUpClick)
EVT_BUTTON(wxID_DOWN, BrowseTileWindow::OnButtonDownClick)
END_EVENT_TABLE()

BrowseTileWindow::BrowseTileWindow(wxWindow* parent, Tile* tile, wxPoint position /* = wxDefaultPosition */) :
Expand All @@ -149,39 +151,17 @@ BrowseTileWindow::BrowseTileWindow(wxWindow* parent, Tile* tile, wxPoint positio
itemList = newd BrowseTileListBox(this, wxID_ANY, tile);
sizer->Add(itemList, wxSizerFlags(1).Expand());

const auto positionString = wxString::Format("x=%i, y=%i, z=%i", tile->getX(), tile->getY(), tile->getZ());

const auto infoSizer = newd wxBoxSizer(wxVERTICAL);

const auto buttons = newd wxBoxSizer(wxHORIZONTAL);

deleteButton = newd wxButton(this, wxID_REMOVE, "Delete");
deleteButton->Enable(false);
buttons->Add(deleteButton);

buttons->AddSpacer(5);

selectRawButton = newd wxButton(this, wxID_FIND, "Select RAW");
selectRawButton->Enable(false);
buttons->Add(selectRawButton);

buttons->AddSpacer(5);

propertiesButton = newd wxButton(this, wxID_ABOUT, "Properties");
propertiesButton->Enable(false);
buttons->Add(propertiesButton);
AddTopOrderButtons(infoSizer);
infoSizer->AddSpacer(5);

infoSizer->Add(buttons);
AddActionButtons(infoSizer);
infoSizer->AddSpacer(5);
infoSizer->Add(newd wxStaticText(this, wxID_ANY, wxString::Format("Position: %s", positionString)), wxSizerFlags(0).Left());
infoSizer->Add(itemCountText = newd wxStaticText(this, wxID_ANY, wxString::Format("Item count: %i", itemList->GetItemCount())), wxSizerFlags(0).Left());
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "Protection zone: " + b2yn(tile->isPZ())), wxSizerFlags(0).Left());
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "No PvP: " + b2yn(tile->getMapFlags() & TILESTATE_NOPVP)), wxSizerFlags(0).Left());
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "No logout: " + b2yn(tile->getMapFlags() & TILESTATE_NOLOGOUT)), wxSizerFlags(0).Left());
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "PvP zone: " + b2yn(tile->getMapFlags() & TILESTATE_PVPZONE)), wxSizerFlags(0).Left());
infoSizer->Add(newd wxStaticText(this, wxID_ANY, "House: " + b2yn(tile->isHouseTile())), wxSizerFlags(0).Left());

sizer->Add(infoSizer, wxSizerFlags(0).Left().DoubleBorder());
AddInformations(infoSizer);

sizer->Add(infoSizer, wxSizerFlags(0).Center().DoubleBorder());

// OK/Cancel buttons
const auto btnSizer = newd wxBoxSizer(wxHORIZONTAL);
Expand All @@ -200,11 +180,75 @@ BrowseTileWindow::~BrowseTileWindow() {
itemList->Unbind(wxEVT_COMMAND_LISTBOX_SELECTED, &BrowseTileWindow::OnItemSelected, this);
}

void BrowseTileWindow::OnItemSelected(wxCommandEvent &WXUNUSED(event)) {
void BrowseTileWindow::AddTopOrderButtons(wxSizer* sizer) {
const auto topOrderButtons = newd wxBoxSizer(wxHORIZONTAL);

upButton = newd wxButton(this, wxID_UP, "Up /\\");
upButton->Enable(false);
topOrderButtons->Add(upButton);

topOrderButtons->AddSpacer(5);

downButton = newd wxButton(this, wxID_DOWN, "Down \\/");
downButton->Enable(false);
topOrderButtons->Add(downButton);

sizer->Add(topOrderButtons, wxSizerFlags(0).Center());
}

void BrowseTileWindow::AddActionButtons(wxSizer* sizer) {
const auto actionButtons = newd wxBoxSizer(wxHORIZONTAL);

deleteButton = newd wxButton(this, wxID_REMOVE, "Delete");
deleteButton->Enable(false);
actionButtons->Add(deleteButton);

actionButtons->AddSpacer(5);

selectRawButton = newd wxButton(this, wxID_FIND, "Select RAW");
selectRawButton->Enable(false);
actionButtons->Add(selectRawButton);

actionButtons->AddSpacer(5);

propertiesButton = newd wxButton(this, wxID_ABOUT, "Properties");
propertiesButton->Enable(false);

actionButtons->Add(propertiesButton);

sizer->Add(actionButtons);
}

void BrowseTileWindow::AddInformations(wxSizer* sizer) {
const auto tile = itemList->GetTile();
const auto positionString = wxString::Format("x=%i, y=%i, z=%i", tile->getX(), tile->getY(), tile->getZ());

sizer->Add(newd wxStaticText(this, wxID_ANY, wxString::Format("Position: %s", positionString)), wxSizerFlags(0).Left());
sizer->Add(itemCountText = newd wxStaticText(this, wxID_ANY, wxString::Format("Item count: %i", itemList->GetItemCount())), wxSizerFlags(0).Left());
sizer->Add(newd wxStaticText(this, wxID_ANY, wxString::Format("Protection zone: %s", b2yn(tile->isPZ()))), wxSizerFlags(0).Left());
sizer->Add(newd wxStaticText(this, wxID_ANY, wxString::Format("No PvP: %s", b2yn(tile->getMapFlags() & TILESTATE_NOPVP))), wxSizerFlags(0).Left());
sizer->Add(newd wxStaticText(this, wxID_ANY, wxString::Format("No logout: %s", b2yn(tile->getMapFlags() & TILESTATE_NOLOGOUT))), wxSizerFlags(0).Left());
sizer->Add(newd wxStaticText(this, wxID_ANY, wxString::Format("PvP zone: %s", b2yn(tile->getMapFlags() & TILESTATE_PVPZONE))), wxSizerFlags(0).Left());
sizer->Add(newd wxStaticText(this, wxID_ANY, wxString::Format("House: %s", b2yn(tile->isHouseTile()))), wxSizerFlags(0).Left());
}

void BrowseTileWindow::UpdateButtons(int selection) {
const auto count = itemList->GetSelectedCount();
const auto tile = itemList->GetTile();
const auto itemsAmount = itemList->GetItemCount();
const auto items = itemList->GetItems();
const auto nextItemIsGround = itemsAmount - 1 == selection ? false : items.at(selection + 1) == tile->ground;

deleteButton->Enable(count != 0);
selectRawButton->Enable(count == 1);
propertiesButton->Enable(count != 0);
propertiesButton->Enable(count == 1);
upButton->Enable(count == 1 && selection != 0 && items.at(selection) != tile->ground);
downButton->Enable(count == 1 && selection != itemsAmount - 1 && !nextItemIsGround);
}

void BrowseTileWindow::OnItemSelected(wxCommandEvent &evt) {
UpdateButtons(evt.GetSelection());
const auto count = itemList->GetSelectedCount();
}

void BrowseTileWindow::OnClickDelete(wxCommandEvent &WXUNUSED(event)) {
Expand Down Expand Up @@ -237,3 +281,31 @@ void BrowseTileWindow::OnClickOK(wxCommandEvent &WXUNUSED(event)) {
void BrowseTileWindow::OnClickCancel(wxCommandEvent &WXUNUSED(event)) {
EndModal(0);
}

void BrowseTileWindow::ChangeItemIndex(bool up /* = true*/) {
const auto i = up ? 1 : -1;
const auto tile = itemList->GetTile();

const auto selectedItemIndex = itemList->GetSelection();
const auto tileItemsSize = tile->items.size() - 1;
auto index = tileItemsSize - selectedItemIndex;

const auto tmpItem = tile->items[index];
tile->items[index] = tile->items[index + i];
tile->items[index + i] = tmpItem;

itemList->UpdateItems();

itemList->DeselectAll();
itemList->SetSelection(selectedItemIndex - i);
UpdateButtons(selectedItemIndex - i);
Refresh();
}

void BrowseTileWindow::OnButtonUpClick(wxCommandEvent &evt) {
ChangeItemIndex();
}

void BrowseTileWindow::OnButtonDownClick(wxCommandEvent &evt) {
ChangeItemIndex(false);
}
25 changes: 23 additions & 2 deletions source/browse_tile_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "map.h"
#include "tile.h"

using ItemsMap = std::map<int, Item*>;

class BrowseTileListBox : public wxVListBox {
public:
BrowseTileListBox(wxWindow* parent, wxWindowID id, Tile* tile);
Expand All @@ -33,12 +35,19 @@ class BrowseTileListBox : public wxVListBox {
void RemoveSelected();
void OnItemDoubleClick(wxCommandEvent &);

Tile* GetTile() const noexcept {
return editTile;
}

ItemsMap GetItems() const noexcept {
return items;
}

void OpenPropertiesWindow(int index);

protected:
void UpdateItems();

using ItemsMap = std::map<int, Item*>;
protected:
ItemsMap items;
Tile* editTile = nullptr;

Expand All @@ -56,13 +65,25 @@ class BrowseTileWindow : public wxDialog {
void OnClickProperties(wxCommandEvent &);
void OnClickOK(wxCommandEvent &);
void OnClickCancel(wxCommandEvent &);
void OnButtonUpClick(wxCommandEvent &);
void OnButtonDownClick(wxCommandEvent &);

void ChangeItemIndex(bool up = true);
void UpdateButtons(int selection);

protected:
void AddTopOrderButtons(wxSizer* sizer);
void AddActionButtons(wxSizer* sizer);
void AddInformations(wxSizer* sizer);

friend class BrowseTileListBox;
BrowseTileListBox* itemList = nullptr;
wxStaticText* itemCountText = nullptr;
wxButton* deleteButton = nullptr;
wxButton* selectRawButton = nullptr;
wxButton* propertiesButton = nullptr;
wxButton* upButton = nullptr;
wxButton* downButton = nullptr;

DECLARE_EVENT_TABLE();
};
Expand Down
95 changes: 50 additions & 45 deletions source/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ uint8_t Item::liquidSubTypeToSpriteSubType(uint8_t id) {
return 8;
case LIQUID_CHOCOLATE:
return 9;
case LIQUID_UNKNOWN:
case LIQUID_CANDY:
return 10;
default:
return 0;
Expand All @@ -449,40 +449,42 @@ std::string Item::LiquidID2Name(uint8_t id) {
return "None";
case LIQUID_WATER:
return "Water";
case LIQUID_BLOOD:
return "Blood";
case LIQUID_WINE:
return "Wine";
case LIQUID_BEER:
return "Beer";
case LIQUID_MUD:
return "Mud";
case LIQUID_BLOOD:
return "Blood";
case LIQUID_SLIME:
return "Slime";
case LIQUID_LEMONADE:
return "Lemonade";
case LIQUID_OIL:
return "Oil";
case LIQUID_URINE:
return "Urine";
case LIQUID_MILK:
return "Milk";
case LIQUID_MANAFLUID:
return "Manafluid";
case LIQUID_LIFEFLUID:
return "Lifefluid";
case LIQUID_OIL:
return "Oil";
case LIQUID_URINE:
return "Urine";
case LIQUID_COCONUT_MILK:
return "Coconut Milk";
case LIQUID_WINE:
return "Wine";
case LIQUID_MUD:
return "Mud";
case LIQUID_FRUIT_JUICE:
return "Fruit Juice";
case LIQUID_LEMONADE:
return "Lemonade";
case LIQUID_RUM:
return "Rum";
case LIQUID_INK:
return "Ink";
case LIQUID_TEA:
return "Tea";
case LIQUID_FRUIT_JUICE:
return "Fruit Juice";
case LIQUID_COCONUT_MILK:
return "Coconut Milk";
case LIQUID_MEAD:
return "Mead";
case LIQUID_TEA:
return "Tea";
case LIQUID_INK:
return "Ink";
case LIQUID_CANDY:
return "Candyfluid";
case LIQUID_CHOCOLATE:
return "Chocolate";
default:
Expand All @@ -498,17 +500,26 @@ uint8_t Item::LiquidName2ID(std::string liquid) {
if (liquid == "water") {
return LIQUID_WATER;
}
if (liquid == "blood") {
return LIQUID_BLOOD;
if (liquid == "wine") {
return LIQUID_WINE;
}
if (liquid == "beer") {
return LIQUID_BEER;
}
if (liquid == "mud") {
return LIQUID_MUD;
}
if (liquid == "blood") {
return LIQUID_BLOOD;
}
if (liquid == "slime") {
return LIQUID_SLIME;
}
if (liquid == "lemonade") {
return LIQUID_LEMONADE;
if (liquid == "oil") {
return LIQUID_OIL;
}
if (liquid == "urine") {
return LIQUID_URINE;
}
if (liquid == "milk") {
return LIQUID_MILK;
Expand All @@ -519,40 +530,34 @@ uint8_t Item::LiquidName2ID(std::string liquid) {
if (liquid == "lifefluid") {
return LIQUID_LIFEFLUID;
}
if (liquid == "oil") {
return LIQUID_OIL;
}
if (liquid == "urine") {
return LIQUID_URINE;
}
if (liquid == "coconut milk") {
return LIQUID_COCONUT_MILK;
}
if (liquid == "wine") {
return LIQUID_WINE;
if (liquid == "lemonade") {
return LIQUID_LEMONADE;
}
if (liquid == "mud") {
return LIQUID_MUD;
if (liquid == "rum") {
return LIQUID_RUM;
}
if (liquid == "fruit juice") {
return LIQUID_FRUIT_JUICE;
}
if (liquid == "rum") {
return LIQUID_RUM;
if (liquid == "coconut milk") {
return LIQUID_COCONUT_MILK;
}
if (liquid == "ink") {
return LIQUID_INK;
if (liquid == "mead") {
return LIQUID_MEAD;
}
if (liquid == "tea") {
return LIQUID_TEA;
}
if (liquid == "mead") {
return LIQUID_MEAD;
if (liquid == "ink") {
return LIQUID_INK;
}
if (liquid == "candyfluid") {
return LIQUID_CANDY;
}
if (liquid == "chocolate") {
return LIQUID_CHOCOLATE;
}
return LIQUID_UNKNOWN;
return LIQUID_NONE;
}

// ============================================================================
Expand Down
2 changes: 1 addition & 1 deletion source/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum SplashType : uint8_t {
LIQUID_MEAD = 16,
LIQUID_TEA = 17,
LIQUID_INK = 18,
LIQUID_UNKNOWN = 19,
LIQUID_CANDY = 19,
LIQUID_CHOCOLATE = 20,

LIQUID_FIRST = LIQUID_WATER,
Expand Down
Loading

0 comments on commit c208cff

Please sign in to comment.