Current time: 23.04.2024, 06:50 Hello There, Guest! (LoginRegister)
Language: english | russian  

Post Reply 
Threaded Mode | Linear Mode
Создание скриптов с поддержкой мультиязычности
» SN:T + json
Author Message
igrik Offline
Administrators

Posts: 2814
Post: #60

wessonsm, держи
Code:
#include "stdafx.h"
#include "..\..\include\homm3.h"
#include "..\..\include\era.h"

using namespace Era;

Patcher* _P;
PatcherInstance* _PI;

///////////////////////////////////////////////////////////////////

class Background {
  public:
    int id;
    int x;
    int y;    
    std::string pcxname;
};

class Button {
  public:    
    int id;
    int x;
    int y;    
    int caption_color;
    std::string defname;
    std::string caption_font;
    std::string caption_text;
    std::string popup_text;
    std::string hint_text;
};

class Namb {
  public:
    int qty;
    int align;
    Background *background;
    Button *buttons;

  Namb (int qty, int align) {
    this->qty = qty;
    this->align = align;
    this->background = new Background;
    this->buttons = new Button[qty];
  }

  ~Namb() {
    delete background;
    delete[] buttons;
  }
};

Namb *namb = NULL;

///////////////////////////////////////////////////////////////////

char* GetJsonStr(const char* json_string_name) {
    return tr(json_string_name);
}

int GetJsonInt(const char* json_string_name) {
    return atoi(GetJsonStr(json_string_name));
}

char* GetButtonsParamStr(int i, const char* key) {    
    sprintf(o_TextBuffer, "namb.button%d.%s", i, key);
    return GetJsonStr(o_TextBuffer);
}

int GetButtonsParamInt(int i, const char* key) {
    sprintf(o_TextBuffer, "namb.button%d.%s", i, key);
    return GetJsonInt(o_TextBuffer);
}

///////////////////////////////////////////////////////////////////
    
// функция загрузки параметров из json
int __stdcall ReadJsonConfig()
{    
    int qty = GetJsonInt("namb.qty");
    int align = GetJsonInt("namb.align");

    namb = new Namb(qty, align);

    namb->background->pcxname = GetJsonStr("namb.background.pcxname");
    namb->background->id = GetJsonInt("namb.background.id");
    namb->background->x = GetJsonInt("namb.background.x");
    namb->background->y = GetJsonInt("namb.background.y");

    for(int i = 0; i < qty; i++) {
        namb->buttons[i].id = GetButtonsParamInt(i, "id");
        namb->buttons[i].x = GetButtonsParamInt(i, "x");
        namb->buttons[i].y = GetButtonsParamInt(i, "y");
        namb->buttons[i].caption_color = GetButtonsParamInt(i, "caption_color");

        namb->buttons[i].defname = GetButtonsParamStr(i, "defname");
        namb->buttons[i].caption_font = GetButtonsParamStr(i, "caption_font");
        namb->buttons[i].caption_text = GetButtonsParamStr(i, "caption_text");
        namb->buttons[i].popup_text = GetButtonsParamStr(i, "popup_text");
        namb->buttons[i].hint_text = GetButtonsParamStr(i, "hint_text");
    }

    return 1;
}

///////////////////////////////////////////////////////////////////

