object selector can select vehicles and structures, proposed rank system

Tobias Zwick 2009-12-04 15:49:11 +01:00
parent 025bd264b0
commit 0c6eaa796a
7 changed files with 305 additions and 108 deletions

View File

@ -90,46 +90,86 @@ public func OnCrewEnabled(object clonk)
}
// call from HUDAdapter (Clonk)
public func OnCrewSelection(object obj, bool deselect)
public func OnCrewSelection(object clonk, bool deselect)
{
// selected
if(!deselect)
{
// if several clonks were selected:
// only the cursor is of interest
var cursor = GetCursor(GetOwner());
//Log("cursor: %s",cursor->GetName());
//if(obj != cursor) return;
// TODO: what if two clonks are selected? Which clonk gets the actionbar?
// fill actionbar
var max = 10;
// inventory
var i;
for(i = 0; i < obj->MaxContentsCount(); ++i)
for(i = 0; i < clonk->MaxContentsCount(); ++i)
{
ActionButton(obj,i);
actionbar[i]->SetObject(obj->GetItem(i),ACTIONTYPE_INVENTORY,i);
actionbar[i]->UpdateSelectionStatus();
}
// make rest invisible
for(; i < GetLength(actionbar); ++i)
{
// we don't have to remove them all the time, no?
if(actionbar[i])
actionbar[i]["Visibility"] = VIS_None;
}
ActionButton(clonk,i,clonk->GetItem(i),ACTIONTYPE_INVENTORY);
}
ClearButtons(i);
// and start effect to monitor vehicles and structures...
// TODO
AddEffect("IntSearchInteractionObjects",clonk,1,10,this,nil,i,max);
}
else
{
// TODO
// remove effect
RemoveEffect("IntSearchInteractionObjects",clonk,0);
ClearButtons();
}
}
public func FxIntSearchInteractionObjectsStart(object target, int num, int temp, startAt, max)
{
if(temp != 0) return;
EffectVar(0,target,num) = startAt;
EffectVar(1,target,num) = max;
EffectCall(target,num,"Timer",target,num,0);
}
public func FxIntSearchInteractionObjectsTimer(object target, int num, int time)
{
// find vehicles & structures
var startAt = EffectVar(0,target,num);
var i = startAt;
var max = EffectVar(1,target,num);
// target->FindObjects(Find_AtPoint(0,0),Find_OCF(OCF_Grab),Find_NoContainer());
// doesnt work!! -> BUG!
var vehicles = FindObjects(Find_AtPoint(target->GetX()-GetX(),target->GetY()-GetY()),Find_OCF(OCF_Grab),Find_NoContainer());
// don't forget the vehicle that the clonk is pushing (might not be found
// by the findobjects because it is not at that point)
var pushed = nil;
if(target->GetProcedure() == "PUSH" && (pushed = target->GetActionTarget()))
{
ActionButton(target,i++,pushed,ACTIONTYPE_VEHICLE);
if(max) if(i >= max) return ClearButtons(i);
}
for(var vehicle in vehicles)
{
// ...and exclude the pushed one here...
if(vehicle == pushed) continue;
ActionButton(target,i++,vehicle,ACTIONTYPE_VEHICLE);
if(max) if(i >= max) return ClearButtons(i);
}
var structures = FindObjects(Find_AtPoint(target->GetX()-GetX(),target->GetY()-GetY()),Find_OCF(OCF_Entrance),Find_NoContainer());
for(var structure in structures)
{
ActionButton(target,i++,structure,ACTIONTYPE_STRUCTURE);
if(max) if(i >= max) return ClearButtons(i);
}
//Message("found %d vehicles and %d structures",target,GetLength(vehicles),GetLength(structures));
return ClearButtons(i);
}
// call from HUDAdapter (Clonk)
public func OnSelectionChanged(int old, int new)
{
@ -147,30 +187,41 @@ public func OnSlotObjectChanged(int slot)
actionbar[slot]->SetObject(obj, ACTIONTYPE_INVENTORY, slot);
}
private func ActionButton(object forClonk, int i)
private func ActionButton(object forClonk, int pos, object interaction, int actiontype)
{
var size = ACBT->GetDefWidth();
var spacing = 12 + size;
// don't forget the spacings between inventory - vehicle,structure
var extra = 0;
if(forClonk->MaxContentsCount() <= i) extra = 80;
if(forClonk->MaxContentsCount() <= pos) extra = 80;
var bt = actionbar[i];
var bt = actionbar[pos];
// no object yet... create it
if(!bt)
{
bt = CreateObject(ACBT,0,0,GetOwner());
}
bt->SetPosition(64 + i * spacing + extra, -16 - size/2);
if(i+1 == 10) bt->SetHotkey(0);
else if(i+1 < 10) bt->SetHotkey(i+1);
bt->SetPosition(64 + pos * spacing + extra, -16 - size/2);
bt->SetCrew(forClonk);
bt->SetObject(interaction,actiontype,pos);
actionbar[i] = bt;
actionbar[pos] = bt;
return bt;
}
private func ClearButtons(int start)
{
// make rest invisible
for(var j = start; j < GetLength(actionbar); ++j)
{
// we don't have to remove them all the time, no?
if(actionbar[j])
actionbar[j]->Clear();
}
}
private func CreateSelectorFor(object clonk)

