11111
This commit is contained in:
@@ -14,17 +14,30 @@ class NewWorldMapC extends LenheartNewUI_Windows {
|
||||
//是否可见
|
||||
// Visible = false;
|
||||
|
||||
//世界
|
||||
World = null;
|
||||
//区域
|
||||
Region = null;
|
||||
//当前自身所在世界
|
||||
SelfMapWorld = 0;
|
||||
//当前自身所在区域
|
||||
SelfMapRegion = 0;
|
||||
//当前地图浏览区域
|
||||
MapRegion = -1;
|
||||
|
||||
//Img
|
||||
WorldMapImg = null;
|
||||
StepImg = null;
|
||||
|
||||
Ani = null;
|
||||
|
||||
|
||||
Timer = Clock();
|
||||
|
||||
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
|
||||
Childrens = [];
|
||||
Region = [];
|
||||
World = [];
|
||||
//注册控件
|
||||
RegisterWidget();
|
||||
|
||||
@@ -34,32 +47,71 @@ class NewWorldMapC extends LenheartNewUI_Windows {
|
||||
// printT(Region);
|
||||
LoadImg();
|
||||
|
||||
|
||||
}
|
||||
|
||||
function LoadImg() {
|
||||
WorldMapImg = Rindro_Image("worldmap.img");
|
||||
StepImg = {};
|
||||
}
|
||||
|
||||
function InitData() {
|
||||
local RegionLst = R_Utils.GetScriptFileReader("region/region.lst");
|
||||
if (RegionLst) {
|
||||
local IO = Sq_Point2Blob(L_sq_P2I(RegionLst.Buffer.C_Object), RegionLst.Size);
|
||||
local i = 2;
|
||||
while (i< RegionLst.Size) {
|
||||
if ((RegionLst.Size - i) >= 10) {
|
||||
IO.seek(i + 6); //内容指示位
|
||||
local FindKey = IO.readn('i');
|
||||
local Key = Rindro_Script.GetBinString(FindKey);
|
||||
if (Key) {
|
||||
local StrFilePath = "region/" + Key.tolower();
|
||||
InitRegion(StrFilePath);
|
||||
}
|
||||
} else break;
|
||||
i += 10;
|
||||
}
|
||||
InitMiniMap();
|
||||
//读取世界
|
||||
local WorldLst = R_Utils.GetLstArr("region/world.lst", "region/");
|
||||
foreach(Path in WorldLst) {
|
||||
InitWorld(Path);
|
||||
}
|
||||
|
||||
//读取区域
|
||||
local RegionLst = R_Utils.GetLstArr("region/region.lst", "region/");
|
||||
foreach(Path in RegionLst) {
|
||||
InitRegion(Path);
|
||||
}
|
||||
|
||||
//读取小地图
|
||||
InitMiniMap();
|
||||
}
|
||||
|
||||
function InitWorld(Path) {
|
||||
local Data = R_Utils.GetFileTableByHandle(Path, function(DataT, IO, i) {
|
||||
local str = Rindro_Script.UnpackData(IO, i);
|
||||
i += 5;
|
||||
//城镇编号
|
||||
if (str == "[areas]") {
|
||||
DataT.Areas <- [];
|
||||
while (true) {
|
||||
local Ret = Rindro_Script.UnpackData(IO, i);
|
||||
i += 5;
|
||||
if (Ret == "[/areas]") break;
|
||||
DataT.Areas.append((Ret.tointeger() - 9));
|
||||
}
|
||||
}
|
||||
//背景
|
||||
else if (str == "[background]") {
|
||||
DataT.Background <- {};
|
||||
DataT.Background.path <- Rindro_Script.UnpackData(IO, i);
|
||||
i += 5;
|
||||
DataT.Background.frame <- Rindro_Script.UnpackData(IO, i).tointeger() - 9;
|
||||
i += 5;
|
||||
}
|
||||
//坐标
|
||||
else if (str == "[pos]") {
|
||||
local Index = Rindro_Script.UnpackData(IO, i).tointeger() - 9;
|
||||
i += 5;
|
||||
local Path = Rindro_Script.UnpackData(IO, i);
|
||||
i += 5;
|
||||
DataT["pos_" + Index] <- [];
|
||||
DataT["pos_" + Index].append(Path);
|
||||
while (true) {
|
||||
local Ret = Rindro_Script.UnpackData(IO, i);
|
||||
i += 5;
|
||||
if (Ret == "[/pos]") break;
|
||||
DataT["pos_" + Index].append((Ret.tointeger() - 9));
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}.bindenv(this));
|
||||
World.append(Data);
|
||||
printT(Data);
|
||||
}
|
||||
|
||||
function InitRegion(Path) {
|
||||
@@ -123,6 +175,7 @@ class NewWorldMapC extends LenheartNewUI_Windows {
|
||||
local Ret = Rindro_Script.UnpackData(IO, i);
|
||||
i += 5;
|
||||
if (Ret == "[/image]") break;
|
||||
Ret = Ret.slice(1, -1);
|
||||
|
||||
local imgpath = Rindro_Script.UnpackData(IO, i);
|
||||
i += 5;
|
||||
@@ -138,6 +191,7 @@ class NewWorldMapC extends LenheartNewUI_Windows {
|
||||
} else break;
|
||||
}
|
||||
}
|
||||
Region[Pos].Data <- Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,16 +206,18 @@ class NewWorldMapC extends LenheartNewUI_Windows {
|
||||
|
||||
}
|
||||
|
||||
Timer = Clock();
|
||||
|
||||
function GetMoveOffset(L, R) {
|
||||
return (-L) + (L.tofloat() * (R.tofloat() / 100.0)).tointeger()
|
||||
}
|
||||
|
||||
//绘制主界面
|
||||
function DrawMain(obj) {
|
||||
local Config = Region[SelfMapRegion];
|
||||
|
||||
//绘制背景
|
||||
WorldMapImg.DrawExPng(0, 0, -83, 0, 0xffffffff, 0.84, 0.84);
|
||||
//绘制地图背景
|
||||
DrawLogic(Config);
|
||||
|
||||
local UniRate = sq_GetAccel(0, 100, Clock() - Timer, 1000);
|
||||
local AccRate = sq_GetAccel(0, 100, Clock() - Timer, 1000, true);
|
||||
@@ -200,16 +256,128 @@ class NewWorldMapC extends LenheartNewUI_Windows {
|
||||
|
||||
WorldMapImg.DrawExPng(7, 20, 470, 0, sq_RGBA(255, 255, 255, ((UniRate.tofloat() / 100.0) * 255.0).tointeger()), 0.6, 0.6);
|
||||
WorldMapImg.DrawExPng(6, 39 + newRelX, 489 + newRelY, sq_ToRadian(-angle.tofloat()), 0xffffffff, 0.6, 0.6);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function Show(obj) {
|
||||
DrawMain(obj);
|
||||
LenheartNewUI_Windows.Show(obj);
|
||||
}
|
||||
|
||||
function GetImgObject(path) {
|
||||
if (!(StepImg.rawin(path))) StepImg.rawset(path, Rindro_Image(path));
|
||||
return StepImg[path];
|
||||
}
|
||||
|
||||
|
||||
// 环绕数法判断点是否在多边形内
|
||||
function IsPointInPolygonWindingNumber(x, y, polygon) {
|
||||
local windingNumber = 0;
|
||||
local n = polygon.len();
|
||||
for (local i = 0; i< n; ++i) {
|
||||
local x1 = polygon[i][0];
|
||||
local y1 = polygon[i][1];
|
||||
local x2 = polygon[(i + 1) % n][0];
|
||||
local y2 = polygon[(i + 1) % n][1];
|
||||
if (y1 <= y) {
|
||||
if (y2 > y && ((x2 - x1) * (y - y1) - (x - x1) * (y2 - y1) > 0)) {
|
||||
windingNumber++;
|
||||
}
|
||||
} else {
|
||||
if (y2 <= y && ((x2 - x1) * (y - y1) - (x - x1) * (y2 - y1)< 0)) {
|
||||
windingNumber--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return windingNumber != 0;
|
||||
}
|
||||
|
||||
|
||||
//绘制世界
|
||||
function DrawWorld(Config) {
|
||||
local MapCurIndex = SelfMapWorld;
|
||||
local BackgroundData = World[MapCurIndex].Background;
|
||||
|
||||
local UniRate = sq_GetAccel(0, 250, Clock() - Timer, 1500);
|
||||
|
||||
local BackgroundDataImgObj = GetImgObject(BackgroundData.path);
|
||||
BackgroundDataImgObj.DrawExPng(BackgroundData.frame, 0, -60, 0, sq_RGBA(255, 255, 255, UniRate), 1.32, 1.32);
|
||||
|
||||
foreach(index in World[MapCurIndex].Areas) {
|
||||
// print(index);
|
||||
if (!(World[MapCurIndex].rawin("pos_" + index))) continue;
|
||||
local Config = World[MapCurIndex]["pos_" + index];
|
||||
local BackgroundDataImgObj = GetImgObject(Config[0]);
|
||||
local PointArr = [];
|
||||
for (local i = 4; i< Config.len(); i += 2) {
|
||||
local Buf = [];
|
||||
Buf.append(Config[i]);
|
||||
Buf.append(Config[i + 1]);
|
||||
PointArr.append(Buf);
|
||||
}
|
||||
if (IsPointInPolygonWindingNumber(IMouse.GetXPos().tofloat(), IMouse.GetYPos().tofloat(), PointArr)) {
|
||||
BackgroundDataImgObj.DrawExPng(Config[1], Config[2], Config[3] - 60, 0, sq_RGBA(255, 255, 255, UniRate), 1.32, 1.32);
|
||||
}
|
||||
foreach(pos in PointArr) {
|
||||
L_sq_DrawImg("interface/windowcommon.img", 50, pos[0], pos[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//绘制区域
|
||||
function DrawArea(Config) {
|
||||
|
||||
}
|
||||
|
||||
//绘制城镇地图
|
||||
function DrawTownMap(Config) {
|
||||
|
||||
// local UniRate = sq_GetAccel(250, 0, Clock() - 3000 - Timer, 1000);
|
||||
// local BackgroundData = Config.Data.Image.background;
|
||||
// if (!(StepImg.rawin(BackgroundData.path))) StepImg.rawset(BackgroundData.path, Rindro_Image(BackgroundData.path));
|
||||
// StepImg[BackgroundData.path].DrawExPng(BackgroundData.frame, 0, -8, 0, sq_RGBA(255, 255, 255, UniRate), 1.0, 1.055);
|
||||
}
|
||||
|
||||
|
||||
//绘制逻辑
|
||||
function DrawLogic(Config) {
|
||||
//绘制世界
|
||||
DrawWorld(Config);
|
||||
//绘制区域
|
||||
DrawArea(Config);
|
||||
//绘制城镇
|
||||
DrawTownMap(Config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//同步自身现在在哪个地图区域
|
||||
function SyncSelfMapRegion() {
|
||||
local Town = L_sq_GetTownIndex();
|
||||
foreach(AreaIndex, Areaobj in Region) {
|
||||
foreach(TownIndex, Townobj in Areaobj.Towns) {
|
||||
if (TownIndex == Town) {
|
||||
SelfMapRegion = AreaIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//同步自身现在在哪个地图世界
|
||||
function SyncSelfMapWorld() {
|
||||
foreach(WorldIndex, Worldobj in World) {
|
||||
foreach(AreaIndex, Areaobj in Worldobj.Areas) {
|
||||
if (AreaIndex == SelfMapRegion) {
|
||||
SelfMapWorld = WorldIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//逻辑入口
|
||||
function Proc(obj) {
|
||||
SyncSelfMapRegion();
|
||||
SyncSelfMapWorld();
|
||||
LenheartNewUI_Windows.SyncPos(X, Y);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user