_Dlg_* __stdcall hook_AdvMapDlg_Construct(HiHook* hook, _Dlg_* dlg)
{
    int HDResX, HDResY, offsetx, offsety, x, y, id, color;
    char *name, *caption, *font;
    
//    HDResX = *(int*)0x4F81BC;    HDResY = *(int*)0x4F81C3;
    HDResX = o_WndMgr->screen_pcx16->width;
    HDResY = o_WndMgr->screen_pcx16->height;
    switch (namb->align)    {
        case 0:        
            offsetx = 0;
            break;

        case 2:        
            offsetx = HDResX - 800;
            break;

        case 1:        
        default:
            offsetx = (HDResX - 800)/2;
            break;                
    }    
    offsety = HDResY - 600;

    CALL_1(_Dlg_*, __thiscall, hook->GetDefaultFunc(), dlg);

    x = namb->background->x;
    y = namb->background->y;
    id = namb->background->id;
    name = (char*)(namb->background->pcxname.c_str());
    
    dlg->AddItem(_DlgStaticPcx8_::Create(x + offsetx, y + offsety, id, name) );

    for (int i=0; i < namb->qty; i++)    {
        x = namb->buttons[i].x;
        y = namb->buttons[i].y;
        id = namb->buttons[i].id;
        color = namb->buttons[i].caption_color;

        name = (char*)(namb->buttons[i].defname.c_str());
        caption = (char*)(namb->buttons[i].caption_text.c_str());
        font = (char*)(namb->buttons[i].caption_font.c_str());
        
        _DlgTextButton_* bttn = _DlgTextButton_::Create(x + offsetx, y + offsety, id, name, caption, font, 0, 1, 0, 0, color);
            bttn->short_tip_text = (char*)(namb->buttons[i].caption_text.c_str());
            bttn->full_tip_text = (char*)(namb->buttons[i].popup_text.c_str());
        dlg->AddItem(bttn);
    }
    return dlg;    
}



int __stdcall hook_BeforeDrawAgems(HiHook* hook, _AdvMgr_* pAdvManager)
{
    _Dlg_* pDlgAdvMap;
    _DlgItem_* pItem;

    pDlgAdvMap = pAdvManager->dlg;

    pItem = pDlgAdvMap->GetItem(namb->background->id);
    pItem->Draw();

    for (int i = 0; i < namb->qty; i++) {
        pItem = pDlgAdvMap->GetItem(namb->buttons[i].id);
        pItem->Draw();
    }

    return CALL_1(int, __thiscall, hook->GetDefaultFunc(), pAdvManager);
}

_LHF_(LoHook_InitTxtFiles)
{
    ReadJsonConfig();
    return EXEC_DEFAULT;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    static _bool_ plugin_On = 0;

    if ( (ul_reason_for_call==DLL_PROCESS_ATTACH) && (!plugin_On) ) {
        plugin_On = 1;
        _P = GetPatcher();
        _PI = _P->CreateInstance("new_buttons");
        ConnectEra();
        _PI->WriteLoHook(0x4EEAC0, LoHook_InitTxtFiles);
        _PI->WriteHiHook(0x401510, SPLICE_, EXTENDED_, THISCALL_, hook_AdvMapDlg_Construct);
        _PI->WriteHiHook(0x40F250, SPLICE_, EXTENDED_, THISCALL_, hook_BeforeDrawAgems);
    }
    return TRUE;
}