View File

@ -161,22 +161,22 @@ public func UpdateRank()
{
if(!crew) return;
// different rank symbols for different clonks possible
var idRank = crew->~RanksID();
if(!idRank) idRank = RANK;
var rank = crew->GetRank();
var nrank = rank % 25;
var brank = rank / 25;
var nrank = rank % DefinitionCall(idRank,"RegularRankCount");
var brank = rank / DefinitionCall(idRank,"RegularRankCount");
var rankx = -1000 * GetDefWidth()/2 + 10000;
var ranky = -15000;
// different rank symbols for different clonks possible
var idRank = crew->~RankSymbolsID();
if(!idRank) idRank = RANK;
SetGraphics(nil,idRank,10,GFXOV_MODE_Action,Format("Rank%d",nrank));
SetObjDrawTransform(1000,0,rankx,0,1000,ranky, 10);
// extra rank (the star if the clonk is too experienced for normal ranks)
if(brank > 0)
if(brank % DefinitionCall(idRank,"ExtraRankCount"))
{
SetGraphics(nil,RANK,11,GFXOV_MODE_Action,Format("RankExtra%d",brank));
SetObjDrawTransform(1000,0,rankx-6000,0,1000,ranky-4000, 11);
@ -185,6 +185,7 @@ public func UpdateRank()
{
SetGraphics(nil,nil,11);
}
}
public func UpdateTitleGraphic()
@ -281,7 +282,7 @@ public func UpdateMagicBar(bool nocall)
private func UpdateName()
{
CustomMessage(Format("@%s",crew->GetName()), this, crew->GetOwner(), 0, 64, nil, nil, nil, MSG_Multiple);
CustomMessage(Format("@%s",crew->GetName()), this, crew->GetOwner(), 0, 65, nil, nil, nil, MSG_Multiple);
cleared = false;
}

View File

@ -22,13 +22,13 @@
-----------------
layer 0 - unused
layer 1 - title
layer 2 - select-marker
layer 2 - actionicon
layer 12 - hotkey
*/
local isSelected, crew, hotkey, myobject, inventory_pos, actiontype;
local isSelected, crew, hotkey, myobject, actiontype;
static const ACTIONTYPE_INVENTORY = 0;
static const ACTIONTYPE_VEHICLE = 1;
@ -39,7 +39,7 @@ protected func Construction()
_inherited();
isSelected = false;
hotkey = false;
hotkey = 0;
myobject = nil;
// parallaxity
@ -58,7 +58,7 @@ public func MouseSelection(int plr)
// object is in inventory
if(actiontype == ACTIONTYPE_INVENTORY)
{
crew->SelectItem(inventory_pos);
crew->SelectItem(hotkey-1);
return true;
}
@ -103,18 +103,33 @@ public func MouseSelection(int plr)
// TODO: more script choices... Selection-Callbacks for all objects
}
public func SetObject(object obj, int type, int inv_pos)
public func Clear()
{
myobject = nil;
actiontype = -1;
hotkey = 0;
this["Visibility"] = VIS_None;
}
public func SetObject(object obj, int type, int pos)
{
if(obj == myobject)
if(type == actiontype)
if(pos+1 == hotkey)
return;
this["Visibility"] = VIS_Owner;
actiontype = type;
myobject = obj;
inventory_pos = inv_pos;
hotkey = pos+1;
RemoveEffect("IntRemoveGuard",myobject);
if(!myobject)
{
SetGraphics(nil,nil,1);
SetName(Format("$LabelSlot$ %d",inventory_pos));
SetName(Format("$LabelSlot$ %d",hotkey-1));
}
else
{
@ -131,41 +146,48 @@ public func SetObject(object obj, int type, int inv_pos)
// create an effect which monitors whether the object is removed
AddEffect("IntRemoveGuard",myobject,1,0,this);
}
ShowHotkey();
UpdateSelectionStatus();
}
public func FxIntRemoveGuardStop(object target, int num, int reason, bool temp)
{
if(reason == 3)
if(target == myobject)
SetObject(nil,0,inventory_pos);
SetObject(nil,0,hotkey-1);
}
public func SetCrew(object c)
{
if(crew == c) return;
crew = c;
SetOwner(c->GetOwner());
this["Visibility"] = VIS_Owner;
}
public func SetHotkey(int num)
public func ShowHotkey()
{
if(num < 0 || num > 9)
if(hotkey > 10 || hotkey <= 0)
{
SetGraphics(nil,nil,12);
hotkey = false;
return;
}
hotkey = true;
var name = Format("%d",num);
SetGraphics(name,NUMB,12,GFXOV_MODE_IngamePicture);
SetObjDrawTransform(300,0,16000,0,300,-30000, 12);
SetClrModulation(RGB(160,0,0),12);
else
{
var num = hotkey;
if(hotkey == 10) num = 0;
var name = Format("%d",num);
SetGraphics(name,NUMB,12,GFXOV_MODE_IngamePicture);
SetObjDrawTransform(300,0,16000,0,300,-30000, 12);
SetClrModulation(RGB(160,0,0),12);
}
}
public func UpdateSelectionStatus()
{
// determine...
isSelected = false;
@ -178,19 +200,34 @@ public func UpdateSelectionStatus()
isSelected = true;
if(actiontype == ACTIONTYPE_INVENTORY)
if(crew->GetSelected() == inventory_pos)
if(crew->GetSelected() == hotkey-1)
isSelected = true;
if(!hotkey) return;
// and set the icon...
if(isSelected)
{
SetClrModulation(RGB(220,0,0),12);
SetObjDrawTransform(500,0,16000,0,500,-30000, 12);
if(actiontype == ACTIONTYPE_VEHICLE)
SetGraphics("LetGo",GetID(),2,GFXOV_MODE_Base);
if(actiontype == ACTIONTYPE_STRUCTURE)
SetGraphics("Exit",GetID(),2,GFXOV_MODE_Base);
}
else
{
SetClrModulation(RGB(160,0,0),12);
SetObjDrawTransform(300,0,16000,0,300,-30000, 12);
SetObjDrawTransform(300,0,16000,0,300,-30000, 12);
if(actiontype == ACTIONTYPE_VEHICLE)
SetGraphics("Grab",GetID(),2,GFXOV_MODE_Base);
if(actiontype == ACTIONTYPE_STRUCTURE)
SetGraphics("Enter",GetID(),2,GFXOV_MODE_Base);
}
SetObjDrawTransform(600,0,-16000,0,600,16000, 2);
}