game bug fixes extended.dll || My Plugins || My GitHub
01.03.2023 20:09
Visit this user's website Find all posts by this user Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Messages In This Thread
Создание скриптов с поддержкой мультиязычности - Berserker - 16.02.2020, 22:49
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 01:05
RE: Создание скриптов с поддержкой мультиязычности - Berserker - 22.02.2020, 02:58
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 03:16
RE: Создание скриптов с поддержкой мультиязычности - Algor - 22.02.2020, 03:26
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 03:28
RE: Создание скриптов с поддержкой мультиязычности - Algor - 22.02.2020, 03:30
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 03:33
RE: Создание скриптов с поддержкой мультиязычности - Berserker - 22.02.2020, 03:33
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 03:37
RE: Создание скриптов с поддержкой мультиязычности - Algor - 22.02.2020, 03:40
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 03:43
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 04:06
RE: Создание скриптов с поддержкой мультиязычности - Berserker - 22.02.2020, 04:10
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 04:13
RE: Создание скриптов с поддержкой мультиязычности - Berserker - 22.02.2020, 05:33
RE: Создание скриптов с поддержкой мультиязычности - ElfbI - 22.02.2020, 15:49
RE: Создание скриптов с поддержкой мультиязычности - Bes - 06.11.2020, 00:41
RE: Создание скриптов с поддержкой мультиязычности - Berserker - 06.11.2020, 01:24
RE: Создание скриптов с поддержкой мультиязычности - wessonsm - 25.02.2023, 20:02
RE: Создание скриптов с поддержкой мультиязычности - XEPOMAHT - 26.02.2023, 20:23
RE: Создание скриптов с поддержкой мультиязычности - wessonsm - 26.02.2023, 20:51
RE: Создание скриптов с поддержкой мультиязычности - daemon_n - 26.02.2023, 08:14
RE: Создание скриптов с поддержкой мультиязычности - wessonsm - 26.02.2023, 18:14
RE: Создание скриптов с поддержкой мультиязычности - Berserker - 27.02.2023, 06:25
RE: Создание скриптов с поддержкой мультиязычности - igrik - 27.02.2023, 10:55
RE: Создание скриптов с поддержкой мультиязычности - wessonsm - 28.02.2023, 01:46
RE: Создание скриптов с поддержкой мультиязычности - XEPOMAHT - 28.02.2023, 02:48
RE: Создание скриптов с поддержкой мультиязычности - igrik - 28.02.2023, 03:21
RE: Создание скриптов с поддержкой мультиязычности - wessonsm - 28.02.2023, 04:54
RE: Создание скриптов с поддержкой мультиязычности - igrik - 01.03.2023 20:09
RE: Создание скриптов с поддержкой мультиязычности - wessonsm - 02.03.2023, 06:05
RE: Создание скриптов с поддержкой мультиязычности - wessonsm - 10.03.2023, 02:52
RE: Создание скриптов с поддержкой мультиязычности - Berserker - 10.03.2023, 07:23
RE: ERA Scripts 1.41 Rus, Eng - Algor - 17.02.2020, 01:14
RE: ERA Scripts 1.41 Rus, Eng - Berserker - 17.02.2020, 01:22
RE: Сборка HoMM3 ERA с модами. - Algor - 17.02.2020, 11:18
RE: ERA Scripts 1.41 Rus, Eng - igrik - 17.02.2020, 11:38
RE: ERA Scripts 1.41 Rus, Eng - Algor - 17.02.2020, 19:05
RE: ERA Scripts 1.41 Rus, Eng - Berserker - 17.02.2020, 20:12
RE: Ваши вопросы по ERM-скриптам - ElfbI - 06.09.2020, 02:05
RE: Ваши вопросы по ERM-скриптам - daemon_n - 06.09.2020, 02:11
RE: Ваши вопросы по ERM-скриптам - Bes - 06.09.2020, 02:13
RE: Ваши вопросы по ERM-скриптам - ElfbI - 06.09.2020, 02:16
RE: Advanced Classes Mod - daemon_n - 14.09.2020, 23:58
RE: Advanced Classes Mod - Berserker - 15.09.2020, 00:08
RE: Advanced Classes Mod - daemon_n - 15.09.2020, 01:15
RE: Advanced Classes Mod - Berserker - 15.09.2020, 01:35
RE: Разные вопросы - Elmore - 05.06.2021, 23:21
RE: Разные вопросы - Berserker - 06.06.2021, 00:29
RE: Разные вопросы - Elmore - 06.06.2021, 01:07
RE: Разные вопросы - Berserker - 06.06.2021, 01:57
RE: Разные вопросы - Elmore - 06.06.2021, 02:17
RE: Разные вопросы - Berserker - 06.06.2021, 02:53
RE: Разные вопросы - Elmore - 11.06.2021, 15:11
RE: Разные вопросы - Berserker - 11.06.2021, 16:25
RE: Разные вопросы - Elmore - 11.06.2021, 17:33
RE: Ваши вопросы по ERM-скриптам - Archer30 - 03.04.2022, 13:33
RE: Ваши вопросы по ERM-скриптам - Berserker - 03.04.2022, 17:48
RE: Ваши вопросы по ERM-скриптам - Archer30 - 03.04.2022, 17:51
RE: Ваши вопросы по ERM-скриптам - wessonsm - 03.04.2022, 17:59
RE: Ваши вопросы по ERM-скриптам - Archer30 - 03.04.2022, 22:36
RE: Ваши вопросы по ERM-скриптам - Berserker - 04.04.2022, 06:05

Forum Jump:

Powered by MyBB Copyright © 2002-2024 MyBB Group