View File

@ -1,37 +1,105 @@
#strict 2
/*
Standard rank definition
Author: Newton
This is a ressource object in which the rank graphics and the rank names
are stored. Any (crew) object can freely define which rank graphics it
wants to use by defining the function func RanksID() { return [myrankid] }.
Any other ranks definition should include this object
*/
global func GetRankName(int rank)
{
var idRank;
// extra rank definition
if(this)
idRank = this->~RanksID();
if(!idRank)
idRank = RANK;
return DefinitionCall(idRank,"RankName",rank);
}
public func RankName(int rank, int extra)
{
if(rank < 0) return nil;
var rrank = rank % RegularRankCount();
var erank = (rank / RegularRankCount() % ExtraRankCount());
// here you see the limits of C4Script
// r=Format("$Rank%d",rrank); is not possible
var r,e;
if(rrank==0) r="$Rank0$";
else if(rrank==1) r="$Rank1$";
else if(rrank==2) r="$Rank2$";
else if(rrank==3) r="$Rank3$";
else if(rrank==4) r="$Rank4$";
else if(rrank==5) r="$Rank5$";
else if(rrank==6) r="$Rank6$";
else if(rrank==7) r="$Rank7$";
else if(rrank==8) r="$Rank8$";
else if(rrank==9) r="$Rank9$";
else if(rrank==10) r="$Rank10$";
else if(rrank==11) r="$Rank11$";
else if(rrank==12) r="$Rank12$";
else if(rrank==13) r="$Rank13$";
else if(rrank==14) r="$Rank14$";
else if(rrank==15) r="$Rank15$";
else if(rrank==16) r="$Rank16$";
else if(rrank==17) r="$Rank17$";
else if(rrank==18) r="$Rank18$";
else if(rrank==19) r="$Rank19$";
else if(rrank==20) r="$Rank20$";
else if(rrank==21) r="$Rank21$";
else if(rrank==22) r="$Rank22$";
else if(rrank==23) r="$Rank23$";
else if(rrank==24) r="$Rank24$";
if(erank==1) e = Format("$RankExtra1$",r);
else if(erank==2) e = Format("$RankExtra2$",r);
else if(erank==3) e = Format("$RankExtra3$",r);
else if(erank==4) e = Format("$RankExtra4$",r);
if(erank) return e;
else return r;
}
public func RegularRankCount() { return 25; }
public func ExtraRankCount() { return 4; }
func Definition(def) {
def["ActMap"] = {
def["ActMap"] = {
Rank0 = { Prototype = Action, Name = "Rank0", X = 0, Y = 0, Wdt = 16, Hgt = 16 },
Rank1 = { Prototype = Action, Name = "Rank1", X = 16, Y = 0, Wdt = 16, Hgt = 16 },
Rank2 = { Prototype = Action, Name = "Rank2", X = 32, Y = 0, Wdt = 16, Hgt = 16 },
Rank3 = { Prototype = Action, Name = "Rank3", X = 48, Y = 0, Wdt = 16, Hgt = 16 },
Rank4 = { Prototype = Action, Name = "Rank4", X = 64, Y = 0, Wdt = 16, Hgt = 16 },
Rank5 = { Prototype = Action, Name = "Rank5", X = 80, Y = 0, Wdt = 16, Hgt = 16 },
Rank6 = { Prototype = Action, Name = "Rank6", X = 96, Y = 0, Wdt = 16, Hgt = 16 },
Rank7 = { Prototype = Action, Name = "Rank7", X = 112, Y = 0, Wdt = 16, Hgt = 16 },
Rank8 = { Prototype = Action, Name = "Rank8", X = 128, Y = 0, Wdt = 16, Hgt = 16 },
Rank9 = { Prototype = Action, Name = "Rank9", X = 144, Y = 0, Wdt = 16, Hgt = 16 },
Rank10 = { Prototype = Action, Name = "Rank10", X = 160, Y = 0, Wdt = 16, Hgt = 16 },
Rank11 = { Prototype = Action, Name = "Rank11", X = 176, Y = 0, Wdt = 16, Hgt = 16 },
Rank12 = { Prototype = Action, Name = "Rank12", X = 192, Y = 0, Wdt = 16, Hgt = 16 },
Rank13 = { Prototype = Action, Name = "Rank13", X = 208, Y = 0, Wdt = 16, Hgt = 16 },
Rank14 = { Prototype = Action, Name = "Rank14", X = 224, Y = 0, Wdt = 16, Hgt = 16 },
Rank15 = { Prototype = Action, Name = "Rank15", X = 240, Y = 0, Wdt = 16, Hgt = 16 },
Rank16 = { Prototype = Action, Name = "Rank16", X = 256, Y = 0, Wdt = 16, Hgt = 16 },
Rank17 = { Prototype = Action, Name = "Rank17", X = 272, Y = 0, Wdt = 16, Hgt = 16 },
Rank18 = { Prototype = Action, Name = "Rank18", X = 288, Y = 0, Wdt = 16, Hgt = 16 },
Rank19 = { Prototype = Action, Name = "Rank19", X = 304, Y = 0, Wdt = 16, Hgt = 16 },
Rank20 = { Prototype = Action, Name = "Rank20", X = 320, Y = 0, Wdt = 16, Hgt = 16 },
Rank21 = { Prototype = Action, Name = "Rank21", X = 336, Y = 0, Wdt = 16, Hgt = 16 },
Rank22 = { Prototype = Action, Name = "Rank22", X = 352, Y = 0, Wdt = 16, Hgt = 16 },
Rank23 = { Prototype = Action, Name = "Rank23", X = 368, Y = 0, Wdt = 16, Hgt = 16 },
Rank24 = { Prototype = Action, Name = "Rank24", X = 384, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra1 = { Prototype = Action, Name = "RankExtra1", X = 400, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra2 = { Prototype = Action, Name = "RankExtra2", X = 416, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra3 = { Prototype = Action, Name = "RankExtra3", X = 432, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra4 = { Prototype = Action, Name = "RankExtra4", X = 448, Y = 0, Wdt = 16, Hgt = 16 }
Rank0 = { Prototype = Action, Name = "Rank0", X = 0, Y = 0, Wdt = 16, Hgt = 16 },
Rank1 = { Prototype = Action, Name = "Rank1", X = 16, Y = 0, Wdt = 16, Hgt = 16 },
Rank2 = { Prototype = Action, Name = "Rank2", X = 32, Y = 0, Wdt = 16, Hgt = 16 },
Rank3 = { Prototype = Action, Name = "Rank3", X = 48, Y = 0, Wdt = 16, Hgt = 16 },
Rank4 = { Prototype = Action, Name = "Rank4", X = 64, Y = 0, Wdt = 16, Hgt = 16 },
Rank5 = { Prototype = Action, Name = "Rank5", X = 80, Y = 0, Wdt = 16, Hgt = 16 },
Rank6 = { Prototype = Action, Name = "Rank6", X = 96, Y = 0, Wdt = 16, Hgt = 16 },
Rank7 = { Prototype = Action, Name = "Rank7", X = 112, Y = 0, Wdt = 16, Hgt = 16 },
Rank8 = { Prototype = Action, Name = "Rank8", X = 128, Y = 0, Wdt = 16, Hgt = 16 },
Rank9 = { Prototype = Action, Name = "Rank9", X = 144, Y = 0, Wdt = 16, Hgt = 16 },
Rank10 = { Prototype = Action, Name = "Rank10", X = 160, Y = 0, Wdt = 16, Hgt = 16 },
Rank11 = { Prototype = Action, Name = "Rank11", X = 176, Y = 0, Wdt = 16, Hgt = 16 },
Rank12 = { Prototype = Action, Name = "Rank12", X = 192, Y = 0, Wdt = 16, Hgt = 16 },
Rank13 = { Prototype = Action, Name = "Rank13", X = 208, Y = 0, Wdt = 16, Hgt = 16 },
Rank14 = { Prototype = Action, Name = "Rank14", X = 224, Y = 0, Wdt = 16, Hgt = 16 },
Rank15 = { Prototype = Action, Name = "Rank15", X = 240, Y = 0, Wdt = 16, Hgt = 16 },
Rank16 = { Prototype = Action, Name = "Rank16", X = 256, Y = 0, Wdt = 16, Hgt = 16 },
Rank17 = { Prototype = Action, Name = "Rank17", X = 272, Y = 0, Wdt = 16, Hgt = 16 },
Rank18 = { Prototype = Action, Name = "Rank18", X = 288, Y = 0, Wdt = 16, Hgt = 16 },
Rank19 = { Prototype = Action, Name = "Rank19", X = 304, Y = 0, Wdt = 16, Hgt = 16 },
Rank20 = { Prototype = Action, Name = "Rank20", X = 320, Y = 0, Wdt = 16, Hgt = 16 },
Rank21 = { Prototype = Action, Name = "Rank21", X = 336, Y = 0, Wdt = 16, Hgt = 16 },
Rank22 = { Prototype = Action, Name = "Rank22", X = 352, Y = 0, Wdt = 16, Hgt = 16 },
Rank23 = { Prototype = Action, Name = "Rank23", X = 368, Y = 0, Wdt = 16, Hgt = 16 },
Rank24 = { Prototype = Action, Name = "Rank24", X = 384, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra1 = { Prototype = Action, Name = "RankExtra1", X = 400, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra2 = { Prototype = Action, Name = "RankExtra2", X = 416, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra3 = { Prototype = Action, Name = "RankExtra3", X = 432, Y = 0, Wdt = 16, Hgt = 16 },
RankExtra4 = { Prototype = Action, Name = "RankExtra4", X = 448, Y = 0, Wdt = 16, Hgt = 16 }
};
};
}

View File

@ -0,0 +1,29 @@
Rank0=Clonk
Rank1=Fähnrich
Rank2=Leutnant
Rank3=Hauptmann
Rank4=Major
Rank5=Oberst
Rank6=Brigadegeneral
Rank7=Generalmajor
Rank8=Generalleutnant
Rank9=General
Rank10=Feldmarschall
Rank11=Kadett
Rank12=Fregattenkapitän
Rank13=Kapitän
Rank14=Konteradmiral
Rank15=Vizeadmiral
Rank16=Admiral
Rank17=Großadmiral
Rank18=Staatsrat
Rank19=Staatssekretär
Rank20=Kanzler
Rank21=Vizepräsident
Rank22=Präsident
Rank23=Ministerpräsident
Rank24=Konsul
RankExtra1=%s Erster Klasse
RankExtra2=%s Zweiten Grades
RankExtra3=%s ohne Gleichen
RankExtra4=Erhabener %s

View File

@ -0,0 +1,29 @@
Rank0=Clonk
Rank1=Ensign
Rank2=Lieutenant
Rank3=Captain
Rank4=Major
Rank5=Lieutenant Colonel
Rank6=Colonel
Rank7=Brigade General
Rank8=Major General
Rank9=Lieutenant General
Rank10=General
Rank11=Midshipman
Rank12=Commander
Rank13=Commodore
Rank14=Rear-Admiral
Rank15=Vice-Admiral
Rank16=Admiral
Rank17=Fleet Admiral
Rank18=Counsellor of State
Rank19=Secretary of State
Rank20=Chancellor
Rank21=Vice President
Rank22=President
Rank23=Premier
Rank24=Konsul
RankExtra1=%s First Class
RankExtra2=%s Second Degree
RankExtra3=%s Without Equal
RankExtra4=Exalted %s

View File

@ -938,24 +938,6 @@ void C4Viewport::DrawCursorInfo(C4TargetFacet &cgo)
cursor );
C4ST_STOP(ObjInfStat)
}
C4ST_STARTNEW(ContStat, "C4Viewport::DrawCursorInfo: Contents")
// Draw contents
if (cursor->Contents.ObjectCount()==1)
{
// Single object
ccgo.Set(cgo.Surface,cgo.X+C4SymbolBorder,cgo.Y+cgo.Hgt-C4SymbolBorder-C4SymbolSize,C4SymbolSize,C4SymbolSize);
cursor->Contents.GetObject()->DrawPicture(ccgo,false,SetRegions);
}
else
{
// Object list
ccgo.Set(cgo.Surface,cgo.X+C4SymbolBorder,cgo.Y+cgo.Hgt-C4SymbolBorder-C4SymbolSize,7*C4SymbolSize,C4SymbolSize);
cursor->Contents.DrawIDList(ccgo,-1,::Definitions,C4D_All,SetRegions,COM_Contents,false);
}
C4ST_STOP(ContStat)
}
void C4Viewport::DrawMenu(C4TargetFacet &cgo)